Source code for allensdk.brain_observatory.behavior.trial_masks
import numpy as np
import pandas as pd
[docs]def trial_types(trials, trial_types):
""" only include trials of certain trial types
Parameters
----------
trials : pandas DataFrame
dataframe of trials
trial_types : list or other iterator
Returns
-------
mask : pandas Series of booleans, indexed to trials DataFrame
"""
if trial_types is not None and len(trial_types) > 0:
return trials['trial_type'].isin(trial_types)
else:
return pd.Series(np.ones((len(trials), ), dtype=bool),
name="trial_type", index=trials.index)
[docs]def contingent_trials(trials):
""" GO & CATCH trials only
Parameters
----------
trials : pandas DataFrame
dataframe of trials
Returns
-------
mask : pandas Series of booleans, indexed to trials DataFrame
"""
return trial_types(trials, ('go', 'catch'))
[docs]def reward_rate(trials, thresh=2.0):
""" masks trials where the reward rate (per minute) is below some threshold.
This de facto omits trials in which the animal was not licking for extended periods
or periods when they were licking indiscriminantly.
Parameters
----------
trials : pandas DataFrame
dataframe of trials
thresh : float, optional
threshold under which trials will not be included, default: 2.0
Returns
-------
mask : pandas Series of booleans, indexed to trials DataFrame
"""
mask = trials['reward_rate'] > thresh
return mask