Пример #1
0
    cv2.line(img, (tail_x, tail_y), (centroid_x, centroid_y), (0, 0, 255), 2, cv2.LINE_AA)

    cv2.circle(img, (head_x, head_y), 6, tuple(np.array(to_rgb("C0")) * 255), -1, lineType=cv2.LINE_AA)
    cv2.circle(img, (centroid_x, centroid_y), 6, tuple(np.array(to_rgb("C1")) * 255), -1, lineType=cv2.LINE_AA)
    cv2.circle(img, (tail_x, tail_y), 6, tuple(np.array(to_rgb("C0")) * 255), -1, lineType=cv2.LINE_AA)

    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])
Пример #2
0
    else:
        color = "C2"
        df = df2

    fig = myfig.Figure(title=f"Figure 1 - {experiment_name}")

    # Show the luminance profile
    p0 = myfig.Plot(fig,
                    num='d',
                    xpos=12,
                    ypos=22,
                    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)
Пример #3
0
df.to_excel(root_path / "found_parameters.xlsx", sheet_name="parameters")

fig = myfig.Figure(title="Found parameters")

fig.add_text(10.5, 22.2 + 1.5, "Optimal parameters", font=fig.font2)

p0 = myfig.Plot(fig,
                num='',
                xpos=1.5,
                ypos=22,
                plot_height=1.25,
                plot_width=1.25,
                lw=1,
                pc='white',
                errorbar_area=False,
                xl="",
                xmin=-1,
                xmax=3,
                xticks=[0, 1, 2],
                xticklabels=["WT", "Het", "Hom"],
                xticklabels_rotation=45,
                yl="tau",
                ymin=-0.1,
                ymax=3.1,
                yticks=[0, 1.5, 3])

p1 = myfig.Plot(fig,
                num='',
                xpos=4.0,
                ypos=22,
                plot_height=1.25,
Пример #4
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)



Пример #5
0
T = 1
bout_clock_probability_below_threshold = 0.008
bout_clock_probability_above_threshold = 0.04
parameter_title = f"Tau: {tau:.1f}; Sigma: {noise_sigma:.1f}; T: {T:.1f}; p_below: {bout_clock_probability_below_threshold:.4f}; p_above: {bout_clock_probability_above_threshold:.4f}"

#####
# Correctness as function of coherence
p0 = myfig.Plot(fig,
                num='b',
                xpos=5,
                ypos=22,
                plot_height=1.25,
                plot_width=1.25,
                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])

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)
# df_histogram_results = pd.read_hdf(root_path / "all_events.h5", key="results_figure2_histograms")
# df_event_triggered_luminance = pd.read_hdf(root_path / "all_events.h5", key="event_triggered_luminance")

df = pd.read_hdf(root_path / "all_events_model_profile1.h5", key="results_figure2")
df_histogram_results = pd.read_hdf(root_path / "all_events_model_profile1.h5", key="results_figure2_histograms")
df_event_triggered_luminance = pd.read_hdf(root_path / "all_events_model_profile1.h5", key="event_triggered_luminance")

#df.to_excel(root_path / "all_events_figure2.xlsx", sheet_name="all_events_model.h5")
#df.groupby("experiment_name").mean().to_excel(root_path / "all_events_model_figure2_experiment_mean.xlsx", sheet_name="all_data")


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

##########
p0 = myfig.Plot(fig, num='a', xpos=1.5, ypos=22, plot_height=0.75, plot_width=1.5,
                    lw=1, pc='white', errorbar_area=False,
                    xl="Turn angle (deg)", xmin=-181, xmax=181, xticks=[-180, -90, 0, 90, 180],
                    yl="Probability", ymin=-0.001, ymax=0.012)

df_selected = df_histogram_results.query("experiment_name == 'virtual_valley_stimulus_drosolarva' and histogram_type == 'angle_change'").reset_index(level=['experiment_name', 'histogram_type'], drop=True)
myfig.Bar(p0, x=df_selected.index, y=df_selected["density"].values, lc='C0', lw=0, width=0.95*362/60)

##########
p0 = myfig.Plot(fig, num='b', xpos=4.5, ypos=22, plot_height=0.75, plot_width=1.5,
                    lw=1, pc='white', errorbar_area=False,
                    xl="Run length (s)", xmin=-0.5, xmax=60.5, xticks=[0, 30, 60],
                    yl="Probability", ymin=-0.001, ymax=0.06)

df_selected = df_histogram_results.query("experiment_name == 'virtual_valley_stimulus_drosolarva' and histogram_type == 'run_length'").reset_index(level=['experiment_name', 'histogram_type'], drop=True)
myfig.Bar(p0, x=df_selected.index, y=df_selected["density"].values, lc='C0', lw=0, width=0.95*61/60)

##########
    ][i]
    color = ['C1', "gray", "C0"][i]
    profile = [c1, c2, c3][i]

    df_selected = df.query("experiment_name == @experiment_name").reset_index(
        level=['experiment_name'], drop=True)
    larva_IDs = df_selected.index.get_level_values('larva_ID').unique().values

    p0 = myfig.Plot(fig,
                    xpos=3 + 5 * i,
                    ypos=20,
                    plot_height=3,
                    plot_width=3,
                    lw=1,
                    title=experiment_name,
                    xl="X (cm)",
                    xmin=-6.1,
                    xmax=6.1,
                    xticks=[-6, -3, 0, 3, 6],
                    yl="Y (cm)",
                    ymin=-6.1,
                    ymax=6.1,
                    yticks=[-6, -3, 0, 3, 6])

    #p0.ax.imshow(profile, extent=(-6, 6, -6, 6), interpolation='bilinear', aspect='auto', cmap='gray', vmin=0, vmax=255, alpha=0.65, zorder=1)

    for larva_ID in larva_IDs:
        print(larva_ID)
        df_selected_larva = df_selected.query(
            "larva_ID == @larva_ID and time >= 15*60 and time < 60*60"
        ).reset_index(level=['larva_ID'], drop=True)[["r", "x", "y"]]
df.to_excel(root_path / "all_events_figure2.xlsx", sheet_name="all_events.h5")
df.groupby("experiment_name").mean().to_excel(
    root_path / "all_events_figure2_experiment_mean.xlsx",
    sheet_name="all_data")

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

##########
p0 = myfig.Plot(fig,
                num='a',
                xpos=1.5,
                ypos=22,
                plot_height=1.25,
                plot_width=1.5,
                lw=1,
                pc='white',
                errorbar_area=False,
                xl="Turn angle (deg)",
                xmin=-181,
                xmax=181,
                xticks=[-180, -90, 0, 90, 180],
                yl="Probability density",
                ymin=-0.001,
                ymax=0.01)

df_selected = df_histogram_results.query(
    "experiment_name == 'virtual_valley_stimulus_drosolarva' and histogram_type == 'angle_change'"
).reset_index(level=['experiment_name', 'histogram_type'], drop=True)
myfig.Bar(p0,
          x=df_selected.index,
          y=df_selected["density"].values,
          lc='C0',
Пример #9
0
 p0 = myfig.Plot(
     fig,
     num='a',
     xpos=1.5 + 2 * rule_i,
     ypos=22,
     plot_height=1.5,
     plot_width=1.5,
     title=rule_name,
     lw=1,
     pc='white',
     errorbar_area=False,
     xl="Run length multiplier",
     xmin=-0.6,
     xmax=4.6,
     xticks=[0, 1, 2, 3, 4],
     xticklabels=["0.25", "0.5", "1", "2", "4"],
     xticklabels_rotation=45,
     yl="Turn angle multiplier" if rule_i == 0 else '',
     ymin=-0.6,
     ymax=4.6,
     yticks=[0, 1, 2, 3, 4],
     yticklabels=["0.25", "0.5", "1", "2", "4"] if rule_i == 0 else [''] *
     5,
     yticklabels_rotation=45,
     zmin=-50,
     zmax=50,
     colormap=cmap,
     show_colormap=True if rule_i == 6 else False,
     zticks=[-50, -25, 0, 14, 25, 50],
     zl=
     "Performance index\n(% change relative to control\nfor fraction of time\nspent in the dark ring)"
 )
                f"neighbor_distances_hom_age{age}dpf.npy")[:, ::10] / 100
            speed_over_time_mutant = np.load(
                root_path / experiment /
                f"speed_over_time_hom_age{age}dpf.npy")[:, :] / 100

        # Speed
        p0 = myfig.Plot(fig,
                        num='a' if i == 0 else '',
                        xpos=3 + i * 2,
                        ypos=15,
                        plot_height=1.25,
                        plot_width=1.5,
                        title=experiment,
                        lw=1,
                        pc='white',
                        errorbar_area=True,
                        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",
Пример #11
0
                        f"leaky_integrator_model2_F_{genotype}_{repeat}.npy")
        except:
            continue

        fig = myfig.Figure(title=f"Model fits to {genotype}", fig_width=26)

        p1_experiment = myfig.Plot(
            fig,
            num='a',
            xpos=1.5,
            ypos=22,
            plot_height=1.25,
            plot_width=1.25,
            title="Experiment",
            lw=1,
            pc='white',
            errorbar_area=False,
            xl="Coherence (%)",
            xmin=-15,
            xmax=115,
            hlines=[50],
            xticks=[0, 25, 50, 100],
            yl="Target function 0\n\nProbability\ncorrect (%)",
            ymin=44,
            ymax=91,
            yticks=[50, 70, 90])

        p1_model = [
            myfig.Plot(fig,
                       num='',
                       xpos=1.5 + 3 * (optimized_i + 1),
                       ypos=22,
Пример #12
0
    interbout_interval_as_function_of_coherence_mutant_mean = (df_extracted_features_mutant.query("genotype == @mutant_name")["inter_bout_interval"]).groupby("stim").mean()
    interbout_interval_as_function_of_coherence_mutant_sem = (df_extracted_features_mutant.query("genotype == @mutant_name")["inter_bout_interval"]).groupby("stim").sem()

    binned_correctness_mutant_mean = df_extracted_binned_features_mutant.query("genotype == @mutant_name").groupby(["stim", "bin"]).mean()
    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])
Пример #13
0
import my_figure as myfig

norm = matplotlib.colors.Normalize(vmin=0, vmax=79)
cmap = matplotlib.cm.get_cmap('seismic')

fig = myfig.Figure(title="Pareto fronts")

y_pos = 22
for error_index0, error_index1, xmin, xmax, xticks, ymin, ymax, yticks in [[0, 1, -10, 1010, [0, 500, 1000], -0.1, 5.1, [0, 2.5, 5]],
                                                                           [1, 2, -0.01, 0.6, [0, 0.25, 0.5], -10, 5010, [0, 2500, 5000]],
                                                                           [2, 3, -10, 5010, [0, 2500, 5000], -5, 205, [0, 100, 200]],
                                                                           [3, 4, -10, 510, [0, 250, 500], -0.01, 0.51, [0, 0.25, 0.5]],
                                                                           ]:

        p0 = myfig.Plot(fig, num='', xpos=1.5, ypos=y_pos, plot_height=2.5, plot_width=2.5,
                        lw=1, pc='white', errorbar_area=False,
                        xl=errornames[error_index0], xmin=xmin, xmax=xmax, xticks=xticks,
                        yl=errornames[error_index1], ymin=ymin, ymax=ymax,yticks=yticks, hlines=[0], vlines=[0])


        print(F[0][:, error_index0].max())
        print(F[0][:, error_index1].max())
        res = NonDominatedSorting().do(F[0])
        x = F[0][res[0]][:, error_index0]
        y = F[0][res[0]][:, error_index1]
        ind = np.where((x < xmax) & (y < ymax))
        x = x[ind]
        y = y[ind]

        myfig.Scatter(p0, x,y, pt='.', ps=8, lw=0, pc='blue',alpha=0.8)

        res = NonDominatedSorting().do(F[-1])
Пример #14
0
    if force < 0:
        direction = "Left"
    else:
        direction = "Right"

    p0 = myfig.Plot(
        fig,
        num='',
        xpos=x_pos + 4,
        ypos=y_pos + 10,
        plot_height=2.5,
        plot_width=2.5,
        title=
        f"Motion arc: {d_ang:0.1f} deg;\nLocation: {location_on_retina:.1f} (Weight {retina_weight:.1f})\nMotion force: {force:.1f} ({direction})",
        lw=1,
        pc='white',
        errorbar_area=False,
        xl="X" if y_pos == 0 else None,
        xmin=-10,
        xmax=10,
        xticks=[-10, -5, 0, 5, 10] if y_pos == 0 else None,
        yl="Y" if x_pos == 0 else None,
        ymin=-10,
        ymax=10,
        yticks=[-10, -5, 0, 5, 10] if x_pos == 0 else None,
        hlines=[0],
        vlines=[0])

    p0.ax.arrow(pos_focal1[0],
                pos_focal1[1],
                pos_focal2[0] - pos_focal1[0],
                pos_focal2[1] - pos_focal1[1],
Пример #15
0
genotype = "hom"

colors = ["C3", "red", "C4"]

fig = myfig.Figure(title=f"Figure 1")

### Speed stats
p0 = myfig.Plot(fig,
                num='',
                xpos=12.0,
                ypos=15,
                plot_height=0.75,
                plot_width=0.5,
                lw=1,
                pc='white',
                errorbar_area=False,
                hlines=[0],
                xl="",
                xmin=-0.5,
                xmax=2.5,
                xticks=[0, 1, 2],
                yl="Speed (cm/s)",
                ymin=-0.1,
                ymax=1.1,
                yticks=[0, 0.5, 1.0])

### Spacing stats
p1 = myfig.Plot(fig,
                num='',
                xpos=12.0,
                ypos=13,
                plot_height=0.75,
Пример #16
0
import numpy as np
import my_figure as myfig
from scipy import stats

root_path = Path("/Users/arminbahl/Desktop/mutant_behavior_data/dot_motion_coherence/disc1_hetinx")

df_all_bouts = pd.read_hdf(root_path / "all_data.h5", key="all_bouts").query("genotype == 'wt'").droplevel(["genotype"])
df_all_bouts = df_all_bouts.query("stim == 0").droplevel(["stim"])

fishes_IDs = df_all_bouts.index.get_level_values('fish_ID').unique().values


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

p0 = myfig.Plot(fig, num='a', xpos=2, ypos=20, plot_height=2, plot_width=2, title = "Original inter-bout-intervals",
                                       lw=1, pc='white', errorbar_area=False,
                                       xl="Inter-bout-interval (s)", xmin=-0.1, xmax=2.1, xticks=[0., 0.5, 1, 1.5, 2],
                                       yl="Next inter-bout-interval (s)", ymin=-0.1, ymax=2.1, yticks=[0., 0.5, 1, 1.5, 2])

p1 = myfig.Plot(fig, num='a', xpos=5, ypos=20, plot_height=2, plot_width=2, title = "Shuffled inter-bout-intervals",
                                       lw=1, pc='white', errorbar_area=False,
                                       xl="Inter-bout-interval (s)", xmin=-0.1, xmax=2.1, xticks=[0., 0.5, 1, 1.5, 2],
                                       yl="", ymin=-0.1, ymax=2.1, yticks=[0., 0.5, 1, 1.5, 2], yticklabels=[""]*5)

p2 = myfig.Plot(fig, num='b', xpos=8, ypos=20, plot_height=1.25, plot_width=1.25, title = "Bout vs. next bout",
                                       lw=1, pc='white', errorbar_area=False,
                                       xl="", xmin=-0.5, xmax=1.5, xticks=[0, 1], xticklabels=["Original data", "Shuffled"], xticklabels_rotation=45,
                                       yl="Correlation coefficient", ymin=-0.1, ymax=0.6, yticks=[0, 0.25, 0.5])

p3 = myfig.Plot(fig, num='b', xpos=10, ypos=20, plot_height=1.25, plot_width=1.25, title = "Bout vs. second-next bout",
                                       lw=1, pc='white', errorbar_area=False,
                                       xl="", xmin=-0.5, xmax=1.5, xticks=[0, 1], xticklabels=["Original data", "Shuffled"], xticklabels_rotation=45,