Loading SpikeSorting Data

Spikesorted output of electrophysiology data.

Relevant Alf objects

  • channels

  • clusters

  • spikes

Loading

[2]:
from one.api import ONE
from brainbox.io.one import SpikeSortingLoader
from ibllib.atlas import AllenAtlas

one = ONE()
ba = AllenAtlas()
pid = 'da8dfec1-d265-44e8-84ce-6ae9c109b8bd'

sl = SpikeSortingLoader(pid=pid, one=one, atlas=ba)
spikes, clusters, channels = sl.load_spike_sorting()
clusters = sl.merge_clusters(spikes, clusters, channels)

More details

Important information

  1. Data sorted with pykilosort is loaded by default. If the pykilosort spikesorting data is not available, the matlab kilosort 2.5 version will be loaded. See Example 1 for more information.

  2. The channel locations in the brain can come from several sources. it will load the most advanced version of the histology available, regardless of the spike sorting version loaded. The steps, from most to least advanced, are:

    • alf: the final version of channel locations, same as resolved with the difference that data has been written out to files

    • resolved: channel location alignments have been agreed upon

    • aligned: channel locations have been aligned, but review or other alignments are pending, potentially not accurate

    • traced: the histology track has been recovered from microscopy, however the depths may not match, inacurate data

  3. The attributes mlapdv, atlas_ids and acronyms in the clusters and channels objects are only available for probe insertions where sl.histology is equal to traced, aligned, resolved or alf.

  4. The cluster and channel locations in the brain are only considered final for probe insertions with sl.histology='resolved'or sl.histology='alf'.

Useful modules

Exploring spikesorting data

Example 1: Loading different spikesorting versions

[3]:
# By default, if available, the data spikesorted with pykilosort is loaded.
# To find the spikesorting version that is loaded we can use
sl.collection

# To see all available spikesorted data for this probe insertion we can list the collections.
# N.B. ks2.5 matlab spikesorted data is stored in the alf/probe00 folder
sl.collections

# The following can be used to load a specific version of spikesorting

# pykilosort version
spikes, clusters, channels = sl.load_spike_sorting(spike_sorter='pykilosort')

# ks2.5 matlab version
spikes, clusters, channels = sl.load_spike_sorting(spike_sorter='')

Example 2: Loading additional data

[4]:
# The default spikes and cluster attributes loaded are:
# spikes - amps, clusters, depths, times
# cluster - channels, depths, metrics

#Other attributes can additionally be loaded in the following way
spikes, clusters, channels = sl.load_spike_sorting(dataset_types=['clusters.amps', 'spikes.samples'])
clusters = sl.merge_clusters(spikes, clusters, channels)

Example 3: Compute firing rate across session

[5]:
from brainbox.ephys_plots import image_fr_plot
from brainbox.processing import bincount2D
import numpy as np

time_bin = 0.05 # time bin in seconds
depth_bin = 10 # depth bin in um

# Remove any nan values
kp_idx = np.bitwise_and(~np.isnan(spikes['times']), ~np.isnan(spikes['depths']))

fr, time, depth = bincount2D(spikes['times'][kp_idx], spikes['depths'][kp_idx], time_bin, depth_bin)

Example 4: Find clusters labelled as good

[6]:
good_clusterIDs = clusters['cluster_id'][clusters['label'] == 1]

Other relevant examples

  • COMING SOON