Skip to content

Commit

Permalink
fix video timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
weiglszonja committed Jul 9, 2024
1 parent 85025be commit d811ce2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/howe_lab_to_nwb/vu2024/vu2024nwbconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ def temporally_align_data_interfaces(self):
if imaging.source_data["frame_indices"] is not None:
# we must fix the timestamps for fiber photometry
frame_indices = imaging.source_data["frame_indices"]
timestamps = fiber_photometry_timestamps[frame_indices]
fiber_photometry.set_aligned_timestamps(aligned_timestamps=timestamps)
imaging.set_aligned_timestamps(aligned_timestamps=timestamps)
else:
imaging.set_aligned_timestamps(aligned_timestamps=fiber_photometry_timestamps)
fiber_photometry_timestamps = fiber_photometry_timestamps[frame_indices]
fiber_photometry.set_aligned_timestamps(aligned_timestamps=fiber_photometry_timestamps)
imaging.set_aligned_timestamps(aligned_timestamps=fiber_photometry_timestamps)

video_interfaces = [self.data_interface_objects[key] for key in self.data_interface_objects if "Video" in key]
for video_interface in video_interfaces:
Expand All @@ -80,13 +78,13 @@ def temporally_align_data_interfaces(self):
else:
raise ValueError(f"Could not determine TTL stream for video file {video_file_path}.")

video_timestamps = video_interface.get_timestamps()
ttl_file_path = fiber_photometry.source_data["ttl_file_path"]
ttl_data = read_mat(filename=ttl_file_path)
first_ttl_frame = get_rising_frames_from_ttl(trace=ttl_data[ttl_stream_name])[0]
video_interface.set_aligned_segment_starting_times(
aligned_segment_starting_times=[video_timestamps[0][first_ttl_frame]]
)
rising_frames = get_rising_frames_from_ttl(trace=ttl_data[ttl_stream_name])
video_timestamps = ttl_data["timestamp"][rising_frames]
if len(video_timestamps) > len(fiber_photometry_timestamps):
video_timestamps = video_timestamps[: len(fiber_photometry_timestamps)]
video_interface.set_aligned_timestamps(aligned_timestamps=[video_timestamps])

self.aligned = True

Expand Down

0 comments on commit d811ce2

Please sign in to comment.