Skip to main content

Library for kinematic analysis of DeepLabCut outputs

Project description

PyPI version PyPI - Downloads

cam cntrl

A post-deeplabcut module for kinematic analysis

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. Currently, this code requires python 3.8 onwards. We recommend using the DEEPLABCUT conda file, and then simply run pip install dlc2kinematics within your environment.

Quick start

pip install dlc2kinematics

Useage

import dlc2kinematics

Load data:

df, bodyparts, scorer = dlc2kinematics.load_data(<path of the h5 file>)

Basic Operations

Compute velocity:

  • For all bodyparts:
    df_vel = dlc2kinematics.compute_velocity(df,bodyparts=['all'])
    
  • For only few bodyparts:
    df_vel = dlc2kinematics.compute_velocity(df,bodyparts=['nose','joystick'])
    

Compute acceleration:

  • For all bodyparts:
    df_acc = dlc2kinematics.compute_acceleration(df,bodyparts=['all'])
    
  • For only few bodyparts:
    df_vel = dlc2kinematics.compute_acceleration(df,bodyparts=['nose','joystick'])
    

Compute speed:

df_speed = dlc2kinematics.compute_speed(df,bodyparts=['nose','joystick'])

Computations in joint coordinates

To compute joint angles, we first create a dictionary where keys are the joint angles and the corresponding values are the set of bodyparts:

joint_dict= {}
joints_dict['R-Elbow']  = ['R_shoulder', 'Right_elbow', 'Right_wrist']

and compute the joint angles with

joint_angles = dlc2kinematics.compute_joint_angles(df,joints_dict)

Compute joint angular velocity with

joint_vel = dlc2kinematics.compute_joint_velocity(joint_angles)

Compute joint angular acceleration with

joint_acc = dlc2kinematics.compute_joint_acceleration(joint_angles)

Compute correlation of angular velocity

corr = dlc2kinematics.compute_correlation(joint_vel, plot=True)

Compute PCA of angular velocity with

pca = dlc2kinematics.compute_pca(joint_vel, plot=True)

PCA-based reconstruction of postures

Compute and plot PCA based on posture reconstruction with:

dlc2kinematics.plot_3d_pca_reconstruction(df_vel, n_components=10, framenumber=500,
                                     bodyparts2plot=bodyparts2plot, bp_to_connect=bp_to_connect)

UMAP Embeddings

dlc2kinematics.compute_umap(df, key=['LeftForelimb', 'RightForelimb'], chunk_length=30, fit_transform=True, n_neighbors=30, n_components=3,metric="euclidean")

Contributing

  • If you spot an issue or have a question, please open an issue with a suitable tag.
  • For code contributions:
    • please see the contributing guide.
    • Please reference all issues this PR addresses in the description text.
    • Before submitting your PR, ensure all code is formatted properly by running
      black .
      
      in the root directory.
    • Assign a reviewer, typically MMathisLab.
    • sign CLA.

Acknowledgements

This code is a collect of contributions from members of the Mathis Laboratory over the years. In particular (alphabetical): Michael Beauzile, Sebastien Hausmann, Jessy Lauer, Mackenzie Mathis, Tanmay Nath, Steffen Schneider.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dlc2kinematics-0.0.1.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

dlc2kinematics-0.0.1-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

Details for the file dlc2kinematics-0.0.1.tar.gz.

File metadata

  • Download URL: dlc2kinematics-0.0.1.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for dlc2kinematics-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a1485291778bcfe0b25d805f30c5a4d33206cf1bcc88ccce8c2790421fefb969
MD5 7c1d601fb967dbb556fa0750fe1fbedb
BLAKE2b-256 c57720f0eba9088eacfc13ed73affdbf63b9007191054248aca5266a47f3c124

See more details on using hashes here.

File details

Details for the file dlc2kinematics-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dlc2kinematics-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for dlc2kinematics-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb489e37469e446ea7e7abd5fb429a72306d5911959c6534c9f5bcffff214d71
MD5 f09fb656ae4cee9ad054da82791fc612
BLAKE2b-256 34ccbd4094feacece003bdaea299cc429933dfb49c449fa7613c25f517f26c21

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page