Source code for allensdk.brain_observatory.behavior.session_metrics

import numpy as np
from allensdk.brain_observatory.behavior import trial_masks as masks

[docs]def response_bias(trials, detect_col, trial_types=("go", "catch")): """ Calculate the response bias for a subset of trial types from a behavioral training dataframe. Args: trials (pandas.DataFrame): Dataframe containing trial-level information from a behavioral training session. Required columns: "trial_type", `detect_col`. detect_col (str): Name of column containing boolean or numeric codings (0/1) for whether or not the mouse had a response. trial_types (iterable<str>): Iterable containing string trial types to check for the response bias. Trials of types not included in this iterable will be ignored. Default=("go", "catch") Return: The response bias (or average value of the `detect_col`) for trials in `trial_types`. """ mask = masks.trial_types(trials, trial_types) return trials[mask][detect_col].mean()
[docs]def num_contingent_trials(session_trials): """ Returns the number of "go" and "catch" trials in a training session dataframe. Args: session_trials (pandas.DataFrame): a pandas.DataFrame describing behavior training trials, with the string column "trial_type" describing the type of trial. Returns (int): Number of "go" and "catch" trials """ return session_trials["trial_type"].isin(["go", "catch"]).sum()