allensdk.internal.brain_observatory.time_sync module

class allensdk.internal.brain_observatory.time_sync.OphysTimeAligner(sync_file, scanner=None, dff_file=None, stimulus_pkl=None, eye_video=None, behavior_video=None, long_stim_threshold=0.2)[source]

Bases: object

property behavior_video_timestamps
property clipped_stim_timestamps

Return the stimulus timestamps with the erroneous initial spike removed (if relevant)

Returns:
timestamps: np.ndarray

An array of stimulus timestamps in seconds with th emonitor delay added

delta: int

Difference between the length of timestamps and the number of frames reported in the stimulus pickle file, i.e. len(timestamps) - len(pkl_file[‘items’][‘behavior’][‘intervalsms’]

property corrected_behavior_video_timestamps
property corrected_eye_video_timestamps
property corrected_ophys_timestamps
property corrected_stim_timestamps

The stimulus timestamps corrected for monitor delay

Returns:
timestamps: np.ndarray

An array of stimulus timestamps in seconds with th emonitor delay added

delta: int

Difference between the length of timestamps and the number of frames reported in the stimulus pickle file, i.e. len(timestamps) - len(pkl_file[‘items’][‘behavior’][‘intervalsms’]

delay: float

The monitor delay in seconds

property dataset
property eye_video_timestamps
property monitor_delay

The monitor delay (in seconds) associated with the session

property ophys_timestamps

Get the timestamps for the ophys data.

property stim_timestamps
allensdk.internal.brain_observatory.time_sync.calculate_monitor_delay(sync_dset, stim_times, photodiode_key, transition_frame_interval=60, max_monitor_delay=0.07)[source]

Calculate monitor delay.

allensdk.internal.brain_observatory.time_sync.corrected_video_timestamps(video_name, timestamps, data_length)[source]
allensdk.internal.brain_observatory.time_sync.get_alignment_array(ref, other, int_method=<ufunc 'floor'>)[source]

Generate an alignment array

allensdk.internal.brain_observatory.time_sync.get_keys(sync_dset: Dataset) dict[source]

Gets the correct keys for the sync file by searching the sync file line labels. Removes key from the dictionary if it is not in the sync dataset line labels. Args:

sync_dset: The sync dataset to search for keys within

Returns:
key_dict: dictionary of key value pairs for finding data in the

sync file

allensdk.internal.brain_observatory.time_sync.get_ophys_data_length(filename)[source]
allensdk.internal.brain_observatory.time_sync.get_photodiode_events(sync_dset, photodiode_key)[source]

Returns the photodiode events with the start/stop indicators and the window init flash stripped off. These transitions occur roughly ~1.0s apart, since the sync square changes state every N frames (where N = 60, and frame rate is 60 Hz). Because there are no markers for when the first transition of this type started, we estimate based on the event intervals. For the first valid event, find the first two events that both meet the following criteria:

The next event occurs ~1.0s later

First the last valid event, find the first two events that both meet the following criteria:

The last valid event occured ~1.0s before

allensdk.internal.brain_observatory.time_sync.get_real_photodiode_events(sync_dset, photodiode_key, anomaly_threshold=0.5)[source]

Gets the photodiode events with the anomalies removed.

allensdk.internal.brain_observatory.time_sync.get_stim_data_length(filename: str) int[source]

Get stimulus data length from .pkl file.

Parameters:
filenamestr

Path of stimulus data .pkl file.

Returns:
int

Stimulus data length.

allensdk.internal.brain_observatory.time_sync.get_video_length(filename)[source]