ibl_alignment_gui.convertors.extract_ephys

Functions

_is_np2

Whether a SpikeGLX file was recorded with a Neuropixels 2.0 probe, read from its metadata.

_process_windows

Compute the RMS and the summed spectral density of windows of a recording.

_rms_windows

Get the first and last sample of each window the RMS is computed on.

_sample2v

Return the factor that converts the raw AP data of a file to Volts.

extract_data

Convert a Kilosort output and its raw data into the datasets the alignment GUI reads.

extract_rmsmap

Write the _ibl_ephysRmsMap and _ibl_ephysSpectra ALF files for a binary file.

ks2_to_alf

Convert Kilosort 2 output to an ALF dataset for single probe data.

rmsmap

Compute the RMS map in the time domain and the spectra for each channel of the probe.

ibl_alignment_gui.convertors.extract_ephys.extract_data(ks_path, ephys_path, out_path)[source]

Convert a Kilosort output and its raw data into the datasets the alignment GUI reads.

Writes the ALF spike sorting datasets, and the RMS and spectral density files for each AP and LF binary file found alongside them. For NP2 recordings without an LF file, as told by their metadata, the LF RMS and spectral density are computed from the AP file.

Parameters:
  • ks_path (pathlib.Path) – Path of the Kilosort output.

  • ephys_path (pathlib.Path) – Path of the raw ephys data.

  • out_path (pathlib.Path) – Path to write the datasets to. Must differ from ks_path so that the Kilosort output is not overwritten.

ibl_alignment_gui.convertors.extract_ephys.extract_rmsmap(fbin, out_folder=None, spectra=True, sample_spacing_secs=10, lfp_from_ap=False, n_workers=4)[source]

Write the _ibl_ephysRmsMap and _ibl_ephysSpectra ALF files for a binary file.

Parameters:
  • fbin (str or pathlib.Path) – Binary file in SpikeGLX format; the attached metadata is looked up alongside it.

  • out_folder (str, pathlib.Path or None) – Folder to write the ALF files to. Defaults to the folder the fbin file lives in.

  • spectra (bool) – Whether to compute the power spectrum, which is only needed for LF data.

  • sample_spacing_secs (float or None) – The RMS and spectra are computed on a sample taken every sample_spacing_secs seconds, which is enough for the plots and reads a fraction of the file. None reads the whole recording.

  • lfp_from_ap (bool) – Whether to compute the LF band from an AP file, for NP2 probes that have no LF file.

  • n_workers (int) – The number of threads the windows are shared between.

Raises:

ValueError – If lfp_from_ap is set for a file that is not from an NP2 probe, whose AP band holds no LFP.

ibl_alignment_gui.convertors.extract_ephys.ks2_to_alf(ks_path, bin_path, out_path, bin_file=None, ampfactor=1, label=None, force=True)[source]

Convert Kilosort 2 output to an ALF dataset for single probe data.

Parameters:
  • ks_path (pathlib.Path) – Path of the Kilosort output.

  • bin_path (pathlib.Path) – Path of the raw data.

  • out_path (pathlib.Path) – Path to write the ALF dataset to.

  • bin_file (pathlib.Path or None) – The specific binary file to read, when the path holds more than one.

  • ampfactor (float) – Factor converting the spike amplitudes to Volts.

  • label (str or None) – Optional label added to the dataset names.

  • force (bool) – Whether to overwrite an existing dataset.

ibl_alignment_gui.convertors.extract_ephys.rmsmap(fbin, spectra=True, sample_spacing_secs=None, lfp_from_ap=False, n_workers=4)[source]

Compute the RMS map in the time domain and the spectra for each channel of the probe.

Parameters:
  • fbin (str, pathlib.Path or spikeglx.Reader) – Binary file in SpikeGLX format; the attached metadata is looked up alongside it.

  • spectra (bool) – Whether to compute the power spectrum, which is only needed for LF data.

  • sample_spacing_secs (float or None) – When given, the RMS and spectra are computed on a sample taken every sample_spacing_secs seconds, of AP_SAMPLE_LENGTH_SECS for the AP band and LF_SAMPLE_LENGTH_SECS for the LF band. When None, the whole recording is read in windows of about RMS_WIN_LENGTH_SECS.

  • lfp_from_ap (bool) – Whether to compute the LF band from an AP file, for NP2 probes that record wideband and have no LF file. The AP data are decimated to the LF sampling rate.

  • n_workers (int) – The number of threads the windows are shared between, each with its own reader. The filtering and FFTs release the GIL, so the threads run in parallel.

Returns:

The RMS amplitudes in channel-time space, the spectral density in channel-frequency space averaged over the windows, the time and frequency scales, and the raw file index of each channel.

Return type:

dict

Notes

The channels are returned in the order they are stored in the binary file, whatever the channel order of the reader, so that they can be indexed with the raw channel indices (channels.rawInd) used by the GUI.

The AP band is destriped before computing the RMS: high-passed at 300 Hz, corrected for the sample shift of the ADCs and re-referenced to the median of the channels of each shank. The LF band is high-passed at 1 Hz.