From 9fbc0f273af68854538eed7a7253ff3a210cc0f8 Mon Sep 17 00:00:00 2001 From: Mayo Faulkner Date: Wed, 13 Dec 2023 12:52:30 +0000 Subject: [PATCH 1/2] randomise session for histology --- ibllib/tests/qc/test_alignment_qc.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ibllib/tests/qc/test_alignment_qc.py b/ibllib/tests/qc/test_alignment_qc.py index bb3e6a433..54bf8bd06 100644 --- a/ibllib/tests/qc/test_alignment_qc.py +++ b/ibllib/tests/qc/test_alignment_qc.py @@ -19,7 +19,6 @@ from ibllib.pipes.histology import register_track, register_chronic_track from one.registration import RegistrationClient - EPHYS_SESSION = 'b1c968ad-4874-468d-b2e4-5ffa9b9964e9' one = ONE(**TEST_DB) brain_atlas = AllenAtlas(25) @@ -37,7 +36,12 @@ class TestTracingQc(unittest.TestCase): def setUpClass(cls) -> None: probe = [''.join(random.choices(string.ascii_letters, k=5)), ''.join(random.choices(string.ascii_letters, k=5))] - ins = create_alyx_probe_insertions(session_path=EPHYS_SESSION, model='3B2', labels=probe, + date = str(datetime.date(2019, np.random.randint(1, 12), np.random.randint(1, 28))) + _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) + cls.eid = str(eid) + # Currently the task protocol of a session must contain 'ephys' in order to create an insertion! + one.alyx.rest('sessions', 'partial_update', id=cls.eid, data={'task_protocol': 'ephys'}) + ins = create_alyx_probe_insertions(session_path=cls.eid, model='3B2', labels=probe, one=one, force=True) cls.probe00_id, cls.probe01_id = (x['id'] for x in ins) data = np.load(Path(Path(__file__).parent.parent. @@ -64,6 +68,7 @@ def test_tracing_not_exists(self): def tearDownClass(cls) -> None: one.alyx.rest('insertions', 'delete', id=cls.probe01_id) one.alyx.rest('insertions', 'delete', id=cls.probe00_id) + one.alyx.rest('sessions', 'delete', id=cls.eid) class TestChronicTracingQC(unittest.TestCase): @@ -73,12 +78,17 @@ def setUpClass(cls) -> None: serial = ''.join(random.choices(string.ascii_letters, k=10)) # Make a chronic insertions - ref = one.eid2ref(EPHYS_SESSION) - insdict = {"subject": ref['subject'], "name": probe, "model": '3B2', "serial": serial} + date = str(datetime.date(2019, np.random.randint(1, 12), np.random.randint(1, 28))) + _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) + cls.eid = str(eid) + # Currently the task protocol of a session must contain 'ephys' in order to create an insertion! + one.alyx.rest('sessions', 'partial_update', id=cls.eid, data={'task_protocol': 'ephys'}) + + insdict = {"subject": 'ZM_1150', "name": probe, "model": '3B2', "serial": serial} ins = one.alyx.rest('chronic-insertions', 'create', data=insdict) cls.chronic_id = ins['id'] # Make a probe insertions - insdict = {"session": EPHYS_SESSION, "name": probe, "model": '3B2', "serial": serial, + insdict = {"session": cls.eid, "name": probe, "model": '3B2', "serial": serial, "chronic_insertion": cls.chronic_id} ins = one.alyx.rest('insertions', 'create', data=insdict) cls.probe_id = ins['id'] @@ -117,6 +127,7 @@ def test_tracing_not_exists(self): def tearDownClass(cls) -> None: one.alyx.rest('insertions', 'delete', id=cls.probe_id) one.alyx.rest('chronic-insertions', 'delete', id=cls.chronic_id) + one.alyx.rest('sessions', 'delete', id=cls.eid) class TestAlignmentQcExisting(unittest.TestCase): From 8454d8d455760d2de834dc0e93002fd1ce543e2e Mon Sep 17 00:00:00 2001 From: Mayo Faulkner Date: Wed, 13 Dec 2023 13:17:40 +0000 Subject: [PATCH 2/2] randomise all seeds --- ibllib/tests/qc/test_alignment_qc.py | 12 ++++++++---- ibllib/tests/qc/test_critical_reasons.py | 3 ++- ibllib/tests/test_oneibl.py | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ibllib/tests/qc/test_alignment_qc.py b/ibllib/tests/qc/test_alignment_qc.py index 54bf8bd06..e4b7a2ba0 100644 --- a/ibllib/tests/qc/test_alignment_qc.py +++ b/ibllib/tests/qc/test_alignment_qc.py @@ -34,9 +34,10 @@ class TestTracingQc(unittest.TestCase): @classmethod def setUpClass(cls) -> None: + rng = np.random.default_rng() probe = [''.join(random.choices(string.ascii_letters, k=5)), ''.join(random.choices(string.ascii_letters, k=5))] - date = str(datetime.date(2019, np.random.randint(1, 12), np.random.randint(1, 28))) + date = str(datetime.date(2019, rng.integers(1, 12), rng.integers(1, 28))) _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) cls.eid = str(eid) # Currently the task protocol of a session must contain 'ephys' in order to create an insertion! @@ -74,11 +75,12 @@ def tearDownClass(cls) -> None: class TestChronicTracingQC(unittest.TestCase): @classmethod def setUpClass(cls) -> None: + rng = np.random.default_rng() probe = ''.join(random.choices(string.ascii_letters, k=5)) serial = ''.join(random.choices(string.ascii_letters, k=10)) # Make a chronic insertions - date = str(datetime.date(2019, np.random.randint(1, 12), np.random.randint(1, 28))) + date = str(datetime.date(2019, rng.integers(1, 12), rng.integers(1, 28))) _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) cls.eid = str(eid) # Currently the task protocol of a session must contain 'ephys' in order to create an insertion! @@ -136,6 +138,7 @@ class TestAlignmentQcExisting(unittest.TestCase): @classmethod def setUpClass(cls) -> None: + rng = np.random.default_rng() data = np.load(Path(Path(__file__).parent.parent. joinpath('fixtures', 'qc', 'data_alignmentqc_existing.npz')), allow_pickle=True) @@ -148,7 +151,7 @@ def setUpClass(cls) -> None: insertion = data['insertion'].tolist() insertion['name'] = ''.join(random.choices(string.ascii_letters, k=5)) insertion['json'] = {'xyz_picks': cls.xyz_picks} - date = str(datetime.date(2019, np.random.randint(1, 12), np.random.randint(1, 28))) + date = str(datetime.date(2019, rng.integers(1, 12), rng.integers(1, 28))) _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) cls.eid = str(eid) # Currently the task protocol of a session must contain 'ephys' in order to create an insertion! @@ -254,6 +257,7 @@ class TestAlignmentQcManual(unittest.TestCase): @classmethod def setUpClass(cls) -> None: + rng = np.random.default_rng() data = np.load(Path(Path(__file__).parent.parent. joinpath('fixtures', 'qc', 'data_alignmentqc_manual.npz')), allow_pickle=True) @@ -268,7 +272,7 @@ def setUpClass(cls) -> None: insertion['name'] = ''.join(random.choices(string.ascii_letters, k=5)) insertion['json'] = {'xyz_picks': cls.xyz_picks} - date = str(datetime.date(2018, np.random.randint(1, 12), np.random.randint(1, 28))) + date = str(datetime.date(2018, rng.integers(1, 12), rng.integers(1, 28))) _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) cls.eid = str(eid) insertion['session'] = cls.eid diff --git a/ibllib/tests/qc/test_critical_reasons.py b/ibllib/tests/qc/test_critical_reasons.py index 4094ff468..934cacab1 100644 --- a/ibllib/tests/qc/test_critical_reasons.py +++ b/ibllib/tests/qc/test_critical_reasons.py @@ -28,10 +28,11 @@ def mock_input(prompt): class TestUserPmtSess(unittest.TestCase): def setUp(self) -> None: + rng = np.random.default_rng() # Make sure tests use correct session ID one.alyx.clear_rest_cache() # Create new session on database with a random date to avoid race conditions - date = str(datetime.date(2022, np.random.randint(1, 12), np.random.randint(1, 28))) + date = str(datetime.date(2022, rng.integers(1, 12), rng.integers(1, 28))) from one.registration import RegistrationClient _, eid = RegistrationClient(one).create_new_session('ZM_1150', date=date) eid = str(eid) diff --git a/ibllib/tests/test_oneibl.py b/ibllib/tests/test_oneibl.py index 9b7fb1049..bd24fc8bf 100644 --- a/ibllib/tests/test_oneibl.py +++ b/ibllib/tests/test_oneibl.py @@ -267,6 +267,7 @@ def test_task_names_extractors(self): class TestRegistration(unittest.TestCase): def setUp(self) -> None: + rng = np.random.default_rng() self.one = ONE(**TEST_DB, cache_rest=None) # makes sure tests start without session created eid = self.one.search(subject=SUBJECT, date_range='2018-04-01', query_type='remote') @@ -292,7 +293,7 @@ def setUp(self) -> None: except HTTPError: self.rev = self.one.alyx.rest('revisions', 'create', data={'name': self.revision}) # Create a new tag - tag_data = {'name': f'test_tag_{np.random.randint(0, 1e3)}', 'protected': True} + tag_data = {'name': f'test_tag_{rng.integers(0, 1e3)}', 'protected': True} self.tag = self.one.alyx.rest('tags', 'create', data=tag_data) def test_registration_datasets(self):