allensdk.brain_observatory.behavior.trials_processing module

allensdk.brain_observatory.behavior.trials_processing.calculate_reward_rate(response_latency=None, starttime=None, window=0.75, trial_window=25, initial_trials=10)[source]
allensdk.brain_observatory.behavior.trials_processing.categorize_one_trial(tr)[source]
allensdk.brain_observatory.behavior.trials_processing.colormap(trial_type, response_type)[source]
allensdk.brain_observatory.behavior.trials_processing.create_extended_trials(trials=None, metadata=None, time=None, licks=None)[source]
allensdk.brain_observatory.behavior.trials_processing.data_to_licks(data, time)[source]
allensdk.brain_observatory.behavior.trials_processing.data_to_metadata(data, time)[source]
allensdk.brain_observatory.behavior.trials_processing.find_licks(reward_times, licks, window=3.5)[source]
allensdk.brain_observatory.behavior.trials_processing.get_change_time_frame_response_latency(trial)[source]
allensdk.brain_observatory.behavior.trials_processing.get_even_sampling(data)[source]

Get status of even_sampling

Parameters:
data: Mapping

foraging2 experiment output data

Returns:
bool:

True if even_sampling is enabled

allensdk.brain_observatory.behavior.trials_processing.get_extended_trials(data, time=None)[source]
allensdk.brain_observatory.behavior.trials_processing.get_image_info_from_trial(trial_log, ti)[source]
allensdk.brain_observatory.behavior.trials_processing.get_mouse_id(exp_data)[source]
allensdk.brain_observatory.behavior.trials_processing.get_ori_info_from_trial(trial_log, ti)[source]
allensdk.brain_observatory.behavior.trials_processing.get_params(exp_data)[source]
allensdk.brain_observatory.behavior.trials_processing.get_response_latency(change_event, trial)[source]
allensdk.brain_observatory.behavior.trials_processing.get_response_type(trials)[source]
allensdk.brain_observatory.behavior.trials_processing.get_stimulus_attr_changes(stim_dict, change_frame, first_frame, last_frame)[source]

Notes

  • assumes only two stimuli are ever shown
  • converts attr_names to lowercase
  • gets the net attr changes from the start of a trial to the end of a trial
allensdk.brain_observatory.behavior.trials_processing.get_time(exp_data)[source]
allensdk.brain_observatory.behavior.trials_processing.get_trial_image_names(trial, stimuli) → Dict[str, str][source]

Gets the name of the stimulus presented at the beginning of the trial and what is it changed to at the end of the trial. Parameters ———- trial: A trial in a behavior ophys session stimuli: The stimuli presentation log for the behavior session

Returns:
A dictionary indicating the starting_stimulus and what the stimulus is

changed to.

allensdk.brain_observatory.behavior.trials_processing.get_trial_lick_times(lick_times, start_time, stop_time)[source]

extract lick times in time range

allensdk.brain_observatory.behavior.trials_processing.get_trial_reward_time(rebased_reward_times, start_time, stop_time)[source]

extract reward times in time range

allensdk.brain_observatory.behavior.trials_processing.get_trial_timing(event_dict: dict, stimulus_presentations_df: pandas.core.frame.DataFrame, licks: List[float], go: bool, catch: bool, auto_rewarded: bool, hit: bool, false_alarm: bool, aborted: bool)[source]

Extract a dictionary of trial timing data. See trial_data_from_log for a description of the trial types.

Parameters:
event_dict: dict

Dictionary of trial events in the well-known pkl file

stimulus_presentations_df: pd.DataFrame

pandas dataframe of stimulus presentations, from the get_stimulus_presentations response for the BehaviorOphysSession.api.

licks: List[float]

list of lick timestamps, from the get_licks response for the BehaviorOphysSession.api.

go: bool

True if “go” trial, False otherwise. Mutually exclusive with catch.

catch: bool

True if “catch” trial, False otherwise. Mutually exclusive with go.

auto_rewarded: bool

True if “auto_rewarded” trial, False otherwise.

hit: bool

True if “hit” trial, False otherwise

false_alarm: bool

True if “false_alarm” trial, False otherwise

aborted: bool

True if “aborted” trial, False otherwise

Returns:
dict
start_time: float

The time the trial started (in seconds elapsed from recording start)

stop_time: float

The time the trial ended (in seconds elapsed from recording start)

trial_length: float

Duration of the trial in seconds

response_time: float

The response time, for non-aborted trials. This is equal to the first lick in the trial. For aborted trials or trials without licks, response_time is NaN.

change_frame: int

The frame number that the stimulus changed

change_time: float

The time in seconds that the stimulus changed

response_latency: float or None

The time in seconds between the stimulus change and the animal’s lick response, if the trial is a “go”, “catch”, or “auto_rewarded” type. If the animal did not respond, return float(“inf”). In all other cases, return None.

Notes

The following parameters are mutually exclusive (exactly one can be true):

hit, miss, false_alarm, aborted, auto_rewarded
allensdk.brain_observatory.behavior.trials_processing.get_trials(data, licks_df, rewards_df, stimulus_presentations_df, rebase)[source]
allensdk.brain_observatory.behavior.trials_processing.get_trials_v0(data, time)[source]
allensdk.brain_observatory.behavior.trials_processing.local_time(iso_timestamp, timezone=None)[source]
allensdk.brain_observatory.behavior.trials_processing.resolve_initial_image(stimuli, start_frame)[source]

Attempts to resolve the initial image for a given start_frame for a trial

Parameters:
stimuli: Mapping

foraging2 shape stimuli mapping

start_frame: int

start frame of the trial

Returns:
initial_image_category_name: str

stimulus category of initial image

initial_image_group: str

group name of the initial image

initial_image_name: str

name of the initial image

allensdk.brain_observatory.behavior.trials_processing.trial_data_from_log(trial)[source]

Infer trial logic from trial log. Returns a dictionary.

  • reward volume: volume of water delivered on the trial, in mL

Each of the following values is boolean:

Trial category values are mutually exclusive * go: trial was a go trial (trial with a stimulus change) * catch: trial was a catch trial (trial with a sham stimulus change)

stimulus_change/sham_change are mutually exclusive * stimulus_change: did the stimulus change (True on ‘go’ trials) * sham_change: stimulus did not change, but response was evaluated (True on ‘catch’ trials)

Each trial can be one (and only one) of the following: * hit (stimulus changed, animal responded in response window) * miss (stimulus changed, animal did not respond in response window) * false_alarm (stimulus did not change, animal responded in response window) * correct_reject (stimulus did not change, animal did not respond in response window) * aborted (animal responded before change time) * auto_rewarded (reward was automatically delivered following the change. This will bias the animals choice and should not be categorized as hit/miss)

allensdk.brain_observatory.behavior.trials_processing.validate_trial_condition_exclusivity(trial_index, **trial_conditions)[source]

ensure that only one of N possible mutually exclusive trial conditions is True