def eid_from_path(self, path_obj): """ From a local path, gets the experiment id :param path_obj: local path or list of local paths :return: eid or list of eids """ # If path_obj is a list recurse through it and return a list if isinstance(path_obj, list): path_obj = [Path(x) for x in path_obj] eid_list = [] for p in path_obj: eid_list.append(self.eid_from_path(p)) return eid_list # else ensure the path ends with mouse,date, number path_obj = Path(path_obj) session_path = alfio.get_session_path(path_obj) # if path does not have a date and a number, or cache is empty return None if session_path is None or self._cache.size == 0: return None # fetch eid from cache ind = ((self._cache['subject'] == session_path.parts[-3]) & (self._cache['start_time'].apply( lambda x: x.isoformat()[:10] == session_path.parts[-2])) & (self._cache['number']) == int(session_path.parts[-1])) ind = np.where(ind.to_numpy())[0] if ind.size > 0: return parquet.np2str(self._cache[['eid_0', 'eid_1']].iloc[ind[0]])
def eid_from_path(self, path_obj: Union[str, Path], use_cache: bool = True) -> Listable(Path): """ From a local path, gets the experiment id :param path_obj: local path or list of local paths :param use_cache: if set to False, will force database connection :return: eid or list of eids """ # If path_obj is a list recurse through it and return a list if isinstance(path_obj, list): path_obj = [Path(x) for x in path_obj] eid_list = [] for p in path_obj: eid_list.append(self.eid_from_path(p)) return eid_list # else ensure the path ends with mouse,date, number path_obj = Path(path_obj) session_path = alfio.get_session_path(path_obj) # if path does not have a date and a number return None if session_path is None: return None # try the cached info to possibly avoid hitting database cache_eid = super().eid_from_path(path_obj) if cache_eid: return cache_eid # if not search for subj, date, number XXX: hits the DB uuid = self.search(subjects=session_path.parts[-3], date_range=session_path.parts[-2], number=session_path.parts[-1]) # Return the uuid if any return uuid[0] if uuid else None
def get_task_extractor_type(task_name): """ Splits the task name according to naming convention: - ignores everything _iblrig_tasks_biasedChoiceWorld3.7.0 returns "biased" _iblrig_tasks_trainingChoiceWorld3.6.0 returns "training' :param task_name: :return: one of ['biased', 'habituation', 'training', 'ephys', 'mock_ephys', 'sync_ephys'] """ if isinstance(task_name, Path): try: settings = rawio.load_settings(get_session_path(task_name)) except json.decoder.JSONDecodeError: return if settings: task_name = settings.get('PYBPOD_PROTOCOL', None) else: return if '_biasedChoiceWorld' in task_name: return 'biased' elif 'biasedScanningChoiceWorld' in task_name: return 'biased' elif 'biasedVisOffChoiceWorld' in task_name: return 'biased' elif '_habituationChoiceWorld' in task_name: return 'habituation' elif '_trainingChoiceWorld' in task_name: return 'training' elif 'ephysChoiceWorld' in task_name: return 'ephys' elif 'ephysMockChoiceWorld' in task_name: return 'mock_ephys' elif task_name and task_name.startswith('_iblrig_tasks_ephys_certification'): return 'sync_ephys'
def get_task_extractor_type(task_name): """ Returns the task type string from the full pybpod task name: _iblrig_tasks_biasedChoiceWorld3.7.0 returns "biased" _iblrig_tasks_trainingChoiceWorld3.6.0 returns "training' :param task_name: :return: one of ['biased', 'habituation', 'training', 'ephys', 'mock_ephys', 'sync_ephys'] """ if isinstance(task_name, Path): try: settings = load_settings(get_session_path(task_name)) except json.decoder.JSONDecodeError: return if settings: task_name = settings.get('PYBPOD_PROTOCOL', None) else: return task_types = _get_task_types_json_config() return next((task_types[tt] for tt in task_types if tt in task_name), None)
def eid_from_path(self, path_obj): # If path_obj is a list recurse through it and return a list if isinstance(path_obj, list): path_obj = [Path(x) for x in path_obj] eid_list = [] for p in path_obj: eid_list.append(self.eid_from_path(p)) return eid_list # else ensure the path ends with mouse,date, number path_obj = Path(path_obj) session_path = get_session_path(path_obj) # if path does not have a date and a number return None if session_path is None: return None # search for subj, date, number XXX: hits the DB uuid = self.search(subjects=session_path.parts[-3], date_range=session_path.parts[-2], number=session_path.parts[-1]) # Return the uuid if any return uuid[0] if uuid else None
def eid_from_path(self, path_obj, use_cache=True): """ From a local path, gets the experiment id :param path_obj: local path or list of local paths :param use_cache: if set to False, will force database connection :return: eid or list of eids """ # If path_obj is a list recurse through it and return a list if isinstance(path_obj, list): path_obj = [Path(x) for x in path_obj] eid_list = [] for p in path_obj: eid_list.append(self.eid_from_path(p)) return eid_list # else ensure the path ends with mouse,date, number path_obj = Path(path_obj) session_path = alfio.get_session_path(path_obj) # if path does not have a date and a number return None if session_path is None: return None # try the cached info to possibly avoid hitting database if self._cache.size > 0 and use_cache: ind = ((self._cache['subject'] == session_path.parts[-3]) & (self._cache['start_time'].apply( lambda x: x.isoformat()[:10] == session_path.parts[-2])) & (self._cache['number']) == int(session_path.parts[-1])) ind = np.where(ind.to_numpy())[0] if ind.size > 0: return parquet.np2str(self._cache[['eid_0', 'eid_1']].iloc[ind[0]]) # if not search for subj, date, number XXX: hits the DB uuid = self.search(subjects=session_path.parts[-3], date_range=session_path.parts[-2], number=session_path.parts[-1]) # Return the uuid if any return uuid[0] if uuid else None
def path_from_eid(self, eid: str, grep_str=None) -> Path: # If eid is a list of eIDs recurse through list and return the results if isinstance(eid, list): path_list = [] for p in eid: path_list.append(self.path_from_eid(p, grep_str=grep_str)) return path_list # If not valid return None if not is_uuid_string(eid): print(eid, " is not a valid eID/UUID string") return # Load data, if no data present on disk return None data = self._load(eid, download_only=True, offline=True) if not data.local_path: return None # If user defined a grep list of specific files return paths to files if grep_str is not None: files = [x for x in data.local_path if grep_str in str(x)] return files # If none of the above happen return the session path of the first file you find session_path = get_session_path(data.local_path[0]) return session_path