Beispiel #1
0
                      pc='white',
                      zorder=2,
                      alpha=0.5)

    print(df.query("genotype == @genotype and gen == 49").mean(axis=0))
    corr_matrix = df.query("genotype == @genotype and gen == 49").corr()
    myfig.Mat([p5, p6, p7][i],
              corr_matrix,
              extent=(0, 5, 0, 5),
              interpolation='nearest',
              origin='upper')

for i, parameter in enumerate(["tau", "sigma", "T", "p_below", "p_above"]):

    values_wt = df.query("genotype == 'wt' and gen == 49")[parameter].values
    values_het = df.query("genotype == 'het' and gen == 49")[parameter].values
    values_hom = df.query("genotype == 'hom' and gen == 49")[parameter].values

    p, stars = bootstrap(values_wt, values_het)
    plot = [p0, p1, p2, p3, p4][i]
    y = [2, 20, 1, 0.025, 0.05][i]
    myfig.Line(plot, x=[0.1, 0.9], y=[y, y], lc='black', lw=0.75)
    myfig.Text(plot, 0.5, y * 1.05, stars)

    p, stars = bootstrap(values_wt, values_hom)
    plot = [p0, p1, p2, p3, p4][i]
    y = [2, 20, 1, 0.025, 0.05][i]
    myfig.Line(plot, x=[1.1, 1.9], y=[y, y], lc='black', lw=0.75)
    myfig.Text(plot, 1.5, y * 1.05, stars)

fig.savepdf(root_path / f"found_parameters", open_pdf=True)
Beispiel #2
0
    writer.append_data(img)

writer.close()
dddd

fig = myfig.Figure(title="Figure 2")

##########
p0 = myfig.Plot(fig, num='c', xpos=3.5, ypos=22, plot_height=1.25, plot_width=1.5,
                    lw=1, pc='white', errorbar_area=False,
                    xl="Time (s)", xmin=-5, xmax=105, xticks=[0, 25, 50, 75, 100], hlines=[30],
                    yl="Larval curvature (deg)", ymin=-1, ymax=60.1, yticks=[0, 30, 60])

myfig.Line(p0, x=df_raw_data_selected_larva.query("time > 930 and time < 1030").index - 930,
           y=df_raw_data_selected_larva.query("time > 930 and time < 1030")["curvature"],
           lc='blue', lw=0.5, zorder=1, alpha=0.5)
myfig.Scatter(p0, x=df_event_data_selected_larva.query("time_at_current_turn_event > 930 and time_at_current_turn_event < 1030")["time_at_current_turn_event"] - 930,
              y=df_event_data_selected_larva.query("time_at_current_turn_event > 930 and time_at_current_turn_event < 1030")["curvature_at_current_turn_event"],
              lc='C1', pt='o', lw=0.5, ps=2, pc='white', zorder=2, alpha=0.5)

##########
p0 = myfig.Plot(fig, num='a', xpos=6.5, ypos=22, plot_height=1.25, plot_width=1.5,
                    lw=1, pc='white', errorbar_area=False,
                    xl="X (cm)", xmin=-4.1, xmax=-4.1+3, xticks=[-4, -3],
                    yl="Y (cm)", ymin=2.8, ymax=2.8+3, yticks=[3, 4])

myfig.Line(p0, x=df_raw_data_selected_larva.query("time > 930 and time < 1030")["x"],
           y=df_raw_data_selected_larva.query("time > 930 and time < 1030")["y"],
           lc='blue', lw=0.5, zorder=1, alpha=0.5)
myfig.Scatter(p0, x=df_event_data_selected_larva.query("time_at_current_turn_event > 930 and time_at_current_turn_event < 1030")["x_at_current_turn_event"],
Beispiel #3
0
                pc='white',
                errorbar_area=False,
                xmin=-15,
                xmax=115,
                hlines=[50],
                xticks=[0, 25, 50, 100],
                xticklabels=[""] * 4,
                yl="Probability\ncorrect (%)",
                ymin=44,
                ymax=91,
                yticks=[50, 70, 90])

print(df_correctness_as_function_of_coherence)
myfig.Line(p0,
           x=[0, 25, 50, 100],
           y=df_correctness_as_function_of_coherence.values,
           lc="black",
           zorder=1)
myfig.Scatter(p0,
              x=[0, 25, 50, 100],
              y=df_correctness_as_function_of_coherence.values,
              lc='black',
              pt='o',
              lw=0.5,
              ps=9.8,
              pc='white',
              zorder=2)

####
# Interbout interval as function of coherence
p0 = myfig.Plot(fig,
Beispiel #4
0
                    plot_height=1.25,
                    plot_width=2.0,
                    lw=1,
                    pc='white',
                    errorbar_area=False,
                    xl="Radial distance from center (cm)",
                    xmin=-0.1,
                    xmax=6.1,
                    xticks=[0, 2, 4, 6],
                    yl="Brightness",
                    ymin=-1,
                    ymax=256,
                    yticks=[0, 128, 255])

    if experiment_name == "virtual_valley_stimulus_drosolarva":
        myfig.Line(p0, x=x, y=c3, lc=color, lw=0.75)
        myfig.Line(p0, x=x, y=c2, lc='gray', lw=0.75)

    if experiment_name == "temporal_phototaxis_drosolarva":
        myfig.Line(p0, x=x, y=c1, lc=color, lw=0.75)
        myfig.Line(p0, x=x, y=c2, lc='gray', lw=0.75)

    for y_pos, time_bin in enumerate(
        ["t15_to_t60", "t15_to_t25", "t25_to_t35", "t35_to_t45",
         "t45_to_t55"]):
        p0 = myfig.Plot(
            fig,
            num='a' if y_pos == 0 else '',
            xpos=1.5,
            ypos=22 - y_pos * 3,
            plot_height=1.25,
        df_selected_larva.loc[df_selected_larva.r > 5.5] = np.nan

        # Downsample the x,y positions to 1 s
        df_selected_larva.index = pd.to_datetime(
            df_selected_larva.index,
            unit='s')  # Convert seconds into datetime objects

        df_selected_larva = df_selected_larva.resample('1s').median()
        df_selected_larva.index = (df_selected_larva.index - pd.to_datetime(
            0, unit='s')).total_seconds()  # Convert back to seconds
        df_selected_larva.index.rename("time", inplace=True)

        myfig.Line(p0,
                   x=df_selected_larva["x"].values[::10],
                   y=df_selected_larva["y"].values[::10],
                   lc=color,
                   zorder=2,
                   lw=0.25,
                   alpha=0.9)
        #myfig.Scatter(p0, x=[df_selected_larva["x"].values[::10][0]], y=[df_selected_larva["y"].values[::10][0]], lc=color, ps=4, pt='o', pc='white', zorder=3, lw=0.2)
        #myfig.Scatter(p0, x=[df_selected_larva["x"].values[::10][-1]], y=[df_selected_larva["y"].values[::10][-1]], lc=color, ps=4, pt='o', pc='white', zorder=3, lw=0.2)

#Show luminance trajectory of one larva

df_selected = df.query(
    "experiment_name == 'virtual_valley_stimulus_control_drosolarva'"
).reset_index(level=['experiment_name'], drop=True)

larva_IDs = df_selected.index.get_level_values('larva_ID').unique().values

larva_ID = larva_IDs[0]
Beispiel #6
0
    i = np.where((data[:, 0] > period-0.2) & (data[:, 1] == 0))[0][0]

    d0.append(data[i - 10:i + 40, 0] - data[i, 0])
    d1.append(data[i - 10:i + 40, 1])
    d2.append(data[i - 10:i + 40, 2])

d0 = np.mean(d0, axis=0)
d1 = np.mean(d1, axis=0)
d2 = np.mean(d2, axis=0)

d1 -= d1.min()
d2 -= d2.min()

d1 /= d1.max()
d2 /= d2.max()

fig = myfig.Figure(title="Closed-loop delay")

p0 = myfig.Plot(fig, xpos=4, ypos=15, plot_height=3, plot_width=4, lw=1, title='Closed-loop delay',
                xl="Time (s)", xmin=-0.1, xmax=0.4, xticks=[0, 0.1, 0.2, 0.3, 0.4],
                yl="Brightness (a.u)", ymin=-0.1, ymax=1.1, yticks=[0, 0.5, 1])

myfig.Line(p0, x=d0, y=d1, lc='C0', zorder=2, lw=1, alpha=0.9, label='Set by computer')
myfig.Line(p0, x=d0, y=d2, lc='C1', zorder=2, lw=1, alpha=0.9, label='Measured by camera')


fig.savepdf(root_path / f"closed_loop_delay", open_pdf=True)



            myfig.Scatter(p0,
                          x=[x],
                          y=[y],
                          lc=color,
                          pt='o',
                          lw=0.5,
                          ps=2,
                          pc='white',
                          zorder=2,
                          alpha=0.5)

            if i > 0:
                myfig.Line(p0,
                           x=[x, previous_x],
                           y=[y, previous_y],
                           lc=color,
                           lw=0.5,
                           zorder=1,
                           alpha=0.5)

            previous_x = x
            previous_y = y

    for i in range(4):
        if i == 0:
            p = ttest_1samp(
                df.query("experiment_name == @experiment_name")
                [f"luminance_change_since_previous_turn_event"] -
                df.query("experiment_name == @experiment_name")
                [f"luminance_change_over_last_10s_before_current_turn_event"],
                0,
p0 = myfig.Plot(fig, num='b', xpos=10.5, ypos=22, plot_height=0.75, plot_width=1.5,
                    lw=1, pc='white', errorbar_area=False,
                    xl="Brightness change during turns", xmin=-81, xmax=81, xticks=[-80, -40, 0, 40, 80],
                    yl="Probability", ymin=-0.001, ymax=df_selected["density"].values.max())

myfig.Bar(p0, x=df_selected.index, y=df_selected["density"].values, lc='C0', lw=0, width=0.95*162/60)


##########
p0 = myfig.Plot(fig, num='e', xpos=14, ypos=22, plot_height=2, plot_width=1.5,
                        lw=1, pc='white', errorbar_area=True, hlines=[0], vlines=[0],
                        xl="Time relative to turn event (s)", xmin=-21.5, xmax=21.5, xticks=[-20, -10, 0, 10, 20],
                        yl="Brightness relative to turn event", ymin=-21, ymax=6, yticks=[-20, -10, 0])

myfig.Line(p0, x=df_event_triggered_luminance.index,
           y=df_event_triggered_luminance.means_experiment,
           yerr=df_event_triggered_luminance.sems_experiment,
           lc='C0', lw=0.5, zorder=1)

myfig.Line(p0, x=df_event_triggered_luminance.index,
           y=df_event_triggered_luminance.means_control,
           yerr=df_event_triggered_luminance.sems_control,
           lc='gray', lw=0.5, zorder=1)



##########
for experiment_name, x_pos, y_pos, color in [["virtual_valley_stimulus_drosolarva", 2, 19, "C0"],
                                             ["virtual_valley_stimulus_control_drosolarva", 2, 17, "gray"]]:

    p0 = myfig.Plot(fig, num='b', xpos=x_pos, ypos=y_pos, plot_height=1.25, plot_width=0.375*24,
                    lw=1, pc='white', errorbar_area=False,
Beispiel #9
0
                       lw=1,
                       xl="Time since last turn (s)",
                       xmin=-0.15,
                       xmax=1.6,
                       xticks=[0, 0.5, 1, 1.5],
                       hlines=[50],
                       ymin=44,
                       ymax=91,
                       yticks=[50, 70, 90],
                       vlines=[0]) for optimized_i in range(7)
        ]

        # Show the target experimental data
        myfig.Line(p1_experiment,
                   x=[0, 25, 50, 100],
                   y=target_correctness_as_function_of_coherence.values,
                   lc="black",
                   zorder=1)
        myfig.Scatter(p1_experiment,
                      x=[0, 25, 50, 100],
                      y=target_correctness_as_function_of_coherence.values,
                      lc='black',
                      pt='o',
                      lw=0.5,
                      ps=9.8,
                      pc='white',
                      zorder=2)

        myfig.Line(
            p2_experiment,
            x=[0, 25, 50, 100],
                        hlines=[0],
                        xmin=-1,
                        xmax=121,
                        xticks=[0, 30, 60, 90, 120],
                        xticklabels=[""] * 5,
                        yl="Speed (cm/s)" if i == 0 else None,
                        ymin=-0.1,
                        ymax=0.51,
                        yticks=[0, 0.25, 0.5] if i == 0 else None,
                        vspans=[[20, 100, "lightgray", 0.6]])

        for j in range(12):
            myfig.Line(p0,
                       x=time_lowrest,
                       y=speed_over_time_wt[j],
                       lc="black",
                       zorder=1,
                       lw=0.25,
                       alpha=0.25)
            myfig.Line(p0,
                       x=time_lowrest,
                       y=speed_over_time_mutant[j],
                       lc=colors[i],
                       zorder=1,
                       lw=0.25,
                       alpha=0.25)

        myfig.Line(p0,
                   x=time_lowrest,
                   y=np.mean(speed_over_time_wt, axis=0),
                   yerr=sem(speed_over_time_wt, axis=0),
Beispiel #11
0
    binned_correctness_mutant_sem = df_extracted_binned_features_mutant.query("genotype == @mutant_name").groupby(["stim", "bin"]).sem()

    binned_same_direction_mutant_mean = df_extracted_binned_features_same_direction_mutant.query("genotype == @mutant_name").groupby(["bin"]).mean()
    binned_same_direction_mutant_sem = df_extracted_binned_features_same_direction_mutant.query("genotype == @mutant_name").groupby(["bin"]).sem()

    histogram_heading_angle_change_mutant_mean = df_extracted_binned_features_heading_angle_change_histograms_mutant.query("genotype == @mutant_name").groupby(["stim", "bin"]).mean()
    histogram_heading_angle_change_mutant_sem = df_extracted_binned_features_heading_angle_change_histograms_mutant.query("genotype == @mutant_name").groupby(["stim", "bin"]).sem()

    #####
    # Correctness as function of coherence
    p0 = myfig.Plot(fig, num='b1', xpos=10, ypos=ypos, plot_height=1.25, plot_width=1.25, title="Wildtype / mutant",
                                   lw=1, pc='white', errorbar_area=False,
                                   xmin=-15, xmax=115, hlines=[50], xticks=[0, 25, 50, 100], xticklabels=[""]*4,
                                   yl="Probability\ncorrect (%)", ymin=44, ymax=91, yticks=[50, 70, 90])

    myfig.Line(p0, x=[0, 25, 50, 100], y=correctness_as_function_of_coherence_wt_mean, yerr=correctness_as_function_of_coherence_wt_sem, lc="black", zorder=1)
    myfig.Scatter(p0, x=[0, 25, 50, 100], y=correctness_as_function_of_coherence_wt_mean, lc='black', pt='o', lw=0.5, ps=9.8, pc='white', zorder=2)

    myfig.Line(p0, x=[0, 25, 50, 100], y=correctness_as_function_of_coherence_mutant_mean, yerr=correctness_as_function_of_coherence_mutant_sem, lc=basecolor, zorder=1)
    myfig.Scatter(p0, x=[0, 25, 50, 100], y=correctness_as_function_of_coherence_mutant_mean, lc=basecolor, pt='o', lw=0.5, ps=9.8, pc='white', zorder=2)

    ####
    # Interbout interval as function of coherence
    p0 = myfig.Plot(fig, num='b2', xpos=10, ypos=ypos - 1.5, plot_height=1.25, plot_width=1.25,
                                       lw=1, pc='white', errorbar_area=False,
                                       xl="Coherence (%)", xmin=-15, xmax=115, xticks=[0, 25, 50, 100], hlines=[50],
                                       yl="Interbout\ninterval (s)", ymin=0.6, ymax=1.9, yticks=[0.7, 1.2, 1.7])

    myfig.Line(p0, x=[0, 25, 50, 100], y=interbout_interval_as_function_of_coherence_wt_mean, yerr=interbout_interval_as_function_of_coherence_wt_sem, lc="black", zorder=1)
    myfig.Scatter(p0, x=[0, 25, 50, 100], y=interbout_interval_as_function_of_coherence_wt_mean, lc='black', pt='o', lw=0.5, ps=9.8, pc='white', zorder=2)
Beispiel #12
0
    p0.ax.arrow(pos_focal1[0],
                pos_focal1[1],
                pos_focal2[0] - pos_focal1[0],
                pos_focal2[1] - pos_focal1[1],
                width=0.2,
                color='C3')

    p0.ax.arrow(pos_other1[0],
                pos_other1[1],
                pos_other2[0] - pos_other1[0],
                pos_other2[1] - pos_other1[1],
                width=0.2,
                color='black')

    myfig.Line(p0,
               x=[pos_focal1[0], pos_other1[0]],
               y=[pos_focal1[1], pos_other1[1]],
               lc='C0')
    myfig.Line(p0,
               x=[pos_focal1[0], pos_other2[0]],
               y=[pos_focal1[1], pos_other2[1]],
               lc='C1')

    circle1 = pl.Circle(pos_focal1, 2, color='r', fill=False)
    p0.ax.add_patch(circle1)

    x_pos += 3.5
    if x_pos == 3.5 * 3:
        x_pos = 0
        y_pos += 3.5

# Show the retina weight function
Beispiel #13
0
    cs_third_next.append(c_third_next)
    cs_third_next_shuffled.append(c_third_next_shuffled)

    all_first_bouts = np.array(all_first_bouts)
    all_next_bouts = np.array(all_next_bouts)
    all_first_bouts_shuffled = np.array(all_first_bouts_shuffled)
    all_next_bouts_shuffled = np.array(all_next_bouts_shuffled)
    ind1 = np.where((all_first_bouts < 2) & (all_next_bouts < 2))
    ind2 = np.where((all_first_bouts_shuffled < 2) & (all_next_bouts_shuffled < 2))

    myfig.Scatter(p0, x=all_first_bouts[ind1], y=all_next_bouts[ind1], lc='C3', pt='.', alpha=0.25, ps=1, lw=0.25, rasterized=True)
    myfig.Scatter(p1, x=all_first_bouts_shuffled[ind2], y=all_next_bouts_shuffled[ind2], lc='gray', pt='.', alpha=0.25, ps=1, lw=0.25, rasterized=True)

    myfig.Scatter(p2, x=[0], y=[c_next], lc='C3', pt='o', ps=1.5, zorder=2)
    myfig.Scatter(p2, x=[1], y=[c_next_shuffled], lc='gray', pt='o', ps=1.5, zorder=2)
    myfig.Line(p2, x=[0,1], y=[c_next, c_next_shuffled], lc='black', lw=0.5, zorder=1)

    myfig.Scatter(p3, x=[0], y=[c_second_next], lc='C3', pt='o', ps=1.5, zorder=2)
    myfig.Scatter(p3, x=[1], y=[c_second_next_shuffled], lc='gray', pt='o', ps=1.5, zorder=2)
    myfig.Line(p3, x=[0, 1], y=[c_second_next, c_second_next_shuffled], lc='black', lw=0.5, zorder=1)

    myfig.Scatter(p4, x=[0], y=[c_third_next], lc='C3', pt='o', ps=1.5, zorder=2)
    myfig.Scatter(p4, x=[1], y=[c_third_next_shuffled], lc='gray', pt='o', ps=1.5, zorder=2)
    myfig.Line(p4, x=[0, 1], y=[c_third_next, c_third_next_shuffled], lc='black', lw=0.5, zorder=1)


print(len(cs_next))
sdf
cs_next = np.array(cs_next)
cs_next_shuffled = np.array(cs_next_shuffled)
cs_second_next = np.array(cs_second_next)