AllenInstitute / AllenSDK

code for reading and processing Allen Institute for Brain Science data
https://allensdk.readthedocs.io/en/latest/
Other
340 stars 150 forks source link

Stimulus timestamps sometimes truncated 1 frame too early #2525

Open aamster opened 2 years ago

aamster commented 2 years ago

Stimulus timestamps are sometimes truncated 1 frame too early. The fingerprint stimulus (the last stimulus) lasts for display frames start_frame:end_frame. The stimulus timestamps should end at end_frame+1. Example: last fingerprint frame lasts for stimulus frames 100 and 101. Therefore it starts at stimulus timestamps frame 100 and ends at 102 (lasts for 100, 101, and ends at 102). But sometimes there is no stimulus timestamps frame end_frame+1.

Example with timestamps 1 frame too short:

>>> stim_file = BehaviorStimulusFile.from_lims(behavior_session_id=959681045, ...)
>>> timestamps = StimulusTimestamps.from_lims(behavior_session_id=959681045, ...)

>>> stimulus_session_frame_indices = np.array(
            stimulus_file.data['items']['behavior']['items']
            ['fingerprint']['frame_indices'])
>>> stimulus_session_frame_indices[-1]
270468
>>>len(stimulus_timestamps.value)
270469

Example with correct timestamps length:

>>> stim_file = BehaviorStimulusFile.from_lims(behavior_session_id=1192665673, ...)
>>> timestamps = StimulusTimestamps.from_lims(behavior_session_id=1192665673, ...)

>>> stimulus_session_frame_indices = np.array(
            stimulus_file.data['items']['behavior']['items']
            ['fingerprint']['frame_indices'])
>>> stimulus_session_frame_indices[-1]
270033
>>>len(stimulus_timestamps.value)
270035

This results in the last stimulus frame lasting 1 frame too few, ie lasts for 1/60 second instead of 1/30 second