Source code for allensdk.brain_observatory.ecephys.data_objects.trials

from typing import Union, Tuple, List

import numpy as np

from allensdk.brain_observatory.behavior.data_objects.trials.trial import (
    Trial)
from allensdk.brain_observatory.behavior.data_objects.\
    trials.trials import Trials


[docs] class VBNTrial(Trial):
[docs] def calculate_change_frame( self, event_dict: dict, go: bool, catch: bool, auto_rewarded: bool) -> Union[int, float]: """ Calculate the frame index of a stimulus change associated with a specific event. Parameters ---------- event_dict: dict Dictionary of trial events in the well-known `pkl` file 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. Returns ------- change_frame: Union[int, float] Index of the change frame; NaN if there is no change Notes ----- This is its own method so that child classes of Trial can implement different logic as needed. """ if go or auto_rewarded: change_frame = event_dict.get(('stimulus_changed', ''))['frame'] elif catch: change_frame = event_dict.get(('sham_change', ''))['frame'] else: change_frame = float("nan") return change_frame
[docs] def add_change_time(self, trial_dict: dict) -> Tuple[dict, float]: """ Add change_time_no_display_delay to a dict representing a single trial. This implementation will just take change_frame and select the value of self._stimulus_timestamps corresponding to that frame. Parameters ---------- trial_dict: dict containing all trial parameters except change_time Returns ------- trial_dict: Same as input, except change_time_no_display_delay field has been added change_time: float The change time value that was added (this is returned separately so that child classes have the option of naming the column something different than 'change_time') Note ---- Modified trial_dict in-place, in addition to returning it """ change_frame = trial_dict['change_frame'] if np.isnan(change_frame): change_time = np.nan else: no_delay = self._stimulus_timestamps.subtract_monitor_delay() change_frame = int(change_frame) change_time = no_delay.value[change_frame] trial_dict['change_time_no_display_delay'] = change_time return trial_dict, change_time
[docs] class VBNTrials(Trials):
[docs] @classmethod def trial_class(cls): """ Return the class to be used to represent a single Trial """ return VBNTrial
[docs] @classmethod def columns_to_output(cls) -> List[str]: """ Return the list of columns to be output in this table """ return ['initial_image_name', 'change_image_name', 'stimulus_change', 'change_time_no_display_delay', 'go', 'catch', 'lick_times', 'response_time', 'reward_time', 'reward_volume', 'hit', 'false_alarm', 'miss', 'correct_reject', 'aborted', 'auto_rewarded', 'change_frame', 'start_time', 'stop_time', 'trial_length']
@property def change_time(self): return self.data['change_time_no_display_delay']