ibllib.ephys.ephysqc

Quality control of raw Neuropixel electrophysiology data.

Functions

extract_rmsmap

Wrapper for rmsmap that outputs _ibl_ephysRmsMap and _ibl_ephysSpectra ALF files

phy_model_from_ks2_path

qc_fpga_task

:fpga_task is the dictionary output of ibllib.io.extractors.ephys_fpga.extract_behaviour_sync : bpod_trials is the dictionary output of ibllib.io.extractors.ephys_trials.extract_all : alf_trials is the ALF _ibl_trials object after extraction (alfio.load_object) :return: qc_session, qc_trials, True means QC passes while False indicates a failure

raw_qc_session

Wrapper that exectutes QC from a session folder and outputs the results whithin the same folder as the original raw data.

rmsmap

Computes RMS map in time domain and spectra for each channel of Neuropixel probe

spike_sorting_metrics_ks2

Given a path containing kilosort 2 output, compute quality metrics and optionally save them to a clusters_metric.csv file

validate_ttl_test

For a mock session on the Ephys Choice world task, check the sync channels for all device properly connected and perform a synchronization if dual probes to check that all channels are recorded properly

Classes

EphysQC

A class for computing Ephys QC metrics.

class EphysQC(probe_id, session_path=None, **kwargs)[source]

Bases: QC

A class for computing Ephys QC metrics.

Parameters:
  • probe_id – An existing and registered probe insertion ID.

  • one – An ONE instance pointing to the database the probe_id is registered with. Optional, will instantiate

default database if not given.

load_data(ensure=True) None[source]

Load any locally available data.

run(update: bool = False, overwrite: bool = True, stream: bool = None, **kwargs) -> (<class 'str'>, <class 'dict'>)[source]

Run QC on samples of the .ap file, and on the entire file for .lf data if it is present.

Parameters:
  • update – bool, whether to update the qc json fields for this probe. Default is False.

  • overwrite – bool, whether to overwrite locally existing outputs of this function. Default is False.

  • stream – bool, whether to stream the samples of the .ap data if not locally available. Defaults to value

set in class init (True if none set). :return: A list of QC output files. In case of a complete run that is one file for .ap and three files for .lf.

rmsmap(sglx, spectra=True, nmod=1)[source]

Computes RMS map in time domain and spectra for each channel of Neuropixel probe

Parameters:
  • sglx – Open spikeglx reader

  • spectra – Whether to compute the spectra

  • nmod – take every nmod windows, in cases where we don’t want to compute over the whole signal

Returns:

a dictionary with amplitudes in channeltime space, channelfrequency space, time and frequency scales

extract_rmsmap(sglx, out_folder=None, overwrite=False, spectra=True, nmod=1)[source]

Wrapper for rmsmap that outputs _ibl_ephysRmsMap and _ibl_ephysSpectra ALF files

Parameters:
  • sglx – Open spikeglx Reader with data for which to compute rmsmap

  • out_folder – folder in which to store output ALF files. Default uses the folder in which the fbin file lives.

  • overwrite – do not re-extract if all ALF files already exist

  • spectra – Whether to compute the spectral density across the signal

  • nmod – take every nmod windows, in cases where we don’t want to compute over the whole signal

Returns:

None

raw_qc_session(session_path, overwrite=False)[source]

Wrapper that exectutes QC from a session folder and outputs the results whithin the same folder as the original raw data.

Parameters:
  • session_path – path of the session (Subject/yyyy-mm-dd/number

  • overwrite – bool (False) Force means overwriting an existing QC file

Returns:

None

validate_ttl_test(ses_path, display=False)[source]

For a mock session on the Ephys Choice world task, check the sync channels for all device properly connected and perform a synchronization if dual probes to check that all channels are recorded properly

Parameters:
  • ses_path – session path

  • display – show the probe synchronization plot if several probes

Returns:

True if tests pass, errors otherwise

spike_sorting_metrics_ks2(ks2_path=None, m=None, save=True, save_path=None)[source]

Given a path containing kilosort 2 output, compute quality metrics and optionally save them to a clusters_metric.csv file

Parameters:

ks2_path

:param save :param save_path: If not given will save into the path given as ks2_path :return:

phy_model_from_ks2_path(ks2_path, bin_path, bin_file=None)[source]
qc_fpga_task(fpga_trials, alf_trials)[source]

:fpga_task is the dictionary output of ibllib.io.extractors.ephys_fpga.extract_behaviour_sync : bpod_trials is the dictionary output of ibllib.io.extractors.ephys_trials.extract_all : alf_trials is the ALF _ibl_trials object after extraction (alfio.load_object) :return: qc_session, qc_trials, True means QC passes while False indicates a failure