cibrrig.preprocess.extract_opto_times ===================================== .. py:module:: cibrrig.preprocess.extract_opto_times .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: cibrrig.preprocess.extract_opto_times._log Functions --------- .. autoapisummary:: cibrrig.preprocess.extract_opto_times.get_opto_df cibrrig.preprocess.extract_opto_times.get_opto_df_digital cibrrig.preprocess.extract_opto_times.process_rec cibrrig.preprocess.extract_opto_times.load_opto_calibration cibrrig.preprocess.extract_opto_times._load_opto_calibration_fn cibrrig.preprocess.extract_opto_times.get_laser_chans cibrrig.preprocess.extract_opto_times.run_file cibrrig.preprocess.extract_opto_times.run_session cibrrig.preprocess.extract_opto_times.run cibrrig.preprocess.extract_opto_times.main Module Contents --------------- .. py:data:: _log .. py:function:: get_opto_df(raw_opto, v_thresh, ni_sr, min_dur=0.001, max_dur=20) Extract optogenetic stimulation events from raw opto data. :param raw_opto: Raw current sent to the laser or LED (1V/A). :type raw_opto: np.ndarray :param v_thresh: Voltage threshold to find crossing. :type v_thresh: float :param ni_sr: Sample rate in Hz. :type ni_sr: float :param min_dur: Minimum stimulation duration in seconds. Defaults to 0.001. :type min_dur: float, optional :param max_dur: Maximum stimulation duration in seconds. Defaults to 20. :type max_dur: float, optional :returns: DataFrame with columns 'on', 'off', 'durs', 'amps', 'on_sec', 'off_sec', and 'dur_sec'. :rtype: pd.DataFrame .. py:function:: get_opto_df_digital(SR, opto_chan) .. py:function:: process_rec(SR, opto_chan, v_thresh=0.5, **kwargs) Create a DataFrame where each row is an opto pulse. Information about the pulse timing, amplitude, and duration are created. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :param opto_chan: Channel number for the opto signal. Defaults to 5. :type opto_chan: int, optional :param v_thresh: Voltage threshold to find crossing. Defaults to 0.5. :type v_thresh: float, optional :returns: DataFrame with columns 'on_sec', 'off_sec', 'dur_sec', and 'amps'. :rtype: pd.DataFrame .. py:function:: load_opto_calibration(session_path) If an opto calibration JSON exists, load it and create a linear interpolation :param session_path: _description_ :type session_path: _type_ .. py:function:: _load_opto_calibration_fn(calib_fn) 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. :param calib_fn: Path to the calibration file. :type calib_fn: Path :returns: Interpolation function for the calibration. :rtype: function .. py:function:: get_laser_chans(session_path) Get the laser channels from the session path. Looks for the sync_map and finds the channels that are labeled as laser. :param session_path: Path to the session data. :type session_path: Path :returns: A tuple containing: - list: Channels to extract. - list: Labels for the channels. :rtype: tuple .. py:function:: run_file(ni_fn, opto_chan, v_thresh, calib_fn, label='opto') Run the opto extraction process on a single NIDQ.bin file. :param input_path: Path to the input data file. :type input_path: Path :param opto_chan: Channel number for the opto signal. :type opto_chan: int :param v_thresh: Voltage threshold to find crossing. :type v_thresh: float :param calib: Path to the calibration file. :type calib: Path :param label: Label for the channel. :type label: str .. py:function:: run_session(session_path, v_thresh) Run the opto extraction process on an entire session. :param session_path: Path to the session data. :type session_path: Path :param v_thresh: Voltage threshold above which a stimulation is registered. :type v_thresh: float .. py:function:: run(input_path, opto_chan=None, v_thresh=0.5, label='laser', calib=None) 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. :param input_path: Path to the input data (file or directory). :type input_path: str :param opto_chan: Channel number for the opto signal. Defaults to None. :type opto_chan: int, optional :param v_thresh: Voltage threshold to find crossing. Defaults to 0.5. :type v_thresh: float, optional :param label: Label for the channel. Defaults to "laser". :type label: str, optional :param calib: Path to the calibration file. Defaults to None. :type calib: str, optional .. py:function:: main(input_path, opto_chan, v_thresh, label, calib) Main entry point for the script. :param input_path: Path to the input data (file or directory). :type input_path: str :param opto_chan: Channel number for the opto signal. Defaults to None. :type opto_chan: int, optional :param v_thresh: Voltage threshold to find crossing. Defaults to 0.5. :type v_thresh: float, optional :param label: Label for the channel. Defaults to "laser". :type label: str, optional :param calib: Path to the calibration file. Defaults to None. :type calib: str, optional