|
1 | 1 | # %% |
2 | | -from proj import Model |
3 | | -from sympy import Matrix, symbols, sin, cos |
4 | 2 |
|
5 | | -model = Model() |
| 3 | + |
| 4 | +from behaviour.tracking.tracking import prepare_tracking_data |
| 5 | +from fcutils.maths.geometry import ( |
| 6 | + calc_angle_between_vectors_of_points_2d as get_bone_angle, |
| 7 | +) |
| 8 | +import numpy as np |
| 9 | +import pandas as pd |
| 10 | + |
| 11 | +# %% |
| 12 | +path = "/Users/federicoclaudi/Dropbox (UCL - SWC)/Rotation_vte/Locomotion/control/behav_data/Zane/ZM_200913_ZM006_videoDeepCut_resnet50_DLCSep6shuffle1_200000.h5" |
| 13 | + |
| 14 | + |
| 15 | +tracking = prepare_tracking_data( |
| 16 | + path, smooth_dir_mvmt=False, likelihood_th=0.8, interpolate_nans=True |
| 17 | +) |
| 18 | + |
| 19 | + |
| 20 | +body_orientation = get_bone_angle( |
| 21 | + tracking["body"].x.values, |
| 22 | + tracking["body"].y.values, |
| 23 | + tracking["tail_base"].x.values, |
| 24 | + tracking["tail_base"].y.values, |
| 25 | +) |
| 26 | + |
6 | 27 |
|
7 | 28 | # %% |
8 | | -( |
9 | | - x, |
10 | | - y, |
11 | | - theta, |
12 | | - L, |
13 | | - R, |
14 | | - m, |
15 | | - m_w, |
16 | | - d, |
17 | | - tau_l, |
18 | | - tau_r, |
19 | | - v, |
20 | | - omega, |
21 | | -) = model.variables.values() |
| 29 | +escapes_file = "/Users/federicoclaudi/Dropbox (UCL - SWC)/Rotation_vte/Locomotion/control/behav_data/Zane/escapes.txt" |
| 30 | +with open(escapes_file, "r") as f: |
| 31 | + escapes = [int(e) for e in f.readlines()] |
22 | 32 |
|
23 | 33 | # %% |
24 | | -x_dot, y_dot, theta_dot = symbols("xdot, ydot, thetadot") |
| 34 | +trials = {} |
| 35 | +for bp in tracking.keys(): |
| 36 | + trials[bp + "_xy"] = [] |
| 37 | + trials[bp + "_speed"] = [] |
| 38 | + |
| 39 | + if bp == "body": |
| 40 | + trials[bp + "_orientation"] = [] |
25 | 41 |
|
26 | | -nu_l_dot, nu_r_dot = symbols("nudot_L, nudot_R") |
27 | 42 |
|
| 43 | +for escape in escapes: |
| 44 | + for bp in tracking.keys(): |
| 45 | + start = escape |
| 46 | + end = start + 1000 |
| 47 | + x = tracking[bp].x[start:end] |
| 48 | + y = tracking[bp].y[start:end] |
| 49 | + s = tracking[bp].speed[start:end] |
28 | 50 |
|
29 | | -vels = Matrix([x_dot, y_dot, theta_dot]) |
| 51 | + trials[bp + "_xy"].append(np.vstack([x, y]).T) |
| 52 | + trials[bp + "_speed"].append(s) |
30 | 53 |
|
31 | | -K = Matrix( |
32 | | - [ |
33 | | - [R / 2 * cos(theta), R / 2 * cos(theta)], |
34 | | - [R / 2 * sin(theta), R / 2 * sin(theta)], |
35 | | - [R / (2 * L), R / (2 * L)], |
36 | | - ] |
| 54 | + if bp == "body": |
| 55 | + trials["body_orientation"].append(body_orientation[start:end]) |
| 56 | + |
| 57 | + |
| 58 | +trials = pd.DataFrame(trials) |
| 59 | + |
| 60 | +# %% |
| 61 | +import matplotlib.pyplot as plt |
| 62 | + |
| 63 | +f, ax = plt.subplots() |
| 64 | + |
| 65 | +for i, trial in trials.iterrows(): |
| 66 | + angle = np.unwrap(np.radians(90 - trial.body_orientation)) |
| 67 | + ax.scatter(trial.body_xy[:, 0], trial.body_xy[:, 1], c=angle) |
| 68 | + |
| 69 | +ax.axis("equal") |
| 70 | + |
| 71 | +# %% |
| 72 | +f, ax = plt.subplots() |
| 73 | +for bp in tracking.keys(): |
| 74 | + ax.plot(tracking[bp].x[5000:5500], tracking[bp].y[5000:5500]) |
| 75 | + |
| 76 | +# %% |
| 77 | +trials.to_hdf( |
| 78 | + "/Users/federicoclaudi/Dropbox (UCL - SWC)/Rotation_vte/Locomotion/control/behav_data/zanes.h5", |
| 79 | + key="hdf", |
37 | 80 | ) |
38 | 81 |
|
39 | | -nu = Matrix([nu_l_dot, nu_r_dot]) |
40 | 82 |
|
41 | | -nu = K.pinv() * vels |
42 | | -nu |
43 | 83 | # %% |
0 commit comments