brainbox.io.spikeglx

Functions

extract_waveforms

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

extract_waveforms(ephys_file, ts, ch, t=2.0, sr=30000, n_ch_probe=385, dtype='int16', offset=0, 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.

  • dtype (str (optional)) – The datatype represented by the bytes in ephys_file.

  • offset (int (optional)) – The offset (in bytes) from the start of ephys_file.

  • 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 alf.io as aio
    >>> 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 = aio.load_object(path_to_alf_out, 'clusters')
    >>> spks_b = aio.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)