Exemple #1
0
    def setup_class(cls):
        """
        Called once for all tests for pycgmIO.
        Sets rounding_precision, loads filenames to
        be used for testing load functions, and sets
        the python version being used.

        We also run the pyCGM code to get a frame of
        output data to test pycgmIO.writeResult().
        """
        cls.rounding_precision = 8
        cwd = os.getcwd()
        if (cwd.split(os.sep)[-1] == "pyCGM_Single"):
            parent = os.path.dirname(cwd)
            os.chdir(parent)
        cls.cwd = os.getcwd()
        cls.pyver = sys.version_info.major

        cls.filename_59993_Frame = os.path.join(
            cls.cwd,
            pyCGM_Helpers.getfilenames(1)[1])
        cls.filename_Sample_Static = os.path.join(
            cls.cwd, 'SampleData/ROM/Sample_Static.csv')
        cls.filename_RoboSM_vsk = os.path.join(
            cls.cwd,
            pyCGM_Helpers.getfilenames(3)[2])

        dynamic_trial, static_trial, vsk_file, _, _ = pyCGM_Helpers.getfilenames(
            x=2)
        motion_data = pycgmIO.loadData(os.path.join(cls.cwd, dynamic_trial))
        static_data = pycgmIO.loadData(os.path.join(cls.cwd, static_trial))
        vsk_data = pycgmIO.loadVSK(os.path.join(cls.cwd, vsk_file), dict=False)
        cal_SM = pycgmStatic.getStatic(static_data, vsk_data, flat_foot=False)
        cls.kinematics = pycgmCalc.calcAngles(motion_data,start=0,end=1,\
                         vsk=cal_SM,splitAnglesAxis=False,formatData=False)
Exemple #2
0
    def setup_class(cls):
        """
        Called once for all tests for Pipelines.
        Sets rounding_precision, and does a one-time load
        of dynamic and static trial data as dictionaries from
        SampleData/Sample_2/.
        """
        cls.rounding_precision = 8
        cwd = os.getcwd()
        if(cwd.split(os.sep)[-1]=="pyCGM_Single"):
            parent = os.path.dirname(cwd)
            os.chdir(parent)
        cls.cwd = os.getcwd()

        cur_dir = cls.cwd
        dynamic_trial, static_trial,_,_,_ = getfilenames(3)
        dynamic_trial = os.path.join(cur_dir, dynamic_trial)
        static_trial = os.path.join(cur_dir, static_trial)
        motionData = loadData(dynamic_trial)
        staticData = loadData(static_trial)
        cls.data_original = dataAsDict(motionData, npArray=True)
        cls.static_original = dataAsDict(staticData, npArray=True)
        for frame in motionData:
            frame['SACR'] = pelvisJointCenter(frame)[2]
        cls.data_with_sacrum_original = dataAsDict(motionData, npArray=True)
        Pipelines.clearMarker(motionData, 'LFHD')
        cls.data_with_sacrum_clear_marker = dataAsDict(motionData, npArray=True)
Exemple #3
0
    def test_getKinetics(self):
        """
        This test provides coverage of the getKinetics function in pycgmKinetics.py,
        defined as getKinetics(data, Bodymass), where data is an array of joint centers 
        and Bodymass is a float or int.

        This test uses helper functions to obtain the data variable (aka joint_centers).

        Each index in accuracyTests is used as parameters for the function getKinetics 
        and the result is then checked to be equal with the same index in 
        accuracyResults using 8 decimal point precision comparison.
        """
        # Testing is done by using 5 different bodymasses and the same joint_center obtained from the helper functions.
        from pyCGM_Single.pyCGM_Helpers import getfilenames
        from pyCGM_Single.pycgmIO import loadData, loadVSK
        from pyCGM_Single.pycgmStatic import getStatic
        from pyCGM_Single.pycgmCalc import calcAngles

        cwd = os.getcwd() + os.sep
        # Data is obtained from the sample files.
        dynamic_trial, static_trial, vsk_file, _, _ = getfilenames(2)
        motionData = loadData(cwd + dynamic_trial)
        staticData = loadData(cwd + static_trial)
        vsk = loadVSK(cwd + vsk_file, dict=False)

        calSM = getStatic(staticData, vsk, flat_foot=False)
        _, joint_centers = calcAngles(motionData,
                                      start=None,
                                      end=None,
                                      vsk=calSM,
                                      splitAnglesAxis=False,
                                      formatData=False,
                                      returnjoints=True)

        accuracyTests = []
        calSM['Bodymass'] = 5.0
        # This creates five individual assertions to check, all with the same joint_centers but different bodymasses.
        for i in range(5):
            accuracyTests.append((joint_centers, calSM['Bodymass']))
            calSM[
                'Bodymass'] += 35.75  #Increment the bodymass by a substantial amount each time.

        accuracyResults = [
            ([246.57466721, 313.55662383, 1026.56323492]),
            ([246.59137623, 313.6216639, 1026.56440096]),
            ([246.60850798, 313.6856272, 1026.56531282]),
            ([246.6260863, 313.74845693, 1026.56594554]),
            ([246.64410308, 313.81017167, 1026.5663452]),
        ]
        for i in range(len(accuracyResults)):
            # Call getKinetics(joint_centers,bodymass) and round each variable in the 3-element returned list to the 8th decimal precision.
            result = [
                np.around(arr, rounding_precision)
                for arr in pycgmKinetics.getKinetics(accuracyTests[i][0],
                                                     accuracyTests[i][1])
            ]

            # Compare the result with the values in the expected results, within a rounding precision of 8.
            np.testing.assert_almost_equal(result[i], accuracyResults[i],
                                           rounding_precision)
Exemple #4
0
    def setup_class(cls):
        """
        Called once for all tests. Loads filenames to be used for testing getStatic() from SampleData/ROM/.
        """
        cwd = os.getcwd()
        if (cwd.split(os.sep)[-1] == "pyCGM_Single"):
            parent = os.path.dirname(cwd)
            os.chdir(parent)
        cls.cwd = os.getcwd()

        dynamic_trial, static_trial, vsk_file, _, _ = pyCGM_Helpers.getfilenames(x=2)
        cls.motion_data = pycgmIO.loadData(os.path.join(cls.cwd, static_trial))
        cls.vsk_data_original = pycgmIO.loadVSK(os.path.join(cls.cwd, vsk_file), dict=False)
        cls.vsk_data = cls.vsk_data_original.copy()
Exemple #5
0
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
Exemple #6
0
    def setup_class(cls):
        """
        Called once for all tests for pycgmCalc.
        Sets rounding_precision, and loads from SampleData/ROM/
        to be used for testing the calculation functions.
        """
        cls.rounding_precision = 8
        cwd = os.getcwd()
        if (cwd.split(os.sep)[-1] == "pyCGM_Single"):
            parent = os.path.dirname(cwd)
            os.chdir(parent)
        cls.cwd = os.getcwd()

        #Load data from SampleData/ROM/ for testing
        dynamic_trial, static_trial, vsk_file, _, _ = pyCGM_Helpers.getfilenames(
            x=2)
        cls.motion_data = pycgmIO.loadData(os.path.join(
            cls.cwd, dynamic_trial))
        cls.static_data = pycgmIO.loadData(os.path.join(cls.cwd, static_trial))
        cls.vsk_data = pycgmIO.loadVSK(os.path.join(cls.cwd, vsk_file),
                                       dict=False)
        cls.cal_SM = pycgmStatic.getStatic(cls.static_data,
                                           cls.vsk_data,
                                           flat_foot=False)