Skip to content

CGM checks with pyCGM2

pyCGM2 adds CGM checks (calibrate the Conventional Gait Model on the subject's static and fit it to a trial), Kalman and PCA gap filling, and the O'Connor and intellEvent event detectors. It is a separate install that OpenMotionLabel never needs: without it, the CGM tab says why it is unavailable and how to set it up, and everything else works.

How it runs

  • In its own environment: pyCGM2 runs in its own Python environment, as a child process started on first use, and the two exchange C3D files. pyCGM2's code stays in its own install (it is CC-BY-SA licensed; OpenMotionLabel contains none of it).
  • On Windows, macOS and Linux: pyCGM2 reads and writes C3D files through BTK, which is published for Windows only. OpenMotionLabel gives pyCGM2 its own BTK-compatible layer over ezc3d instead, so BTK is not needed. On the same files, pyCGM2 gives the same results through it as through BTK.
  • CGM2.2 to 2.5 and OpenSim: these models run OpenSim's inverse kinematics, so their environment needs OpenSim. pyCGM2 4.4 writes the paths of its OpenSim files with Windows separators; on macOS and Linux OpenMotionLabel loads those pyCGM2 modules with / instead (in memory: pyCGM2's files are not changed). If OpenSim fails, pyCGM2 computes the angles without it, and the CGM tab says so.
  • Time: the inverse kinematics runs at about 10 frames per second on an Apple Silicon Mac, so a 1,000-frame trial takes under two minutes. A pyCGM2 call may take 600 s by default (oml config set pycgm2.timeout <seconds>).

Setting it up

Once, in a conda environment whose name starts with pycgm2 (opensim=4.5 can be left out if you use only CGM1.0 to 2.1):

conda create -n pycgm2 -c conda-forge -c opensim-org python=3.10 "numpy>=1.25,<1.26" opensim=4.5 scipy pandas matplotlib-base scikit-learn seaborn beautifulsoup4 lxml pyyaml yamlordereddictloader openpyxl jinja2 onnxruntime python-dotenv python-docx docxtpl
conda activate pycgm2
pip install ezc3d

Install ezc3d with pip, not conda: OpenSim's conda package brings an older ezc3d library that replaces conda-forge's, and conda-forge's ezc3d then fails to import (pip's ezc3d carries its own copy).

Then install pyCGM2 from a clone of its repository, at the commit OpenMotionLabel is tested with (83112a73, 4.4rc2): run pip install --no-deps . in that folder, then copy its Data/normativeData and Data/intellEventModels folders into a Data folder in the environment's site-packages, as pyCGM2's conda recipe does. Finally, from the environment where OpenMotionLabel is installed:

oml pycgm2 doctor

It says where it looked, what it found and what works. In the CGM tab, Look again picks up a new install without restarting.

  • oml config set pycgm2.python <path> points OpenMotionLabel at another environment.
  • oml config set pycgm2.btk btk makes pyCGM2 use BTK itself where it is installed (the default, auto, uses the ezc3d layer whenever ezc3d is installed).

Using it

  • Check with CGM calibrates the chosen model (CGM1.0 to 2.5) on the session's static and fits it to the open trial; nothing in the trial changes. The report lists each model output's range, pyCGM2's anomaly report, and any error pyCGM2 logged and carried on after.
  • Fill gaps with Kalman (Burke et al. 2016) or PCA (Gløersen and Federolf 2016), as one undo step.
  • Detect events with O'Connor or intellEvent.

The tab also keeps the subject's measurements that pyCGM2 needs (body mass, leg lengths, knee and ankle widths, …). It fills them from the trial's PROCESSING group, or from a VSK or MP file of the session, and lets you edit them; each change is one undo step.

From the command line, oml label --cgm CGM2.4 checks the labels with the CGM after labeling, when pyCGM2 is there.