Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def _get_days_per_condition(data_path, condition, odor_valence=None):
    res = analysis.load_all_cons(data_path)
    analysis.add_indices(res)
    lick_res = convert(res, condition)
    if odor_valence is not None:
        add_odor_value(lick_res, condition)
        lick_res = filter.filter(lick_res, {'odor_valence': odor_valence})

    days = []
    list_of_dates = lick_res['day']
    list_of_mice = lick_res['mouse']
    _, mouse_ixs = np.unique(list_of_mice, return_inverse=True)
    for mouse_ix in np.unique(mouse_ixs):
        mouse_dates = list_of_dates[mouse_ixs == mouse_ix]
        counts = np.unique(mouse_dates)
        days.append(counts)
    return days
Ejemplo n.º 5
0
def get_days_per_mouse(data_path, condition, odor_valence='CS+'):
    res = analysis.load_all_cons(data_path)
    analysis.add_indices(res)
    days_per_mouse = np.array(
        _get_days_per_condition(data_path, condition, odor_valence))
    first_day_per_mouse = np.array([x[0] for x in days_per_mouse])
    last_day_per_mouse = np.array([x[-1] for x in days_per_mouse])

    if hasattr(condition, 'csp') or hasattr(condition, 'pt_csp'):
        res_behavior = analyze_behavior(data_path, condition)
        res_behavior_csp = filter.filter(res_behavior,
                                         {'odor_valence': odor_valence})
        res_behavior_summary = reduce.filter_reduce(res_behavior_csp,
                                                    filter_keys='mouse',
                                                    reduce_key='learned_day')
        mice, ix = np.unique(res_behavior_summary['mouse'],
                             return_inverse=True)
        temp = res_behavior_summary['learned_day'][ix]
        temp[temp == None] = last_day_per_mouse[temp == None]
        temp[np.isnan(temp)] = last_day_per_mouse[np.isnan(temp)]
        learned_days_per_mouse = np.ceil(temp)
    else:
        learned_days_per_mouse = last_day_per_mouse
    return learned_days_per_mouse, last_day_per_mouse
Ejemplo n.º 6
0
    #                       select_dict={'mouse':mouse, 'odor_valence':valence},
    #                       error_key= error_key,
    #                       plot_function=plt.fill_between,
    #                       colors = 'black',
    #                       plot_args=fill_args,
    #                       ax_args = ax_args,
    #                       path=save_path)


condition = experimental_conditions.BEHAVIOR_MPFC_YFP_DISCRIMINATION
data_path = os.path.join(Config.LOCAL_DATA_PATH,
                         Config.LOCAL_DATA_BEHAVIOR_FOLDER, condition.name)
save_path = os.path.join(Config.LOCAL_DATA_PATH, Config.LOCAL_FIGURE_PATH,
                         'MISC', 'ball_movement', condition.name)

res = analysis.load_all_cons(data_path)
analysis.add_indices(res)
res = _convert(res, condition)
res = _filter(res)
behavior.behavior_analysis.add_odor_value(res, condition)
print(np.unique(res['mouse']))

_angle(res)
# _average_velocity(res, save_path)
# _hist(res, save_path)
_example_velocity(res, save_path)

# print(res.keys())
# print(res['mouse'])
# print(res['day'])