|
6 | 6 |
|
7 | 7 | #### A post-deeplabcut module for kinematic analysis |
8 | 8 |
|
9 | | -### under construction ... |
| 9 | +This repo will continue to grow, but here are some helper functions to get you started. Note, the API is subject to change. You can run the functions on data files obtained from running inference with [DeepLabCut](http://deeplabcut.org/). Currently, this code requires python 3.8 onwards. We recommend using the [DEEPLABCUT conda file](https://deeplabcut.github.io/DeepLabCut/docs/installation.html), and then simply run `pip install dlc2kinematics` within your environment. |
10 | 10 |
|
11 | | -Currently this is not yet publicly available, but feel free to "watch" or "star" to be notified of updates. |
12 | 11 |
|
13 | 12 | ## Quick start |
14 | 13 |
|
15 | | -`pip install dlc2kinematics` |
| 14 | +``` bash |
| 15 | +pip install dlc2kinematics |
| 16 | +``` |
| 17 | +## Useage |
16 | 18 |
|
17 | | -## License |
| 19 | +``` python |
| 20 | +import dlc2kinematics |
| 21 | +``` |
18 | 22 |
|
19 | | -DLC2Kinematics is freely available for non-commercial use, and may be redistributed under these conditions. Please, see the license for further details. |
| 23 | +Load data: |
20 | 24 |
|
21 | | -## Contact |
| 25 | +``` python |
| 26 | +df, bodyparts, scorer = dlc2kinematics.load_data(<path of the h5 file>) |
| 27 | +``` |
22 | 28 |
|
23 | | -Mackenzie Mathis - [email protected] |
| 29 | +### Basic Operations |
| 30 | + |
| 31 | +Compute velocity: |
| 32 | + |
| 33 | + - For all bodyparts: |
| 34 | + ``` python |
| 35 | + df_vel = dlc2kinematics.compute_velocity(df,bodyparts=['all']) |
| 36 | + ``` |
| 37 | + - For only few bodyparts: |
| 38 | + ``` python |
| 39 | + df_vel = dlc2kinematics.compute_velocity(df,bodyparts=['nose','joystick']) |
| 40 | + ``` |
| 41 | + |
| 42 | +Compute acceleration: |
| 43 | + |
| 44 | +- For all bodyparts: |
| 45 | + ``` python |
| 46 | + df_acc = dlc2kinematics.compute_acceleration(df,bodyparts=['all']) |
| 47 | + ``` |
| 48 | +- For only few bodyparts: |
| 49 | + ``` python |
| 50 | + df_vel = dlc2kinematics.compute_acceleration(df,bodyparts=['nose','joystick']) |
| 51 | + ``` |
| 52 | + |
| 53 | +Compute speed: |
| 54 | + |
| 55 | +``` python |
| 56 | +df_speed = dlc2kinematics.compute_speed(df,bodyparts=['nose','joystick']) |
| 57 | +``` |
| 58 | + |
| 59 | +### Computations in joint coordinates |
| 60 | + |
| 61 | +To compute joint angles, we first create a dictionary where keys are the joint angles and the corresponding values are the set of bodyparts: |
| 62 | + |
| 63 | +``` python |
| 64 | +joint_dict= {} |
| 65 | +joints_dict['R-Elbow'] = ['R_shoulder', 'Right_elbow', 'Right_wrist'] |
| 66 | +``` |
| 67 | + |
| 68 | +and compute the joint angles with |
| 69 | + |
| 70 | +``` python |
| 71 | +joint_angles = dlc2kinematics.compute_joint_angles(df,joints_dict) |
| 72 | +``` |
| 73 | + |
| 74 | +Compute joint angular velocity with |
| 75 | + |
| 76 | +``` python |
| 77 | +joint_vel = dlc2kinematics.compute_joint_velocity(joint_angles) |
| 78 | +``` |
| 79 | + |
| 80 | +Compute joint angular acceleration with |
| 81 | + |
| 82 | +``` python |
| 83 | +joint_acc = dlc2kinematics.compute_joint_acceleration(joint_angles) |
| 84 | +``` |
| 85 | + |
| 86 | +Compute correlation of angular velocity |
| 87 | + |
| 88 | +``` python |
| 89 | +corr = dlc2kinematics.compute_correlation(joint_vel, plot=True) |
| 90 | +``` |
| 91 | + |
| 92 | +Compute PCA of angular velocity with |
| 93 | + |
| 94 | +``` python |
| 95 | +pca = dlc2kinematics.compute_pca(joint_vel, plot=True) |
| 96 | +``` |
| 97 | +### PCA-based reconstruction of postures |
| 98 | + |
| 99 | +Compute and plot PCA based on posture reconstruction with: |
| 100 | + |
| 101 | +``` python |
| 102 | +dlc2kinematics.plot_3d_pca_reconstruction(df_vel, n_components=10, framenumber=500, |
| 103 | + bodyparts2plot=bodyparts2plot, bp_to_connect=bp_to_connect) |
| 104 | +``` |
| 105 | + |
| 106 | +### UMAP Embeddings |
| 107 | +``` python |
| 108 | +dlc2kinematics.compute_umap(df, key=['LeftForelimb', 'RightForelimb'], chunk_length=30, fit_transform=True, n_neighbors=30, n_components=3,metric="euclidean") |
| 109 | +``` |
| 110 | + |
| 111 | +## Contributing |
| 112 | + |
| 113 | +- If you spot an issue or have a question, please open an [issue](https://github.com/AdaptiveMotorControlLab/dlc2kinematics/issues) with a suitable tag. |
| 114 | +- For [code contributions](https://github.com/AdaptiveMotorControlLab/dlc2kinematics/pulls): |
| 115 | + - please see the [contributing guide](docs/CONTRIBUTING.md). |
| 116 | + - Please reference all issues this PR addresses in the description text. |
| 117 | + - Before submitting your PR, ensure all code is formatted properly by running |
| 118 | + ``` bash |
| 119 | + black . |
| 120 | + ``` |
| 121 | + in the root directory. |
| 122 | + - Assign a reviewer, typically [MMathisLab](https://github.com/MMathisLab). |
| 123 | + - sign CLA. |
| 124 | + |
| 125 | +## Acknowledgements |
| 126 | + |
| 127 | +This code is a collect of contributions from members of the Mathis Laboratory over the years. In particular (alphabetical): |
| 128 | +Michael Beauzile, Sebastien Hausmann, Jessy Lauer, Mackenzie Mathis, Tanmay Nath, Steffen Schneider. |
0 commit comments