-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpycgm_embed.py
68 lines (52 loc) · 2.92 KB
/
pycgm_embed.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pyCGM
###########
#This file is an example of how to call the pycgm code without a console, or more likely, as a
# way to integrate the code into your own system/software
#There are a few commented parts that show how to use some pipeline functions such as filtering.
##########
import sys
import os
try: from pyCGM_Single.Pipelines import rigid_fill, filtering, prep,clearMarker
except: print("Could not import Pipelines.py, possibly missing scipy\n Otherwise check the directory locations")
from pyCGM_Single import pycgmStatic
from pyCGM_Single import pycgmIO
from pyCGM_Single import pycgmCalc
from pyCGM_Single import pyCGM_Helpers
def loadData(dynamic_trial,static_trial,vsk_file):
#load the data, usually there is some checks in here to make sure we loaded
# correctly, but for now we assume its loaded
motionData = pycgmIO.loadData(dynamic_trial)
vsk = pycgmIO.loadVSK(vsk_file,dict=False)
staticData = pycgmIO.loadData(static_trial)
#The vsk is loaded, if dict=True (default), we combine
#vsk = pycgmIO.createVskDataDict(vsk[0],vsk[1])
return motionData,vsk,staticData
def main():
#Load the filenames
#pyCGM_Helpers.py contains some sample directory data based on github directories
dynamic_trial,static_trial,vsk_file,outputfile,CoM_output = pyCGM_Helpers.getfilenames(x=2) #change x to use different files
#Load a dynamic trial, static trial, and vsk (subject measurements)
motionData,vskData,staticData = loadData(dynamic_trial,static_trial,vsk_file)
#Calibrate the static offsets and subject measurements
calSM = pycgmStatic.getStatic(staticData,vskData,flat_foot=False)
# #Load data as a dictionary instead of a frame-by-frame array of dictionary
# staticDataDict = pycgmIO.dataAsDict(staticData,npArray=True)
# motionDataDict = pycgmIO.dataAsDict(motionData,npArray=True)
# #### Start Pipeline oeprations
# movementFilled = rigid_fill(motionDataDict,staticDataDict)
# movementFiltered = filtering(motionDataDict)
# movementFinal = prep(movementFiltered)
# motionData = movementFinal
# ### End pipeline operations
#hack for changing the global coordinates until finding a proper way
# this impacts the global angles, such as pelvis, but not the anatomical angles (e.g., hip)
#calSM['GCS'] = pycgmStatic.rotmat(x=0,y=0,z=180)
#calSM['HeadOffset'] = 0 #example of manually modifying a subject measurement
kinematics,joint_centers=pycgmCalc.calcAngles(motionData,start=None,end=None,vsk=calSM,splitAnglesAxis=False,formatData=False,returnjoints=True)
kinetics=pycgmCalc.calcKinetics(joint_centers, calSM['Bodymass'])
#Write the results to a csv file, if wanted,
# otherwise could just return the angles/axis to some other function
pycgmIO.writeResult(kinematics,outputfile,angles=True,axis=False)
pycgmIO.writeKinetics(CoM_output,kinetics) #quick save of CoM
return
main()