How to use spikeinterface - 10 common examples

To help you get started, we’ve selected a few spikeinterface examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SpikeInterface / spikeinterface / tests / test_imports.py View on Github external
def test_import():
    import spikeinterface.extractors as se
    import spikeinterface.toolkit as st
    import spikeinterface.sorters as ss
    import spikeinterface.comparison as sc
    import spikeinterface.widgets as sw

    # se
    recording, sorting_true = se.example_datasets.toy_example(duration=60, num_channels=4, seed=0)

    # st
    rec_f = st.preprocessing.bandpass_filter(recording)

    # ss
    print(ss.available_sorters())

    # sc
    sc.compare_two_sorters(sorting_true, sorting_true)

    # sw
    sw.plot_timeseries(rec_f)
github SpikeInterface / spikeinterface / tests / test_imports.py View on Github external
def test_import():
    import spikeinterface.extractors as se
    import spikeinterface.toolkit as st
    import spikeinterface.sorters as ss
    import spikeinterface.comparison as sc
    import spikeinterface.widgets as sw

    # se
    recording, sorting_true = se.example_datasets.toy_example(duration=60, num_channels=4, seed=0)

    # st
    rec_f = st.preprocessing.bandpass_filter(recording)

    # ss
    print(ss.available_sorters())

    # sc
    sc.compare_two_sorters(sorting_true, sorting_true)

    # sw
    sw.plot_timeseries(rec_f)
github SpikeInterface / spikeinterface / tests / test_imports.py View on Github external
import spikeinterface.widgets as sw

    # se
    recording, sorting_true = se.example_datasets.toy_example(duration=60, num_channels=4, seed=0)

    # st
    rec_f = st.preprocessing.bandpass_filter(recording)

    # ss
    print(ss.available_sorters())

    # sc
    sc.compare_two_sorters(sorting_true, sorting_true)

    # sw
    sw.plot_timeseries(rec_f)
github SpikeInterface / spikeinterface / tests / test_imports.py View on Github external
import spikeinterface.toolkit as st
    import spikeinterface.sorters as ss
    import spikeinterface.comparison as sc
    import spikeinterface.widgets as sw

    # se
    recording, sorting_true = se.example_datasets.toy_example(duration=60, num_channels=4, seed=0)

    # st
    rec_f = st.preprocessing.bandpass_filter(recording)

    # ss
    print(ss.available_sorters())

    # sc
    sc.compare_two_sorters(sorting_true, sorting_true)

    # sw
    sw.plot_timeseries(rec_f)
github SpikeInterface / spikeinterface / examples / modules / comparison / generate_erroneous_sorting.py View on Github external
def generate_erroneous_sorting():
    rec, sorting_true = se.example_datasets.toy_example(num_channels=4, duration=10, seed=10)
    
    sorting_err = se.NumpySortingExtractor()
    sorting_err.set_sampling_frequency(sorting_true.get_sampling_frequency())
    
    # sorting_true have 10 units
    np.random.seed(0)
    
    # unit 1 2 are perfect
    for u in [1, 2]:
        st = sorting_true.get_unit_spike_train(u)
        sorting_err.add_unit(u, st)

    # unit 3 4 (medium) 10 (low) have medium to low agreement
    for u, score in [(3, 0.8),  (4, 0.75), (10, 0.3)]:
        st = sorting_true.get_unit_spike_train(u)
        st = np.sort(np.random.choice(st, size=int(st.size*score), replace=False))
github SpikeInterface / spikeinterface / examples / modules / comparison / generate_erroneous_sorting.py View on Github external
nframes = rec.get_num_frames()
    for u in [15,16,17]:
        st = np.random.randint(0, high=nframes, size=35)
        sorting_err.add_unit(u, st)
        
    
    
    return sorting_true, sorting_err
    


    
if __name__ == '__main__':
    # just for check
    sorting_true, sorting_err = generate_erroneous_sorting()
    comp = sc.compare_sorter_to_ground_truth(sorting_true, sorting_err, exhaustive_gt=True)
    sw.plot_agreement_matrix(comp, ordered=True)
    plt.show()
github SpikeInterface / spikeinterface / examples / modules / comparison / generate_erroneous_sorting.py View on Github external
for u in [15,16,17]:
        st = np.random.randint(0, high=nframes, size=35)
        sorting_err.add_unit(u, st)
        
    
    
    return sorting_true, sorting_err
    


    
if __name__ == '__main__':
    # just for check
    sorting_true, sorting_err = generate_erroneous_sorting()
    comp = sc.compare_sorter_to_ground_truth(sorting_true, sorting_err, exhaustive_gt=True)
    sw.plot_agreement_matrix(comp, ordered=True)
    plt.show()
github SpikeInterface / spikeinterface / examples / modules / widgets / plot_3_recsort_gallery.py View on Github external
'''
RecordingExtractor+SortingExtractor Widgets Gallery
===================================================

Here is a gallery of all the available widgets using a pair of RecordingExtractor-SortingExtractor objects.
'''

import spikeinterface.extractors as se
import spikeinterface.widgets as sw

##############################################################################
# First, let's create a toy example with the `extractors` module:

recording, sorting = se.example_datasets.toy_example(duration=10, num_channels=4, seed=0)

##############################################################################
# plot_unit_waveforms()
# ~~~~~~~~~~~~~~~~~~~~~~~~

w_wf = sw.plot_unit_waveforms(recording, sorting, max_num_waveforms=100)

##############################################################################
# plot_amplitudes_distribution()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

w_ampd = sw.plot_amplitudes_distribution(recording, sorting, max_num_waveforms=300)

##############################################################################
# plot_amplitudes_timeseres()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
github SpikeInterface / spikeinterface / examples / getting_started / plot_getting_started.py View on Github external
# - :code:`toolkit` : processing toolkit for pre-, post-processing, validation, and automatic curation
# - :code:`sorters` : Python wrappers of spike sorters
# - :code:`comparison` : comparison of spike sorting output
# - :code:`widgets` : visualization


import spikeinterface.extractors as se
import spikeinterface.toolkit as st
import spikeinterface.sorters as ss
import spikeinterface.comparison as sc
import spikeinterface.widgets as sw

##############################################################################
# First, let's create a toy example with the :code:`extractors` module:

recording, sorting_true = se.example_datasets.toy_example(duration=10, num_channels=4, seed=0)

##############################################################################
# :code:`recording` is a :code:`RecordingExtractor` object, which extracts information about channel ids, channel locations
# (if present), the sampling frequency of the recording, and the extracellular  traces. :code:`sorting_true` is a
# :code:`SortingExtractor` object, which contains information about spike-sorting related information,  including unit ids,
# spike trains, etc. Since the data are simulated, :code:`sorting_true` has ground-truth information of the spiking
# activity of each unit.
#
# Let's use the :code:`widgets` module to visualize the traces and the raster plots.

w_ts = sw.plot_timeseries(recording, trange=[0,5])
w_rs = sw.plot_rasters(sorting_true, trange=[0,5])

##############################################################################
# This is how you retrieve info from a :code:`RecordingExtractor`...
github SpikeInterface / spikeinterface / examples / modules / toolkit / plot_1_preprocessing.py View on Github external
Before spike sorting, you may need to preproccess your signals in order to improve the spike sorting performance.
You can do that in SpikeInterface using the :code:`toolkit.preprocessing` submodule.

"""

import numpy as np
import matplotlib.pylab as plt
import scipy.signal

import spikeinterface.extractors as se
import spikeinterface.toolkit as st

##############################################################################
# First, let's create a toy example:

recording, sorting = se.example_datasets.toy_example(num_channels=4, duration=10, seed=0)

##############################################################################
# Apply filters
# -----------------
#  
# Now apply a bandpass filter and a notch filter (separately) to the
# recording extractor. Filters are also RecordingExtractor objects.

recording_bp = st.preprocessing.bandpass_filter(recording, freq_min=300, freq_max=6000)
recording_notch = st.preprocessing.notch_filter(recording, freq=1000, q=10)

##############################################################################
# Now let's plot the power spectrum of non-filtered, bandpass filtered,
# and notch filtered recordings.

f_raw, p_raw = scipy.signal.welch(recording.get_traces(), fs=recording.get_sampling_frequency())