def test_registration_session(self): behavior_path = self.session_path.joinpath('raw_behavior_data') behavior_path.mkdir() settings_file = behavior_path.joinpath('_iblrig_taskSettings.raw.json') with open(settings_file, 'w') as fid: json.dump(MOCK_SESSION_SETTINGS, fid) rc = registration.RegistrationClient(one=one) rc.register_session(self.session_path) eid = one.search(subjects=SUBJECT, date_range=['2018-04-01', '2018-04-01'])[0] datasets = one.alyx.rest('datasets', 'list', session=eid) for ds in datasets: self.assertTrue(ds['hash'] is not None) self.assertTrue(ds['file_size'] is not None) self.assertTrue(ds['version'] == version.ibllib()) # checks the procedure of the session ses_info = one.alyx.rest('sessions', 'read', id=eid) self.assertTrue(ses_info['procedures'] == ['Ephys recording with acute probe(s)']) one.alyx.rest('sessions', 'delete', id=eid) # re-register the session as behaviour this time MOCK_SESSION_SETTINGS['PYBPOD_PROTOCOL'] = '_iblrig_tasks_trainingChoiceWorld6.3.1' with open(settings_file, 'w') as fid: json.dump(MOCK_SESSION_SETTINGS, fid) rc.register_session(self.session_path) eid = one.search(subjects=SUBJECT, date_range=['2018-04-01', '2018-04-01'])[0] ses_info = one.alyx.rest('sessions', 'read', id=eid) self.assertTrue(ses_info['procedures'] == ['Behavior training/tasks'])
def job_creator(root_path, one=None, dry=False, rerun=False, max_md5_size=None): """ Server function that will look for creation flags and for each: 1) create the sessions on Alyx 2) register the corresponding raw data files on Alyx 3) create the tasks to be run on Alyx :param root_path: main path containing sessions or session path :param one :param dry :param rerun :param max_md5_size :return: """ if not one: one = ONE() rc = registration.RegistrationClient(one=one) flag_files = list(Path(root_path).glob('**/extract_me.flag')) flag_files += list(Path(root_path).glob('**/raw_session.flag')) all_datasets = [] for flag_file in flag_files: session_path = flag_file.parent _logger.info(f'creating session for {session_path}') if dry: continue flag_file.unlink() # if the subject doesn't exist in the database, skip try: rc.create_session(session_path) except ibllib.exceptions.AlyxSubjectNotFound: continue files, dsets = registration.register_session_raw_data( session_path, one=one, max_md5_size=max_md5_size) if dsets is not None: all_datasets.extend(dsets) session_type = rawio.get_session_extractor_type(session_path) if session_type in ['biased', 'habituation', 'training']: pipe = training_preprocessing.TrainingExtractionPipeline( session_path, one=one) # only start extracting ephys on a raw_session.flag elif session_type in ['ephys' ] and flag_file.name == 'raw_session.flag': pipe = ephys_preprocessing.EphysExtractionPipeline(session_path, one=one) else: _logger.info( f"Session type {session_type} as no matching extractor {session_path}" ) return if rerun: rerun__status__in = '__all__' else: rerun__status__in = ['Waiting'] pipe.create_alyx_tasks(rerun__status__in=rerun__status__in) return all_datasets
def test_registration_session(self): settings = { 'SESSION_DATE': '2018-04-01', 'SESSION_DATETIME': '2018-04-01T12:48:26.795526', 'PYBPOD_CREATOR': ['test_user', 'f092c2d5-c98a-45a1-be7c-df05f129a93c', 'local'], 'SESSION_NUMBER': '002', 'SUBJECT_NAME': 'clns0730', 'PYBPOD_BOARD': '_iblrig_mainenlab_behavior_1', 'PYBPOD_PROTOCOL': '_iblrig_tasks_ephysChoiceWorld', 'IBLRIG_VERSION_TAG': '5.4.1', 'SUBJECT_WEIGHT': 22, } with tempfile.TemporaryDirectory() as td: # creates the local session session_path = Path(td).joinpath('clns0730', '2018-04-01', '002') alf_path = session_path.joinpath('alf') alf_path.mkdir(parents=True) alf_path.joinpath('spikes.times.npy').touch() alf_path.joinpath('spikes.amps.npy').touch() behavior_path = session_path.joinpath('raw_behavior_data') behavior_path.mkdir() settings_file = behavior_path.joinpath( '_iblrig_taskSettings.raw.json') with open(settings_file, 'w') as fid: json.dump(settings, fid) rc = registration.RegistrationClient(one=one) rc.register_session(session_path) eid = one.search(subjects='clns0730', date_range=['2018-04-01', '2018-04-01'])[0] datasets = one.alyx.get( '/datasets?subject=clns0730&date=2018-04-01') for ds in datasets: self.assertTrue(ds['hash'] is not None) self.assertTrue(ds['file_size'] is not None) self.assertTrue(ds['version'] == version.ibllib()) one.alyx.rest('sessions', 'delete', id=eid)