Skip to content

Commit

Permalink
Merge pull request #58 from samuelbray32/master
Browse files Browse the repository at this point in the history
Use ptp to detect pause time if dio video stamps unavailable
  • Loading branch information
edeno authored Oct 4, 2023
2 parents 2ee025a + 4a23927 commit 1ee4f4f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions rec_to_nwb/processing/builder/originators/position_originator.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,21 @@ def get_position_with_corrected_timestamps(position_tracking_path, ptp_enabled):
mcu_neural_timestamps.loc[dio_camera_ticks[is_valid_tick]]
)

# The DIOs and camera frames are initially unaligned. There is a
# half second pause at the start to allow for alignment.
pause_mid_time = find_acquisition_timing_pause(dio_systime)

# Estimate the frame rate from the DIO camera ticks as a sanity check.
frame_rate_from_dio = get_framerate(dio_systime[dio_systime > pause_mid_time])
logger.info(
"Camera frame rate estimated from DIO camera ticks:"
f" {frame_rate_from_dio:0.1f} frames/s"
)
if len(dio_systime) > 0:
# The DIOs and camera frames are initially unaligned. There is a
# half second pause at the start to allow for alignment.
pause_mid_time = find_acquisition_timing_pause(dio_systime)

# Estimate the frame rate from the DIO camera ticks as a sanity check.
frame_rate_from_dio = get_framerate(
dio_systime[dio_systime > pause_mid_time]
)
logger.info(
"Camera frame rate estimated from DIO camera ticks:"
f" {frame_rate_from_dio:0.1f} frames/s"
)
else:
pause_mid_time = None

# Match the camera frames to the position tracking
# Number of video frames can be different from online tracking because
Expand All @@ -202,6 +207,11 @@ def get_position_with_corrected_timestamps(position_tracking_path, ptp_enabled):
if ptp_enabled:
logger.info("PTP detected")
ptp_systime = np.asarray(video_position_info.HWTimestamp)

if pause_mid_time is None:
# estimate pause_mid_time from ptp timestamps if dio was missing
pause_mid_time = find_acquisition_timing_pause(ptp_systime)

frame_rate_from_ptp = get_framerate(
ptp_systime[ptp_systime > pause_mid_time]
)
Expand Down

0 comments on commit 1ee4f4f

Please sign in to comment.