pupil-labs / pupil

Open source eye tracking
https://pupil-labs.com
GNU Lesser General Public License v3.0
1.47k stars 676 forks source link

large negative jump in timestamps #1449

Closed cboulay closed 5 years ago

cboulay commented 5 years ago

Some of our data folders are refusing to load in Pupil Player. The printed error is "Could not generate world timestamps from eye timestamps. This is an invalid recording.". This is because we're failing the assertion in player_methods.py at Line 687 that min_ts < max_ts. Our timestamps start really high, then after 1100-1200 samples there is a large jump from ~74701 to ~34.

fname0 = '000\\eye0_timestamps.npy'
fname1 = '000\\eye1_timestamps.npy'
eye_ts0 = np.load(fname0)
eye_ts1 = np.load(fname1)
eye_ts0[1270:1280]
array([7.47012500e+04, 7.47012612e+04, 7.47012836e+04, 7.47012948e+04,
       7.47013060e+04, 7.47013284e+04, 3.39829990e+01, 3.40053990e+01,
       3.40277990e+01, 3.40501990e+01])
eye_ts1[1130:1140]
array([7.47012929e+04, 7.47013153e+04, 7.47013265e+04, 3.39810890e+01,
       3.39922890e+01, 3.40146890e+01, 3.40258890e+01, 3.40706890e+01,
       3.40930890e+01, 3.41154890e+01])

I also have simultaneous LabstreamingLayer recordings.

stream['time_series'][528:532]
Out[55]: 
[["{'topic': 'pupil.0', 'confidence': 0.8238804936408997, 'ellipse': {'center': [365.3705368041992, 326.51734161376953], 'axes': [57.71068572998047, 74.57137298583984], 'angle': 89.38726043701172}, 'diameter': 74.57137298583984, 'norm_pos': [0.5708914637565613, 0.31975553830464676], 'timestamp': 74701.305987, 'method': '2d c++', 'id': 0}"],
 ["{'topic': 'pupil.0', 'confidence': 0.8706846237182617, 'ellipse': {'center': [365.2934265136719, 326.48206329345703], 'axes': [58.15135955810547, 75.40060424804688], 'angle': 88.56385040283203}, 'diameter': 75.40060424804688, 'norm_pos': [0.5707709789276123, 0.3198290348052979], 'timestamp': 74701.328387, 'method': '2d c++', 'id': 0}"],
 ["{'topic': 'pupil.0', 'confidence': 0.9050938487052917, 'ellipse': {'center': [365.1299285888672, 326.54576873779297], 'axes': [58.36911392211914, 75.26219940185547], 'angle': 88.9308090209961}, 'diameter': 75.26219940185547, 'norm_pos': [0.570515513420105, 0.31969631512959795], 'timestamp': 33.982998999999836, 'method': '2d c++', 'id': 0}"],
 ["{'topic': 'pupil.0', 'confidence': 0.9414516687393188, 'ellipse': {'center': [365.0822219848633, 326.2925109863281], 'axes': [58.4393196105957, 75.45659637451172], 'angle': 88.37746429443362}, 'diameter': 75.45659637451172, 'norm_pos': [0.5704409718513489, 0.3202239354451497], 'timestamp': 34.00539900000149, 'method': '2d c++', 'id': 0}"]]

stream['time_stamps'][528:532]
Out[56]: array([74701.344911 , 74701.3616819, 74701.3933302, 74701.4104163])

stream['info']['name']
Out[57]: ['Pupil Python Representation - Eye 0']

It looks like the pupil internal timestamps started off using the same clock that LSL uses, then abruptly switched to something that looks like 'time since start'.

Can I safely modify the timestamps to remove this large step? Do I need to modify eye0, eye1, gaze, and pupil or will Pupil Player rewrite the latter 2 as long as I fix the first 2?

How can we stop this from happening in the future?

papr commented 5 years ago

@cboulay Sorry for the delayed response. Have you been using hmd-eyes for this recording? Yes, you can readjust the timestamps. If you use offline pupil detection and calibration you will only need to adjust eye0 and eye1. If you want to make use of the recorded data, you will have to adjust pupil and gaze, too.

cboulay commented 5 years ago

Hi Pablo. Yes, this is using hmd-eyes.

papr commented 5 years ago

As it turns out, Pupil Capture does allow time resets during a recording via Pupil Remote. Hmd-eyes uses this method to synchronize time before each calibration. This will be fixed in the upcoming versions of hmd-eyes and Capture.

Until then, use this script to readjust the eye timestamps: https://gist.github.com/papr/c945076fa0fbea9c679646a335509486

Call fix_negative_time_jumps() and pass the path to your inconsistent recording as string.

Caveats

This script does not adjust your gaze and pupil data. It is recommended to rerun offline pupil detection after running this script.

papr commented 5 years ago

Fixed in https://github.com/pupil-labs/hmd-eyes/releases/tag/v1.0-beta