コード例 #1
0
bouts = []
for i, bout in track(_bouts.iterrows()):
    bouts.append(LocomotionBout(bout, linearize_to=center_line))

# %%
f = plt.figure(figsize=(12, 12))
axes = f.subplot_mosaic("""
        AAADDD
        AAAEEE
        AAAFFF
        BBBGGG
        CCCHHI
    """)
f.tight_layout()

_ = draw.Hairpin(ax=axes["A"])
for n, bout in enumerate(bouts):
    # draw 2d and linearized tracking
    draw.Tracking(bout.x, bout.y, ax=axes["A"])

    draw.Tracking(bout.linearized.x, bout.linearized.y, ax=axes["B"])

    # draw speed accel and ang vel along track
    axes["D"].plot(bout.linearized.x, bout.speed, color="k", alpha=0.5)
    axes["E"].plot(bout.linearized.x, bout.acceleration, color="k", alpha=0.5)

    axes["F"].plot(bout.linearized.x, bout.thetadot, color="k", alpha=0.5)
    axes["G"].plot(bout.linearized.x, bout.thetadotdot, color="k", alpha=0.5)

    # mark peak acceleration etc
    # peak_accel = np.where(bout.acceleration > np.percentile(bout.acceleration, 80))[0]
コード例 #2
0
import matplotlib.pyplot as plt
from loguru import logger

import kino.draw.locomotion as draw_locomotion

from analysis.load import load_complete_bouts
import draw

logger.remove()
logger.add(sys.stdout, level="INFO")
"""
    Plots complete bouts through the arena,
    but with the linearized track also
"""

# load and clean complete bouts
bouts = load_complete_bouts(keep=10, duration_max=12)

# %%

f, ax = plt.subplots(figsize=(7, 9))

draw.Hairpin(alpha=0.25)
# plot paws/com trajectory
draw_locomotion.plot_locomotion_2D(bouts[1], ax)

plt.show()

# %%
コード例 #3
0
    from myterial import pink

    import draw

    f, ax = plt.subplots(figsize=(7, 10))

    # load and draw tracking data
    from fcutils.path import files

    for fp in files(
            "/Users/federicoclaudi/Dropbox (UCL)/Rotation_vte/Locomotion/analysis/control/",
            "*.h5",
    ):
        tracking = pd.read_hdf(fp, key="hdf")
        tracking.x = 20 - tracking.x + 20
        # draw.Tracking.scatter(tracking.x, tracking.y, c=tracking.theta, vmin=0, vmax=360, cmap='bwr', lw=1, ec='k')
        draw.Tracking(tracking.x, tracking.y, alpha=0.7)

    # draw hairpin arena
    draw.Hairpin(ax)

    # draw waypoints
    wps = Waypoints()
    for wp in wps:
        draw.Arrow(wp.x, wp.y, wp.theta, 2, width=4, color=pink, outline=True)

    # fit dubin path
    dubin = DubinPath(wps).fit()
    draw.Tracking(dubin.x, dubin.y, lw=2, color="k")
    plt.show()
コード例 #4
0
                c=c[::5],
                s=50,
                alpha=0.8,
            )


if __name__ == "__main__":
    tr = HairpinTrace()

    import sys

    sys.path.append("./")

    # try:

    #     from data.dbase.db_tables import Tracking

    #     trk = Tracking.get_session_tracking(
    #         "FC_210413_AAA1110750_d11", body_only=True
    #     )
    # except:
    #     trk = None

    import draw

    tr.draw()

    draw.Hairpin()

    plt.show()
コード例 #5
0
# merge bouts for heatmaps
X, Y, S, A, T, AV, AA = merge_locomotion_bouts(bouts)

# %%

f = plt.figure(figsize=(20, 20))
f._save_name = "complete_bouts"
axes = f.subplot_mosaic("""
        AABC
        AADE
    """)

for ax in "ABCDE":
    axes[ax].axis("equal")
    draw.Hairpin(ax=axes[ax], set_ax=True if ax == "A" else False)

    if ax != "A":
        axes[ax].axis("equal")
        axes[ax].axis("off")

# draw tracking traces
for bout in bouts:
    draw.Tracking(bout.x + 0.5, bout.y + 0.5, ax=axes["A"])

# draw speed heatmap
draw.Tracking.heatmap(
    X + 0.5,
    Y + 0.5,
    c=S,
    gridsize=(40, 60),
コード例 #6
0
    left_line,
    center_line,
    right_line,
    left_to_track,
    center_to_track,
    right_to_track,
    control_points,
) = tp.extract_track_from_image(points_spacing=2,
                                k=K,
                                apply_extra_spacing=True,
                                restrict_extremities=True)

# ? plot
f, ax = plt.subplots(figsize=(8, 12))

_ = draw.Hairpin()

P = [0, 0.125, 1]
colors = make_palette(pink_dark, blue_dark, len(P))
traces = []
for n, p in enumerate(P):
    trace, _ = tp.fit_best_trace(
        control_points,
        center_line,
        K,
        angle_cost=p,
        length_cost=(1 - p) * 5e-3,
    )

    # draw best trace
    X = convolve_with_gaussian(trace.x, kernel_width=11)
コード例 #7
0
    # speed
    axes["C"].plot(centered_bout.x, bout.body.speed, color="k", alpha=0.25)

# draw the v_max
for y_max in [2.5]:
    vmax = np.sqrt((y_max * 60) / (center_line.curvature))
    vmax[np.isinf(vmax)] = np.nan
    # vmax = vmax * VMAX_FACTOR + VMAX_SHIFT

    axes["C"].plot(center_line.comulative_distance,
                   vmax,
                   label=f"y_max: {y_max}",
                   lw=3)

# draw the track
draw.Hairpin(ax=axes["A"], set_ax=True)
draw.Tracking(left_line.x, left_line.y, ax=axes["A"])
draw.Tracking(center_line.x, center_line.y, ls="--", ax=axes["A"])
draw.Tracking.scatter(
    center_line.x,
    center_line.y,
    c=center_line.curvature,
    ax=axes["A"],
    s=75,
    ec="k",
    lw=0.5,
    zorder=100,
)

draw.Tracking(right_line.x, right_line.y, ax=axes["A"])