.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/qualitymetrics/plot_3_quality_mertics.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_3_quality_mertics.py: Quality Metrics Tutorial ======================== After spike sorting, you might want to validate the 'goodness' of the sorted units. This can be done using the :code:`qualitymetrics` submodule, which computes several quality metrics of the sorted units. .. GENERATED FROM PYTHON SOURCE LINES 9-21 .. 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_snrs, compute_firing_rates, compute_isi_violations, calculate_pc_metrics, compute_quality_metrics, ) .. GENERATED FROM PYTHON SOURCE LINES 22-24 First, let's download a simulated dataset from the repo 'https://gin.g-node.org/NeuralEnsemble/ephy_testing_data' .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: Python local_path = si.download_dataset(remote_path="mearec/mearec_test_10s.h5") recording, sorting = se.read_mearec(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 31-35 Create SortingAnalyzer ----------------------- For quality metrics we need first to create a :code:`SortingAnalyzer`. .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python analyzer = si.create_sorting_analyzer(sorting=sorting, recording=recording, format="memory") 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 #1 5.0 25.562669 #2 4.3 13.83222 #3 3.0 21.930929 #4 4.8 7.43754 #5 3.7 7.451768 #6 5.1 20.824095 #7 11.1 7.341508 #8 19.5 8.092696 #9 12.9 8.956527 .. GENERATED FROM PYTHON SOURCE LINES 72-74 Some metrics are based on the principal component scores, so the exwtension need to be computed before. For instance: .. GENERATED FROM PYTHON SOURCE LINES 74-85 .. code-block:: Python analyzer.compute("principal_components", n_components=3, mode="by_channel_global", whiten=True) metrics = compute_quality_metrics( analyzer, metric_names=[ "isolation_distance", "d_prime", ], ) print(metrics) .. 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( Fitting PCA: 0%| | 0/10 [00:00 5.3 #1 22503.96533 27.426984 25.562669 5.0 #2 126067352822193792.0 24.75911 13.83222 4.3 #3 895298620985875968.0 30.90995 21.930929 3.0 #4 167417577384036896.0 28.448716 7.43754 4.8 #5 86612678156279200.0 20.730191 7.451768 3.7 #6 2142994535281708800.0 37.228947 20.824095 5.1 #7 8878.390636 28.968743 7.341508 11.1 #8 5827.4073 20.999115 8.092696 19.5 #9 7100.39125 30.249492 8.956527 12.9 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.745 seconds) .. _sphx_glr_download_tutorials_qualitymetrics_plot_3_quality_mertics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_3_quality_mertics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_3_quality_mertics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_3_quality_mertics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_