@@ -168,8 +168,7 @@ def get_licks(self) -> pd.DataFrame:
168168 """
169169 # Get licks from pickle file instead of sync
170170 data = self ._behavior_stimulus_file ()
171- offset = frame_time_offset (data )
172- stimulus_timestamps = self .get_stimulus_timestamps () + offset
171+ stimulus_timestamps = self .get_stimulus_timestamps ()
173172 lick_frames = (data ["items" ]["behavior" ]["lick_sensors" ][0 ]
174173 ["lick_events" ])
175174 lick_times = [stimulus_timestamps [frame ] for frame in lick_frames ]
@@ -183,8 +182,10 @@ def get_rewards(self) -> pd.DataFrame:
183182 delivered rewards.
184183 """
185184 data = self ._behavior_stimulus_file ()
186- # No sync timestamps to rebase on, so pass dummy rebase function
187- return get_rewards (data , lambda x : x )
185+ offset = frame_time_offset (data )
186+ # No sync timestamps to rebase on, but do need to align to
187+ # trial events, so add the offset as the "rebase" function
188+ return get_rewards (data , lambda x : x + offset )
188189
189190 def get_running_data_df (self ) -> pd .DataFrame :
190191 """Get running speed data.
@@ -280,7 +281,8 @@ def get_stimulus_templates(self) -> Dict[str, np.ndarray]:
280281 return get_stimulus_templates (data )
281282
282283 def get_stimulus_timestamps (self ) -> np .ndarray :
283- """Get stimulus timestamps (vsyncs) from pkl file.
284+ """Get stimulus timestamps (vsyncs) from pkl file. Align to the
285+ (frame, time) points in the trial events.
284286
285287 NOTE: Located with behavior_session_id. Does not use the sync_file
286288 which requires ophys_session_id.
@@ -293,7 +295,9 @@ def get_stimulus_timestamps(self) -> np.ndarray:
293295 """
294296 data = self ._behavior_stimulus_file ()
295297 vsyncs = data ["items" ]["behavior" ]["intervalsms" ]
296- return np .hstack ((0 , vsyncs )).cumsum () / 1000.0 # cumulative time
298+ cum_sum = np .hstack ((0 , vsyncs )).cumsum () / 1000.0 # cumulative time
299+ offset = frame_time_offset (data )
300+ return cum_sum + offset
297301
298302 def get_task_parameters (self ) -> dict :
299303 """Get task parameters from pkl file.
@@ -320,7 +324,9 @@ def get_trials(self) -> pd.DataFrame:
320324 data = self ._behavior_stimulus_file ()
321325 rewards = self .get_rewards ()
322326 stimulus_presentations = self .get_stimulus_presentations ()
323- # Pass a dummy rebase function since we don't have two time streams
327+ # Pass a dummy rebase function since we don't have two time streams,
328+ # and the frame times are already aligned to trial events in their
329+ # respective getters
324330 trial_df = get_trials (data , licks , rewards , stimulus_presentations ,
325331 lambda x : x )
326332
0 commit comments