Quick benchmarck with new API and new sorters (april 2021)
Quick benchmark with new spikeinetrface API with new sorters¶
In spring 2021 the spikeinterface is refactored deeply.
During this refactoring some sorters have been added.
Here quick benchmark with one simulated dataset with MEArec.
In [7]:
%matplotlib inline
In [8]:
from pathlib import Path
import os
import shutil
from pprint import pprint
import getpass
import numpy as np
import matplotlib.pyplot as plt
import MEArec as mr
import neo
import quantities as pq
import spikeinterface.extractors as se
import spikeinterface.widgets as sw
import spikeinterface.sorters as ss
from spikeinterface.comparison import GroundTruthStudy
In [9]:
basedir = '/mnt/data/sam/DataSpikeSorting/'
basedir = Path(basedir)
workdir = basedir / 'mearec_bench_2021'
study_folder = workdir /'study_mearec_march_2021'
tmp_folder = workdir / 'tmp'
tmp_folder.mkdir(parents=True, exist_ok=True)
generate recording with mearec¶
In [ ]:
template_filename = workdir / 'templates_Neuronexus-32_100.h5'
probe = 'Neuronexus-32'
n_cell = 15
duration = 10 * 60.
recording_filename = workdir / f'recordings_{n_cell}cells_{probe}_{duration:0.0f}s.h5'
fs = 30000.
#~ spgen = mr.SpikeTrainGenerator()
rec_params = mr.get_default_recordings_params()
rec_params['recordings']['fs'] = fs
rec_params['recordings']['sync_rate'] = None
rec_params['recordings']['sync_jitter'] = 5
rec_params['recordings']['noise_level'] = 5
rec_params['recordings']['filter'] = False
rec_params['recordings']['chunk_duration'] = 10.
rec_params['spiketrains']['duration'] = duration
rec_params['spiketrains']['n_exc'] = n_cell
rec_params['spiketrains']['n_inh'] = 0
rec_params['templates']['n_overlap_pairs'] = None
rec_params['templates']['min_dist'] = 0
recgen = mr.gen_recordings(params=rec_params, #spgen=spgen,
templates=template_filename, verbose=True,
n_jobs=1, tmp_mode='memmap',
tmp_folder=str(tmp_folder))
mr.save_recording_generator(recgen, filename=recording_filename)
set sorter path¶
In [3]:
user = getpass.getuser()
kilosort_path = f'/home/{user}/Documents/SpikeInterface/code_sorters/KiloSort1'
ss.KilosortSorter.set_kilosort_path(kilosort_path)
kilosort2_path = f'/home/{user}/Documents/SpikeInterface/code_sorters/Kilosort2'
ss.Kilosort2Sorter.set_kilosort2_path(kilosort2_path)
kilosort2_5_path = f'/home/{user}/Documents/SpikeInterface/code_sorters/Kilosort2.5'
ss.Kilosort2_5Sorter.set_kilosort2_5_path(kilosort2_path)
kilosort3_path = f'/home/{user}/Documents/SpikeInterface/code_sorters/Kilosort3'
ss.Kilosort3Sorter.set_kilosort3_path(kilosort3_path)
ironclust_path = f'/home/{user}/Documents/SpikeInterface/code_sorters/ironclust/'
ss.IronClustSorter.set_ironclust_path(ironclust_path)
create study¶
In [6]:
mearec_filename = workdir / 'recordings_15cells_Neuronexus-32_600s.h5'
if study_folder.is_dir():
shutil.rmtree(study_folder)
rec = se.MEArecRecordingExtractor(mearec_filename)
sorting_gt = se.MEArecSortingExtractor(mearec_filename)
print(rec)
print(sorting_gt)
gt_dict = {'rec0' : (rec, sorting_gt) }
study = GroundTruthStudy.create(study_folder, gt_dict)
plot probe¶
In [14]:
study = GroundTruthStudy(study_folder)
rec = study.get_recording()
probe = rec.get_probe()
print(probe)
from probeinterface.plotting import plot_probe
plot_probe(probe)
Out[14]:
run sorters¶
In [ ]:
sorter_list = ['spykingcircus', 'kilosort2', 'kilosort3', 'tridesclous']
study = GroundTruthStudy(study_folder)
study.run_sorters(sorter_list, mode_if_folder_exists='overwrite', verbose=False)
study.copy_sortings()
collect results¶
In [4]:
study = GroundTruthStudy(study_folder)
study.copy_sortings()
study.run_comparisons(exhaustive_gt=True, delta_time=1.5)
comparisons = study.comparisons
dataframes = study.aggregate_dataframes()
In [10]:
for (rec_name, sorter_name), comp in comparisons.items():
print()
print('*'*20)
print(rec_name, sorter_name)
print(comp.count_score)
Agreement matrix¶
In [11]:
for (rec_name, sorter_name), comp in comparisons.items():
fig, ax = plt.subplots()
sw.plot_agreement_matrix(comp, ax=ax)
fig.suptitle(rec_name+' '+ sorter_name)
Accuracy vs SNR¶
In [ ]: