ibllib.dsp.voltage

Module to work with raw voltage traces. Spike sorting pre-processing functions.

Functions

agc

Automatic gain control

decompress_destripe_cbin

From a spikeglx Reader object, decompresses and apply ADC.

destripe

Super Car (super slow also...) - far from being set in stone but a good workflow example

fk

Frequency-wavenumber filter: filters apparent plane-waves velocity

kfilt

Applies a butterworth filter on the 0-axis with tapering / padding

reject_channels

Computes the

reject_channels(x, fs, butt_kwargs=None, threshold=0.6, trx=1)[source]

Computes the

Parameters
  • x – demultiplexed array (ntraces, nsample)

  • fs – sampling frequency (Hz)

  • trx – number of traces each side (1)

  • {'N' (butt kwargs (optional, None), butt_kwargs =) – 4, ‘Wn’: 0.05, ‘btype’: ‘lp’}

  • threshold – r value below which a channel is rejected

Returns

agc(x, wl=0.5, si=0.002, epsilon=1e-08)[source]

Automatic gain control

Parameters
  • x – seismic array (sample last dimension)

  • wl – window length (secs)

  • si – sampling interval (secs)

  • epsilon – whitening (useful mainly for synthetic data)

Returns

fk(x, si=0.002, dx=1, vbounds=None, btype='highpass', ntr_pad=0, ntr_tap=None, lagc=0.5, collection=None, kfilt=None)[source]

Frequency-wavenumber filter: filters apparent plane-waves velocity

Parameters

x – the input array to be filtered. dimension, the filtering is considering

axis=0: spatial dimension, axis=1 temporal dimension. (ntraces, ns) :param si: sampling interval (secs) :param dx: spatial interval (usually meters) :param vbounds: velocity high pass [v1, v2], cosine taper from 0 to 1 between v1 and v2 :param btype: {‘lowpass’, ‘highpass’}, velocity filter : defaults to highpass :param ntr_pad: padding will add ntr_padd mirrored traces to each side :param ntr_tap: taper (if None, set to ntr_pad) :param lagc: length of agc in seconds. If set to None or 0, no agc :param kfilt: optional (None) if kfilter is applied, parameters as dict (bounds are in m-1 according to the dx parameter) kfilt = {‘bounds’: [0.05, 0.1], ‘btype’, ‘highpass’} :param collection: vector length ntraces. Each unique value set of traces is a collection on which the FK filter will run separately (shot gaters, receiver gathers) :return:

kfilt(x, collection=None, ntr_pad=0, ntr_tap=None, lagc=300, butter_kwargs=None)[source]

Applies a butterworth filter on the 0-axis with tapering / padding

Parameters

x – the input array to be filtered. dimension, the filtering is considering

axis=0: spatial dimension, axis=1 temporal dimension. (ntraces, ns) :param collection: :param ntr_pad: traces added to each side (mirrored) :param ntr_tap: n traces for apodizatin on each side :param lagc: window size for time domain automatic gain control (no agc otherwise) :param butter_kwargs: filtering parameters: defaults: {‘N’: 3, ‘Wn’: 0.1, ‘btype’: ‘highpass’} :return:

destripe(x, fs, tr_sel=None, neuropixel_version=1, butter_kwargs=None, k_kwargs=None)[source]

Super Car (super slow also…) - far from being set in stone but a good workflow example

Parameters
  • x – demultiplexed array (ntraces, nsample)

  • fs – sampling frequency

  • (optional) (neuropixel_version) – 1 or 2. Useful for the ADC shift correction. If None, no correction is applied

  • tr_sel – index array for the first axis of x indicating the selected traces. On a full workflow, one should scan sparingly the full file to get a robust estimate of the selection. If None, and estimation is done using only the current batch is provided for convenience but should be avoided in production.

  • butter_kwargs – (optional, None) butterworth params, see the code for the defaults dict

  • k_kwargs – (optional, None) K-filter params, see the code for the defaults dict

Returns

x, filtered array

decompress_destripe_cbin(sr, output_file=None, h=None, wrot=None, append=False, nc_out=None, ns2add=0)[source]

From a spikeglx Reader object, decompresses and apply ADC. Saves output as a flat binary file in int16 Production version with optimized FFTs - requires pyfftw

Parameters
  • sr – seismic reader object (spikeglx.Reader)

  • output_file – (optional, defaults to .bin extension of the compressed bin file)

  • h – (optional)

  • wrot – (optional) whitening matrix [nc x nc] or amplitude scalar to apply to the output

  • append – (optional, False) for chronic recordings, append to end of file

  • nc_out – (optional, True) saves non selected channels (synchronisation trace) in output

  • ns2add – (optional) for kilosort, adds padding samples at the end of the file so the total

number of samples is a multiple of the batchsize :return: