Skip to content

Commit 9d95966

Browse files
authored
Merge pull request #1591 from AllenInstitute/GH-1324/behavior-sessions-time-alignment
GH-1324: Bugfix: Update behavior sessions time sources
2 parents c0d5d40 + 95cd409 commit 9d95966

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [ 1.8.0]
5+
### Bug Fixes
6+
- Internal LIMS data served to `BehaviorDataSession` class now all use the same timestamp source
7+
48
## [1.7.1] = 2020-05-5
59

610
### Bug Fixes

allensdk/internal/api/behavior_data_lims_api.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)