vtk helper tools/functions for musculoskeletal analyses
Project description
pyMSKT (Musculoskeletal Toolkit)
pyMSKT is an open-source library for performing quantitative analyses of the musculoskeletal system. It enables creation of surface meshes of musculoskeletal anatomy and then processes these meshes to get quantitative outcomes and visualizatons, like for cartilage thickness.
Installation
Pip install from pypi
# create environment
conda env create -n mskt
conda activate mskt
pip install mskt
Conda / pip install from source
# clone repository
git clone https://github.com/gattia/pymskt.git
# move into directory
cd pymskt
# CREATE ENVIRONMENT:
conda env create -n mskt
conda activate mskt
# INSTALLING DEPENDENCIES
# Recommend pip becuase cycpd and pyfocusr are available on pypi (but not conda)
pip install -r requirements.txt
# IF USING PIP
pip install .
Conda only install (not-recommended)
-
Clone this repository & install dependencies:
# clone repository git clone https://github.com/gattia/pymskt.git # move into directory cd pymskt # CREATE ENVIRONMENT: conda env create -n mskt conda activate mskt # Install all available requirements conda install --file requirements-conda.txt # pip (below) can alternatively be used to install dependencies in conda env # Return to root dir cd ..
-
Clone cycpd & install: (ONLY NEEDED FOR CONDA INSTALL)
git clone https://github.com/gattia/cycpd.git cd cycpd pip install . cd ..
-
Clone pyfocusr & install: (ONLY NEEDED FOR CONDA INSTALL)
git clone https://github.com/gattia/pyfocusr.git cd pyfocusr pip install . cd ..
-
Install pymskt: (ONLY NEEDED FOR CONDA INSTALL)
cd pymskt pip install .
To install itkwidgets (for visualization):
If you are using jupyterlab instead of jupyter notebook, you also need to install an extension:
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib jupyterlab-datawidgets itkwidgets
Examples
There are jupyter notebook examples in the directory /examples
pyMSKT allows you to easily create bone meshes and attribute cartilage to the bone for calculating quantitative outcomes.
femur = BoneMesh(path_seg_image=location_seg, # path to the segmentation image being used.
label_idx=5, # what is the label of this bone.
list_cartilage_labels=[1]) # labels for cartilage associted with bone.
# Create the bone mesh
femur.create_mesh()
# Calcualte cartialge thickness for the cartialge meshes associated with the bone
femur.calc_cartilage_thickness()
femur.save_mesh(os.path.expanduser'~/Downloads/femur.vtk')
The saved file can be viewed in many mesh viewers such as 3D Slicer or Paraview. Or, better yet they can be viewed in your jupyter notebook using itkwidgets:
from itkwidgets import view
view(geometries=[femur.mesh])
After creating the above mesh, creating cartilage subregions & an anatomical coordinate system is as simple as:
# Load in full seg image
seg_image = sitk.ReadImage(location_seg)
# break into sub regions. (weightbearing / trochlea / posterior condyles)
seg_image = mskt.image.cartilage_processing.get_knee_segmentation_with_femur_subregions(seg_image)
# assign femoral condyle cartilage sub regions to femur
femur.seg_image = seg_image
femur.list_cartilage_labels=[11, 12, 13, 14, 15]
femur.assign_cartilage_regions()
# use cartilage regions to fit cylinder to condyles and create anatomic coordinate system
femur_acs = FemurACS(femur, cart_label=(11, 12, 13, 14, 15))
femur_acs.fit()
The resulting anatomical coorindate system can be used to create arrows & visualize the result:
AP_arrow = get_arrow(femur_acs.ap_axis, origin=femur_acs.origin )
IS_arrow = get_arrow(femur_acs.is_axis, origin=femur_acs.origin)
ML_arrow = get_arrow(femur_acs.ml_axis, origin=femur_acs.origin)
view(geometries=[femur.mesh, AP_arrow, IS_arrow, ML_arrow])
Anatomical Coordinate System - Cartilage Thickness | Anatomical Coordinate System - Cartilage Subregions |
---|---|
An example of how the cartilage thickness values are computed:
Development / Contributing
General information for contributing can be found here
Tests
- Running tests requires pytest (
conda install pytest
orpip install pytest
) - Run tests using
pytest
ormake test
in the home directory.
Coverage
- Coverage results/info requires
coverage
(conda install coverage
orpip install coverage
) - Can get coverage statistics by running:
coverage run -m pytest
or if using make:make coverage
Notes for development
- When updating cython code, it is not re-built when we re-install using the basic
python setup.py install
. Therefore we force it to do this:python setup.py build_ext -i --force
Tests
If you add a new function, or functionality to pymskt
please add appropriate tests as well.
The tests are located in /testing
and are organized as:
/testing/[pymskt_submodule]/[python_filename_being_tested]/[name_of_function_being_tested]_test.py
The tests use pytest
. If you are not familiar with pytest
a brief example is provided here.
Currently, 37 tests are being skipped for one of 2 (maybe 3) reasons. 1. They arent implemented yet and they are a placeholder. 2. They rely on a function that has small machine-to-machine differences so they dont pass or 3. A breaking change occured since result meshes were last saved. If you want to help but dont know how or where to start, filling in / fixing these tests would be a great place to start! And greatly appreciated.
Code of Conduct
We have adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the Code of Conduct.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file mskt-0.0.11.tar.gz
.
File metadata
- Download URL: mskt-0.0.11.tar.gz
- Upload date:
- Size: 46.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59dc4424b735b8042abf2b071688f9e7ccc526c5c92b015323e03163945d8039 |
|
MD5 | 663c6e23ffe3e5c3cc9679d7b25313fc |
|
BLAKE2b-256 | f0315e549649ee73039804f02d6e9e2cc5a58749caaa44f39f9990091476982e |
File details
Details for the file mskt-0.0.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mskt-0.0.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 840.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 691b76330f8185bb99cab5576eec12a6ed11cee31f8465775de900acdb0228be |
|
MD5 | aa006d1d363ea0fbbc0e26957e3e71de |
|
BLAKE2b-256 | 1b97f5f41a2ce74ce02a2ae1f3f1a440b420116d4b21e331f8a329e3f2324efe |
File details
Details for the file mskt-0.0.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mskt-0.0.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 843.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3b1ccf203b57517b286178b8ee6a694e829dd340b363d7fb945ca6b4f817a27 |
|
MD5 | f09157e40a2327879c35f3632bfddc2c |
|
BLAKE2b-256 | b1abb10e9a94a6927c3596b1cb5f70af983fd507b6156ca36599f7edd57e782b |
File details
Details for the file mskt-0.0.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mskt-0.0.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 852.1 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 234e5a3e8638cec8f293024b018fc59935dcea25c372c2f233ef4253a67d6578 |
|
MD5 | 628a6d6c330627efe47e579d4ca0fb86 |
|
BLAKE2b-256 | 68057b3400978b29ee56f5e8be30a43fcfe2117b684752fb5daf87ad067db8fb |
File details
Details for the file mskt-0.0.11-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mskt-0.0.11-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 808.1 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f9f1ec7b3c541f7faa07c9f19d1c53f77a994422d128fa9976899c67d0af7c |
|
MD5 | 9c288d6ef331515e2314451360306c19 |
|
BLAKE2b-256 | 58300e85a008d39c6eed08862e349bb09fabae82b68f87b2cb90cdc0df734c99 |