Skip to content

Commit

Permalink
small test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipuch committed May 14, 2023
1 parent 6b7021f commit b42e4d2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import os
from pathlib import Path

import ezc3d
import numpy as np
from pyomeca import Markers

from bionc import (
Expand All @@ -16,9 +12,12 @@
BiomechanicalModel,
JointType,
)
from tests.utils import TestUtils

from right_side_lower_limb import harrington2007, generate_c3d_file

# special load to test the script
# otherwise one could have use standard import
bionc = TestUtils.bionc_folder()
module = TestUtils.load_module(bionc + "/examples/model_creation/right_side_lower_limb.py")

def model_creation_from_measured_data(c3d_filename: str = "statref.c3d") -> BiomechanicalModel:
"""
Expand All @@ -29,8 +28,8 @@ def model_creation_from_measured_data(c3d_filename: str = "statref.c3d") -> Biom
model = BiomechanicalModelTemplate()
# de_leva = DeLevaTable(total_mass=100, sex="female")

right_hip_joint = lambda m, bio: harrington2007(m["RFWT"], m["LFWT"], m["RBWT"], m["LBWT"])[0]
left_hip_joint = lambda m, bio: harrington2007(m["RFWT"], m["LFWT"], m["RBWT"], m["LBWT"])[1]
right_hip_joint = lambda m, bio: module.harrington2007(m["RFWT"], m["LFWT"], m["RBWT"], m["LBWT"])[0]
left_hip_joint = lambda m, bio: module.harrington2007(m["RFWT"], m["LFWT"], m["RBWT"], m["LBWT"])[1]
right_knee_joint = lambda m, bio: MarkerTemplate.middle_of(m, bio, "RKNI", "RKNE")
right_ankle_joint = lambda m, bio: MarkerTemplate.middle_of(m, bio, "RANE", "RANI")
left_knee_joint = lambda m, bio: MarkerTemplate.middle_of(m, bio, "LKNI", "LKNE")
Expand Down Expand Up @@ -265,7 +264,7 @@ def model_creation_from_measured_data(c3d_filename: str = "statref.c3d") -> Biom

def main():
# create a c3d file with data
filename = generate_c3d_file(two_side=True)
filename = module.generate_c3d_file(two_side=True)
# Create the model from a c3d file and markers as template
model = model_creation_from_measured_data(filename)

Expand Down
43 changes: 43 additions & 0 deletions tests/test_biomech_model_lower_limbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import numpy as np
import pytest

from .utils import TestUtils


@pytest.mark.parametrize(
"bionc_type",
[
"numpy",
"casadi",
],
)
def test_biomech_model(bionc_type):

bionc = TestUtils.bionc_folder()
module_c3d = TestUtils.load_module(bionc + "/examples/model_creation/right_side_lower_limb.py")
module = TestUtils.load_module(bionc + "/examples/model_creation/two_side_lower_limbs.py")

# Generate c3d file
filename = module_c3d.generate_c3d_file(two_side=True)
# Generate model
natural_model = module.model_creation_from_measured_data(filename)

# delete c3d file
os.remove(filename)

if bionc_type == "casadi":
natural_model = natural_model.to_mx()

# Test model
assert natural_model.nb_segments == 7
assert natural_model.nb_markers == 30
assert natural_model.nb_markers_technical == 18
assert natural_model.nb_joints == 6
assert natural_model.nb_joint_constraints == 18
assert natural_model.nb_rigid_body_constraints == 6 * 7
assert natural_model.nb_holonomic_constraints == 60

assert natural_model.nb_Q == 7 * 12
assert natural_model.nb_Qdot == 7 * 12
assert natural_model.nb_Qddot == 7 * 12

0 comments on commit b42e4d2

Please sign in to comment.