utils2p/synchronization.py
def process_odor_line(line,
                      freq=30000,
                      arduino_commands=(
                          "None",
                          "Odor1",
                          "Odor2",
                          "Odor3",
                          "Odor4",
                          "Odor5",
                          "Odor6",
                          "Odor1R",
                          "Odor2R",
                          "Odor1L",
                          "Odor2L",
                          "Odor1B",
                          "Odor2B",
                          "WaterB",
                          "bubbleMFC_R0",
                          "MFC1_R2",
                          "MFC2_L1",
                      ),
                      step_size=0.2703,
                      filter_only=False):
    """
    The odor line is based on a PWM signal for the Arduino controlling the
    valves. This function applies a Butterworth filter and converts the
    resulting voltages to level indices. The corresponding the setting of the
    valves are given by the `arduino_commands` argument.

    Parameters
    ----------
    line : numpy array
        Unprocessed odor line from h5 file.
    freq : int
        Frequency of ThorSync. Necessary for the Butterworth filter.
    arduino_commands : list of strings
        Description of the valve settings for commands sent to arduino.
        Note: The order matters since the serial communications between
        computer and Arduino is based on the index in the list.
        This index is converted to a PWM signal that is recorded by ThorSync.
    step_size : float
        The voltage step size between different levels of the PWM. This is used
        to convert the voltage to indices.
    filter_only : bool
        If `True`, only the filtered line is returned instead of the odors
        based on the `arduino_commands`. This is useful for determining
        the `step_size`.

    Returns
    -------
    numpy array of strings
    """
    b, a = scipy.signal.butter(3, 10, fs=freq)
    filtered_line = scipy.signal.filtfilt(b, a, line)
    if filter_only:
        return filtered_line
    indices = np.rint(filtered_line / step_size).astype(int)
    for index in np.unique(indices):
        mask = (indices == index)
        filtered_mask = epoch_length_filter(mask, freq)
        indices[mask & ~filtered_mask] = 0
    return np.array(arduino_commands)[indices]

    The odor line is based on a PWM signal for the Arduino controlling the
    valves. This function applies a Butterworth filter and converts the
    resulting voltages to level indices. The corresponding the setting of the
    valves are given by the `arduino_commands` argument.

    Parameters
    ----------
    line : numpy array
        Unprocessed odor line from h5 file.
    freq : int
        Frequency of ThorSync. Necessary for the Butterworth filter.
    arduino_commands : list of strings
        Description of the valve settings for commands sent to arduino.
        Note: The order matters since the serial communications between
        computer and Arduino is based on the index in the list.
        This index is converted to a PWM signal that is recorded by ThorSync.
    step_size : float
        The voltage step size between different levels of the PWM. This is used
        to convert the voltage to indices.
    filter_only : bool
        If `True`, only the filtered line is returned instead of the odors
        based on the `arduino_commands`. This is useful for determining
        the `step_size`.

    Returns
    -------
    numpy array of strings
    
The odor line is based on a PWM signal for the Arduino controlling the
valves. This function applies a Butterworth filter and converts the
resulting voltages to level indices. The corresponding the setting of the
valves are given by the `arduino_commands` argument.

Parameters

line : numpy array
Unprocessed odor line from h5 file.
freq : int
Frequency of ThorSync. Necessary for the Butterworth filter.
arduino_commands : list of strings
Description of the valve settings for commands sent to arduino.
Note: The order matters since the serial communications between
computer and Arduino is based on the index in the list.
This index is converted to a PWM signal that is recorded by ThorSync.
step_size : float
The voltage step size between different levels of the PWM. This is used
to convert the voltage to indices.
filter_only : bool
If `True`, only the filtered line is returned instead of the odors
based on the `arduino_commands`. This is useful for determining
the `step_size`.

Returns

numpy array of strings
The odor line is based on a PWM signal for the Arduino controlling the valves . This function applies a Butterworth filter and converts the resulting voltages to level indices . The corresponding the setting of the valves are given by the ` arduino_commands ` argument . Parameters line : numpy array Unprocessed odor line from h5 file . freq : int Frequency of ThorSync . Necessary for the Butterworth filter . arduino_commands : list of strings Description of the valve settings for commands sent to arduino . Note : The order matters since the serial communications between computer and Arduino is based on the index in the list . This index is converted to a PWM signal that is recorded by ThorSync . step_size : float The voltage step size between different levels of the PWM . This is used to convert the voltage to indices . filter_only : bool If ` True ` only the filtered line is returned instead of the odors based on the ` arduino_commands ` . This is useful for determining the ` step_size ` . Returns numpy array of strings
def process_odor_line(line,
                      freq=30000,
                      arduino_commands=(
                          "None",
                          "Odor1",
                          "Odor2",
                          "Odor3",
                          "Odor4",
                          "Odor5",
                          "Odor6",
                          "Odor1R",
                          "Odor2R",
                          "Odor1L",
                          "Odor2L",
                          "Odor1B",
                          "Odor2B",
                          "WaterB",
                          "bubbleMFC_R0",
                          "MFC1_R2",
                          "MFC2_L1",
                      ),
                      step_size=0.2703,
                      filter_only=False):
    b, a = scipy.signal.butter(3, 10, fs=freq)
    filtered_line = scipy.signal.filtfilt(b, a, line)
    if filter_only:
        return filtered_line
    indices = np.rint(filtered_line / step_size).astype(int)
    for index in np.unique(indices):
        mask = (indices == index)
        filtered_mask = epoch_length_filter(mask, freq)
        indices[mask & ~filtered_mask] = 0
    return np.array(arduino_commands)[indices]
def process_odor_line ( line , freq = 30000 , arduino_commands = ( "None" , "Odor1" , "Odor2" , "Odor3" , "Odor4" , "Odor5" , "Odor6" , "Odor1R" , "Odor2R" , "Odor1L" , "Odor2L" , "Odor1B" , "Odor2B" , "WaterB" , "bubbleMFC_R0" , "MFC1_R2" , "MFC2_L1" , ) , step_size = 0.2703 , filter_only = False ) : b , a = scipy . signal . butter ( 3 , 10 , fs = freq ) filtered_line = scipy . signal . filtfilt ( b , a , line ) if filter_only : return filtered_line indices = np . rint ( filtered_line / step_size ) . astype ( int ) for index in np . unique ( indices ) : mask = ( indices == index ) filtered_mask = epoch_length_filter ( mask , freq ) indices [ mask & ~ filtered_mask ] = 0 return np . array ( arduino_commands ) [ indices ]
The odor line is based on a PWM signal for the Arduino controlling the
valves.
The odor line is based on a PWM signal for the Arduino controlling the valves .
"""
    The odor line is based on a PWM signal for the Arduino controlling the
    valves. This function applies a Butterworth filter and converts the
    resulting voltages to level indices. The corresponding the setting of the
    valves are given by the `arduino_commands` argument.

    Parameters
    ----------
    line : numpy array
        Unprocessed odor line from h5 file.
    freq : int
        Frequency of ThorSync. Necessary for the Butterworth filter.
    arduino_commands : list of strings
        Description of the valve settings for commands sent to arduino.
        Note: The order matters since the serial communications between
        computer and Arduino is based on the index in the list.
        This index is converted to a PWM signal that is recorded by ThorSync.
    step_size : float
        The voltage step size between different levels of the PWM. This is used
        to convert the voltage to indices.
    filter_only : bool
        If `True`, only the filtered line is returned instead of the odors
        based on the `arduino_commands`. This is useful for determining
        the `step_size`.

    Returns
    -------
    numpy array of strings
    """
line
freq
arduino_commands
step_size
filter_only