Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #4
0
def load_files(dynamic_trial, static_trial, vsk_file):
    """
    Uses load functions from pycgmIO to load data from c3d and
    vsk files.
    """
    motion_data = loadData(dynamic_trial)
    static_data = loadData(static_trial)
    vsk_data = loadVSK(vsk_file, dict=False)
    return motion_data, static_data, vsk_data
Beispiel #5
0
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
Beispiel #6
0
    def test_loadData_c3d(self, frame, data_key, expected_data):
        """
        This function tests pycgmIO.loadData(filename), where filename
        is a string indicating the file path of a CSV or C3D file to load.

        This function use 59993_Frame_Static.c3d in SampleData for testing.
        """
        c3d_results = pycgmIO.loadData(self.filename_59993_Frame)
        result_data = c3d_results[frame][data_key]
        np.testing.assert_almost_equal(result_data, expected_data,
                                       self.rounding_precision)
Beispiel #7
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()
Beispiel #8
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)
Beispiel #9
0
 def test_loadData_invalid_filename(self):
     #Test that loading a non-existent filename returns None.
     assert pycgmIO.loadData("NonExistentFile") is None