.. 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-20 .. code-block:: Python import spikeinterface.core as si import spikeinterface.extractors as se from spikeinterface.postprocessing import compute_principal_components from spikeinterface.qualitymetrics import compute_quality_metrics .. GENERATED FROM PYTHON SOURCE LINES 21-25 Let's download a simulated dataset from the repo 'https://gin.g-node.org/NeuralEnsemble/ephy_testing_data' Let's imagine that the ground-truth sorting is in fact the output of a sorter. .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: Python local_path = si.download_dataset(remote_path="mearec/mearec_test_10s.h5") recording, sorting = se.read_mearec(file_path=local_path) print(recording) print(sorting) .. rst-class:: sphx-glr-script-out .. code-block:: none MEArecRecordingExtractor: 32 channels - 32.0kHz - 1 segments - 320,000 samples - 10.00s float32 dtype - 39.06 MiB file_path: /home/docs/spikeinterface_datasets/ephy_testing_data/mearec/mearec_test_10s.h5 MEArecSortingExtractor: 10 units - 1 segments - 32.0kHz file_path: /home/docs/spikeinterface_datasets/ephy_testing_data/mearec/mearec_test_10s.h5 .. GENERATED FROM PYTHON SOURCE LINES 32-37 Create SortingAnalyzer ----------------------- For this example, we will need a :code:`SortingAnalyzer` and some extensions to be computed first .. GENERATED FROM PYTHON SOURCE LINES 37-46 .. 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 /home/docs/checkouts/readthedocs.org/user_builds/spikeinterface/checkouts/3072/src/spikeinterface/core/job_tools.py:103: UserWarning: `n_jobs` is not set so parallel processing is disabled! To speed up computations, it is recommended to set n_jobs either globally (with the `spikeinterface.set_global_job_kwargs()` function) or locally (with the `n_jobs` argument). Use `spikeinterface.set_global_job_kwargs?` for more information about job_kwargs. warnings.warn( estimate_sparsity: 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 True #1 True #2 True #3 True #4 False #5 False #6 True #7 False #8 True #9 True dtype: boolean ['#0', '#1', '#2', '#3', '#6', '#8', '#9'] .. GENERATED FROM PYTHON SOURCE LINES 67-68 And now let's create a sorting that contains only curated units and save it. .. GENERATED FROM PYTHON SOURCE LINES 68-75 .. 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 UnitsSelectionSorting: 7 units - 1 segments - 32.0kHz .. raw:: html
NumpyFolder: 7 units - 1 segments - 32.0kHz
Unit IDs
    ['#0' '#1' '#2' '#3' '#6' '#8' '#9']
Annotations
    Unit Properties


      .. GENERATED FROM PYTHON SOURCE LINES 76-77 We can also save the analyzer with only theses units .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. 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: 32 channels - 7 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 7.930 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 `_