Skip to content

Add documentation to handle (physical) units of recording channels#3844

Merged
alejoe91 merged 27 commits into
SpikeInterface:mainfrom
h-mayorquin:metric_system_units_docs
May 27, 2025
Merged

Add documentation to handle (physical) units of recording channels#3844
alejoe91 merged 27 commits into
SpikeInterface:mainfrom
h-mayorquin:metric_system_units_docs

Conversation

@h-mayorquin
Copy link
Copy Markdown
Collaborator

Ok guys, I will need your feedback. I am also adding another preprocessor wrapper that handles this for the user.

@h-mayorquin h-mayorquin added documentation Improvements or additions to documentation core Changes to core module preprocessing Related to preprocessing module labels Apr 7, 2025
@h-mayorquin h-mayorquin self-assigned this Apr 7, 2025
Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
Comment thread src/spikeinterface/preprocessing/scale.py Outdated
@chrishalcrow
Copy link
Copy Markdown
Member

Looks great - doc was super clear and easy to read!

h-mayorquin and others added 2 commits April 8, 2025 08:48
Co-authored-by: Chris Halcrow <57948917+chrishalcrow@users.noreply.github.com>
@h-mayorquin h-mayorquin marked this pull request as ready for review April 8, 2025 14:49
Copy link
Copy Markdown
Member

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before being really careful my one concern with this doc as written is that for the average user we don't need to scale_to_uV. It happens with argument flags in various functions. The way this documentation works it sounds like I always have to create a scaled recording rather than keep my unscaled and scale at the function level. I think the doc about other physical units is great, but I'm worried that this might actually confuse users on how to use the library since the scaling for uV is baked in to other functions the class is for people that just need their recording scaled for other purposes right?

Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
@h-mayorquin
Copy link
Copy Markdown
Collaborator Author

h-mayorquin commented Apr 16, 2025

but I'm worried that this might actually confuse users on how to use the library since the scaling for uV is baked in to other functions

what would be the confusion exactly?

@zm711
Copy link
Copy Markdown
Member

zm711 commented Apr 16, 2025

The confusion is do I need to do a scale_to_uV step in all of my pipelines? ie

recording = read_intan()
scaled_rec = scale_to_uV(recording)
sorting = run_sorter(xx)
# or spikeglx
recording = read_spikeglx()
scaled_rec= scale_to_uV(recording)
sorting=run_sorter()

The scaling is not required in a pipeline. But when I read these docs I feel like I have to explicitly run this step no matter what. I think it is helpful for people to know scaling is important but the main way the library has people interact with ephys scaling is with the return_scaled soon to be return_in_uV (or whatever we decided) as a function argument. Not as a preprocessing step. Does that make sense? I think the docs are good, but I'm worried people will not realize when they should scale outside of function calls vs inside. For another example. If I take a scale_to_uV recording what happens if I try to return_scaled? I shouldn't rescale again (I think you may have added an error, but then that mechanism seems weird. Because data should be scaled. Maybe this is worth an actual discussion because I'm worried I'm not being clear.

@h-mayorquin
Copy link
Copy Markdown
Collaborator Author

The scaling is not required in a pipeline. But when I read these docs I feel like I have to explicitly run this step no matter what.

Thanks.
We can add a comment that scaling is not needed in sorters.

I think the docs are good, but I'm worried people will not realize when they should scale outside of function calls vs inside.

This is not clear to me either. Is it to you?

but the main way the library has people interact with ephys scaling is with the return_scaled soon to be return_in_uV

I don't agree with this or want it.

Yes, I think we should discuss this on the meeting tomorrow. I am fine if you want add a list of pipes/algorithms where the units don't matter and an explanation on why they don't but I don't have that knowledge and I users are in a better position to understand if they want to run their algorithms on raw data or in units.

@zm711
Copy link
Copy Markdown
Member

zm711 commented Apr 16, 2025

@yger it seems like maybe some changes to SC2 broke testing?

@h-mayorquin
Copy link
Copy Markdown
Collaborator Author

Ok @zm711 I added some notes in the direction that you wanted. Check it out and let me know what you think. I still think that this is a good topic to discuss on the next meeting.

Copy link
Copy Markdown
Member

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more comments.

Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
SpikeInterface provides tools to handle both situations.

It's important to note that **most spike sorters work fine on raw digital (ADC) units** and not scaling is needed.
Many preprocessing tools are also linear transformations, and if the ADC is implemented as a linear transformation, the overall effect can be preserved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could say that is relatively common here to be a linear transformation (although you discuss gain/offset later on).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment on this direction.

Comment thread doc/how_to/physical_units.rst
Comment thread doc/how_to/physical_units.rst
Comment thread doc/how_to/physical_units.rst Outdated
Comment thread src/spikeinterface/preprocessing/scale.py Outdated
self.set_channel_offsets(offsets=0.0)


scale_to_physical_units = ScaleToPhysicalUnits
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, could you change this to

from spikeinterface.core.core_tools import define_function_handling_dict_from_class
scale_to_physical_units = define_function_handling_dict_from_class(ScaleToPhysicalUnits, name="scale_to_physical_units")

then will works with dicts of recs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

This function define_function_handling_dict_from_class needs way more documentation of what it has now.

Comment thread src/spikeinterface/preprocessing/scale.py Outdated
Comment thread src/spikeinterface/preprocessing/scale.py Outdated
h-mayorquin and others added 2 commits May 14, 2025 10:47
Co-authored-by: Chris Halcrow <57948917+chrishalcrow@users.noreply.github.com>
Comment thread src/spikeinterface/preprocessing/scale.py Outdated
Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com>
Copy link
Copy Markdown
Member

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reread this I request two minor changes and then I feel good about this.

Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
h-mayorquin and others added 2 commits May 20, 2025 15:12
Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com>
@h-mayorquin
Copy link
Copy Markdown
Collaborator Author

OK, I implemented changed based on the last round of review @zm711 .

Copy link
Copy Markdown
Member

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two grammar fixes :)

still slight preference for a mentioned of return_scaled but after merging the grammar fixes I'm fine with approving and then if we have user issues/confusion we can adjust to what they need.

Comment thread doc/how_to/physical_units.rst Outdated
Comment thread doc/how_to/physical_units.rst Outdated
h-mayorquin and others added 2 commits May 20, 2025 16:05
Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com>
Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com>
@h-mayorquin
Copy link
Copy Markdown
Collaborator Author

Two grammar fixes :)

still slight preference for a mentioned of return_scaled but after merging the grammar fixes I'm fine with approving and then if we have user issues/confusion we can adjust to what they need.

I don't want to mention this until #3794 is done.

@zm711
Copy link
Copy Markdown
Member

zm711 commented May 20, 2025

I don't want to mention this until #3794 is done.

Yeah I forgot about that until you pushed another commit :)

That works for me!

@alejoe91 alejoe91 merged commit 8099784 into SpikeInterface:main May 27, 2025
15 checks passed
@h-mayorquin h-mayorquin deleted the metric_system_units_docs branch May 27, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core module documentation Improvements or additions to documentation preprocessing Related to preprocessing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants