brainbox.io.spikeglx

Functions

extract_waveforms

Extracts spike waveforms from binary ephys data file, after (optionally) common-average-referencing (CAR) spatial noise.

Classes

Streamer

pid = 'e31b4e39-e350-47a9-aca4-72496d99ff2a' one = ONE() sr = Streamer(pid=pid, one=one) raw_voltage = sr[int(t0 * sr.fs):int((t0 + nsecs) * sr.fs), :]

extract_waveforms(ephys_file, ts, ch, t=2.0, sr=30000, n_ch_probe=385, car=True)[source]

Extracts spike waveforms from binary ephys data file, after (optionally) common-average-referencing (CAR) spatial noise.

Parameters:
  • ephys_file (string) – The file path to the binary ephys data.

  • ts (ndarray_like) – The timestamps (in s) of the spikes.

  • ch (ndarray_like) – The channels on which to extract the waveforms.

  • t (numeric (optional)) – The time (in ms) of each returned waveform.

  • sr (int (optional)) – The sampling rate (in hz) that the ephys data was acquired at.

  • n_ch_probe (int (optional)) – The number of channels of the recording.

  • car (bool (optional)) – A flag to perform CAR before extracting waveforms.

Returns:

waveforms – An array of shape (#spikes, #samples, #channels) containing the waveforms.

Return type:

ndarray

Examples

  1. Extract all the waveforms for unit1 with and without CAR.
    >>> import numpy as np
    >>> import brainbox as bb
    >>> import one.alf.io as alfio
    >>> import ibllib.ephys.spikes as e_spks
    (*Note, if there is no 'alf' directory, make 'alf' directory from 'ks2' output directory):
    >>> e_spks.ks2_to_alf(path_to_ks_out, path_to_alf_out)
    # Get a clusters bunch and a units bunch from a spikes bunch from an alf directory.
    >>> clstrs_b = alfio.load_object(path_to_alf_out, 'clusters')
    >>> spks_b = alfio.load_object(path_to_alf_out, 'spikes')
    >>> units_b = bb.processing.get_units_bunch(spks, ['times'])
    # Get the timestamps and 20 channels around the max amp channel for unit1, and extract the
    # two sets of waveforms.
    >>> ts = units_b['times']['1']
    >>> max_ch = max_ch = clstrs_b['channels'][1]
    >>> if max_ch < 10:  # take only channels greater than `max_ch`.
    >>>     ch = np.arange(max_ch, max_ch + 20)
    >>> elif (max_ch + 10) > 385:  # take only channels less than `max_ch`.
    >>>     ch = np.arange(max_ch - 20, max_ch)
    >>> else:  # take `n_c_ch` around `max_ch`.
    >>>     ch = np.arange(max_ch - 10, max_ch + 10)
    >>> wf = bb.io.extract_waveforms(path_to_ephys_file, ts, ch, car=False)
    >>> wf_car = bb.io.extract_waveforms(path_to_ephys_file, ts, ch, car=True)
    
class Streamer(pid, one, typ='ap', cache_folder=None, remove_cached=False)[source]

Bases: Reader

pid = ‘e31b4e39-e350-47a9-aca4-72496d99ff2a’ one = ONE() sr = Streamer(pid=pid, one=one) raw_voltage = sr[int(t0 * sr.fs):int((t0 + nsecs) * sr.fs), :]

read(nsel=slice(0, 10000, None), csel=slice(None, None, None), sync=True, volts=True)[source]

overload the read function by downloading the necessary chunks