def _clean_log()

in neural/utils_mous.py [0:0]


def _clean_log(log):
    '''Auxiliary function to preprocess the log_files table.
    Cleans and reformats the log_files table.
    Input:
        log (pandas table)
    Output:
        log_cleaned (pandas table)
    '''
    # Relabel condition: only applies to sample where condition changes
    translate = dict(
        ZINNEN='sentence',
        WOORDEN='word_list',
        FIX='fix',
        QUESTION='question',
        Response='response',
        ISI='isi',
        blank='blank',
    )
    for key, value in translate.items():
        sel = log.Code.astype(str).str.contains(key)
        log.loc[sel, 'condition'] = value
    log.loc[log.Code == '', 'condition'] = 'blank'

    # Annotate sequence idx and extend context to all trials
    start = 0
    block = 0
    context = 'init'
    log['new_context'] = False
    query = 'condition in ("word_list", "sentence")'
    for idx, row in log.query(query).iterrows():
        log.loc[start:idx, 'context'] = context
        log.loc[start:idx, 'block'] = block
        log.loc[idx, 'new_context'] = True
        context = row.condition
        block += 1
        start = idx
    log.loc[start:, 'context'] = context
    log.loc[start:, 'block'] = block

    # Format time
    log['time'] = 0
    idx = log.Time.str.isnumeric() == True  # noqa
    log.loc[idx, 'time'] = log.loc[idx, 'Time'].astype(float) / 1e4

    # Extract individual word
    log.loc[log.condition.isna(), 'condition'] = 'word'
    idx = log.condition == 'word'
    words = log.Code.str.strip('0123456789 ')
    log.loc[idx, 'word'] = words.loc[idx]
    sel = log.query('word=="" and condition=="word"').index
    log.loc[sel, 'word'] = np.nan
    log.loc[log.word.isna() & (log.condition == "word"), 'condition'] = 'blank'
    return log