def _read_settings_json_compatibility_enforced(json_file): with open(json_file) as js: md = json.load(js) if 'IBLRIG_VERSION_TAG' not in md.keys(): md['IBLRIG_VERSION_TAG'] = '3.2.3' if not md['IBLRIG_VERSION_TAG']: logger_.warning("You appear to be on an untagged version...") return md # 2018-12-05 Version 3.2.3 fixes (permanent fixes in IBL_RIG from 3.2.4 on) if version.le(md['IBLRIG_VERSION_TAG'], '3.2.3'): if 'LAST_TRIAL_DATA' in md.keys(): md.pop('LAST_TRIAL_DATA') if 'weighings' in md['PYBPOD_SUBJECT_EXTRA'].keys(): md['PYBPOD_SUBJECT_EXTRA'].pop('weighings') if 'water_administration' in md['PYBPOD_SUBJECT_EXTRA'].keys(): md['PYBPOD_SUBJECT_EXTRA'].pop('water_administration') if 'IBLRIG_COMMIT_HASH' not in md.keys(): md['IBLRIG_COMMIT_HASH'] = 'f9d8905647dbafe1f9bdf78f73b286197ae2647b' # parse the date format to Django supported ISO dt = dateparser.parse(md['SESSION_DATETIME']) md['SESSION_DATETIME'] = ibllib.time.date2isostr(dt) # add the weight key if it doesn't already exists if 'SUBJECT_WEIGHT' not in md.keys(): md['SUBJECT_WEIGHT'] = None return md
def rename_files_compatibility(ses_path, version_tag): if version.le(version_tag, '3.2.3'): task_code = ses_path.glob('**/_ibl_trials.iti_duration.npy') for fn in task_code: fn.replace(fn.parent.joinpath('_ibl_trials.itiDuration.npy')) task_code = ses_path.glob('**/_iblrig_taskCodeFiles.raw.zip') for fn in task_code: fn.replace(fn.parent.joinpath('_iblrig_codeFiles.raw.zip'))
def extract_all(session_path, save=True, bpod_trials=None, settings=None): """ Extracts a training session from its path. NB: Wheel must be extracted first in order to extract trials.firstMovement_times. :param session_path: the path to the session to be extracted :param save: if true a subset of the extracted data are saved as ALF :param bpod_trials: list of Bpod trial data :param settings: the Bpod session settings :return: trials: Bunch/dict of trials :return: wheel: Bunch/dict of wheel positions :return: out_Files: list of output files """ extractor_type = ibllib.io.extractors.base.get_session_extractor_type( session_path) _logger.info(f"Extracting {session_path} as {extractor_type}") bpod_trials = bpod_trials or rawio.load_data(session_path) settings = settings or rawio.load_settings(session_path) if extractor_type == 'training': _logger.info('training session on ' + settings['PYBPOD_BOARD']) wheel, files_wheel = training_wheel.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) trials, files_trials = training_trials.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) elif extractor_type == 'biased' or extractor_type == 'ephys': _logger.info('biased session on ' + settings['PYBPOD_BOARD']) wheel, files_wheel = training_wheel.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) trials, files_trials = biased_trials.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) elif extractor_type == 'habituation': from ibllib.misc import version _logger.info('habituation session on ' + settings['PYBPOD_BOARD']) if version.le(settings['IBLRIG_VERSION_TAG'], '5.0.0'): _logger.warning("No extraction of legacy habituation sessions") return None, None, None trials, files_trials = habituation_trials.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) wheel = None files_wheel = [] else: raise ValueError(f"No extractor for task {extractor_type}") _logger.info('session extracted \n') # timing info in log return trials, wheel, (files_trials + files_wheel) if save else None
def extract_all(session_path, save=True, bpod_trials=None, settings=None): """ Extracts a training session from its path. NB: Wheel must be extracted first in order to extract trials.firstMovement_times. :param session_path: the path to the session to be extracted :param save: if true a subset of the extracted data are saved as ALF :param bpod_trials: list of Bpod trial data :param settings: the Bpod session settings :return: trials: Bunch/dict of trials :return: wheel: Bunch/dict of wheel positions :return: out_Files: list of output files """ extractor_type = ibllib.io.extractors.base.get_session_extractor_type(session_path) _logger.info(f"Extracting {session_path} as {extractor_type}") bpod_trials = bpod_trials or rawio.load_data(session_path) settings = settings or rawio.load_settings(session_path) _logger.info(f'{extractor_type} session on {settings["PYBPOD_BOARD"]}') # Determine which additional extractors are required extra = [] if extractor_type == 'ephys': # Should exclude 'ephys_biased' _logger.debug('Engaging biased TrialsTableEphys') extra.append(biased_trials.TrialsTableEphys) if extractor_type in ['biased_opto', 'ephys_biased_opto']: _logger.debug('Engaging opto_trials LaserBool') extra.append(opto_trials.LaserBool) # Determine base extraction if extractor_type in ['training', 'ephys_training']: trials, files_trials = training_trials.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) # This is hacky but avoids extracting the wheel twice. # files_trials should contain wheel files at the end. files_wheel = [] wheel = OrderedDict({k: trials.pop(k) for k in tuple(trials.keys()) if 'wheel' in k}) elif 'biased' in extractor_type or 'ephys' in extractor_type: trials, files_trials = biased_trials.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save, extra_classes=extra) files_wheel = [] wheel = OrderedDict({k: trials.pop(k) for k in tuple(trials.keys()) if 'wheel' in k}) elif extractor_type == 'habituation': if settings['IBLRIG_VERSION_TAG'] and version.le(settings['IBLRIG_VERSION_TAG'], '5.0.0'): _logger.warning("No extraction of legacy habituation sessions") return None, None, None trials, files_trials = habituation_trials.extract_all( session_path, bpod_trials=bpod_trials, settings=settings, save=save) wheel = None files_wheel = [] else: raise ValueError(f"No extractor for task {extractor_type}") _logger.info('session extracted \n') # timing info in log return trials, wheel, (files_trials + files_wheel) if save else None
def _read_settings_json_compatibility_enforced(json_file): with open(json_file) as js: md = json.load(js) if 'IBLRIG_VERSION_TAG' not in md.keys(): md['IBLRIG_VERSION_TAG'] = '3.2.3' # 2018-12-05 Version 3.2.3 fixes (permanent fixes in IBL_RIG from 3.2.4 on) if version.le(md['IBLRIG_VERSION_TAG'], '3.2.3'): if 'LAST_TRIAL_DATA' in md.keys(): md.pop('LAST_TRIAL_DATA') if 'weighings' in md['PYBPOD_SUBJECT_EXTRA'].keys(): md['PYBPOD_SUBJECT_EXTRA'].pop('weighings') if 'water_administration' in md['PYBPOD_SUBJECT_EXTRA'].keys(): md['PYBPOD_SUBJECT_EXTRA'].pop('water_administration') if 'IBLRIG_COMMIT_HASH' not in md.keys(): md['IBLRIG_COMMIT_HASH'] = 'f9d8905647dbafe1f9bdf78f73b286197ae2647b' # change the date format to proper ISO dt = datetime.datetime.strptime(md['SESSION_DATETIME'], '%Y-%m-%d %H:%M:%S.%f') md['SESSION_DATETIME'] = ibllib.time.date2isostr(dt) if 'SUBJECT_WEIGHT' not in md.keys(): md['SUBJECT_WEIGHT'] = None return md
def assert_g(self, v0, v_): self.assertFalse(version.eq(v0, v_)) self.assertTrue(version.ge(v0, v_)) self.assertFalse(version.le(v0, v_)) self.assertTrue(version.gt(v0, v_)) self.assertFalse(version.lt(v0, v_))