Note
Click here to download the full example code
Curation Tutorial¶
After spike sorting and computing validation metrics, you can automatically curate the spike sorting output using the
quality metrics. This can be done with the toolkit.curation
submodule.
import spikeinterface.extractors as se
import spikeinterface.toolkit as st
import spikeinterface.sorters as ss
First, let’s create a toy example:
recording, sorting = se.example_datasets.toy_example(num_channels=4, duration=30, seed=0)
and let’s spike sort using klusta
sorting_KL = ss.run_klusta(recording)
print('Units:', sorting_KL.get_unit_ids())
print('Number of units:', len(sorting_KL.get_unit_ids()))
Out:
RUNNING SHELL SCRIPT: /home/docs/checkouts/readthedocs.org/user_builds/spikeinterface/checkouts/0.13.0/examples/modules/toolkit/klusta_output/run_klusta.sh
/home/docs/checkouts/readthedocs.org/user_builds/spikeinterface/checkouts/0.13.0/doc/sources/spikesorters/spikesorters/basesorter.py:158: ResourceWarning: unclosed file <_io.TextIOWrapper name=63 encoding='UTF-8'>
self._run(recording, self.output_folders[i])
Units: [0, 2, 3, 4, 5, 6, 7, 8, 9]
Number of units: 9
There are several available functions that enables to only retrieve units with respect to some rules. For example, let’s automatically curate the sorting output so that only the units with SNR > 10 and mean firing rate > 2.3 Hz are kept:
sorting_fr = st.curation.threshold_firing_rates(sorting_KL, duration_in_frames=recording.get_num_frames(), threshold=2.3, threshold_sign='less')
print('Units after FR theshold:', sorting_fr.get_unit_ids())
print('Number of units after FR theshold:', len(sorting_fr.get_unit_ids()))
sorting_snr = st.curation.threshold_snrs(sorting_fr, recording, threshold=10, threshold_sign='less')
print('Units after SNR theshold:', sorting_snr.get_unit_ids())
print('Number of units after SNR theshold:', len(sorting_snr.get_unit_ids()))
Out:
Units after FR theshold: [0, 3]
Number of units after FR theshold: 2
Units after SNR theshold: [3]
Number of units after SNR theshold: 1
Let’s now check with the toolkit.validation
submodule that all units have a firing rate > 10 and snr > 0
fr = st.validation.compute_firing_rates(sorting_snr, duration_in_frames=recording.get_num_frames())
snrs = st.validation.compute_snrs(sorting_snr, recording)
print('Firing rates:', fr)
print('SNR:', snrs)
Out:
Firing rates: [2.33333333]
SNR: [14.61125006]
Total running time of the script: ( 0 minutes 4.415 seconds)