ibllib.io.spikeglx

Functions

get_hardware_config

Reads the neuropixel_wirings.json file containing sync mapping and parameters :param config_file: folder or json file :return: dictionary or None

get_neuropixel_version_from_files

get_neuropixel_version_from_folder

get_sync_map

glob_ephys_files

From an arbitrary folder (usually session folder) gets the ap and lf files and labels Associated to the subfolders where they are the expected folder tree is: ├── 3A │ ├── imec0 │ ├── sync_testing_g0_t0.imec0.ap.bin │ │ └── sync_testing_g0_t0.imec0.lf.bin │ └── imec1 │ ├── sync_testing_g0_t0.imec1.ap.bin │ └── sync_testing_g0_t0.imec1.lf.bin └── 3B ├── sync_testing_g0_t0.nidq.bin ├── imec0 │ ├── sync_testing_g0_t0.imec0.ap.bin │ └── sync_testing_g0_t0.imec0.lf.bin └── imec1 ├── sync_testing_g0_t0.imec1.ap.bin └── sync_testing_g0_t0.imec1.lf.bin

read

Function to read from a spikeglx binary file without instantiating the class.

read_meta_data

Reads the spkike glx metadata file and parse in a dictionary Agnostic: does not make any assumption on the keys/content, it just parses key=values

split_sync

The synchronization channels are stored as single bits, this will split the int16 original channel into 16 single bits channels

Classes

Reader

Class for SpikeGLX reading purposes Some format description was found looking at the Matlab SDK here https://github.com/billkarsh/SpikeGLX/blob/master/MATLAB-SDK/DemoReadSGLXData.m

class Reader(sglx_file)[source]

Bases: object

Class for SpikeGLX reading purposes Some format description was found looking at the Matlab SDK here https://github.com/billkarsh/SpikeGLX/blob/master/MATLAB-SDK/DemoReadSGLXData.m

property shape
property is_mtscomp
property version

return:

property type

ap, lf or nidq. Useful to index dictionaries

Type

return

property fs

sampling frequency (Hz)

Type

return

property nc

number of channels

Type

return

property ns

number of samples

Type

return

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

Read from slices or indexes :param slice_n: slice or sample indices :param slice_c: slice or channel indices :return: float32 array

read_samples(first_sample=0, last_sample=10000, channels=None)[source]

reads all channels from first_sample to last_sample, following numpy slicing convention sglx.read_samples(first=0, last=100) would be equivalent to slicing the array D D[:,0:100] where the last axis represent time and the first channels.

param first_sample

first sample to be read, python slice-wise

param last_sample

last sample to be read, python slice-wise

param channels

slice or numpy array of indices

return

numpy array of int16

read_sync_digital(_slice=slice(0, 10000, None))[source]

Reads only the digital sync trace at specified samples using slicing syntax >>> sync_samples = sr.read_sync_digital(slice(0,10000))

read_sync_analog(_slice=slice(0, 10000, None))[source]

Reads only the analog sync traces at specified samples using slicing syntax >>> sync_samples = sr.read_sync_analog(slice(0,10000))

read_sync(_slice=slice(0, 10000, None), threshold=1.2, floor_percentile=10)[source]

Reads all sync trace. Convert analog to digital with selected threshold and append to array :param _slice: samples slice :param threshold: (V) threshold for front detection, defaults to 1.2 V :param floor_percentile: 10% removes the percentile value of the analog trace before

thresholding. This is to avoid DC offset drift

Returns

int8 array

compress_file(keep_original=True, **kwargs)[source]

Compresses :param keep_original: defaults True. If False, the original uncompressed file is deleted

and the current spikeglx.Reader object is modified in place

Parameters

kwargs

Returns

pathlib.Path of the compressed *.cbin file

decompress_file(keep_original=True, **kwargs)[source]

Decompresses a mtscomp file :param keep_original: defaults True. If False, the original compressed file (input) is deleted and the current spikeglx.Reader object is modified in place NB: This is not equivalent to overwrite (which replaces the output file) :return: pathlib.Path of the decompressed *.bin file

verify_hash()[source]

Computes SHA-1 hash and returns True if it matches metadata, False otherwise :return: boolean

read(sglx_file, first_sample=0, last_sample=10000)[source]

Function to read from a spikeglx binary file without instantiating the class. Gets the meta-data as well.

>>> ibllib.io.spikeglx.read('/path/to/file.bin', first_sample=0, last_sample=1000)
Parameters
  • sglx_file – full path the the binary file to read

  • first_sample – first sample to be read, python slice-wise

  • last_sample – last sample to be read, python slice-wise

Returns

Data array, sync trace, meta-data

read_meta_data(md_file)[source]

Reads the spkike glx metadata file and parse in a dictionary Agnostic: does not make any assumption on the keys/content, it just parses key=values

Parameters

md_file – last sample to be read, python slice-wise

Returns

Data array, sync trace, meta-data

split_sync(sync_tr)[source]

The synchronization channels are stored as single bits, this will split the int16 original channel into 16 single bits channels

Parameters

sync_tr – numpy vector: samples of synchronisation trace

Returns

int8 numpy array of 16 channels, 1 column per sync trace

get_neuropixel_version_from_folder(session_path)[source]
get_neuropixel_version_from_files(ephys_files)[source]
glob_ephys_files(session_path, suffix='.meta', ext='bin', recursive=True, bin_exists=True)[source]

From an arbitrary folder (usually session folder) gets the ap and lf files and labels Associated to the subfolders where they are the expected folder tree is: ├── 3A │ ├── imec0 │ ├── sync_testing_g0_t0.imec0.ap.bin │ │ └── sync_testing_g0_t0.imec0.lf.bin │ └── imec1 │ ├── sync_testing_g0_t0.imec1.ap.bin │ └── sync_testing_g0_t0.imec1.lf.bin └── 3B

├── sync_testing_g0_t0.nidq.bin ├── imec0 │ ├── sync_testing_g0_t0.imec0.ap.bin │ └── sync_testing_g0_t0.imec0.lf.bin └── imec1

├── sync_testing_g0_t0.imec1.ap.bin └── sync_testing_g0_t0.imec1.lf.bin

Parameters
  • bin_exists

  • suffix

  • ext – file extension to look for, default ‘bin’ but could also be ‘meta’ or ‘ch’

  • recursive

  • session_path – folder, string or pathlib.Path

  • glob_pattern – pattern to look recursively for (defaults to ‘*.ap.*bin)

Returns

a list of dictionaries with keys ‘ap’: apfile, ‘lf’: lffile and ‘label’

get_hardware_config(config_file)[source]

Reads the neuropixel_wirings.json file containing sync mapping and parameters :param config_file: folder or json file :return: dictionary or None

get_sync_map(folder_ephys)[source]