Skip to content

Commit 895042b

Browse files
authored
Merge pull request #849 from int-brain-lab/camera_fixes
Camera fixes
2 parents be2d939 + 637c1fb commit 895042b

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

ibllib/io/extractors/video_motion.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ def fix_keys(alf_object):
442442
# Compute wheel velocity
443443
self.wheel_vel, _ = wh.velocity_filtered(wheel_pos, 1000)
444444
# Load in original camera times
445-
self.camera_times = alfio.load_file_content(next(alf_path.rglob(f'_ibl_{self.label}Camera.times*.npy')))
446445
self.camera_path = str(next(self.session_path.joinpath('raw_video_data').glob(f'_iblrig_{self.label}Camera.raw*.mp4')))
447446
self.camera_meta = vidio.get_video_meta(self.camera_path)
448447

@@ -461,17 +460,25 @@ def fix_keys(alf_object):
461460
# Check if the ttl and video sizes match up
462461
self.tdiff = self.ttls.size - self.camera_meta['length']
463462

463+
# Load in original camera times if available otherwise set to ttls
464+
camera_times = next(alf_path.rglob(f'_ibl_{self.label}Camera.times*.npy'), None)
465+
self.camera_times = alfio.load_file_content(camera_times) if camera_times else self.ttls
466+
464467
if self.tdiff < 0:
465468
# In this case there are fewer ttls than camera frames. This is not ideal, for now we pad the ttls with
466469
# nans but if this is too many we reject the wheel alignment based on the qc
467470
self.ttl_times = self.ttls
468471
self.times = np.r_[self.ttl_times, np.full((np.abs(self.tdiff)), np.nan)]
472+
if self.camera_times.size != self.camera_meta['length']:
473+
self.camera_times = np.r_[self.camera_times, np.full((np.abs(self.tdiff)), np.nan)]
469474
self.short_flag = True
470475
elif self.tdiff > 0:
471476
# In this case there are more ttls than camera frames. This happens often, for now we remove the first
472477
# tdiff ttls from the ttls
473478
self.ttl_times = self.ttls[self.tdiff:]
474479
self.times = self.ttls[self.tdiff:]
480+
if self.camera_times.size != self.camera_meta['length']:
481+
self.camera_times = self.camera_times[self.tdiff:]
475482
self.short_flag = False
476483

477484
# Compute the frame rate of the camera

ibllib/pipes/video_tasks.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def run_qc(self, camera_data=None, update=True):
190190
if camera_data is None:
191191
camera_data, _ = self.extract_camera(save=False)
192192
qc = run_camera_qc(
193-
self.session_path, self.cameras, one=self.one, camlog=True, sync_collection=self.sync_collection, sync_type=self.sync)
193+
self.session_path, self.cameras, one=self.one, camlog=True, sync_collection=self.sync_collection, sync_type=self.sync,
194+
update=update)
194195
return qc
195196

196197
def _run(self, update=True, **kwargs):
@@ -284,7 +285,8 @@ def signature(self):
284285
[(f'_{self.sync_namespace}_sync.channels.npy', self.sync_collection, True),
285286
(f'_{self.sync_namespace}_sync.polarities.npy', self.sync_collection, True),
286287
(f'_{self.sync_namespace}_sync.times.npy', self.sync_collection, True),
287-
('*.wiring.json', self.sync_collection, True),
288+
(f'_{self.sync_namespace}_*.wiring.json', self.sync_collection, False),
289+
(f'_{self.sync_namespace}_*.meta', self.sync_collection, True),
288290
('*wheel.position.npy', 'alf', False),
289291
('*wheel.timestamps.npy', 'alf', False),
290292
('*experiment.description*', '', False)],
@@ -308,7 +310,8 @@ def run_qc(self, camera_data=None, update=True):
308310
if camera_data is None:
309311
camera_data, _ = self.extract_camera(save=False)
310312
qc = run_camera_qc(
311-
self.session_path, self.cameras, one=self.one, sync_collection=self.sync_collection, sync_type=self.sync)
313+
self.session_path, self.cameras, one=self.one, sync_collection=self.sync_collection, sync_type=self.sync,
314+
update=update)
312315
return qc
313316

314317
def _run(self, update=True, **kwargs):
@@ -347,7 +350,7 @@ def signature(self):
347350
'input_files': [(f'_iblrig_{cam}Camera.raw.mp4', self.device_collection, True) for cam in self.cameras],
348351
'output_files': [(f'_ibl_{cam}Camera.dlc.pqt', 'alf', True) for cam in self.cameras] +
349352
[(f'{cam}Camera.ROIMotionEnergy.npy', 'alf', True) for cam in self.cameras] +
350-
[(f'{cam}ROIMotionEnergy.position.npy', 'alf', True)for cam in self.cameras]
353+
[(f'{cam}ROIMotionEnergy.position.npy', 'alf', True) for cam in self.cameras]
351354
}
352355

353356
return signature
@@ -504,8 +507,11 @@ def signature(self):
504507
# In particular the raw videos don't need to be downloaded as they can be streamed
505508
[(f'_iblrig_{cam}Camera.raw.mp4', self.device_collection, True) for cam in self.cameras] +
506509
[(f'{cam}ROIMotionEnergy.position.npy', 'alf', False) for cam in self.cameras] +
510+
[(f'{cam}Camera.ROIMotionEnergy.npy', 'alf', False) for cam in self.cameras] +
507511
# The trials table is used in the DLC QC, however this is not an essential dataset
508-
[('_ibl_trials.table.pqt', self.trials_collection, False)],
512+
[('_ibl_trials.table.pqt', self.trials_collection, False),
513+
('_ibl_wheel.position.npy', self.trials_collection, False),
514+
('_ibl_wheel.timestamps.npy', self.trials_collection, False)],
509515
'output_files': [(f'_ibl_{cam}Camera.features.pqt', 'alf', True) for cam in self.cameras] +
510516
[('licks.times.npy', 'alf', True)]
511517
}
@@ -522,7 +528,7 @@ def _run(self, overwrite=True, run_qc=True, plot_qc=True):
522528
523529
"""
524530
# Check if output files exist locally
525-
exist, output_files = self.assert_expected(self.signature['output_files'], silent=True)
531+
exist, output_files = self.assert_expected(self.output_files, silent=True)
526532
if exist and not overwrite:
527533
_logger.warning('EphysPostDLC outputs exist and overwrite=False, skipping computations of outputs.')
528534
else:

ibllib/qc/camera.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,15 @@ def is_metric(x):
420420
outcome = max(map(spec.QC.validate, values))
421421

422422
if update:
423-
extended = {
424-
k: spec.QC.NOT_SET if v is None else v
425-
for k, v in self.metrics.items()
426-
}
423+
extended = dict()
424+
for k, v in self.metrics.items():
425+
if v is None:
426+
extended[k] = spec.QC.NOT_SET.name
427+
elif isinstance(v, tuple):
428+
extended[k] = tuple(i.name if isinstance(i, spec.QC) else i for i in v)
429+
else:
430+
extended[k] = v.name
431+
427432
self.update_extended_qc(extended)
428433
self.update(outcome, namespace)
429434
return outcome, self.metrics

0 commit comments

Comments
 (0)