cibrrig.preprocess.extract_opto_times

This script extracts the optogenetic stimulation times from the NIDAQ file. It is similar to the extract_frame_times.py script, but it extracts optogenetic stimulation times instead of frame times. The script reads the raw data from the NIDAQ file, processes it to find the optogenetic stimulation times, and saves the results in an ALF file. The script can be run from the command line using the main function, which takes the input path to the NIDAQ file as an argument. The script also provides options to specify the optogenetic channel, voltage threshold, and label for the extracted data.

Attributes

_log

Functions

get_opto_df(raw_opto, v_thresh, ni_sr[, min_dur, max_dur])

Extract optogenetic stimulation events from raw opto data.

get_opto_df_digital(SR, opto_chan)

process_rec(SR, opto_chan[, v_thresh])

Create a DataFrame where each row is an opto pulse.

load_opto_calibration(session_path)

If an opto calibration JSON exists, load it and create a

_load_opto_calibration_fn(calib_fn)

Load the opto calibration function from a file.

get_laser_chans(session_path)

Get the laser channels from the session path.

run_file(ni_fn, opto_chan, v_thresh, calib_fn[, label])

Run the opto extraction process on a single NIDQ.bin file.

run_session(session_path, v_thresh)

Run the opto extraction process on an entire session.

run(input_path[, opto_chan, v_thresh, label, calib])

Run the opto extraction process on the given input path.

main(input_path, opto_chan, v_thresh, label, calib)

Main entry point for the script.

Module Contents

cibrrig.preprocess.extract_opto_times._log[source]
cibrrig.preprocess.extract_opto_times.get_opto_df(raw_opto, v_thresh, ni_sr, min_dur=0.001, max_dur=20)[source]

Extract optogenetic stimulation events from raw opto data.

Parameters:
  • raw_opto (np.ndarray) – Raw current sent to the laser or LED (1V/A).

  • v_thresh (float) – Voltage threshold to find crossing.

  • ni_sr (float) – Sample rate in Hz.

  • min_dur (float, optional) – Minimum stimulation duration in seconds. Defaults to 0.001.

  • max_dur (float, optional) – Maximum stimulation duration in seconds. Defaults to 20.

Returns:

DataFrame with columns ‘on’, ‘off’, ‘durs’, ‘amps’, ‘on_sec’, ‘off_sec’, and ‘dur_sec’.

Return type:

pd.DataFrame

cibrrig.preprocess.extract_opto_times.get_opto_df_digital(SR, opto_chan)[source]
cibrrig.preprocess.extract_opto_times.process_rec(SR, opto_chan, v_thresh=0.5, **kwargs)[source]

Create a DataFrame where each row is an opto pulse. Information about the pulse timing, amplitude, and duration are created.

Parameters:
  • SR (spikeglx.Reader) – SpikeGLX reader object for the recording.

  • opto_chan (int, optional) – Channel number for the opto signal. Defaults to 5.

  • v_thresh (float, optional) – Voltage threshold to find crossing. Defaults to 0.5.

Returns:

DataFrame with columns ‘on_sec’, ‘off_sec’, ‘dur_sec’, and ‘amps’.

Return type:

pd.DataFrame

cibrrig.preprocess.extract_opto_times.load_opto_calibration(session_path)[source]

If an opto calibration JSON exists, load it and create a linear interpolation

Parameters:

session_path (_type_) – _description_

cibrrig.preprocess.extract_opto_times._load_opto_calibration_fn(calib_fn)[source]

Load the opto calibration function from a file. If a calibration file exists, load it and create a linear interpolation function to convert command voltage to light power.

Parameters:

calib_fn (Path) – Path to the calibration file.

Returns:

Interpolation function for the calibration.

Return type:

function

cibrrig.preprocess.extract_opto_times.get_laser_chans(session_path)[source]

Get the laser channels from the session path. Looks for the sync_map and finds the channels that are labeled as laser.

Parameters:

session_path (Path) – Path to the session data.

Returns:

A tuple containing:
  • list: Channels to extract.

  • list: Labels for the channels.

Return type:

tuple

cibrrig.preprocess.extract_opto_times.run_file(ni_fn, opto_chan, v_thresh, calib_fn, label='opto')[source]

Run the opto extraction process on a single NIDQ.bin file.

Parameters:
  • input_path (Path) – Path to the input data file.

  • opto_chan (int) – Channel number for the opto signal.

  • v_thresh (float) – Voltage threshold to find crossing.

  • calib (Path) – Path to the calibration file.

  • label (str) – Label for the channel.

cibrrig.preprocess.extract_opto_times.run_session(session_path, v_thresh)[source]

Run the opto extraction process on an entire session.

Parameters:
  • session_path (Path) – Path to the session data.

  • v_thresh (float) – Voltage threshold above which a stimulation is registered.

cibrrig.preprocess.extract_opto_times.run(input_path, opto_chan=None, v_thresh=0.5, label='laser', calib=None)[source]

Run the opto extraction process on the given input path.

If input path is a session directory, the script will run on all the NIDQ files in the session. If input path is a single file, the script will run on that file.

Parameters:
  • input_path (str) – Path to the input data (file or directory).

  • opto_chan (int, optional) – Channel number for the opto signal. Defaults to None.

  • v_thresh (float, optional) – Voltage threshold to find crossing. Defaults to 0.5.

  • label (str, optional) – Label for the channel. Defaults to “laser”.

  • calib (str, optional) – Path to the calibration file. Defaults to None.

cibrrig.preprocess.extract_opto_times.main(input_path, opto_chan, v_thresh, label, calib)[source]

Main entry point for the script.

Parameters:
  • input_path (str) – Path to the input data (file or directory).

  • opto_chan (int, optional) – Channel number for the opto signal. Defaults to None.

  • v_thresh (float, optional) – Voltage threshold to find crossing. Defaults to 0.5.

  • label (str, optional) – Label for the channel. Defaults to “laser”.

  • calib (str, optional) – Path to the calibration file. Defaults to None.