ibllib.tests.integration.test_camera_extraction

Integration tests for the camera extraction and QC.

Folders used:
  • camera/

  • ephys/ephys_choice_world_task/ibl_witten_27/2021-01-21/001/

  • ephys/choice_world_init/KS022/2019-12-10/001

  • Subjects_init/ZM_1098/2019-01-25/001/

  • training/CSHL_003/2019-04-05/001/

NB: These tests hit the main Alyx database. This is required for full coverage of the QC (in particular the CameraQC._ensure_required_data method and MotionAlign using eid2ref).

Classes

TestCameraQC

Test the video QC on some failure cases.

TestEphysCameraExtractor

TestTrainingCameraExtractor

TestTrainingCameraExtractorNew

Starting with version 8.28.0 of IBLRIG, the first trial of the state machine is no longer used for timing the initial delay and waiting for the first camera trigger.

TestVideoQC

Test the video QC on some failure cases

TestWheelAlignment

TestWheelMotionNRG

class TestTrainingCameraExtractor(*args, **kwargs)[source]

Bases: IntegrationTest

required_files = ['camera/FMR007/2021-02-25/001', 'camera/ZFM-01867/2021-03-23/002']

An optional list of required files/folders to glob for, relative to data_path.

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

test_groom_pin_state()[source]
e7098000-62a0-46a4-99df-981ee2b56988 (ZFM-01867/2/2021-03-23)

In this session there were occasions where the GPIO would change twice after an audio TTL, perhaps because the audio TTLs are often split up into two short TTLs on Bpod, some of which are caught by the camera, others not.

The function removes the short audio TTLs then assigns the rest to the GPIO fronts. The unassigned audio TTL fronts and GPIO changes are removed. Usually if the TTL low-to-high is not assigned to a GPIO front, neither is the high-to-low, so both are removed. However sometimes because of mis-assigning (due to clock drift, short TTLs, faulty wiring, etc.) there are some ‘orphaned’ TTLs/GPIO fronts leaving us with two low-to-high fronts (or high-to-low) in a row. These so-called orphaned fronts should be removed too. The goal is to end up with an array of audio TTL times and GPIO times that are the same length.

Debugging output states: - 2316 fronts TLLs less than 5ms apart - 11 audio TTL rises were not detected by the camera - 346 pin state rises could not be attributed to an audio TTL - 10 audio TTL falls were not detected by the camera - 345 pin state falls could not be attributed to an audio TTL - 3 orphaned TTLs removed

The output arrays are not aligned per se, but should at least have most GPIO fronts correctly assigned to the corresponding audio TTLs.

Returns:

test_extraction(mock_vc)[source]

Mock the VideoCapture class of cv2 so that we can control the number of frames

Parameters:

mock_vc

Returns:

test_basic_extraction(mock_vc, mock_aux)[source]

Tests extraction of a session without pin state and GPIO files, etc.

Parameters:
  • mock_vc – A mock OpenCV VideoCapture object for stubbing the video length

  • mock_aux – A mock object for stubbing the load_embedded_frame_data function

Returns:

class TestTrainingCameraExtractorNew(*args, **kwargs)[source]

Bases: IntegrationTest

Starting with version 8.28.0 of IBLRIG, the first trial of the state machine is no longer used for timing the initial delay and waiting for the first camera trigger. Instead, the first trial is now identical to the remaining trials. Here we test the extraction of the camera timestamps from such sessions. The integration data has a purposefully added 1-second delay between starting the camera and start of the first trial - this is not normally the case. It has been added here to test the effect of decoupling camera start and first trial on the synchronization of the camera timestamps with the Bpod trials.

required_files = ['training/8.28.0/2025-06-12/002/*']

An optional list of required files/folders to glob for, relative to data_path.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_extraction_sound_sync(mock_vc)[source]

In this test the camera timestamps are synchronized by means of the sound TTL recorded by the camera. The extractor should be able to handle this and extrapolate the camera triggers that have been missed before start of the first trial.

test_extraction_no_frame_data(mock_vc, mock_aux)[source]

In this test the camera can not be synchronized by means of the sound TTL. This will lead to a shift of the camera timestamps with respect to the Bpod trials leading to faulty synchronization.

class TestEphysCameraExtractor(*args, **kwargs)[source]

Bases: IntegrationTest

required_files = ['camera/SWC_054/2020-10-07/001', 'ephys/ephys_choice_world_task/ibl_witten_27/2021-01-21/001', 'Subjects_init/ZM_1098/2019-01-25/001']

An optional list of required files/folders to glob for, relative to data_path.

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

tearDown() None[source]

Hook method for deconstructing the test fixture after testing it.

test_groom_pin_state()[source]
test_extraction(mock_vc)[source]

Mock the VideoCapture class of cv2 so that we can control the number of frames

Parameters:

mock_vc

Returns:

test_basic_extraction(mock_vc, mock_aux)[source]

Tests extraction of a session without pin state and GPIO files, etc.

Parameters:
  • mock_vc – A mock OpenCV VideoCapture object for stubbing the video length

  • mock_aux – A mock object for stubbing the load_embedded_frame_data function

Returns:

test_get_video_length()[source]
class TestVideoQC(*args, **kwargs)[source]

Bases: IntegrationTest

Test the video QC on some failure cases

required_files = ['camera/10_sec_vids', 'camera/10sec_bad_location']

An optional list of required files/folders to glob for, relative to data_path.

classmethod setUpClass() None[source]

Load a few 10 second videos for testing the various video QC checks

tearDown() None[source]

Hook method for deconstructing the test fixture after testing it.

test_video_checks(display=False)[source]
class TestCameraQC(*args, **kwargs)[source]

Bases: IntegrationTest

Test the video QC on some failure cases.

required_files = ['Subjects_init/ZM_1098/2019-01-25/001', 'camera/SWC_054/2020-10-07/001', 'camera/FMR007/2021-02-25/001', 'camera/NR_0020/2022-01-27/001', 'camera/6c6983ef-7383-4989-9183-32b1a300d17a_frame_samples.npy', 'camera/7082d576-4eb4-41dc-a16e-8a742829a83a_frame_samples.npy', 'camera/451bc9c0-113c-408e-a924-122ffe44306e_frame_samples.npy']

An optional list of required files/folders to glob for, relative to data_path.

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

test_incomplete_session()[source]
test_ephys_session(mock_ext, mock_meta)[source]

Tests the full QC process for an ephys session.

Mock a load of things so we don’t need the full video file.

Parameters:
  • mock_ext – mock cv.VideoCapture in camera extractor module

  • mock_meta – mock get_video_meta

Returns:

test_training_session(mock_ext, mock_meta)[source]

Tests the full QC process for a training session. Mock a load of things so we don’t need the ful video file.

Parameters:
  • mock_ext – mock cv.VideoCapture in camera extractor module

  • mock_meta – mock get_video_meta

Returns:

test_habituation_session(mock_ext, mock_meta)[source]

Tests the full QC process for a habituation session. :return:

test_load_sess_params()[source]

Test that the session description file is used in the load_data method.

side_effect()[source]
class TestWheelMotionNRG(*args, **kwargs)[source]

Bases: IntegrationTest

required_files = ['camera/6c6983ef-7383-4989-9183-32b1a300d17a_frame_samples.npy', 'camera/SWC_054/2020-10-07/001']

An optional list of required files/folders to glob for, relative to data_path.

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

side_effect()[source]
test_wheel_motion()[source]
class TestWheelAlignment(*args, **kwargs)[source]

Bases: IntegrationTest

required_files = ['training/CSHL_003/2019-04-05/001', 'ephys/choice_world_init/KS022/2019-12-10/001']

An optional list of required files/folders to glob for, relative to data_path.

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

test_alignment_ephys_session()[source]