예제 #1
0
def test_total_head_pokes():
    assert total_head_pokes([
        'StartSession', 'PokeOn1', 'LPressOn', 'PokeOn1', 'RPressOn', 'PokeOn1'
    ]) == 3
    assert total_head_pokes([
        'StartSession', 'LPressOn', 'PokeOn1', 'PokeOn1', 'RPressOn', 'PokeOn1'
    ]) == 3
    assert total_head_pokes([
        'StartSession', 'PokeOn1', 'PokeOn1', 'LPressOn', 'RPressOn',
        'RPressOn', 'PokeOn1'
    ]) == 3
def trough_train_function(loaded_file, i):
    """
    :param loaded_file: file output from operant box
    :param i: number of days analyzing
    :return: data frame of all analysis extracted from file (one animal)
    """
    (timecode, eventcode) = extract_info_from_file(loaded_file, 500)
    (dippers, dippers_retrieved, retrieval_latency) = reward_retrieval(timecode, eventcode)
    (ind_dur, tot_dur, ind_dur_iti, tot_dur_iti) = cue_responding_duration(timecode, eventcode, 'StartSession', 'EndSession', "PokeOn1", "PokeOff1")
    # ITI is meaningless here because we are using the whole session
    total_pokes = total_head_pokes(eventcode)

    file_keys = list(loaded_file.keys())
    for constant in ['File', 'Start Date', 'End Date', 'Subject', 'Experiment', 'Group', 'Box', 'Start Time', 'End Time', 'MSN', 'W']:
        file_keys.remove(constant)

    # All that's left in the list file_keys should be any group labels. 
    group_ids = []
    for group in file_keys:
        group_ids.append(loaded_file[group])

    df2 = pd.DataFrame([[loaded_file['Subject'], int(i + 1), float(dippers), float(dippers_retrieved),
                         float(retrieval_latency), float(ind_dur), float(tot_dur), float(total_pokes), *group_ids]],
                       columns=column_list+file_keys)

    return df2
예제 #3
0
def PCER_function(loaded_file, i):
    """
    :param loaded_file: file output from operant box
    :param i: number of days analyzing
    :return: data frame of all analysis extracted from file (one animal)
    """
    (timecode, eventcode) = extract_info_from_file(loaded_file, 500)
    (dippers, dippers_retrieved, retrieval_latency) = reward_retrieval(timecode, eventcode)
    cue_iti_responding(timecode, eventcode, 'StartTrial', 'EndTrial', 'PokeOn1')
    (ind_dur, tot_dur, ind_dur_iti, tot_dur_iti) = cue_responding_duration(timecode, eventcode, 'StartTrial',
                                                                           'EndTrial', 'PokeOn1', 'PokeOff1')
    total_pokes = total_head_pokes(eventcode)
    (all_cue_length_poke_rates, all_iti_length_poke_rates, subtracted_poke_rates) = \
        response_rate_across_cue_iti(timecode, eventcode, 'StartTrial', 'EndTrial', 'PokeOn1')
    new_cols = ['Subject'] + ['Cue_' + str(i + 1) for i in range(len(all_cue_length_poke_rates))] + \
               ['ITI_' + str(i + 1) for i in range(len(all_cue_length_poke_rates))] + \
               ['ES_' + str(i + 1) for i in range(len(all_cue_length_poke_rates))]
    across_cue_df = pd.DataFrame([([loaded_file['Subject']]+all_cue_length_poke_rates+all_iti_length_poke_rates+subtracted_poke_rates)],
                                 columns=new_cols)

    df2 = pd.DataFrame([[loaded_file['Subject'], int(i + 1), float(dippers), float(dippers_retrieved),
                         float(retrieval_latency), float(ind_dur), float(tot_dur), float(total_pokes)]],
                       columns=column_list)
    df2 = pd.merge(df2, across_cue_df, how='left', on=['Subject'])

    return df2