def extract_all(session_path, save=False, bpod_trials=False, settings=False): """Extract all datasets from habituationChoiceWorld Note: only the datasets from the HabituationTrials extractor will be saved to disc. :param session_path: The session path where the raw data are saved :param save: If True, the datasets that are considered standard are saved to the session path :param bpod_trials: The raw Bpod trial data :param settings: The raw Bpod sessions :returns: a dict of datasets and a corresponding list of file names """ if not bpod_trials: bpod_trials = raw.load_data(session_path) if not settings: settings = raw.load_settings(session_path) # Standard datasets that may be saved as ALFs params = dict(session_path=session_path, bpod_trials=bpod_trials, settings=settings) out, fil = run_extractor_classes(HabituationTrials, save=save, **params) # The extra datasets non_standard = [ ItiInTimes, StimOffTriggerTimes, StimCenterTriggerTimes, StimCenterTimes ] data, _ = run_extractor_classes(non_standard, save=False, **params) # Merge the extracted data out.update(data) fil.extend([None for _ in data.keys()]) return out, fil
def extract_all(session_path, save=False, bpod_trials=None, settings=None): if not bpod_trials: bpod_trials = raw.load_data(session_path) if not settings: settings = raw.load_settings(session_path) if settings is None or settings['IBLRIG_VERSION_TAG'] == '': settings = {'IBLRIG_VERSION_TAG': '100.0.0'} base = [ FeedbackType, ContrastLR, ProbabilityLeft, Choice, RepNum, RewardVolume, FeedbackTimes, Intervals, ResponseTimes, GoCueTriggerTimes, GoCueTimes ] # Version check if version.ge(settings['IBLRIG_VERSION_TAG'], '5.0.0'): base.extend([ StimOnTriggerTimes, StimOnOffFreezeTimes, ItiInTimes, StimOffTriggerTimes, StimFreezeTriggerTimes, ErrorCueTriggerTimes ]) else: base.extend([IncludedTrials, ItiDuration, StimOnTimes]) out, fil = run_extractor_classes(base, save=save, session_path=session_path, bpod_trials=bpod_trials, settings=settings) return out, fil
def extract_all(session_path, save=True, bin_exists=False): """ For the IBL ephys task, reads ephys binary file and extract: - sync - wheel - behaviour - video time stamps :param session_path: '/path/to/subject/yyyy-mm-dd/001' :param save: Bool, defaults to False :return: outputs, files """ extractor_type = extractors_base.get_session_extractor_type(session_path) _logger.info(f"Extracting {session_path} as {extractor_type}") basecls = [FpgaTrials] if extractor_type in ['ephys', 'mock_ephys', 'sync_ephys']: basecls.extend([ProbaContrasts]) elif extractor_type in ['ephys_biased_opto']: from ibllib.io.extractors import opto_trials basecls.extend([ biased_trials.ProbabilityLeft, biased_trials.ContrastLR, opto_trials.LaserBool ]) sync, chmap = get_main_probe_sync(session_path, bin_exists=bin_exists) outputs, files = extractors_base.run_extractor_classes( basecls, session_path=session_path, save=save, sync=sync, chmap=chmap) return outputs, files
def _extract(self, extractor_classes=None, **kwargs): base = [Intervals, GoCueTimes, ResponseTimes, Choice, StimOnOffFreezeTimes, ContrastLR, FeedbackTimes, FeedbackType, RewardVolume, ProbabilityLeft, Wheel] out, _ = run_extractor_classes( base, session_path=self.session_path, bpod_trials=self.bpod_trials, settings=self.settings, save=False ) table = AlfBunch({k: out.pop(k) for k in list(out.keys()) if k not in self.var_names}) assert len(table.keys()) == 12 return table.to_df(), *(out.pop(x) for x in self.var_names if x != 'table')
def extract_all(session_path, save=True, bin_exists=False): """ For the IBL ephys task, reads ephys binary file and extract: - sync - wheel - behaviour - video time stamps :param session_path: '/path/to/subject/yyyy-mm-dd/001' :param save: Bool, defaults to False :return: outputs, files """ sync, chmap = get_main_probe_sync(session_path, bin_exists=bin_exists) outputs, files = run_extractor_classes([CameraTimestamps, FpgaTrials], session_path=session_path, save=save, sync=sync, chmap=chmap) return outputs, files
def extract_all(session_path, save=True, bin_exists=False): """ For the IBL ephys task, reads ephys binary file and extract: - sync - wheel - behaviour - video time stamps :param session_path: '/path/to/subject/yyyy-mm-dd/001' :param save: Bool, defaults to False :return: outputs, files """ extractor_type = extractors_base.get_session_extractor_type(session_path) _logger.info(f"Extracting {session_path} as {extractor_type}") basecls = [FpgaTrials] sync, chmap = get_main_probe_sync(session_path, bin_exists=bin_exists) outputs, files = extractors_base.run_extractor_classes( basecls, session_path=session_path, save=save, sync=sync, chmap=chmap) return outputs, files
def extract_all(session_path, save=False, bpod_trials=None, settings=None): """Extract trials and wheel data. For task versions >= 5.0.0, outputs wheel data and trials.table dataset (+ some extra datasets) Parameters ---------- session_path : str, pathlib.Path The path to the session save : bool If true save the data files to ALF bpod_trials : list of dicts The Bpod trial dicts loaded from the _iblrig_taskData.raw dataset settings : dict The Bpod settings loaded from the _iblrig_taskSettings.raw dataset Returns ------- A list of extracted data and a list of file paths if save is True (otherwise None) """ if not bpod_trials: bpod_trials = raw.load_data(session_path) if not settings: settings = raw.load_settings(session_path) if settings is None or settings['IBLRIG_VERSION_TAG'] == '': settings = {'IBLRIG_VERSION_TAG': '100.0.0'} base = [RepNum, GoCueTriggerTimes] # Version check if version.ge(settings['IBLRIG_VERSION_TAG'], '5.0.0'): # We now extract a single trials table base.extend([ StimOnTriggerTimes, ItiInTimes, StimOffTriggerTimes, StimFreezeTriggerTimes, ErrorCueTriggerTimes, TrialsTable, PhasePosQuiescence ]) else: base.extend([ Intervals, Wheel, FeedbackType, ContrastLR, ProbabilityLeft, Choice, IncludedTrials, ItiDuration, StimOnTimes_deprecated, RewardVolume, FeedbackTimes, ResponseTimes, GoCueTimes, PhasePosQuiescence ]) out, fil = run_extractor_classes( base, save=save, session_path=session_path, bpod_trials=bpod_trials, settings=settings) return out, fil
def extract_all(session_path, save=False, bpod_trials=False, settings=False): """Extract all datasets from habituationChoiceWorld Note: only the datasets from the HabituationTrials extractor will be saved to disc. :param session_path: The session path where the raw data are saved :param save: If True, the datasets that are considered standard are saved to the session path :param bpod_trials: The raw Bpod trial data :param settings: The raw Bpod sessions :returns: a dict of datasets and a corresponding list of file names """ if not bpod_trials: bpod_trials = raw.load_data(session_path) if not settings: settings = raw.load_settings(session_path) # Standard datasets that may be saved as ALFs params = dict(session_path=session_path, bpod_trials=bpod_trials, settings=settings) out, fil = run_extractor_classes(HabituationTrials, save=save, **params) return out, fil
def extract_all(session_path, save=True, bin_exists=False): """ For the IBL ephys task, reads ephys binary file and extract: - sync - wheel - behaviour - video time stamps :param session_path: '/path/to/subject/yyyy-mm-dd/001' :param save: Bool, defaults to False :param version: bpod version, defaults to None :return: outputs, files """ assert save # fixme with wheel positions, this function can't work without saving the data sync, chmap = _get_main_probe_sync(session_path, bin_exists=bin_exists) outputs, files = run_extractor_classes([CameraTimestamps, FpgaTrials], session_path=session_path, save=save, sync=sync, chmap=chmap) return outputs, files
def extract_all(session_path, save=False, bpod_trials=False, settings=False, extra_classes=None): """ Same as training_trials.extract_all except... - there is no RepNum - ContrastLR is extracted differently - IncludedTrials is only extracted for 5.0.0 or greater :param session_path: :param save: :param bpod_trials: :param settings: :param extra_classes: additional BaseBpodTrialsExtractor subclasses for custom extractions :return: """ if not bpod_trials: bpod_trials = raw.load_data(session_path) if not settings: settings = raw.load_settings(session_path) if settings is None or settings['IBLRIG_VERSION_TAG'] == '': settings = {'IBLRIG_VERSION_TAG': '100.0.0'} base = [GoCueTriggerTimes] # Version check if version.ge(settings['IBLRIG_VERSION_TAG'], '5.0.0'): # We now extract a single trials table base.extend([ StimOnTriggerTimes, ItiInTimes, StimOffTriggerTimes, StimFreezeTriggerTimes, ErrorCueTriggerTimes, TrialsTableBiased, IncludedTrials, PhasePosQuiescence ]) else: base.extend([ Intervals, Wheel, FeedbackType, ContrastLR, ProbabilityLeft, Choice, ItiDuration, StimOnTimes_deprecated, RewardVolume, FeedbackTimes, ResponseTimes, GoCueTimes, PhasePosQuiescence ]) if extra_classes: base.extend(extra_classes) out, fil = run_extractor_classes( base, save=save, session_path=session_path, bpod_trials=bpod_trials, settings=settings) return out, fil
def extract_all(session_path, bpod_trials=None, settings=None, save=False): """Extract the wheel data. NB: Wheel extraction is now called through ibllib.io.training_trials.extract_all Parameters ---------- session_path : str, pathlib.Path The path to the session save : bool If true save the data files to ALF bpod_trials : list of dicts The Bpod trial dicts loaded from the _iblrig_taskData.raw dataset settings : dict The Bpod settings loaded from the _iblrig_taskSettings.raw dataset Returns ------- A list of extracted data and a list of file paths if save is True (otherwise None) """ return run_extractor_classes(Wheel, save=save, session_path=session_path, bpod_trials=bpod_trials, settings=settings)
def extract_all(session_path, session_type=None, save=True, **kwargs): """ For the IBL ephys task, reads ephys binary file and extract: - video time stamps :param session_path: '/path/to/subject/yyyy-mm-dd/001' :param session_type: the session type to extract, i.e. 'ephys', 'training' or 'biased'. If None the session type is inferred from the settings file. :param save: Bool, defaults to False :param kwargs: parameters to pass to the extractor :return: outputs, files """ if session_type is None: session_type = get_session_extractor_type(session_path) if not session_type or session_type not in _get_task_types_json_config( ).values(): raise ValueError( f"Session type {session_type} has no matching extractor") elif 'ephys' in session_type: # assume ephys == FPGA labels = assert_valid_label( kwargs.pop('labels', ('left', 'right', 'body'))) labels = (labels, ) if isinstance(labels, str) else labels # Ensure list/tuple extractor = [partial(CameraTimestampsFPGA, label) for label in labels] if 'sync' not in kwargs: kwargs['sync'], kwargs['chmap'] = \ get_main_probe_sync(session_path, bin_exists=kwargs.pop('bin_exists', False)) else: # assume Bpod otherwise assert kwargs.pop('labels', 'left'), 'only left camera is currently supported' extractor = CameraTimestampsBpod outputs, files = run_extractor_classes(extractor, session_path=session_path, save=save, **kwargs) return outputs, files
def _extract(self): # Extract all trials... # Get all stim_sync events detected ttls = [raw.get_port_events(tr, 'BNC1') for tr in self.bpod_trials] # Report missing events n_missing = sum(len(pulses) != 3 for pulses in ttls) # Check if all stim syncs have failed to be detected if n_missing == len(ttls): _logger.error( f'{self.session_path}: Missing ALL BNC1 TTLs ({n_missing} trials)' ) elif n_missing > 0: # Check if any stim_sync has failed be detected for every trial _logger.warning( f'{self.session_path}: Missing BNC1 TTLs on {n_missing} trial(s)' ) # Extract datasets common to trainingChoiceWorld training = [ ContrastLR, FeedbackTimes, Intervals, GoCueTimes, StimOnTriggerTimes ] out, _ = run_extractor_classes(training, session_path=self.session_path, save=False, bpod_trials=self.bpod_trials, settings=self.settings) # GoCueTriggerTimes is the same event as StimOnTriggerTimes out['goCueTrigger_times'] = out['stimOnTrigger_times'].copy() # StimOn times stimOn_times = np.full(out['stimOnTrigger_times'].shape, np.nan) stim_center_triggers, _ = (StimCenterTriggerTimes( self.session_path).extract(self.bpod_trials, self.settings)) for i, (sync, last) in enumerate(zip(ttls, stim_center_triggers)): """We expect there to be 3 pulses per trial; if this is the case, stim on will be the second pulse. If 1 pulse is missing, we can only be confident of the correct one if both pulses occur before the stim center trigger""" if len(sync) == 3 or (len(sync) == 2 and sum(pulse < last for pulse in sync) == 2): stimOn_times[i] = sync[1] out['stimOn_times'] = stimOn_times # RewardVolume trial_volume = [x['reward_amount'] for x in self.bpod_trials] out['rewardVolume'] = np.array(trial_volume).astype(np.float64) # StimOffTrigger times (not saved) stimOffTriggers, _ = (StimOffTriggerTimes(self.session_path).extract( self.bpod_trials, self.settings)) # StimOff times """ There should be exactly three TTLs per trial. stimOff_times should be the first TTL pulse. If 1 or more pulses are missing, we can not be confident of assigning the correct one. """ out['stimOff_times'] = np.array([ sync[0] if len(sync) == 3 else np.nan for sync, off in zip(ttls[1:], stimOffTriggers) ]) # FeedbackType is always positive out['feedbackType'] = np.ones(len(out['feedback_times']), dtype=np.int8) # NB: We lose the last trial because the stim off event occurs at trial_num + 1 n_trials = out['stimOff_times'].size return [out[k][:n_trials] for k in self.var_names]
def extract_all(session_path, bpod_trials=None, settings=None, save=False): return run_extractor_classes(Wheel, save=save, session_path=session_path, bpod_trials=bpod_trials, settings=settings)