def path_from_eid(self, eid: str) -> Optional[Listable(Path)]: """ From an experiment id or a list of experiment ids, gets the local cache path :param eid: eid (UUID) or list of UUIDs :return: eid or list of eids """ # 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)) return path_list # If not valid return None if not alfio.is_uuid_string(eid): print(eid, " is not a valid eID/UUID string") return if self._cache.size == 0: return # load path from cache ic = find_first_2d(self._cache[['eid_0', 'eid_1']].to_numpy(), parquet.str2np(eid)) if ic is not None: ses = self._cache.iloc[ic] return Path(self._par.CACHE_DIR).joinpath( ses['lab'], 'Subjects', ses['subject'], ses['start_time'].isoformat()[:10], str(ses['number']).zfill(3))
def _make_dataclass_offline(self, eid, dataset_types=None, cache_dir=None, **kwargs): if self._cache.size == 0: return SessionDataInfo() # select the session npeid = parquet.str2np(eid)[0] df = self._cache[self._cache['eid_0'] == npeid[0]] df = df[df['eid_1'] == npeid[1]] # select datasets df = df[ismember(df['dataset_type'], dataset_types)[0]] return SessionDataInfo.from_pandas(df, self._get_cache_dir(cache_dir))
def test_uuids_conversions(self): str_uuid = 'a3df91c8-52a6-4afa-957b-3479a7d0897c' one_np_uuid = np.array([-411333541468446813, 8973933150224022421]) two_np_uuid = np.tile(one_np_uuid, [2, 1]) # array gives a list self.assertTrue(all(map(lambda x: x == str_uuid, np2str(two_np_uuid)))) # single uuid gives a string self.assertTrue(np2str(one_np_uuid) == str_uuid) # list uuids with some None entries uuid_list = [ 'bc74f49f33ec0f7545ebc03f0490bdf6', 'c5779e6d02ae6d1d6772df40a1a94243', None, '643371c81724378d34e04a60ef8769f4' ] assert np.all(str2np(uuid_list)[2, :] == 0)
def path_from_eid(self, eid: str, use_cache=True) -> Path: """ From an experiment id or a list of experiment ids, gets the local cache path :param eid: eid (UUID) or list of UUIDs :param use_cache: if set to False, will force database connection :return: eid or list of eids """ # 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)) return path_list # If not valid return None if not alfio.is_uuid_string(eid): print(eid, " is not a valid eID/UUID string") return # first try avoid hitting the database if self._cache.size > 0 and use_cache: ic = parquet.find_first_2d( self._cache[['eid_0', 'eid_1']].to_numpy(), parquet.str2np(eid)) if ic is not None: ses = self._cache.iloc[ic] return Path(self._par.CACHE_DIR).joinpath( ses['lab'], 'Subjects', ses['subject'], ses['start_time'].isoformat()[:10], str(ses['number']).zfill(3)) # if it wasn't successful, query Alyx ses = self.alyx.rest('sessions', 'list', django=f'pk,{eid}') if len(ses) == 0: return None else: return Path(self._par.CACHE_DIR).joinpath( ses[0]['lab'], 'Subjects', ses[0]['subject'], ses[0]['start_time'][:10], str(ses[0]['number']).zfill(3))