示例#1
0
def no_response_bias(session_summary):
    """the mouse meets this criterion if their last session exhibited a
    response bias between 10% and 90%
        Args:
        session_summary (pd.DataFrame): Pandas dataframe with daily values for 'response_bias',
        ordered ascending by training day, for at least 1 day. If dataframe is not
        properly ordered, criterion may not be correctly calculated. This function does not
        sort the data to preserve prior behavior (sorting column was not required by mtrain function).
        The mtrain implementation created the required columns if they didn't exist, so 
        a more informative error is raised here to assist end-users in debugging.
    Returns:
        bool: True if criterion is met, False otherwise
    """
    if len(session_summary) < 1:
        raise DataFrameIndexError("Not enough data in session_summary frame. "
                                  "Expected >= 1 row(s), got {}".format(
                                      len(session_summary)))
    try:
        response_bias = session_summary['response_bias'].iloc[-1]
    except KeyError as e:
        raise DataFrameKeyError(
            "Failed accessing last values in colum"
            "'response_bias'.\n df length={}, df columns={}\n".format(
                len(session_summary), list(session_summary)), e)
    criteria = (response_bias < 0.9) & (response_bias > 0.1)
    logger.info(
        "'No response bias' criteria met: {} (response bias={})".format(
            criteria, response_bias))
    return criteria
示例#2
0
def yesterday_was_good(session_summary):
    """Returns true if the last day showed a peak d-prime above 2
    Args:
        session_summary (pd.DataFrame): Pandas dataframe with daily values for 'dprime_peak',
        ordered ascending by training day, for at least 1 day. If dataframe is not
        properly ordered, criterion may not be correctly calculated. This function does not
        sort the data to preserve prior behavior (sorting column was not required by mtrain function).
        The mtrain implementation created the required columns if they didn't exist, so 
        a more informative error is raised here to assist end-users in debugging.
    Returns:
        bool: True if criterion is met, False otherwise
    """
    if len(session_summary) < 1:
        raise DataFrameIndexError("Not enough data in session_summary frame. "
                                  "Expected >= 1 row(s), got {}".format(
                                      len(session_summary)))
    try:
        last_day = session_summary['dprime_peak'].iloc[-1]
    except KeyError as e:
        raise DataFrameKeyError(
            "Failed accessing last three values in colum"
            "'dprime_peak'.\n df length={}, df columns={}\n".format(
                len(session_summary), list(session_summary)), e)
    criteria = bool(last_day > 2)
    logger.info("'Yesterday was good' criteria met: {}".format(criteria))
    return criteria
示例#3
0
def meets_engagement_criteria(session_summary):
    """
    Returns true if engagement criteria were met for the past 3 days, else false.
    Args:
        session_summary (pd.DataFrame): Pandas dataframe with daily values for 'dprime_peak' and 'num_engaged_trials',
        ordered ascending by training day, for at least 3 days. If dataframe is not
        properly ordered, criterion may not be correctly calculated. This function does not
        sort the data to preserve prior behavior (sorting column was not required by mtrain function)
        The mtrain implementation created the required columns if they didn't exist, so 
        a more informative error is raised here to assist end-users in debugging.
    Returns:
        bool: True if criterion is met, False otherwise
    """
    criteria = 3
    if len(session_summary) < 3:
        raise DataFrameIndexError("Not enough data in session_summary frame. "
                                  "Expected >= 3 rows, got {}".format(
                                      len(session_summary)))
    try:
        session_summary['engagement_criteria'] = (
            (session_summary['dprime_peak'] > 1.0)
            & (session_summary['num_engaged_trials'] > 100))
        engaged_days = session_summary['engagement_criteria'].iloc[-3:].sum()
    except KeyError as e:
        raise DataFrameKeyError(
            "Failed accessing columns 'dprime_peak' and/or "
            "'num_engaged_trials' for 3 days.\n df length={}, df columns={}\n".
            format(len(session_summary), list(session_summary)), e)
    return engaged_days == criteria
示例#4
0
def two_out_of_three_aint_bad(session_summary):
    """Returns true if 2 of the last 3 days showed a peak
    d-prime above 2.

    Args:
        session_summary (pd.DataFrame): Pandas dataframe with daily values for 'dprime_peak',
        ordered ascending by training day, for at least the past 3 days. If dataframe is not
        properly ordered, criterion may not be correctly calculated. This function does not
        sort the data to preserve prior behavior (sorting column was not required by mtrain function).
        The mtrain implementation created the required columns if they didn't exist, so 
        a more informative error is raised here to assist end-users in debugging.
    Returns:
        bool: True if criterion is met, False otherwise
    """
    if len(session_summary) < 3:
        raise DataFrameIndexError("Not enough data in session_summary frame. "
                                  "Expected >= 3 rows, got {}".format(
                                      len(session_summary)))
    try:
        last_three = session_summary["dprime_peak"][-3:]
    except KeyError as e:
        raise DataFrameKeyError(
            "Failed accessing last three values in colum"
            "'dprime_peak'.\n df length={}, df columns={}\n".format(
                len(session_summary), list(session_summary)), e)
    logger.info('dprime_peak over last three days: {}'.format(
        list(last_three)))
    criteria = bool(
        ((last_three > 2).sum() > 1)  # at least two of the last three
    )
    logger.info(
        "'Two out of three ain't bad' criteria met: '{}'".format(criteria))
    return criteria
示例#5
0
def whole_lotta_trials(session_summary):
    """
    Mouse meets this criterion if the last session has more than 300 trials.
    Args:
        session_summary (pd.DataFrame): Pandas dataframe with daily values for 'num_contingent_trials',
        ordered ascending by training day, for at least 1 day. If dataframe is not
        properly ordered, criterion may not be correctly calculated. This function does not
        sort the data to preserve prior behavior (sorting column was not required by mtrain function).
        The mtrain implementation created the required columns if they didn't exist, so 
        a more informative error is raised here to assist end-users in debugging.
    Returns:
        bool: True if criterion is met, False otherwise
    """
    if len(session_summary) < 1:
        raise DataFrameIndexError("Not enough data in session_summary frame. "
                                  "Expected >= 1 row(s), got {}".format(
                                      len(session_summary)))
    try:
        num_trials = session_summary['num_contingent_trials'].iloc[-1]
    except KeyError as e:
        raise DataFrameKeyError(
            "Failed accessing last values in colum"
            "'num_contingent_trials'.\n df length={}, df columns={}\n".format(
                len(session_summary), list(session_summary)), e)
    criteria = num_trials > 300
    logger.info("'Trials > 300' criteria met: {} (n trials={})".format(
        criteria, num_trials))
    return criteria
示例#6
0
    def get_running_speed(self) -> RunningSpeed:
        """Get running speed using timestamps from
        self.get_stimulus_timestamps.

        NOTE: Do not correct for monitor delay.

        :returns: RunningSpeed -- a NamedTuple containing the subject's
            timestamps and running speeds (in cm/s)
        """
        running_data_df = self.get_running_data_df()
        if running_data_df.index.name != "timestamps":
            raise DataFrameIndexError(
                f"Expected index to be named 'timestamps' but got "
                "'{running_data_df.index.name}'.")
        return RunningSpeed(timestamps=running_data_df.index.values,
                            values=running_data_df.speed.values)
示例#7
0
 def _get_running_speed_df(stimulus_file: StimulusFile,
                           stimulus_timestamps: StimulusTimestamps,
                           filtered: bool = True,
                           zscore_threshold: float = 1.0) -> pd.DataFrame:
     running_data_df = get_running_df(data=stimulus_file.data,
                                      time=stimulus_timestamps.value,
                                      lowpass=filtered,
                                      zscore_threshold=zscore_threshold)
     if running_data_df.index.name != "timestamps":
         raise DataFrameIndexError(
             f"Expected running_data_df index to be named 'timestamps' "
             f"But instead got: '{running_data_df.index.name}'")
     running_speed = pd.DataFrame({
         "timestamps": running_data_df.index.values,
         "speed": running_data_df.speed.values
     })
     return running_speed
示例#8
0
    def get_running_speed(self, lowpass=True) -> pd.DataFrame:
        """Get running speed using timestamps from
        self.get_stimulus_timestamps.

        NOTE: Do not correct for monitor delay.

        :returns: pd.DataFrame
            index: timestamps
            speed : subject's running speeds (in cm/s)
        """
        running_data_df = self.get_running_acquisition_df(lowpass=lowpass)
        if running_data_df.index.name != "timestamps":
            raise DataFrameIndexError(
                f"Expected index to be named 'timestamps' but got "
                f"'{running_data_df.index.name}'.")
        return pd.DataFrame({
            "timestamps": running_data_df.index.values,
            "speed": running_data_df.speed.values
        })