def read_sessions(folders, key=frontactivity_key, selector=None, includeinfokey=True): if isinstance(folders, str): folders = [folders] multikey = not isinstance(key,str) & np.iterable(key) if multikey and selector is None: raise ValueError("A table selector has to be specified for multi-keys.") sessions = [] for path in folders: if multikey: tables = [pd.read_hdf(storepath(path), k) for k in key] session = selector(*tables) else: session = pd.read_hdf(storepath(path), key) if selector is not None: session = selector(session) if len(session) > 0 and key != info_key and includeinfokey: info = pd.read_hdf(storepath(path), info_key) info.reset_index(inplace=True) keys = [n for n in session.index.names if n is not None] session.reset_index(inplace=True) session['subject'] = info.subject.iloc[0] session['session'] = info.session.iloc[0] session.set_index(['subject', 'session'], inplace=True) session.set_index(keys, append=True, inplace=True) sessions.append(session) return pd.concat(sessions)
def findsessions(folder, days=None): sessionpaths = glob.glob(os.path.join(folder,'**/front_video.csv')) folders = (os.path.split(path)[0] for path in sessionpaths) folders = [path for path in folders if os.path.exists(storepath(path))] if days is not None: if type(days) is slice: folders = folders[days] elif np.iterable(days): folders = [folders[day] for day in days] else: folders = [folders[days]] return folders
def read_sessions(folders, key=frontactivity_key, selector=None, includeinfokey=True): if isinstance(folders, str): folders = [folders] sessions = [] for path in folders: session = pd.read_hdf(storepath(path), key) if selector is not None: session = selector(session) if key != info_key and includeinfokey: info = pd.read_hdf(storepath(path), info_key) info.reset_index(inplace=True) keys = [n for n in session.index.names if n is not None] session.reset_index(inplace=True) session['subject'] = info.subject.iloc[0] session['session'] = info.session.iloc[0] session.set_index(['subject', 'session'], inplace=True) session.set_index(keys, append=True, inplace=True) sessions.append(session) return pd.concat(sessions)
def read_rewards(path): return pd.read_hdf(storepath(path), rewards_key)
def read_activity(path): return pd.read_hdf(storepath(path), frontactivity_key)