Skip to content

Commit fa7431f

Browse files
authored
Merge branch 'main' into ruff-test
2 parents 016d134 + 1c474e1 commit fa7431f

50 files changed

Lines changed: 735 additions & 287 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@ If you find SpikeInterface useful in your research, please cite:
134134
```
135135

136136
Please also cite other relevant papers for the specific components you use.
137-
For a ful list of references, please check the [references](https://spikeinterface.readthedocs.io/en/latest/references.html) page.
137+
For a full list of references, please check the [references](https://spikeinterface.readthedocs.io/en/latest/references.html) page.

doc/how_to/handle_drift.rst

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,38 +1455,32 @@ Plot the results
14551455
We load back the results and use the widgets module to explore the
14561456
estimated drift motion.
14571457

1458-
For all methods we have 4 plots: \* top left: time vs estimated peak
1459-
depth \* top right: time vs peak depth after motion correction \* bottom
1460-
left: the average motion vector across depths and all motion across
1461-
spatial depths (for non-rigid estimation) \* bottom right: if motion
1462-
correction is non rigid, the motion vector across depths is plotted as a
1463-
map, with the color code representing the motion in micrometers.
1464-
1465-
A few comments on the figures: \* the preset **‘rigid_fast’** has only
1466-
one motion vector for the entire probe because it is a “rigid” case. The
1467-
motion amplitude is globally underestimated because it averages across
1468-
depths. However, the corrected peaks are flatter than the non-corrected
1469-
ones, so the job is partially done. The big jump at=600s when the probe
1470-
start moving is recovered quite well. \* The preset **kilosort_like**
1471-
gives better results because it is a non-rigid case. The motion vector
1472-
is computed for different depths. The corrected peak locations are
1473-
flatter than the rigid case. The motion vector map is still be a bit
1474-
noisy at some depths (e.g around 1000um). \* The preset **dredge** is
1475-
offcial DREDge re-implementation in spikeinterface. It give the best
1476-
result : very fast and smooth motion estimation. Very few noise. This
1477-
method also capture very well the non rigid motion gradient along the
1478-
probe. The best method on the market at the moement. An enormous thanks
1479-
to the dream team : Charlie Windolf, Julien Boussard, Erdem Varol, Liam
1480-
Paninski. Note that in the first part of the recording before the
1481-
imposed motion (0-600s) we clearly have a non-rigid motion: the upper
1482-
part of the probe (2000-3000um) experience some drifts, but the lower
1483-
part (0-1000um) is relatively stable. The method defined by this preset
1484-
is able to capture this. \* The preset **nonrigid_accurate** this is the
1485-
ancestor of “dredge” before it was published. It seems to give the good
1486-
results on this recording but with bit more noise. \* The preset
1487-
**dredge_fast** similar than dredge but faster (using grid_convolution).
1488-
\* The preset **nonrigid_fast_and_accurate** a variant of
1489-
nonrigid_accurate but faster (using grid_convolution).
1458+
For all methods we have 4 plots:
1459+
* top left: time vs estimated peak
1460+
* top right: time vs peak depth after motion correction
1461+
* bottom left: the average motion vector across depths and all motion across spatial depths (for non-rigid estimation)
1462+
* bottom right: if motion correction is non rigid, the motion vector across depths is plotted as a map,
1463+
with the color code representing the motion in micrometers.
1464+
1465+
A few comments on the figures:
1466+
* the preset **‘rigid_fast’** has only one motion vector for the entire probe because it is a “rigid” case. The
1467+
motion amplitude is globally underestimated because it averages across depths. However, the corrected peaks
1468+
are flatter than the non-corrected ones, so the job is partially done. The big jump at=600s when the probe start
1469+
moving is recovered quite well.
1470+
* The preset **kilosort_like** gives better results because it is a non-rigid case. The motion vector is computed
1471+
for different depths. The corrected peak locations are flatter than the rigid case. The motion vector map is still
1472+
be a bit noisy at some depths (e.g around 1000um).
1473+
* The preset **dredge** is official DREDge re-implementation in spikeinterface. It give the best result : very fast
1474+
and smooth motion estimation. Very few noise. This method also capture very well the non rigid motion gradient along
1475+
the probe. The best method on the market at the moement. An enormous thanks to the dream team : Charlie Windolf,
1476+
Julien Boussard, Erdem Varol, Liam Paninski. Note that in the first part of the recording before the imposed motion
1477+
(0-600s) we clearly have a non-rigid motion: the upper part of the probe (2000-3000um) experience some drifts, but the
1478+
lower part (0-1000um) is relatively stable. The method defined by this preset is able to capture this.
1479+
* The preset **nonrigid_accurate** this is the ancestor of “dredge” before it was published. It seems to give good results
1480+
on this recording but with bit more noise.
1481+
* The preset **dredge_fast** similar than dredge but faster (using grid_convolution).
1482+
* The preset **nonrigid_fast_and_accurate** a variant of
1483+
nonrigid_accurate but faster (using grid_convolution).
14901484

14911485
.. code:: ipython3
14921486

doc/how_to/process_by_channel_group.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ to any preprocessing function.
9797
shifted_recordings = spre.phase_shift(split_recording_dict)
9898
filtered_recording = spre.bandpass_filter(shifted_recording)
9999
referenced_recording = spre.common_reference(filtered_recording)
100+
good_channels_recording = spre.detect_and_remove_bad_channels(filtered_recording)
100101
101102
We can then aggregate the recordings back together using the ``aggregate_channels`` function
102103

103104
.. code-block:: python
104105
105-
combined_preprocessed_recording = aggregate_channels(referenced_recording)
106+
combined_preprocessed_recording = aggregate_channels(good_channels_recording)
106107
107108
Now, when ``combined_preprocessed_recording`` is used in sorting, plotting, or whenever
108109
calling its :py:func:`~get_traces` method, the data will have been

doc/modules/preprocessing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ interpolated with the :code:`interpolate_bad_channels()` function (channels labe
247247
# Case 2 : interpolate then
248248
rec_clean = interpolate_bad_channels(recording=rec, bad_channel_ids=bad_channel_ids)
249249
250+
Once you have tested these functions and decided on your workflow, you can use the `detect_and_*`
251+
functions to do everything at once. These return a Preprocessor class, so are consistent with
252+
the "chain" concept for this module. For example:
253+
254+
.. code-block:: python
255+
256+
# detect and remove bad channels
257+
rec_only_good_channels = detect_and_remove_bad_channels(recording=rec)
258+
259+
# detect and interpolate the bad channels
260+
rec_interpolated_channels = detect_and_interpolate_bad_channels(recording=rec)
261+
250262
251263
* :py:func:`~spikeinterface.preprocessing.detect_bad_channels()`
252264
* :py:func:`~spikeinterface.preprocessing.interpolate_bad_channels()`

examples/how_to/handle_drift.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,33 @@ def preprocess_chain(rec):
133133
# We load back the results and use the widgets module to explore the estimated drift motion.
134134
#
135135
# For all methods we have 4 plots:
136+
#
136137
# * top left: time vs estimated peak depth
137138
# * top right: time vs peak depth after motion correction
138139
# * bottom left: the average motion vector across depths and all motion across spatial depths (for non-rigid estimation)
139140
# * bottom right: if motion correction is non rigid, the motion vector across depths is plotted as a map, with the color code representing the motion in micrometers.
140141
#
141142
# A few comments on the figures:
142-
# * the preset **'rigid_fast'** has only one motion vector for the entire probe because it is a "rigid" case.
143-
# The motion amplitude is globally underestimated because it averages across depths.
144-
# However, the corrected peaks are flatter than the non-corrected ones, so the job is partially done.
145-
# The big jump at=600s when the probe start moving is recovered quite well.
146-
# * The preset **kilosort_like** gives better results because it is a non-rigid case.
147-
# The motion vector is computed for different depths.
148-
# The corrected peak locations are flatter than the rigid case.
149-
# The motion vector map is still be a bit noisy at some depths (e.g around 1000um).
150-
# * The preset **dredge** is offcial DREDge re-implementation in spikeinterface.
151-
# It give the best result : very fast and smooth motion estimation. Very few noise.
152-
# This method also capture very well the non rigid motion gradient along the probe.
153-
# The best method on the market at the moement.
154-
# An enormous thanks to the dream team : Charlie Windolf, Julien Boussard, Erdem Varol, Liam Paninski.
155-
# Note that in the first part of the recording before the imposed motion (0-600s) we clearly have a non-rigid motion:
156-
# the upper part of the probe (2000-3000um) experience some drifts, but the lower part (0-1000um) is relatively stable.
157-
# The method defined by this preset is able to capture this.
158-
# * The preset **nonrigid_accurate** this is the ancestor of "dredge" before it was published.
159-
# It seems to give the good results on this recording but with bit more noise.
160-
# * The preset **dredge_fast** similar than dredge but faster (using grid_convolution).
161-
# * The preset **nonrigid_fast_and_accurate** a variant of nonrigid_accurate but faster (using grid_convolution).
143+
# * the preset **'rigid_fast'** has only one motion vector for the entire probe because it is a "rigid" case.
144+
# The motion amplitude is globally underestimated because it averages across depths.
145+
# However, the corrected peaks are flatter than the non-corrected ones, so the job is partially done.
146+
# The big jump at=600s when the probe start moving is recovered quite well.
147+
# * The preset **kilosort_like** gives better results because it is a non-rigid case.
148+
# The motion vector is computed for different depths.
149+
# The corrected peak locations are flatter than the rigid case.
150+
# The motion vector map is still be a bit noisy at some depths (e.g around 1000um).
151+
# * The preset **dredge** is offcial DREDge re-implementation in spikeinterface.
152+
# It give the best result : very fast and smooth motion estimation. Very few noise.
153+
# This method also capture very well the non rigid motion gradient along the probe.
154+
# The best method on the market at the moement.
155+
# An enormous thanks to the dream team : Charlie Windolf, Julien Boussard, Erdem Varol, Liam Paninski.
156+
# Note that in the first part of the recording before the imposed motion (0-600s) we clearly have a non-rigid motion:
157+
# the upper part of the probe (2000-3000um) experience some drifts, but the lower part (0-1000um) is relatively stable.
158+
# The method defined by this preset is able to capture this.
159+
# * The preset **nonrigid_accurate** this is the ancestor of "dredge" before it was published.
160+
# It seems to give the good results on this recording but with bit more noise.
161+
# * The preset **dredge_fast** similar than dredge but faster (using grid_convolution).
162+
# * The preset **nonrigid_fast_and_accurate** a variant of nonrigid_accurate but faster (using grid_convolution).
162163
#
163164
#
164165

@@ -205,6 +206,7 @@ def preprocess_chain(rec):
205206
# We can see here that some clusters seem to be more compact on the 'y' axis, especially for the preset "nonrigid_accurate".
206207
#
207208
# Be aware that there are two ways to correct for the motion:
209+
#
208210
# 1. Interpolate traces and detect/localize peaks again (`interpolate_recording()`)
209211
# 2. Compensate for drifts directly on peak locations (`correct_motion_on_peaks()`)
210212
#

src/spikeinterface/benchmark/benchmark_matching.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def run(self, **job_kwargs):
3838
self.result = {"sorting": sorting, "spikes": spikes}
3939
self.result["templates"] = self.templates
4040

41-
def compute_result(self, with_collision=False, **result_params):
41+
def compute_result(self, with_collision=False, match_score=0.5, exhaustive_gt=True):
4242
sorting = self.result["sorting"]
43-
comp = compare_sorter_to_ground_truth(self.gt_sorting, sorting, exhaustive_gt=True)
43+
comp = compare_sorter_to_ground_truth(
44+
self.gt_sorting, sorting, exhaustive_gt=exhaustive_gt, match_score=match_score
45+
)
4446
self.result["gt_comparison"] = comp
4547
if with_collision:
4648
self.result["gt_collision"] = CollisionGTComparison(self.gt_sorting, sorting, exhaustive_gt=True)

src/spikeinterface/benchmark/benchmark_merging.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ def run(self, **job_kwargs):
3535

3636
self.result["sorting"] = merged_analyzer.sorting
3737

38-
def compute_result(self, **result_params):
38+
def compute_result(self, match_score=0.5, exhaustive_gt=True):
3939
sorting = self.result["sorting"]
40-
comp = compare_sorter_to_ground_truth(self.gt_sorting, sorting, exhaustive_gt=True)
40+
comp = compare_sorter_to_ground_truth(
41+
self.gt_sorting, sorting, exhaustive_gt=exhaustive_gt, match_score=match_score
42+
)
4143
self.result["gt_comparison"] = comp
4244

4345
_run_key_saved = [("sorting", "sorting"), ("merges", "pickle"), ("merged_pairs", "pickle"), ("outs", "pickle")]

src/spikeinterface/benchmark/benchmark_sorter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ def run(self):
2626
sorting = NumpySorting.from_sorting(raw_sorting)
2727
self.result = {"sorting": sorting}
2828

29-
def compute_result(self, exhaustive_gt=True):
29+
def compute_result(self, match_score=0.5, exhaustive_gt=True):
3030
# run becnhmark result
3131
sorting = self.result["sorting"]
32-
comp = compare_sorter_to_ground_truth(self.gt_sorting, sorting, exhaustive_gt=exhaustive_gt)
32+
comp = compare_sorter_to_ground_truth(
33+
self.gt_sorting, sorting, exhaustive_gt=exhaustive_gt, match_score=match_score
34+
)
3335
self.result["gt_comparison"] = comp
3436

3537
_run_key_saved = [

src/spikeinterface/core/analyzer_extension_core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* ComputeNoiseLevels which is very convenient to have
1010
"""
1111

12-
import warnings
13-
1412
import numpy as np
1513

1614
from .sortinganalyzer import AnalyzerExtension, register_result_extension

src/spikeinterface/core/baserecording.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55

66
import numpy as np
7-
from probeinterface import Probe, ProbeGroup, read_probeinterface, select_axes, write_probeinterface
7+
from probeinterface import read_probeinterface, write_probeinterface
88

99
from .base import BaseSegment
1010
from .baserecordingsnippets import BaseRecordingSnippets

0 commit comments

Comments
 (0)