ibllib.io.spikeglx

class ibllib.io.spikeglx.Reader(sglx_file)

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

compress_file(keep_original=True, **kwargs)

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)

Decompresses a mtscomp file :param keep_original: defaults True. If False, the original compressed file is deleted

and the current spikeglx.Reader object is modified in place
Returns:pathlib.Path of the decompressed *.bin file
fs
Returns:sampling frequency (Hz)
nc
Returns:number of channels
ns
Returns:number of samples
read(nsel=slice(0, 10000, None), csel=slice(None, None, None), sync=True)

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)

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(_slice=slice(0, 10000, None), threshold=1.2)

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 :return: int8 array

read_sync_analog(_slice=slice(0, 10000, None))

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

read_sync_digital(_slice=slice(0, 10000, None))

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

type
Returns:ap, lf or nidq. Useful to index dictionaries
verify_hash()

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

ibllib.io.spikeglx.get_hardware_config(config_file)

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

ibllib.io.spikeglx.glob_ephys_files(session_path, suffix='.meta', recursive=True, bin_exists=True)

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
  • 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’

ibllib.io.spikeglx.read(sglx_file, first_sample=0, last_sample=10000)

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

ibllib.io.spikeglx.read_meta_data(md_file)

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
ibllib.io.spikeglx.split_sync(sync_tr)

The synchronization channelx 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