allensdk.brain_observatory.behavior.session_apis.data_transforms.behavior_data_transforms module

class allensdk.brain_observatory.behavior.session_apis.data_transforms.behavior_data_transforms.BehaviorDataTransforms(extractor: allensdk.brain_observatory.behavior.session_apis.abcs.data_extractor_base.behavior_data_extractor_base.BehaviorDataExtractorBase)[source]

Bases: allensdk.brain_observatory.behavior.session_apis.abcs.session_base.behavior_base.BehaviorBase

This class provides methods that transform data extracted from LIMS or JSON data sources into final data products necessary for populating a BehaviorSession.

get_behavior_session_id(self)[source]

Returns the behavior_session_id associated with this experiment, if applicable.

get_extended_trials(self) → pandas.core.frame.DataFrame[source]

Get extended trials from pkl file

Returns:
pd.DataFrame

A dataframe containing extended behavior trial information.

get_licks(self) → pandas.core.frame.DataFrame[source]

Get lick data from pkl file. This function assumes that the first sensor in the list of lick_sensors is the desired lick sensor. If this changes we need to update to get the proper line.

Since licks can occur outside of a trial context, the lick times are extracted from the vsyncs and the frame number in lick_events. Since we don’t have a timestamp for when in “experiment time” the vsync stream starts (from self.get_stimulus_timestamps), we compute it by fitting a linear regression (frame number x time) for the start_trial and end_trial events in the trial_log, to true up these time streams.

Returns:pd.DataFrame Two columns: “time”, which contains the sync time of the licks that occurred in this session and “frame”, the frame numbers of licks that occurred in this session
get_metadata(self) → allensdk.brain_observatory.behavior.metadata.behavior_metadata.BehaviorMetadata[source]

Return metadata about the session. :rtype: BehaviorMetadata

get_monitor_delay(self) → float[source]

Return monitor delay for behavior only sessions (in seconds)

get_rewards(self) → pandas.core.frame.DataFrame[source]

Get reward data from pkl file, based on pkl file timestamps (not sync file).

Returns:pd.DataFrame – A dataframe containing timestamps of delivered rewards.
get_running_acquisition_df(self, lowpass=True, zscore_threshold=10.0) → pandas.core.frame.DataFrame[source]

Get running speed acquisition data from a behavior pickle file.

NOTE: Rebases timestamps with the self.get_stimulus_timestamps() method which varies between the BehaviorDataTransformer and the BehaviorOphysDataTransformer.

Parameters:
lowpass: bool (default=True)

Whether to apply a 10Hz low-pass filter to the running speed data.

zscore_threshold: float

The threshold to use for removing outlier running speeds which might be noise and not true signal

Returns:
pd.DataFrame
Dataframe with an index of timestamps and the following columns:

“speed”: computed running speed “dx”: angular change, computed during data collection “v_sig”: voltage signal from the encoder “v_in”: the theoretical maximum voltage that the encoder

will reach prior to “wrapping”. This should theoretically be 5V (after crossing 5V goes to 0V, or vice versa). In practice the encoder does not always reach this value before wrapping, which can cause transient spikes in speed at the voltage “wraps”.

get_running_speed(self, lowpass=True) → pandas.core.frame.DataFrame[source]

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)
get_stimulus_frame_rate(self) → float[source]
get_stimulus_presentations(self) → pandas.core.frame.DataFrame[source]

Get stimulus presentation data.

NOTE: Uses timestamps that do not account for monitor delay.

Returns:pd.DataFrame – Table whose rows are stimulus presentations (i.e. a given image, for a given duration, typically 250 ms) and whose columns are presentation characteristics.
get_stimulus_templates(self) → Union[allensdk.brain_observatory.behavior.stimulus_processing.stimulus_templates.StimulusTemplate, NoneType][source]

Get stimulus templates (movies, scenes) for behavior session.

Returns:
StimulusTemplate or None if there are no images for the experiment
get_stimulus_timestamps(self) → numpy.ndarray[source]

Get stimulus timestamps (vsyncs) from pkl file. Align to the (frame, time) points in the trial events.

NOTE: Located with behavior_session_id. Does not use the sync_file which requires ophys_session_id.

Returns:
np.ndarray

Timestamps associated with stimulus presentations on the monitor that do no account for monitor delay.

get_task_parameters(self) → dict[source]

Get task parameters from pkl file.

Returns:
dict

A dictionary containing parameters used to define the task runtime behavior.

get_trials(self) → pandas.core.frame.DataFrame[source]

Get trials from pkl file

Returns:
pd.DataFrame

A dataframe containing behavioral trial start/stop times, and trial data