.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/metrics/plot_3_quality_metrics.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_metrics_plot_3_quality_metrics.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-17 .. code-block:: Python import spikeinterface.core as si from spikeinterface.metrics import ( compute_snrs, compute_presence_ratios, compute_isi_violations, ) .. GENERATED FROM PYTHON SOURCE LINES 18-19 First, let's generate a simulated recording and sorting .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. 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 25-29 Create SortingAnalyzer ----------------------- For quality metrics we need first to create a :code:`SortingAnalyzer`. .. GENERATED FROM PYTHON SOURCE LINES 29-33 .. 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 SortingAnalyzer: 4 channels - 10 units - 1 segments - memory - sparse - has recording Loaded 0 extensions .. GENERATED FROM PYTHON SOURCE LINES 34-36 Depending on which metrics we want to compute we will need first to compute some necessary extensions. (if not computed an error message will be raised) .. GENERATED FROM PYTHON SOURCE LINES 36-45 .. code-block:: Python analyzer.compute("random_spikes", method="uniform", max_spikes_per_unit=600, seed=2205) analyzer.compute("waveforms", ms_before=1.3, ms_after=2.6, n_jobs=2) analyzer.compute("templates", operators=["average", "median", "std"]) analyzer.compute("noise_levels") print(analyzer) .. rst-class:: sphx-glr-script-out .. code-block:: none compute_waveforms (workers: 2 processes fork): 0%| | 0/10 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_3_quality_metrics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_3_quality_metrics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_