Beispiel #1
0
def plot_atype_test(result_d, t_ignore=0, plot_inds=[]):

    inhib_vals = result_d['inhibition_values']

    ret_figs = []

    s_v_fig = bplt.figure(title='Somatic Membrane Potential')
    ret_figs.append(s_v_fig)

    a_v_fig = bplt.figure(title='Apical Membrane Potential')
    ret_figs.append(a_v_fig)

    s_ika_fig = bplt.figure(title='Somatic A-Type Current')
    ret_figs.append(s_ika_fig)
    a_ika_fig = bplt.figure(title='Apical A-Type Current')
    ret_figs.append(a_ika_fig)

    s_v_items = []
    a_v_items = []
    s_i_items = []
    a_i_items = []

    i_ig = np.squeeze(np.where(result_d['t'] > t_ignore))
    t_arr = np.array(result_d['t'][i_ig]) - t_ignore

    for i_i, i_val in enumerate(inhib_vals):
        leg_str = '{0} %'.format(i_val * 100)
        s_v_line = s_v_fig.line(t_arr,
                                result_d['soma_v_dict'][i_i][i_ig],
                                color=colrs[i_i],
                                line_width=3)
        s_v_items.append((leg_str, [
            s_v_line,
        ]))
        a_v_line = a_v_fig.line(t_arr,
                                result_d['apical_v_dict'][i_i][i_ig],
                                color=colrs[i_i],
                                line_width=3)
        a_v_items.append((leg_str, [
            a_v_line,
        ]))

        s_i_line = s_ika_fig.line(t_arr,
                                  result_d['soma_ika_dict'][i_i][i_ig],
                                  color=colrs[i_i],
                                  line_width=3)
        s_i_items.append((leg_str, [
            s_i_line,
        ]))
        a_i_line = a_ika_fig.line(t_arr,
                                  result_d['apical_ika_dict'][i_i][i_ig],
                                  color=colrs[i_i],
                                  line_width=3)
        a_i_items.append((leg_str, [
            a_i_line,
        ]))

    s_v_leg = bmod.Legend(items=s_v_items, location='center')
    s_v_fig.add_layout(s_v_leg, 'right')

    a_v_leg = bmod.Legend(items=a_v_items, location='center')
    a_v_fig.add_layout(a_v_leg, 'right')

    s_i_leg = bmod.Legend(items=s_i_items, location='center')
    s_ika_fig.add_layout(s_i_leg, 'right')

    a_i_leg = bmod.Legend(items=a_i_items, location='center')
    a_ika_fig.add_layout(a_i_leg, 'right')

    return ret_figs
                                     color=colors[agent_index], size=10)
    larva_legend_items.append(('Larva {}'.format(agent_index), [larva_circle]))

    for end_point in points:
        larva_arrow = mdl.Arrow(end=mdl.VeeHead(fill_color=colors[agent_index],
                                                line_color=colors[agent_index],
                                                size=10),
                                line_color=colors[agent_index],
                                line_width=line_width,
                                x_start=start_point[0], y_start=start_point[1],
                                x_end=end_point[0], y_end=end_point[1])
        larva_plot.add_layout(larva_arrow)

        start_point = end_point

larva_legend = mdl.Legend(items=larva_legend_items, location='top_right')
larva_plot.add_layout(larva_legend, 'right')

larva_plot.title.text_font_size = title_font_size
larva_plot.legend.label_text_font_size = legend_font_size
larva_plot.yaxis.axis_line_width = axis_line_width
larva_plot.xaxis.axis_line_width = axis_line_width
larva_plot.yaxis.axis_label_text_font_size = axis_font_size
larva_plot.xaxis.axis_label_text_font_size = axis_font_size
larva_plot.yaxis.major_label_text_font_size = axis_tick_font_size
larva_plot.xaxis.major_label_text_font_size = axis_tick_font_size
larva_plot.ygrid.grid_line_width = grid_line_width
larva_plot.xgrid.grid_line_width = grid_line_width


plt.show(larva_plot)
Beispiel #3
0
def plot_spike_accel_aligned(in_h5_file, exclude_list=[], normalize=False):
    if normalize:
        acc_fig = bplt.figure(title='Normalized Spike Acceleration vs Time')
    else:
        acc_fig = bplt.figure(title='Spike Acceleration vs Time')
    acc_fig.xaxis.axis_label = 'time (sec)'
    acc_fig.yaxis.axis_label = 'spike acceleration (%)'
    print('Plotting spike acceleration from {}'.format(in_h5_file))

    my_lines = []
    my_circles = []
    legend_items = []

    with pd.HDFStore(in_h5_file) as h5_data:
        f_i = 0
        name_sort = list(h5_data.keys())
        name_sort.sort()

        for f_name in name_sort:

            if 'spike_rates' in f_name:
                name = f_name.split('/')[1]
                name_parts = name.split('_')
                leg_name = ' '.join(name_parts[:name_parts.index('CA1')])

                if leg_name not in exclude_list:
                    ach_time = h5_data[name + '/ach_times'][0] + 0.5

                    acc_spikes = h5_data[name + '/spike_times'].loc[
                        h5_data[name + '/spike_times'] > ach_time].to_numpy()
                    acc_isr = 1.0 / np.diff(acc_spikes)

                    acc_t = acc_spikes[:-1]
                    sp0 = acc_spikes[0]

                    freq_i = h5_data['frequency_table'].index[
                        h5_data['frequency_table']['Filename'] == name]
                    freq_val = h5_data['frequency_table']['Frequency'][
                        freq_i].values[0]

                    sp_accel = (acc_isr - freq_val) / freq_val * 100

                    if normalize:
                        max_accel = np.max(sp_accel)
                        my_lines.append(
                            acc_fig.line(acc_t - sp0,
                                         sp_accel / max_accel,
                                         line_width=2,
                                         color=colrs[f_i]))
                        my_circles.append(
                            acc_fig.circle(acc_t - sp0,
                                           sp_accel / max_accel,
                                           size=6,
                                           color=colrs[f_i]))

                    else:
                        my_lines.append(
                            acc_fig.line(acc_t - sp0,
                                         sp_accel,
                                         line_width=3,
                                         color=colrs[f_i]))
                        my_circles.append(
                            acc_fig.circle(acc_t - sp0,
                                           sp_accel,
                                           size=6,
                                           color=colrs[f_i]))
                    legend_items.append(
                        (leg_name, [my_circles[-1], my_lines[-1]]))
                    f_i += 1
    my_legend = bmod.Legend(items=legend_items, location='center')

    acc_fig.add_layout(my_legend, 'right')

    return acc_fig
Beispiel #4
0
def main(input_path, input_path_bmi, average, year_break):
    # Welcoming message
    print("\n############################")
    print("##   LINEAIR REGRESSION   ##")
    print("##          v1.1          ##")
    print("############################\n")

    # Show the paths
    print("USING PATHS:")
    print("  - Price database: {}".format(input_path))
    print("  - BMI database:   {}".format(input_path_bmi))

    # Read database
    print("\nReading database...")
    db_price = pd.read_csv(input_path)
    print("Done, reading BMI database...")
    db_BMI = pd.read_csv(input_path_bmi)
    print("Done")

    # Fill NaN
    db_price = db_price.fillna(0)
    db_BMI = db_BMI.fillna(0)

    # Custom
    print("Collecting graphs...")
    price, BMI, price_years, BMI_years, total_things = collect_graphs(
        db_price, db_BMI)
    print("\nDone")

    # Now plot price VS time
    print("Plotting...")

    # Create hover tool
    hover = bkm.HoverTool(tooltips=[("Country",
                                     "@country"), ("Year",
                                                   "@year"), ("Value",
                                                              "@value")])

    # Create figure
    f_price = plt.figure(title="Price per country, with Lineair Regression",
                         x_axis_label="Years",
                         y_axis_label="Price",
                         tools=[
                             hover,
                             bkm.WheelZoomTool(),
                             bkm.BoxZoomTool(),
                             bkm.PanTool(),
                             bkm.SaveTool(),
                             bkm.ResetTool()
                         ],
                         width=900)
    f_BMI = plt.figure(title="BMI per country, with Lineair Regression",
                       x_axis_label="Years",
                       y_axis_label="BMI",
                       tools=[
                           hover,
                           bkm.WheelZoomTool(),
                           bkm.BoxZoomTool(),
                           bkm.PanTool(),
                           bkm.SaveTool(),
                           bkm.ResetTool()
                       ],
                       width=900)

    # Generate random RGB list
    RGBs = []
    N = 8
    for r in range(N):
        for g in range(N):
            for b in range(N):
                if r == g == b == N:
                    # NO WHITE
                    continue
                # Add to the RGBs list
                RGBs.append(
                    bokeh.colors.RGB(int((r / N) * 255), int((g / N) * 255),
                                     int((b / N) * 255)))

    legend_list_price = []
    legend_list_BMI = []
    total_x_price = []
    total_x_BMI = []
    total_y_price = []
    total_y_BMI = []
    progress_bar = ProgressBar(max_amount=len(price))
    for country in price:
        price_list = price[country]
        BMI_list = BMI[country]
        price_year_list = price_years[country]
        BMI_year_list = BMI_years[country]

        # Now plot the graph
        line_elem, circle_elem, new_RGBs = plot_list(f_price, price_year_list,
                                                     price_list, country, RGBs)
        RGBs = list(new_RGBs)
        legend_list_price.append(
            (country + " (price)", [line_elem, circle_elem]))
        # Do the same for BMI
        line_elem, circle_elem, new_RGBs = plot_list(f_BMI, BMI_year_list,
                                                     BMI_list, country, RGBs)
        RGBs = list(new_RGBs)
        legend_list_BMI.append((country + " (BMI)", [line_elem, circle_elem]))

        # Add to the total_x and total_y
        total_x_price += price_list
        total_x_BMI += BMI_list
        total_y_price += price_year_list
        total_y_BMI += BMI_year_list
        progress_bar.update()

    print("Done")

    # Alright, we're nearly done: only add lineair regression
    print("Doing lineair regression...")

    if year_break > -1:
        # Use this year to break
        old_y = list(total_y_price)
        old_x = list(total_x_price)
        total_y_price = []
        total_x_price = []
        for i, year in enumerate(old_y):
            if year >= year_break:
                total_x_price.append(old_x[i])
                total_y_price.append(year)
        old_y = list(total_y_BMI)
        old_x = list(total_x_BMI)
        total_y_BMI = []
        total_x_BMI = []
        for i, year in enumerate(old_y):
            if year >= year_break:
                total_x_BMI.append(old_x[i])
                total_y_BMI.append(year)

    legend_list_price.append(
        plot_lineair_regression(f_price, total_y_price, total_x_price))
    legend_list_BMI.append(
        plot_lineair_regression(f_BMI, total_y_BMI, total_x_BMI))

    # Do legend and show
    legend_price = bkm.Legend(items=legend_list_price,
                              location=(0, 0),
                              click_policy="mute")
    legend_BMI = bkm.Legend(items=legend_list_BMI,
                            location=(0, 0),
                            click_policy="mute")

    f_price.add_layout(legend_price, "right")
    f_BMI.add_layout(legend_BMI, "right")

    print("Done")

    plt.output_file("lineair_regression.html", mode="inline")
    layout = bokeh.layouts.Column(f_price, f_BMI)
    plt.show(layout)

    print("\nDone.")
Beispiel #5
0
def plot_spike_accel(in_h5_file, exclude_list=[], normalize=False, t_start=0):

    if normalize:
        acc_fig = bplt.figure(title='Normalized Spike Acceleration vs Time')
    else:
        acc_fig = bplt.figure(title='Spike Acceleration vs Time')
    acc_fig.xaxis.axis_label = 'time (sec)'
    acc_fig.yaxis.axis_label = 'spike acceleration (%)'
    print('Plotting spike acceleration from {}'.format(in_h5_file))

    my_lines = []
    my_circles = []
    legend_items = []

    with pd.HDFStore(in_h5_file) as h5_data:
        f_i = 0
        name_sort = list(h5_data.keys())
        name_sort.sort()

        for f_name in name_sort:

            if 'spike_rates' in f_name:

                name_parts = f_name.split('/')[1].split('_')
                leg_name = ' '.join(name_parts[:name_parts.index('CA1')])

                if leg_name not in exclude_list:
                    if normalize:

                        max_accel = np.max(h5_data[f_name]['Spike_Accel'])
                        my_lines.append(
                            acc_fig.line(h5_data[f_name]['time'],
                                         h5_data[f_name]['Spike_Accel'] /
                                         max_accel,
                                         line_width=3,
                                         color=colrs[f_i]))
                        my_circles.append(
                            acc_fig.circle(h5_data[f_name]['time'],
                                           h5_data[f_name]['Spike_Accel'] /
                                           max_accel,
                                           size=6,
                                           color=colrs[f_i]))

                    else:
                        my_lines.append(
                            acc_fig.line(h5_data[f_name]['time'],
                                         h5_data[f_name]['Spike_Accel'],
                                         line_width=3,
                                         color=colrs[f_i]))
                        my_circles.append(
                            acc_fig.circle(h5_data[f_name]['time'],
                                           h5_data[f_name]['Spike_Accel'],
                                           size=6,
                                           color=colrs[f_i]))
                    legend_items.append(
                        (leg_name, [my_circles[-1], my_lines[-1]]))
                    f_i += 1
    my_legend = bmod.Legend(items=legend_items, location='center')

    acc_fig.add_layout(my_legend, 'right')
    acc_fig.x_range.start = t_start
    return acc_fig