Skip to content

Commit

Permalink
propagate latest changes to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rennis250 committed Apr 3, 2024
1 parent bb76cc0 commit 9c90ba4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
gaze = rec.gaze

print()
pprint.pprint(rec.unique_events)
pprint.pprint(rec._unique_events)
print()

event1_ts = rec.unique_events["recording.begin"]
event2_ts = rec.unique_events["recording.end"]
event1_ts = rec._unique_events["recording.begin"]
event2_ts = rec._unique_events["recording.end"]
between_two_events = gaze.ts[(gaze.ts >= event1_ts) & (gaze.ts <= event2_ts)]
print(event1_ts, event2_ts)

Expand Down
16 changes: 8 additions & 8 deletions examples/make_gaze_overlay_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ def convert_neon_pts_to_video_pts(neon_pts, neon_time_base, video_time_base):
container = plv.open("video.mp4", mode="w")

out_video_stream = container.add_stream("mpeg4", rate=fps)
out_video_stream.width = scene.width
out_video_stream.height = scene.height
out_video_stream.width = scene_video.width
out_video_stream.height = scene_video.height
out_video_stream.pix_fmt = "yuv420p"

out_audio_stream = container.add_stream("aac", rate=scene_audio.sample_rate)

neon_time_base = scene.data[0].time_base
neon_time_base = scene_video.data[0].time_base
video_time_base = Fraction(1, fps)

avg_neon_pts_size = int(np.mean(np.diff([f.pts for f in scene.data if f is not None])))
avg_neon_pts_size = int(np.mean(np.diff([f.pts for f in scene_video.data if f is not None])))
avg_video_pts_size = convert_neon_pts_to_video_pts(
avg_neon_pts_size, neon_time_base, video_time_base
)

start_ts = rec._unique_events["recording.begin"]
end_ts = rec._unique_events["recording.end"]

avg_frame_dur = np.mean(np.diff(scene.ts))
pre_ts = np.arange(start_ts, scene.ts[0] - avg_frame_dur, avg_frame_dur)
post_ts = np.arange(scene.ts[-1] + avg_frame_dur, end_ts, avg_frame_dur)
avg_frame_dur = np.mean(np.diff(scene_video.ts))
pre_ts = np.arange(start_ts, scene_video.ts[0] - avg_frame_dur, avg_frame_dur)
post_ts = np.arange(scene_video.ts[-1] + avg_frame_dur, end_ts, avg_frame_dur)

my_ts = np.concatenate((pre_ts, scene.ts, post_ts))
my_ts = np.concatenate((pre_ts, scene_video.ts, post_ts))

fields = [
"gyro_x",
Expand Down
3 changes: 3 additions & 0 deletions examples/print_diagnostic_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
scene = rec.scene

for stream in rec.streams.values():
if isinstance(stream, nr.stream.av_stream.AudioVideoStream):
continue

name = stream.name

print(name)
Expand Down
6 changes: 4 additions & 2 deletions examples/sample_and_iterate_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
combined_data = zip(
rec.gaze.sample(sample_ts),
rec.imu.sample(sample_ts),
rec.scene.sample(sample_ts),
rec.scene.video_stream.sample(sample_ts),
rec.eye.sample(sample_ts),
)
for gaze_datum, imu_datum, scene_frame, eye_frame in combined_data:
Expand Down Expand Up @@ -66,5 +66,7 @@
gaze_samples_np = nr.sampled_to_numpy(gaze.sample(gaze.ts[:15]))

# NOTE: the following is quite intense on the RAM.
scene_samples_np = nr.sampled_to_numpy(rec.scene.sample(rec.scene.ts[:15]))
scene_samples_np = nr.sampled_to_numpy(
rec.scene.video_stream.sample(rec.scene.video_stream.ts[:15])
)
print(scene_samples_np.shape)
3 changes: 1 addition & 2 deletions src/pupil_labs/neon_recording/neon_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

class NeonRecording:
def __init__(self, rec_dir_in: pathlib.Path | str):

pathlib.Path(rec_dir_in)
self._rec_dir = pathlib.Path(rec_dir_in)
if not self._rec_dir.exists() or not self._rec_dir.is_dir():
raise FileNotFoundError(f"Directory not found or not valid: {self._rec_dir}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _load(self):
self._backing_data = self._backing_container.streams.video[0]
self._data = self._backing_data.frames
setattr(self._data, "ts", self._ts)
self._ts_rel = self._ts - self._recording._start_ts
self._ts_rel = self._ts - self._recording.start_ts
setattr(self._data, "ts_rel", self._ts_rel)

self._width = self._data[0].width
Expand Down
2 changes: 1 addition & 1 deletion src/pupil_labs/neon_recording/stream/gaze_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _load(self) -> None:
# we use gaze_200hz from cloud for the rec gaze stream
# ts, raw = self._load_ts_and_data(rec_dir, 'gaze ps1')
gaze_200hz_ts, gaze_200hz_raw = self._load_ts_and_data("gaze_200hz")
gaze_200hz_ts_rel = gaze_200hz_ts - self._recording._start_ts
gaze_200hz_ts_rel = gaze_200hz_ts - self._recording.start_ts

# load up raw timestamps in original ns format,
# in case useful at some point
Expand Down
2 changes: 1 addition & 1 deletion src/pupil_labs/neon_recording/stream/imu/imu_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _load(self):
log.info("NeonRecording: Loading IMU data")

imu_rec = IMURecording(
self._recording._rec_dir / "extimu ps1.raw", self._recording._start_ts
self._recording._rec_dir / "extimu ps1.raw", self._recording.start_ts
)

self._data = imu_rec.raw
Expand Down

0 comments on commit 9c90ba4

Please sign in to comment.