.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/qualitymetrics/plot_4_curation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_qualitymetrics_plot_4_curation.py: Curation Tutorial ================== After spike sorting and computing quality metrics, you can automatically curate the spike sorting output using the quality metrics that you have calculated. .. GENERATED FROM PYTHON SOURCE LINES 11-12 Import the modules and/or functions necessary from spikeinterface .. GENERATED FROM PYTHON SOURCE LINES 12-18 .. code-block:: Python import spikeinterface.core as si from spikeinterface.qualitymetrics import compute_quality_metrics .. GENERATED FROM PYTHON SOURCE LINES 19-21 Let's generate a simulated dataset, and imagine that the ground-truth sorting is in fact the output of a sorter. .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python recording, sorting = si.generate_ground_truth_recording() print(recording) print(sorting) .. rst-class:: sphx-glr-script-out .. code-block:: none GroundTruthRecording (InjectTemplatesRecording): 4 channels - 25.0kHz - 1 segments 250,000 samples - 10.00s - float32 dtype - 3.81 MiB GroundTruthSorting (NumpySorting): 10 units - 1 segments - 25.0kHz .. GENERATED FROM PYTHON SOURCE LINES 27-32 Create SortingAnalyzer ----------------------- For this example, we will need a :code:`SortingAnalyzer` and some extensions to be computed first .. GENERATED FROM PYTHON SOURCE LINES 32-41 .. code-block:: Python analyzer = si.create_sorting_analyzer(sorting=sorting, recording=recording, format="memory") analyzer.compute(["random_spikes", "waveforms", "templates", "noise_levels"]) analyzer.compute("principal_components", n_components=3, mode="by_channel_local") print(analyzer) .. rst-class:: sphx-glr-script-out .. code-block:: none estimate_sparsity (no parallelization): 0%| | 0/10 [00:00 7.5) & (metrics["isi_violations_ratio"] < 0.2) & (metrics["nn_hit_rate"] > 0.90) print(keep_mask) keep_unit_ids = keep_mask[keep_mask].index.values keep_unit_ids = [unit_id for unit_id in keep_unit_ids] print(keep_unit_ids) .. rst-class:: sphx-glr-script-out .. code-block:: none 0 False 1 False 2 False 3 True 4 False 5 True 6 True 7 False 8 False 9 True dtype: bool ['3', '5', '6', '9'] .. GENERATED FROM PYTHON SOURCE LINES 62-63 And now let's create a sorting that contains only curated units and save it. .. GENERATED FROM PYTHON SOURCE LINES 63-70 .. code-block:: Python curated_sorting = sorting.select_units(keep_unit_ids) print(curated_sorting) curated_sorting.save(folder="curated_sorting") .. rst-class:: sphx-glr-script-out .. code-block:: none GroundTruthSorting (UnitsSelectionSorting): 4 units - 1 segments - 25.0kHz .. raw:: html
NumpyFolder (NumpyFolderSorting): 4 units - 1 segments - 25.0kHz
Unit IDs
    ['3' '5' '6' '9']
Annotations
  • name : GroundTruthSorting
Properties
    gt_unit_locations[[12.629008 -7.895358 7.6198726] [22.504269 29.685955 18.601088 ] [29.937254 29.228424 43.268787 ] [ 7.276633 -9.420886 33.948456 ]]


.. GENERATED FROM PYTHON SOURCE LINES 71-72 We can also save the analyzer with only theses units .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. code-block:: Python clean_analyzer = analyzer.select_units(unit_ids=keep_unit_ids, format="zarr", folder="clean_analyzer") print(clean_analyzer) .. rst-class:: sphx-glr-script-out .. code-block:: none SortingAnalyzer: 4 channels - 4 units - 1 segments - zarr - sparse - has recording Loaded 6 extensions: random_spikes, waveforms, templates, noise_levels, principal_components, quality_metrics .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.527 seconds) .. _sphx_glr_download_tutorials_qualitymetrics_plot_4_curation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_4_curation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_4_curation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_4_curation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_