def load_results_train_test_scores(data_path):
    res = defaultdict(list)
    experiment_dirs = sorted(
        [os.path.join(data_path, d) for d in os.listdir(data_path)])

    keys = [
        'DAQ_O_ON_F', 'DAQ_O_OFF_F', 'DAQ_W_ON_F', 'DAQ_O_ON', 'DAQ_O_OFF',
        'DAQ_W_ON', 'TRIAL_FRAMES', 'TRIAL_PERIOD', 'NAME_MOUSE', 'NAME_PLANE',
        'NAME_DATE', 'decode_style', 'neurons', 'shuffle', 'split_style'
    ]
    for exp_dir in experiment_dirs:
        data_dirs = sorted(glob.glob(os.path.join(exp_dir, '*' + '.pkl')))
        config_dirs = sorted(glob.glob(os.path.join(exp_dir, '*.json')))
        for data_dir, config_dir in zip(data_dirs, config_dirs):
            config = tools.file_io.load_json(config_dir)
            cur_res = tools.file_io.load_pickle(data_dir)

            for k in keys:
                cur_res[k] = np.array([config[k]] * len(cur_res['scores']))
            reduce.chain_defaultdicts(res, cur_res)

    add_indices(res)
    add_time(res)

    for i, _ in enumerate(res['scores']):
        res['top_score'].append(np.max(res['scores'][i]))
    res['top_score'] = np.array(res['top_score'])
    return res
Exemple #2
0
def analyze_behavior(data_path, condition):
    res = analysis.load_all_cons(data_path)
    analysis.add_indices(res)
    analysis.add_time(res)
    lick_res = convert(res, condition)
    days_per_mouse = _get_days_per_condition(data_path, condition)
    last_day_per_mouse = np.array([x[-1] for x in days_per_mouse])
    plot_res = agglomerate_days(lick_res, condition,
                                condition.training_start_day,
                                last_day_per_mouse)
    add_odor_value(plot_res, condition)
    add_behavior_stats(plot_res, condition)
    return plot_res
Exemple #3
0
def get_licks_per_day(data_path, condition, return_raw=False):
    res = analysis.load_all_cons(data_path)
    analysis.add_indices(res)
    analysis.add_time(res)
    lick_res = convert(res, condition)
    lick_res['lick_boolean'] = np.array([y > 0 for y in lick_res['lick']])
    out = reduce.new_filter_reduce(lick_res, ['odor', 'day', 'mouse'],
                                   'lick_boolean')
    if return_raw:
        add_odor_value(lick_res, condition)
        return lick_res
    else:
        return out
Exemple #4
0
def custom_analyze_behavior(data_path, condition, start_time, end_time):
    import analysis
    from behavior import behavior_analysis
    res = analysis.load_all_cons(data_path)
    analysis.add_indices(res)
    analysis.add_time(res)
    lick_res = custom_convert(res, condition, start_time, end_time)
    days_per_mouse = behavior_analysis._get_days_per_condition(
        data_path, condition)
    last_day_per_mouse = np.array([x[-1] for x in days_per_mouse])
    plot_res = behavior_analysis.agglomerate_days(lick_res, condition,
                                                  condition.training_start_day,
                                                  last_day_per_mouse)
    analysis.add_odor_value(plot_res, condition)
    behavior_analysis.add_behavior_stats(plot_res, condition)
    return plot_res
Exemple #5
0
                raise ValueError('sorting method is not recognized')
            sorted_list_of_psths = [x[ixs, :] for x in list_of_psths]
            psth = psth[ixs, :]
        else:
            sorted_list_of_psths = list_of_psths

        images.append(psth)
        odor_on_times.append(odor_on)
        water_on_times.append(water_on)
        list_of_odor_names.append(odors_copy)
    return images, odor_on_times, water_on_times, list_of_odor_names, sorted_list_of_psths


res = analysis.load_data(data_path)
analysis.add_indices(res)
analysis.add_time(res)
if condition_config.plot_big:
    mice = np.unique(res['mouse'])
    list_of_days_per_mouse = condition_config.plot_big_days
    list_of_images = []
    list_of_list_of_psths = []
    odor_on_times = []
    water_on_times = []
    days = [int(not condition_config.plot_big_naive)]
    for i, day in enumerate(list_of_days_per_mouse):
        mouse = mice[i]
        if day != -1:
            images, odor_on_times, water_on_times, list_of_odor_names, list_of_psth = helper(
                res, mouse, [day], condition_config)
            list_of_list_of_psths.append(list_of_psth)
            list_of_images.append(images[0])