cibrrig.preprocess.nidq_utils ============================= .. py:module:: cibrrig.preprocess.nidq_utils .. autoapi-nested-parse:: I/O functions with NIDAQ data specifically for some of our physiology needs. This module is primarily focused on loading and manipulating data from the NIDAQ files recorded by spikeglx, and passes most computation to the physiology module, which is more general in scope. Attributes ---------- .. autoapisummary:: cibrrig.preprocess.nidq_utils._log Functions --------- .. autoapisummary:: cibrrig.preprocess.nidq_utils.get_triggers cibrrig.preprocess.nidq_utils.get_trig_string cibrrig.preprocess.nidq_utils._extract_ds_chan cibrrig.preprocess.nidq_utils.load_mmap cibrrig.preprocess.nidq_utils.binary_onsets cibrrig.preprocess.nidq_utils.get_tvec cibrrig.preprocess.nidq_utils.get_tvec_from_fn cibrrig.preprocess.nidq_utils.get_tvec_from_SR cibrrig.preprocess.nidq_utils.load_ds_pdiff cibrrig.preprocess.nidq_utils.load_dia_emg cibrrig.preprocess.nidq_utils.filt_int_ds_dia cibrrig.preprocess.nidq_utils.extract_hr_channel cibrrig.preprocess.nidq_utils.extract_temp cibrrig.preprocess.nidq_utils.filt_int_ds_arbitrary Module Contents --------------- .. py:data:: _log .. py:function:: get_triggers(session_path) Looks through all the NIDQ files to extract the trigger strings. :param session_path: Path to the session directory. :type session_path: Path :returns: Sorted list of trigger strings found in the NIDQ files. :rtype: list .. py:function:: get_trig_string(in_str) Extract the trigger string from a given input string using regex. :param in_str: Input string containing the trigger information. :type in_str: str :returns: Extracted trigger string. :rtype: str .. py:function:: _extract_ds_chan(SR, chan_id, ds_factor=10) Extract and downsample a specific analog channel from the SpikeGLX reader. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :param chan_id: Channel ID to extract. :type chan_id: int :param ds_factor: Downsampling factor. Defaults to 10. :type ds_factor: int, optional :returns: A tuple containing: - np.ndarray: Downsampled data from the specified channel. - float: Downsampled sampling rate. :rtype: tuple .. py:function:: load_mmap(fn) Load a memory-mapped Nidaq file. :param fn: Path to the Nidaq.bin file. :type fn: Path :returns: A tuple containing: - np.ndarray: Memory-mapped data array. - dict: Metadata dictionary. :rtype: tuple .. py:function:: binary_onsets(x, thresh) Binarize a signal at the level "thresh" and return the onset and offset indices. :param x: Input signal. :type x: np.ndarray :param thresh: Threshold value to determine binary state of HIGH (1) or LOW (0). :type thresh: float :returns: A tuple containing: - np.ndarray: Indices of onset samples. - np.ndarray: Indices of offset samples. :rtype: tuple :raises ValueError: If the number of onsets does not match the number of offsets. .. py:function:: get_tvec(dat, sr) Generate a time vector for a given data array and sampling rate. :param dat: Data array. :type dat: np.ndarray :param sr: Sampling rate. :type sr: float :returns: Time vector. :rtype: np.ndarray .. py:function:: get_tvec_from_fn(fn) Generate a time vector from a Nidaq file. :param fn: Path to the Nidaq file. :type fn: Path :returns: Time vector corresponding to the data in the file. :rtype: np.ndarray .. py:function:: get_tvec_from_SR(SR) Generate a time vector from a SpikeGLX reader object. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :returns: Time vector corresponding to the data in the reader object. :rtype: np.ndarray .. py:function:: load_ds_pdiff(SR, chan_id, ds_factor=10, inhale_dir=-1) Load and downsample the pdiff (differential pressure sensor) data. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :param chan_id: Channel ID for the pdiff signal. :type chan_id: int :param ds_factor: Downsampling factor. Defaults to 10. :type ds_factor: int, optional :param inhale_dir: Direction of inhalation. Defaults to -1. :type inhale_dir: int, optional :returns: A tuple containing: - np.ndarray: Downsampled pdiff data. - float: Downsampled sampling rate. :rtype: tuple .. py:function:: load_dia_emg(SR, chan_id) Read the raw diaphragm EMG data. Does not downsample the data Subtract the mean from the raw data. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :param chan_id: Channel ID for the diaphragm EMG signal. :type chan_id: int :returns: A tuple containing: - np.ndarray: Raw diaphragm EMG data. - float: Sampling rate of the diaphragm recording. :rtype: tuple .. py:function:: filt_int_ds_dia(x, sr, ds_factor=10, rel_height=0.95, heartbeats=None) Filter, integrate, and downsample the diaphragm EMG signal. Detect and summarize the diaphragm bursts. Uses median filtering to smooth the signal, which can be slow but is effective. :param x: Raw diaphragm EMG signal. :type x: np.ndarray :param sr: Sampling rate of the input signal. :type sr: float :param ds_factor: Downsampling factor. Defaults to 10. :type ds_factor: int, optional :param rel_height: Relative height for burst detection. Defaults to 0.95. :type rel_height: float, optional :param heartbeats: Precomputed heartbeats. Defaults to None. :type heartbeats: np.ndarray, optional :returns: A tuple containing: - pd.DataFrame: DataFrame with burst statistics. - np.ndarray: Downsampled and normalized diaphragm signal. - float: Downsampled sampling rate. - np.ndarray: Heart rate data. - np.ndarray: Filtered diaphragm signal. - np.ndarray: Detected heartbeats. :rtype: tuple .. py:function:: extract_hr_channel(SR, ekg_chan=2) Extract heart rate from a dedicated EKG channel. First subtracts the mean from the EKG signal. Passes the mean-subtracted EKG signal to the physiology.extract_hr_from_ekg function. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :param ekg_chan: Channel ID for the EKG signal. Defaults to 2. :type ekg_chan: int, optional :returns: Timestamps of detected heartbeats. :rtype: np.ndarray :raises ValueError: If the EKG signal cannot be processed. .. py:function:: extract_temp(SR, temp_chan=7, ds_factor=10) Extract the temperature from the FHC DC temp controller. Assumes the manufacturer's calibration. :param SR: SpikeGLX reader object for the recording. :type SR: spikeglx.Reader :param temp_chan: Channel ID for the temperature signal. Defaults to 7. :type temp_chan: int, optional :param ds_factor: Downsampling factor. Defaults to 10. :type ds_factor: int, optional :returns: Downsampled temperature data. :rtype: np.ndarray .. py:function:: filt_int_ds_arbitrary(x, sr, ds_factor=10) Filter, integrate, and downsample an arbitrary signal. Applies a second order Butterworth bandpass filter between 300 and 5000 Hz. :param x: Input signal. :type x: np.ndarray :param sr: Sampling rate of the input signal. :type sr: float :param ds_factor: Downsampling factor. Defaults to 10. :type ds_factor: int, optional :returns: A tuple containing: - np.ndarray: Processed and downsampled signal. - float: Downsampled sampling rate. - np.ndarray: Filtered signal. :rtype: tuple