Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def read_rewards(path):
    return pd.read_hdf(storepath(path), rewards_key)
Ejemplo n.º 5
0
def read_activity(path):
    return pd.read_hdf(storepath(path), frontactivity_key)
def read_rewards(path):
    return pd.read_hdf(storepath(path), rewards_key)
def read_activity(path):
    return pd.read_hdf(storepath(path), frontactivity_key)