Skip to content

Commit

Permalink
Merge branch 'main' into add_name_to_repr
Browse files Browse the repository at this point in the history
  • Loading branch information
h-mayorquin authored Apr 30, 2024
2 parents 64a8432 + b6c2c91 commit 619f37d
Show file tree
Hide file tree
Showing 38 changed files with 1,076 additions and 394 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
files: ^src/
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',
'sphinx_gallery.gen_gallery',
'numpydoc',
'sphinx_design',
Expand Down
157 changes: 111 additions & 46 deletions doc/how_to/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ object to disk.
float32 dtype - 39.06 MiB
CommonReferenceRecording: 32 channels - 32.0kHz - 1 segments - 320,000 samples - 10.00s
float32 dtype - 39.06 MiB
Use cache_folder=/tmp/spikeinterface_cache/tmpsgoh2z3y/DLGW1J8V
Use cache_folder=/tmp/spikeinterface_cache/tmpxozot7du/PS8C5MPU
write_binary_recording with n_jobs = 4 and chunk_size = 32000
Expand All @@ -245,7 +245,9 @@ object to disk.
BinaryFolderRecording: 32 channels - 32.0kHz - 1 segments - 320,000 samples - 10.00s
float32 dtype - 39.06 MiB
To reload a preprocessed recording that was saved to disk, you can use ``load_extractor()`` function from the ``core`` module.
To reload a preprocessed recording that was saved to disk, you can use
``load_extractor()`` function from the ``core`` module.

Now you are ready to spike sort using the ``spikeinterface.sorters``
module! Let’s first check which sorters are implemented and which are
Expand Down Expand Up @@ -294,7 +296,7 @@ available parameters are dictionaries and can be accessed with:
{'apply_preprocessing': True,
'cache_preprocessing': {'delete_cache': True,
'memory_limit': 0.5,
'mode': None},
'mode': 'memory'},
'clustering': {'legacy': False},
'debug': False,
'detection': {'detect_threshold': 4, 'peak_sign': 'neg'},
Expand All @@ -306,6 +308,7 @@ available parameters are dictionaries and can be accessed with:
'selection': {'method': 'smart_sampling_amplitudes',
'min_n_peaks': 100000,
'n_peaks_per_channel': 5000,
'seed': 42,
'select_per_channel': False},
'sparsity': {'method': 'ptp', 'threshold': 0.25}}
Expand Down Expand Up @@ -351,9 +354,15 @@ Let’s run ``spykingcircus2`` as well, with default parameters:
print(sorting_SC2)
.. parsed-literal::
NumpyFolderSorting: 10 units - 1 segments - 32.0kHz
write_memory_recording: 0%| | 0/1 [00:00<?, ?it/s]
.. parsed-literal::
NumpyFolderSorting: 8 units - 1 segments - 32.0kHz
The ``sorting_TDC`` and ``sorting_SC2`` are ``BaseSorting`` objects. We
Expand All @@ -368,7 +377,7 @@ can print the units found using:
.. parsed-literal::
Units found by tridesclous: [0 1 2 3 4 5 6 7 8 9]
Units found by spyking-circus2: [0 1 2 3 4 5 6 7 8 9]
Units found by spyking-circus2: [0 1 2 3 4 5 6 7]
If a sorter is not installed locally, we can also avoid installing it
Expand Down Expand Up @@ -436,7 +445,7 @@ and then to compute, for example, quality metrics. Computations with the
.. parsed-literal::
<spikeinterface.core.analyzer_extension_core.ComputeWaveforms at 0x7f49d5ddabb0>
<spikeinterface.core.analyzer_extension_core.ComputeWaveforms at 0x7fa6f222c5b0>
Expand Down Expand Up @@ -476,7 +485,7 @@ There are many more properties we can calculate
.. parsed-literal::
<spikeinterface.postprocessing.spike_amplitudes.ComputeSpikeAmplitudes at 0x7f49d5e36340>
<spikeinterface.postprocessing.spike_amplitudes.ComputeSpikeAmplitudes at 0x7fa6f241cb20>
Expand All @@ -500,12 +509,56 @@ Many of the extensions have parameters you can tune
.. parsed-literal::
<spikeinterface.postprocessing.template_similarity.ComputeTemplateSimilarity at 0x7f49d5e0ed90>
<spikeinterface.postprocessing.template_similarity.ComputeTemplateSimilarity at 0x7fa6f2379ac0>
As you can see, it becomes a bit overwhelming if you’re computing lots
of extensions. Luckily, there’s some nice syntax for this very
situation. We can redo the last nine compute statements in one command
as follows:

.. code:: ipython3
extensions_to_compute = [
"random_spikes",
"waveforms",
"noise_levels",
"templates",
"spike_amplitudes",
"unit_locations",
"spike_locations",
"correlograms",
"template_similarity"
]
extension_params = {
"unit_locations": {"method": "center_of_mass"},
"spike_locations": {"ms_before": 0.1},
"correlograms": {"bin_ms": 0.1},
"template_similarity": {"method": "cosine_similarity"}
}
analyzer_TDC.compute(extensions_to_compute, extension_params=extension_params)
.. parsed-literal::
compute_waveforms: 0%| | 0/10 [00:00<?, ?it/s]
.. parsed-literal::
Compute : spike_amplitudes + spike_locations: 0%| | 0/10 [00:00<?, ?it/s]
Which you might find easier. Note that if we pass no extension
parameters, the computation simply uses the default parameters.

Find out more about the available parameters and extensions
`here <https://spikeinterface.readthedocs.io/en/latest/modules/postprocessing.html#available-postprocessing-extensions>`__.
`here <https://spikeinterface.readthedocs.io/en/latest/modules/postprocessing.html>`__.

The calculations are saved in the ``extensions`` subfolder of the
``SortingAnalyzer`` folder. Similar to the waveforms we can access them
Expand All @@ -520,7 +573,7 @@ a historgram of spike amplitudes
.. image:: get_started_files/get_started_52_0.png
.. image:: get_started_files/get_started_55_0.png


You can check which extensions have been saved (in your local folder)
Expand All @@ -534,8 +587,8 @@ and which have been loaded (in your enviroment)…
.. parsed-literal::
['random_spikes', 'waveforms', 'templates', 'noise_levels', 'template_similarity', 'spike_amplitudes', 'correlograms', 'spike_locations', 'unit_locations']
['random_spikes', 'waveforms', 'noise_levels', 'templates', 'spike_amplitudes', 'unit_locations', 'spike_locations', 'correlograms', 'template_similarity']
['noise_levels', 'spike_locations', 'template_similarity', 'waveforms', 'spike_amplitudes', 'templates', 'correlograms', 'unit_locations', 'random_spikes']
['random_spikes', 'noise_levels', 'correlograms', 'waveforms', 'templates', 'unit_locations', 'template_similarity', 'spike_amplitudes', 'spike_locations']
…or delete an extension…
Expand All @@ -559,7 +612,7 @@ since we just deleted it)
.. parsed-literal::
['random_spikes', 'waveforms', 'templates', 'noise_levels', 'template_similarity', 'correlograms', 'spike_locations', 'unit_locations']
['noise_levels', 'templates', 'spike_locations', 'template_similarity', 'waveforms', 'correlograms', 'unit_locations', 'random_spikes']
And any deleted extensions are easily recomputed
Expand All @@ -579,7 +632,7 @@ And any deleted extensions are easily recomputed
.. parsed-literal::
<spikeinterface.postprocessing.spike_amplitudes.ComputeSpikeAmplitudes at 0x7f49b80eadc0>
<spikeinterface.postprocessing.spike_amplitudes.ComputeSpikeAmplitudes at 0x7fa6f2095310>
Expand Down Expand Up @@ -656,6 +709,19 @@ in the same way as earlier
analyzer_TDC.compute("quality_metrics", qm_params)
analyzer_TDC.get_extension("quality_metrics").get_data()
.. parsed-literal::
/home/nolanlab/Chris/Developing/spikeinterface/src/spikeinterface/qualitymetrics/misc_metrics.py:846: UserWarning: Some units have too few spikes : amplitude_cutoff is set to NaN
warnings.warn(f"Some units have too few spikes : amplitude_cutoff is set to NaN")
/home/nolanlab/Chris/Developing/spikeinterface/src/spikeinterface/qualitymetrics/misc_metrics.py:999: UserWarning: The recording is too short given the specified 'interval_s' and 'min_num_bins'. Drift metrics will be set to NaN
warnings.warn(
/home/nolanlab/Chris/Developing/spikeinterface/src/spikeinterface/qualitymetrics/misc_metrics.py:147: UserWarning: Bin duration of 60s is larger than recording duration. Presence ratios are set to NaN.
warnings.warn(
.. raw:: html

<div>
Expand Down Expand Up @@ -719,7 +785,7 @@ in the same way as earlier
<td>0.0</td>
<td>1.536918</td>
<td>NaN</td>
<td>27.140698</td>
<td>27.449127</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -743,7 +809,7 @@ in the same way as earlier
<td>0.0</td>
<td>1.311148</td>
<td>NaN</td>
<td>24.059540</td>
<td>24.363658</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -767,7 +833,7 @@ in the same way as earlier
<td>0.0</td>
<td>2.016703</td>
<td>NaN</td>
<td>24.387525</td>
<td>24.339651</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -791,7 +857,7 @@ in the same way as earlier
<td>0.0</td>
<td>2.011083</td>
<td>NaN</td>
<td>26.948630</td>
<td>26.662774</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -815,7 +881,7 @@ in the same way as earlier
<td>0.0</td>
<td>0.680199</td>
<td>NaN</td>
<td>9.585650</td>
<td>9.632134</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -839,7 +905,7 @@ in the same way as earlier
<td>0.0</td>
<td>0.965515</td>
<td>NaN</td>
<td>13.196613</td>
<td>13.269441</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -863,7 +929,7 @@ in the same way as earlier
<td>0.0</td>
<td>1.177009</td>
<td>NaN</td>
<td>8.193233</td>
<td>8.206179</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -885,9 +951,9 @@ in the same way as earlier
<td>NaN</td>
<td>0.0</td>
<td>0.0</td>
<td>0.973417</td>
<td>0.974259</td>
<td>0.155</td>
<td>8.808388</td>
<td>8.791409</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -911,7 +977,7 @@ in the same way as earlier
<td>0.0</td>
<td>0.949695</td>
<td>0.310</td>
<td>11.125336</td>
<td>11.190016</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand All @@ -933,9 +999,9 @@ in the same way as earlier
<td>NaN</td>
<td>0.0</td>
<td>0.0</td>
<td>1.021080</td>
<td>1.027925</td>
<td>0.270</td>
<td>8.281832</td>
<td>8.340747</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
Expand Down Expand Up @@ -963,15 +1029,16 @@ web-based visualization. For this to work you need to install
w1 = sw.plot_quality_metrics(analyzer_TDC, display=False, backend="sortingview")
https://figurl.org/f?v=npm://@fi-sci/figurl-sortingview@12/dist&d=sha1://c0312bc14387471531af9913147098b94cc640cf
https://figurl.org/f?v=npm://@fi-sci/figurl-sortingview@12/dist&d=sha1://25075d7e8810c6239e2be02f288285091283c283


.. code:: ipython3
w2 = sw.plot_sorting_summary(analyzer_TDC, display=False, curation=True, backend="sortingview")
https://figurl.org/f?v=npm://@fi-sci/figurl-sortingview@12/dist&d=sha1://688cd7a233857847b5663e565dbf3f2807887013
https://figurl.org/f?v=npm://@fi-sci/figurl-sortingview@12/dist&d=sha1://588f5c77f7f1f445addcc219c648213d5324b123


The sorting summary plot can also be used for manual labeling and
Expand Down Expand Up @@ -1112,11 +1179,11 @@ performance and plot a confusion matrix
.. image:: get_started_files/get_started_84_1.png
.. image:: get_started_files/get_started_87_1.png



.. image:: get_started_files/get_started_84_2.png
.. image:: get_started_files/get_started_87_2.png


When comparing two sorters (2.), we can see the matching of units
Expand All @@ -1133,14 +1200,14 @@ between sorters. Units which are not matched have -1 as their unit id:
0 0.0
1 1.0
2 8.0
3 2.0
4 5.0
5 4.0
6 7.0
2 2.0
3 3.0
4 -1.0
5 -1.0
6 4.0
7 6.0
8 9.0
9 3.0
8 7.0
9 5.0
dtype: float64
Expand All @@ -1158,14 +1225,12 @@ or the reverse:
0 0.0
1 1.0
2 3.0
3 9.0
4 5.0
5 4.0
2 2.0
3 3.0
4 6.0
5 9.0
6 7.0
7 6.0
8 2.0
9 8.0
7 8.0
dtype: float64
Expand All @@ -1190,11 +1255,11 @@ graph showing how the units are matched between the sorters.
.. image:: get_started_files/get_started_90_1.png
.. image:: get_started_files/get_started_93_1.png



.. image:: get_started_files/get_started_90_2.png
.. image:: get_started_files/get_started_93_2.png


We see that 10 unit were found by all sorters (note that this simulated
Expand Down
Binary file removed doc/how_to/get_started_files/get_started_52_0.png
Binary file not shown.
Binary file added doc/how_to/get_started_files/get_started_55_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/how_to/get_started_files/get_started_90_1.png
Binary file not shown.
Binary file removed doc/how_to/get_started_files/get_started_90_2.png
Binary file not shown.
Binary file added doc/how_to/get_started_files/get_started_93_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/how_to/get_started_files/get_started_93_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 619f37d

Please sign in to comment.