Git Product home page Git Product logo

bioviz's Introduction

logo DOI badge Actions Status Coverage Status PyPI Downloads

Pyomeca is a python library allowing you to carry out a complete biomechanical analysis; in a simple, logical and concise way.

Pyomeca documentation

See Pyomeca's documentation site.

Example

Pyomeca implements specialized functionalities commonly used in biomechanics. As an example, let's process the electromyographic data contained in this c3d file.

You can follow along without installing anything by using our binder server: Binder

from pyomeca import Analogs

data_path = "../tests/data/markers_analogs.c3d"
muscles = [
    "Delt_ant",
    "Delt_med",
    "Delt_post",
    "Supra",
    "Infra",
    "Subscap",
]
emg = Analogs.from_c3d(data_path, suffix_delimiter=".", usecols=muscles)
emg.plot(x="time", col="channel", col_wrap=3)

svg

emg_processed = (
    emg.meca.band_pass(order=2, cutoff=[10, 425])
    .meca.center()
    .meca.abs()
    .meca.low_pass(order=4, cutoff=5, freq=emg.rate)
    .meca.normalize()
)

emg_processed.plot(x="time", col="channel", col_wrap=3)

svg

import matplotlib.pyplot as plt

fig, axes = plt.subplots(ncols=2, figsize=(10, 4))

emg_processed.mean("channel").plot(ax=axes[0])
axes[0].set_title("Mean EMG activation")

emg_processed.plot.hist(ax=axes[1], bins=50)
axes[1].set_title("EMG activation distribution")

svg

See the documentation for more details and examples.

Features

  • Signal processing routine commonly used in biomechanics such as filters, normalization, onset detection, outliers detection, derivatives, etc.
  • Common matrix manipulation routines implemented such as getting Euler angles to/from a rototranslation matrix, creating a system of axes, setting a rotation or translation, transpose or inverse, etc.
  • Easy reading and writing interface to common files in biomechanics (c3d, csv, xlsx,mat, trc, sto, mot)
  • All of xarray's awesome features

The following illustration shows all of pyomeca's public API. An interactive version is available in the documentation.

api

Installation

Pyomeca itself is a pure Python package, but its dependencies are not. The easiest way to get everything installed is to use conda.

To install pyomeca with its recommended dependencies using the conda command line tool:

conda install -c conda-forge pyomeca

Now that you have installed pyomeca, you should be able to import it:

import pyomeca

Integration with other modules

Pyomeca is designed to work well with other libraries that we have developed:

  • pyosim: interface between OpenSim and pyomeca to perform batch musculoskeletal analyses
  • ezc3d: Easy to use C3D reader/writer in C++, Python and Matlab
  • biorbd: C++ interface and add-ons to the Rigid Body Dynamics Library, with Python and Matlab binders.

Bug reports & questions

Pyomeca is Apache-licensed and the source code is available on GitHub. If any questions or issues come up as you use pyomeca, please get in touch via GitHub issues. We welcome any input, feedback, bug reports, and contributions.

Citing Pyomeca

DOI

If you use pyomeca in your academic work, please consider citing our paper as:

@article{Martinez2020,
  doi = {10.21105/joss.02431},
  url = {https://doi.org/10.21105/joss.02431},
  year = {2020},
  publisher = {The Open Journal},
  volume = {5},
  number = {53},
  pages = {2431},
  author = {Romain Martinez and Benjamin Michaud and Mickael Begon},
  title = {`pyomeca`: An Open-Source Framework for Biomechanical Analysis},
  journal = {Journal of Open Source Software}
}

Please consider citing the xarray project, which pyomeca is based on:

@article{jors-xarray,
title = {Xarray: N-D labeled arrays and datasets in Python},
author = {Joe Hamman and Stephan Hoyer},
year = {2017},
journal = {Journal of Open Research Software}
}

Contributors

Pyomeca is an open-source project created and supported by the S2M lab.

bioviz's People

Contributors

aceglia avatar evecharbie avatar ipuch avatar pariterre avatar romainmartinez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bioviz's Issues

Dimensions for movement file

Hey!

I've been trying to make bioviz accept my numpy array of nFrames x nDof and it was giving me an error of being the wrong dimension, but when it was transposed it worked. Just double checking that the dimension is actually nDof x nFrames not as written in the readme file.

Can't run examples

Salut,

J'essaye d'utiliser les exemples de biorbd-viz, mais je n'arrive pas à les faire rouler. Sont-ils sensés fonctionner?

3d_viz.py

Traceback (most recent call last): File "3d_viz.py", line 48, in <module> all_rt_real.append(RotoTrans(angles=[0, 0, 0], angle_sequence="yxz", translations=d[:, 0, 0])) File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/pyomeca/rototrans.py", line 28, in __new__ rt = cls.rt_from_euler_angles(angles=angles, angle_sequence=angle_sequence, translations=translations) File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/pyomeca/rototrans.py", line 152, in rt_from_euler_angles if angles.get_num_frames() != 0 and translations.get_num_frames() == 0: AttributeError: 'list' object has no attribute 'get_num_frames'

biorbd_viz.py

Traceback (most recent call last): File "biorbd_viz.py", line 9, in <module> b = BiorbdViz(model_path="pyomecaman.bioMod") File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/BiorbdViz/__init__.py", line 126, in __init__ self.set_q(self.Q) File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/BiorbdViz/__init__.py", line 155, in set_q self.__set_rt_from_q() File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/BiorbdViz/__init__.py", line 518, in __set_rt_from_q self.vtk_model.update_rt(self.rt) File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/BiorbdViz/biorbd_vtk.py", line 818, in update_rt self.new_rt_set(all_rt) File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/BiorbdViz/biorbd_vtk.py", line 801, in new_rt_set self.update_rt(all_rt) File "/home/andre/anaconda3/envs/rbdl/lib/python3.7/site-packages/BiorbdViz/biorbd_vtk.py", line 833, in update_rt pts.InsertNextPoint(rt.translation() + rt[0:3, 0] * self.rt_length) TypeError: InsertNextPoint argument 1: only size-1 arrays can be converted to Python scalars

Marker labelling

Is there any functionality to plot on the visualizer

  1. visualize the c3d file markers
  2. marker names, both of the ones on the model itself, as well as my c3d file?

I'm trying visualize the joint angle reconstruction and want to see how much IK error we're getting with respect to the input markers.

Also, is there a link to bioviz documentations somewhere? I didn't notice a link when i went through the readme page

I am also interested in calculating the RMSE between the c3d markers and the model markers, but I can ask about that in the main biorbd repo. I can see in the documentation that I can calculate the marker positions manually using biorbd.rigidbody.markers and calculate my RMSE, but just want to make sure that this isn't already being calculated - maybe the Kalman filter residual?

Interface BVH

That could be interesting to have a GUI that helps mapping a bioMod model to a Poser model and export a BVH file, so movements it can be shown in Poser

Gravity vector error when gravity is zero

Traceback (most recent call last):
  File "/home/puchaud/Projets_Python/Test_Pyomeca/energy_test/energy.py", line 68, in <module>
    biorbd_viz1 = bioviz.Viz(p, segments_center_of_mass_size=0.05)
  File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/__init__.py", line 354, in __init__
    self.__set_gravity_vector()
  File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/__init__.py", line 1206, in __set_gravity_vector
    self.vtk_model.new_gravity_vector(id_matrix, gravity, length, normalization_ratio=0.3, vector_color=(0, 0, 0))
  File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/biorbd_vtk.py", line 1884, in new_gravity_vector
    length = length * normalization_ratio / length
ZeroDivisionError: float division by zero

import bioviz error

Hi,

After installing bioviz using anaconda I get the following error once I am trying to import this package into python:

In [2]: import bioviz

ImportError Traceback (most recent call last)
in
----> 1 import bioviz

~/anaconda3/envs/msc_thesis/lib/python3.9/site-packages/bioviz/init.py in
15 import casadi
16 import pyomeca
---> 17 from .biorbd_vtk import VtkModel, VtkWindow, Mesh, Rototrans
18 from PyQt5.QtWidgets import (
19 QSlider,

~/anaconda3/envs/msc_thesis/lib/python3.9/site-packages/bioviz/biorbd_vtk.py in
10 from PyQt5.QtGui import QPalette, QColor
11
---> 12 from vtk import (
13 vtkActor,
14 vtkCellArray,

~/anaconda3/envs/msc_thesis/lib/python3.9/site-packages/vtk.py in
28 import importlib
29 # import vtkmodules.all
---> 30 all_m = importlib.import_module('vtkmodules.all')
31
32 # import vtkmodules

~/anaconda3/envs/msc_thesis/lib/python3.9/importlib/init.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129

~/anaconda3/envs/msc_thesis/lib/python3.9/site-packages/vtkmodules/all.py in
63 from .vtkIOImport import *
64 from .vtkIOVideo import *
---> 65 from .vtkIOFFMPEG import *
66 from .vtkIOExportPDF import *
67 from .vtkRenderingGL2PSOpenGL2 import *

ImportError: libopenh264.so.5: cannot open shared object file: No such file or directory

Any ideas why this is happening?

Improvement suggestions

[] Nom du modèle en entête
[] Cadre autours de l'animation
[] Lettres aux axes global (xyz)
[] Boutons pour orientations par plans
[] légende (markers, com, etc)

Markers are not displayed when only one frame

In the function load_experimental_markers when a markers array of a size (N, M, 1) is sent the markers are not displayed.
I can look at it, I oppen the issue so that it is somewhere.

Add reaction force

We should be able to add external forces when loading a kinematics file

experimental markers need to be exactly the size of model markers

This is problematic as this was a feature of bioptim to find tracked markers and display them automatically in the animation.

https://github.com/pyomeca/bioptim/blob/2cecbe2cecb1ee262af857d83ba077a09d91d01f/bioptim/optimization/solution.py#L1409-L1417

Error message:
Traceback (most recent call last): File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/__init__.py", line 881, in __animate_from_slider self.__set_experimental_markers_from_frame() File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/__init__.py", line 1130, in __set_experimental_markers_from_frame self.vtk_model.update_experimental_markers( File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/biorbd_vtk.py", line 481, in update_experimental_markers self._update_experimental_marker_link(virtual_to_experimental_markers_indices) File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/biorbd_vtk.py", line 564, in _update_experimental_marker_link self._new_experimental_marker_link(virtual_to_experimental_markers_indices) File "/home/puchaud/Projets_Python/Pyomeca_github/bioviz/bioviz/biorbd_vtk.py", line 528, in _new_experimental_marker_link points.InsertNextPoint(self.markers["experimental"].data[:3, i, 0].data) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/home/puchaud/miniconda3/envs/bio23/lib/python3.11/site-packages/xarray/core/dataarray.py", line 817, in __getitem__ return self.isel(indexers=self._item_key_to_dict(key)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/puchaud/miniconda3/envs/bio23/lib/python3.11/site-packages/xarray/core/dataarray.py", line 1402, in isel variable = self._variable.isel(indexers, missing_dims=missing_dims) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/puchaud/miniconda3/envs/bio23/lib/python3.11/site-packages/xarray/core/variable.py", line 1336, in isel return self[key] ~~~~^^^^^ File "/home/puchaud/miniconda3/envs/bio23/lib/python3.11/site-packages/xarray/core/variable.py", line 880, in __getitem__ data = as_indexable(self._data)[indexer] ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "/home/puchaud/miniconda3/envs/bio23/lib/python3.11/site-packages/xarray/core/indexing.py", line 1330, in __getitem__ return array[key] ~~~~~^^^^^ IndexError: index 5 is out of bounds for axis 1 with size 5

Error when no marker defined in bioMod

Traceback (most recent call last):
File "/home/user/Documents/PyCharm/plugins/python-ce/helpers/pydev/pydevd.py", line 1438, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/user/Documents/PyCharm/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/user/Documents/Programmation/Eve/Modeles/ModeleVisu.py", line 50, in
b = bioviz.Viz(model_chemin)
File "/home/user/anaconda3/envs/Trampo_bioptim/lib/python3.8/site-packages/bioviz/init.py", line 361, in init
self.set_q(self.Q)
File "/home/user/anaconda3/envs/Trampo_bioptim/lib/python3.8/site-packages/bioviz/init.py", line 401, in set_q
self.__set_markers_from_q()
File "/home/user/anaconda3/envs/Trampo_bioptim/lib/python3.8/site-packages/bioviz/init.py", line 790, in __set_markers_from_q
self.markers[0:3, :, :] = self.Markers.get_data(Q=self.Q, compute_kin=False)
File "/home/user/anaconda3/envs/Trampo_bioptim/lib/python3.8/site-packages/bioviz/init.py", line 82, in get_data
self.get_data_func(**kwargs)
File "/home/user/anaconda3/envs/Trampo_bioptim/lib/python3.8/site-packages/bioviz/init.py", line 103, in _get_data_from_casadi
self.data[:, :, 0] = np.array(self.markers(Q))
ValueError: could not broadcast input array from shape (0,0) into shape (3,0)

Add event

A list of list could permit to show events

Export videos in .mpeg4

Hello,

It would be great features to:

  1. export in mpeg4.
  2. Export a video directly from command lines.
  3. Get the same frame rate when two or more phases are in the same OCP.

Problem following biorbd 1.11.0 ?

Traceback (most recent call last):
File "/home/charbie/Documents/Programmation/BiorbdOptim/bioptim/examples/getting_started/pendulum.py", line 208, in
main()
File "/home/charbie/Documents/Programmation/BiorbdOptim/bioptim/examples/getting_started/pendulum.py", line 157, in main
sol.animate(n_frames=100)
File "/home/charbie/Documents/Programmation/BiorbdOptim/bioptim/optimization/solution/solution.py", line 1275, in animate
self.ocp.nlp[i].model.animate(
File "/home/charbie/Documents/Programmation/BiorbdOptim/bioptim/models/biorbd/biorbd_model.py", line 756, in animate
all_bioviz.append(bioviz.Viz(biorbd_model.path, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/charbie/miniconda3/envs/dev_bioptim/lib/python3.11/site-packages/bioviz/init.py", line 255, in init
for i, rt in enumerate(self.allGlobalJCS.get_data(Q=self.Q, compute_kin=False)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/charbie/miniconda3/envs/dev_bioptim/lib/python3.11/site-packages/bioviz/interfaces_collection.py", line 37, in get_data
self.get_data_func(**kwargs)
File "/home/charbie/miniconda3/envs/dev_bioptim/lib/python3.11/site-packages/bioviz/interfaces_collection.py", line 287, in _get_data_from_eigen
allJCS = self.m.allGlobalJCS()
^^^^^^^^^^^^^^^^^^^^^
TypeError: Joints.allGlobalJCS() missing 1 required positional argument: 'Q'

error after compiled biorbd

I tried to compile biorbd, so i installed each package manually but when i ran my code i had some error like :

ffmpeg: error while loading shared libraries: libopenh264.so.5: cannot open shared object file: No such file or directory

And

2022-05-24 11:20:42.439 (   8.902s) [        E24EA740]vtkOpenGLRenderWindow.c:493    ERR| vtkEGLRenderWindow (0x563cfeb71e50): GLEW could not be initialized: Missing GL version

Two errors appeared at different time, i found how to not have this problem by import specific version of each package by using:

conda install -c conda-forge python=3.9 numpy=1.22.3 scipy=1.8.0 packaging=21.3 setuptools matplotlib pandas=1.4.2 pyomeca casadi tinyxml vtk=9.0.3 pyqt=5.9.2 graphviz ipopt=3.14.6 pyqtgraph rbdl=3.1.3 pkgconfig cmake swig

it may also come from a problem with ffmpeg and vtk version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.