Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'''
import spikeinterface.extractors as se
import spikeinterface.widgets as sw
##############################################################################
# First, let's create a toy example with the `extractors` module:
recording, sorting_true = se.example_datasets.toy_example(duration=10, num_channels=4, seed=0)
##############################################################################
# Let's run some spike sorting:
import spikeinterface.sorters as ss
sorting_MS4 = ss.run_mountainsort4(recording)
sorting_KL = ss.run_klusta(recording)
##############################################################################
# Widgets using SortingComparison
# ---------------------------------
#
# We can compare the spike sorting output to the ground-truth sorting :code:`sorting_true` using the
# :code:`comparison` module. :code:`comp_MS4` and :code:`comp_KL` are :code:`SortingComparison` objects
import spikeinterface.comparison as sc
comp_MS4 = sc.compare_sorter_to_ground_truth(sorting_true, sorting_MS4)
comp_KL = sc.compare_sorter_to_ground_truth(sorting_true, sorting_KL)
##############################################################################
# plot_confusion_matrix()
import spikeinterface.extractors as se
import spikeinterface.sorters as sorters
import spikeinterface.comparison as sc
import spikeinterface.widgets as sw
##############################################################################
# First, let's create a toy example:
recording, sorting = se.example_datasets.toy_example(num_channels=4, duration=20, seed=0)
#############################################################################
# Then run 3 spike sorters and compare their ouput.
sorting_KL = sorters.run_klusta(recording)
sorting_MS4 = sorters.run_mountainsort4(recording)
sorting_TDC = sorters.run_tridesclous(recording)
#############################################################################
# Compare multiple spike sorter outputs
# -------------------------------------------
mcmp = sc.compare_multiple_sorters(sorting_list=[sorting_KL, sorting_MS4, sorting_TDC],
name_list=['KL', 'MS4', 'TDC'], verbose=True)
#############################################################################
# The multiple sorters comparison internally computes pairwise comparison,
# that can be accessed as follows:
print(mcmp.comparisons[0].sorting1, mcmp.comparisons[0].sorting2)
mcmp.comparisons[0].get_mapped_sorting1().get_mapped_unit_ids()
import spikeinterface.extractors as se
import spikeinterface.sorters as sorters
import spikeinterface.comparison as sc
##############################################################################
# First, let's create a toy example:
recording, sorting = se.example_datasets.toy_example(num_channels=4, duration=10, seed=0)
#############################################################################
# Then run two spike sorters and compare their ouput.
sorting_KL = sorters.run_klusta(recording)
sorting_MS4 = sorters.run_mountainsort4(recording)
#############################################################################
# The :code:`compare_two_sorters` function allows us to compare the spike
# sorting output. It returns a :code:`SortingComparison` object, with methods
# to inspect the comparison output easily. The comparison matches the
# units by comparing the agreement between unit spike trains.
#
# Let’s see how to inspect and access this matching.
cmp_KL_MS4 = sc.compare_two_sorters(sorting1=sorting_KL, sorting2=sorting_MS4,
sorting1_name='klusta', sorting2_name='ms4')
#############################################################################
# In order to check which units were matched, the :code:`get_mapped_sorting`
# methods can be used. If units are not matched they are listed as -1.
print('Available sorters', ss.available_sorters())
print('Installed sorters', ss.installed_sorter_list)
##############################################################################
# The :code:`ss.installed_sorter_list` will list the sorters installed in the machine. Each spike sorter
# is implemented as a class. We can see we have Klusta and Mountainsort4 installed.
# Spike sorters come with a set of parameters that users can change. The available parameters are dictionaries and
# can be accessed with:
print(ss.get_default_params('mountainsort4'))
print(ss.get_default_params('klusta'))
##############################################################################
# Let's run mountainsort4 and change one of the parameter, the detection_threshold:
sorting_MS4 = ss.run_mountainsort4(recording=recording_cmr, detect_threshold=6)
##############################################################################
# Alternatively we can pass full dictionary containing the parameters:
ms4_params = ss.get_default_params('mountainsort4')
ms4_params['detect_threshold'] = 4
ms4_params['curation'] = False
# parameters set by params dictionary
sorting_MS4_2 = ss.run_mountainsort4(recording=recording, **ms4_params)
##############################################################################
# Let's run Klusta as well, with default parameters:
sorting_KL = ss.run_klusta(recording=recording_cmr)
##############################################################################
# Parameters can be changed either by passing a full dictionary, or by
# passing single arguments.
# Mountainsort4 spike sorting
default_ms4_params['detect_threshold'] = 4
default_ms4_params['curation'] = False
# parameters set by params dictionary
sorting_MS4 = ss.run_mountainsort4(recording=recording, **default_ms4_params,
output_folder='tmp_MS4')
##############################################################################
# parameters set by params dictionary
sorting_MS4_10 = ss.run_mountainsort4(recording=recording, detect_threshold=10,
output_folder='tmp_MS4')
##############################################################################
print('Units found with threshold = 4:', sorting_MS4.get_unit_ids())
print('Units found with threshold = 10:', sorting_MS4_10.get_unit_ids())
# -----------------------------------
#
default_ms4_params = ss.Mountainsort4Sorter.default_params()
print(default_ms4_params)
##############################################################################
# Parameters can be changed either by passing a full dictionary, or by
# passing single arguments.
# Mountainsort4 spike sorting
default_ms4_params['detect_threshold'] = 4
default_ms4_params['curation'] = False
# parameters set by params dictionary
sorting_MS4 = ss.run_mountainsort4(recording=recording, **default_ms4_params,
output_folder='tmp_MS4')
##############################################################################
# parameters set by params dictionary
sorting_MS4_10 = ss.run_mountainsort4(recording=recording, detect_threshold=10,
output_folder='tmp_MS4')
##############################################################################
print('Units found with threshold = 4:', sorting_MS4.get_unit_ids())
print('Units found with threshold = 10:', sorting_MS4_10.get_unit_ids())
print(ss.get_default_params('klusta'))
##############################################################################
# Let's run mountainsort4 and change one of the parameter, the detection_threshold:
sorting_MS4 = ss.run_mountainsort4(recording=recording_cmr, detect_threshold=6)
##############################################################################
# Alternatively we can pass full dictionary containing the parameters:
ms4_params = ss.get_default_params('mountainsort4')
ms4_params['detect_threshold'] = 4
ms4_params['curation'] = False
# parameters set by params dictionary
sorting_MS4_2 = ss.run_mountainsort4(recording=recording, **ms4_params)
##############################################################################
# Let's run Klusta as well, with default parameters:
sorting_KL = ss.run_klusta(recording=recording_cmr)
##############################################################################
# The :code:`sorting_MS4` and :code:`sorting_MS4` are :code:`SortingExtractor` objects. We can print the units found using:
print('Units found by Mountainsort4:', sorting_MS4.get_unit_ids())
print('Units found by Klusta:', sorting_KL.get_unit_ids())
##############################################################################
# Once we have paired :code:`RecordingExtractor` and :code:`SortingExtractor` objects we can post-process, validate, and curate the
# results. With the :code:`toolkit.postprocessing` submodule, one can, for example, get waveforms, templates, maximum