Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

randomise session for histology #687

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions ibllib/tests/qc/test_alignment_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,9 +34,15 @@ 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))]
ins = create_alyx_probe_insertions(session_path=EPHYS_SESSION, model='3B2', labels=probe,
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!
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.
Expand All @@ -64,21 +69,28 @@ 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):
@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
ref = one.eid2ref(EPHYS_SESSION)
insdict = {"subject": ref['subject'], "name": probe, "model": '3B2', "serial": serial}
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!
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']
Expand Down Expand Up @@ -117,6 +129,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):
Expand All @@ -125,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)
Expand All @@ -137,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!
Expand Down Expand Up @@ -243,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)
Expand All @@ -257,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
Expand Down
3 changes: 2 additions & 1 deletion ibllib/tests/qc/test_critical_reasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ibllib/tests/test_oneibl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down
Loading