Skip to content

Commit

Permalink
Switch exposing block method to use closest block to video start time
Browse files Browse the repository at this point in the history
- previous method using number of frames failed for session 660023_2023-08-08
  • Loading branch information
bjhardcastle committed Sep 25, 2024
1 parent 24e545d commit 92e22b4
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/npc_mvr/mvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ def get_video_frame_times(
if camera not in camera_to_video_path:
continue
num_frames_in_video = get_total_frames_in_video(camera_to_video_path[camera])
json_start_time = datetime.datetime.fromisoformat(
camera_to_json_data[camera]["TimeStart"].strip("Z")
)
sync_start_time = npc_sync.get_sync_data(sync_path_or_dataset).start_time
# check that exposing time in results is close to video start time in metadata:
assert (
sync_start_time < json_start_time
), f"Video start time from json info {json_start_time} is before sync start time {sync_start_time} for {camera}: cannot align frames if first exposure not captured on sync"

estimated_start_time_on_sync = (json_start_time - sync_start_time).seconds
# if sync + MVR started long before experiment (ie. pretest that wasn't
# stopped) sync will have extra exposing times at start that we need to ignore.
# outlier long exposing intervals help us identify MVR recordings being
Expand All @@ -551,17 +561,8 @@ def get_video_frame_times(
), f"Exposing times not split correctly for {camera}"
exposing_times = min(
exposing_time_blocks,
key=lambda block: abs(len(block) - num_frames_in_video),
key=lambda block: abs(block[0] - estimated_start_time_on_sync),
)
# check that exposing time in results is close to video start time in metadata:
json_start_time = datetime.datetime.fromisoformat(
camera_to_json_data[camera]["TimeStart"].strip("Z")
)
sync_start_time = npc_sync.get_sync_data(sync_path_or_dataset).start_time
assert (
sync_start_time < json_start_time
), f"Video start time from json info {json_start_time} is before sync start time {sync_start_time} for {camera}: cannot align frames if first exposure not captured on sync"
estimated_start_time_on_sync = (json_start_time - sync_start_time).seconds
_threshold = 10 # the allowable difference in seconds between the system time on sync computer and the system time on the vidmon computer
assert (
abs(estimated_start_time_on_sync - exposing_times[0]) < _threshold
Expand Down

0 comments on commit 92e22b4

Please sign in to comment.