Spaces:
Running on T4
Running on T4
File size: 1,832 Bytes
326d3cc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Generate the project model; optional MHR-neutral NPZ replaces synthetic reference proportions."""
import argparse
import sys
from pathlib import Path
import numpy as np
import yaml
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from baseball_batting.anatomy import model_spec,build_opensim
from baseball_batting.temporal3d import MHR_CORE
from baseball_batting.storage import atomic_json
def reference_neutral():
points=np.zeros((70,3),float)
for side,sign in (("left",1),("right",-1)):
entries={"hip":[.15*sign,.9,0],"knee":[.15*sign,.5,0],"ankle":[.15*sign,.1,0],
"shoulder":[.2*sign,1.4,0],"elbow":[.5*sign,1.4,0],"wrist":[.8*sign,1.4,0],
"big_toe":[.15*sign,0,.15],"small_toe":[.2*sign,0,.15],"heel":[.15*sign,0,-.05]}
for name,value in entries.items():points[MHR_CORE[side+"_"+name]]=value
points[49 if side=="left" else 28]=[.87*sign,1.42,.03]
points[61 if side=="left" else 40]=[.87*sign,1.38,-.03]
points[0]=[0,1.65,.05];points[69]=[0,1.5,0]
return points
if __name__=="__main__":
parser=argparse.ArgumentParser();parser.add_argument("--neutral");parser.add_argument("--output",default="models/BattingKinematics-v1.osim")
args=parser.parse_args();root=Path(__file__).resolve().parents[1]
neutral=np.load(args.neutral)["neutral_mhr70_m"] if args.neutral else reference_neutral()
spec=model_spec(neutral,yaml.safe_load((root/"configs/anatomical_model.yaml").read_text()))
spec["proportion_source"]="supplied_neutral_MHR" if args.neutral else "synthetic_reference_template_replaced_per_subject_at_runtime"
path=Path(args.output);path.parent.mkdir(parents=True,exist_ok=True)
build_opensim(spec,path);atomic_json(path.with_suffix(".json"),spec)
print(f"Generated {path}: 35-DOF kinematic proxy")
|