Skip to content

Commit 124c803

Browse files
committed
improve
1 parent 052b2d7 commit 124c803

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

doc/how_to/physical_units.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
Working with physical units in SpikeInterface recordings
22
========================================================
33

4-
In neurophysiology recordings, data is often stored in raw ADC (Analog-to-Digital Converter) units but at various points in an analysis pipeline the end-user may want to observe their data in physical units.
4+
In neurophysiology recordings, data is often stored in raw ADC (Analog-to-Digital Converter) integer values but needs to be analyzed in physical units.
55
For extracellular recordings, this is typically microvolts (µV), but some recording devices may use different physical units.
66
SpikeInterface provides tools to handle both situations.
77

8-
It's important to note that **most spike sorters work fine on raw digital (ADC) units** and scaling is not needed.
8+
It's important to note that **most spike sorters work fine on raw digital (ADC) units** and scaling is not needed. Going a step further, some sorters, such as Kilosort 3, require their input to be in raw ADC units.
9+
The specific behavior however depends on the spike sorter, so it's important to understand the specific input requirements in a case per case basis.
10+
911
Many preprocessing tools are also linear transformations, and if the ADC is implemented as a linear transformation which is fairly common, then the overall effect can be preserved.
10-
That is, **preprocessing steps can often be applied either before or after unit conversion without affecting the outcome.**
12+
That is, **preprocessing steps can often be applied either before or after unit conversion without affecting the outcome.**. That said, there are rough edges to this approach.
13+
preprocessing algorithms like filtering, whitening, centering, interpolation and common reference require casting to float within the pipeline. We advise users to experiment
14+
with different approaches to find the best one for their specific use case.
15+
1116

12-
Therefore, **it is usually safe to work in raw ADC units unless a specific tool or analysis requires physical units**.
17+
Therefore, **it is usually safe to work in raw ADC integer values unless a specific tool or analysis requires physical units**.
1318
If you are interested in visualizations, comparability across devices, or outputs with interpretable physical scales (e.g., microvolts), converting to physical units is recommended.
1419
Otherwise, remaining in raw units can simplify processing and preserve performance.
1520

@@ -36,13 +41,12 @@ SpikeInterface provides two preprocessing classes for converting recordings to p
3641
``RecordingExtractor`` class and ensures that the data is returned in physical units when calling `get_traces <https://spikeinterface.readthedocs.io/en/stable/api.html#spikeinterface.core.BaseRecording.get_traces>`_
3742

3843
1. ``scale_to_uV``: The primary function for extracellular recordings. SpikeInterface is centered around
39-
extracellular recordings, and this function is designed to convert the data to microvolts (µV). Many plotting
40-
and analyzing functions in SpikeInterface expect data in microvolts, so this is the recommended approach for most users.
44+
extracellular recordings, and this function is designed to convert the data to microvolts (µV).
4145
2. ``scale_to_physical_units``: A general function for any physical unit conversion. This will allow you to extract the data in any
42-
physical unit, not just microvolts. This is useful for other types of recordings, such as force measurements in Newtons but should be
43-
handled with care.
46+
physical unit, not just microvolts. This is useful for other types of recordings, such as force measurements in Newtons but should be
47+
handled with care.
4448

45-
For most users working with extracellular recordings, ``scale_to_uV`` is the recommended choice:
49+
For most users working with extracellular recordings, ``scale_to_uV`` is the recommended choice if they want to work in physical units:
4650

4751
.. code-block:: python
4852
@@ -71,7 +75,7 @@ Both preprocessors automatically:
7175
3. Update the recording properties to reflect that data is now in physical units
7276

7377
Setting Custom Physical Units
74-
---------------------------
78+
-----------------------------
7579

7680
While most extractors automatically set the appropriate ``gain_to_uV`` and ``offset_to_uV`` values,
7781
there might be cases where you want to set custom physical units. In these cases, you can set
@@ -88,7 +92,7 @@ You need to set these properties for every channel, which allows for the case wh
8892
# Set custom physical units
8993
num_channels = recording.get_num_channels()
9094
values = ["volts"] * num_channels
91-
recording.set_property(key='physical_unit', value=values)
95+
recording.set_property(key='physical_unit', values=values)
9296
9397
gain_values = [0.001] * num_channels # Convert from ADC to volts
9498
recording.set_property(key='gain_to_unit', values=gain_values) # Convert to volts

src/spikeinterface/preprocessing/scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, recording):
6464
self.set_channel_offsets(offsets=0.0)
6565

6666

67-
scale_to_physical_units = define_function_handling_dict_from_class(ScaleToPhysicalUnits, "scale_to_physical_units")
67+
scale_to_physical_units = define_function_handling_dict_from_class(ScaleToPhysicalUnits, name="scale_to_physical_units")
6868

6969

7070
def scale_to_uV(recording: BasePreprocessor) -> BasePreprocessor:

0 commit comments

Comments
 (0)