Exemplo n.º 1
0
 def test_loadVSK_exceptions(self):
     """
     Test that loading a non-existent file raises an
     exception.
     """
     with pytest.raises(Exception):
         pycgmIO.loadVSK("NonExistentFilename")
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
0
 def vsk_loader(self, path):
     try:
         vsk = loadVSK(
             path,
             dict=False)  # this needs changing as dict false returns a dict
         self.mainwindow.explorer_widget.populate_vsk_form(path, vsk)
         self.mainwindow.set_vsk(vsk)
     except Exception:
         self.mainwindow.ui.messageBrowser.setText('Could not load VSK')
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 9
0
    def test_loadVSK_dict(self):
        """
        We test pycgmIO.loadVSK returning as a dictionary.
        """
        result_vsk = pycgmIO.loadVSK(self.filename_RoboSM_vsk, dict=False)
        expected_result = {
            'ASISx': 0.0,
            'ASISy': 140.533599853516,
            'ASISz': 0.0,
            'BHDy': 65.2139663696289,
            'Beta': 0.314000427722931,
            'Bodymass': 72.0,
            'C': 0.0,
            'C7x': -160.832626342773,
            'C7z': 35.1444931030273,
            'HEADy': 63.3674736022949,
            'HJCy': 0.0,
            'HeadOffset': 0.290628731250763,
            'HeadOx': 0.167465895414352,
            'HeadOy': 0.0252241939306259,
            'HeadOz': 700.027526855469,
            'Height': 1730.0,
            'InterAsisDistance': 281.118011474609,
            'LANKy': 0.0,
            'LASIx': 0.0,
            'LASIz': 0.0,
            'LBHDx': -171.985321044922,
            'LELBy': 0.0,
            'LFINy': 0.0,
            'LFOOy': -3.58954524993896,
            'LFOOz': -15.6271200180054,
            'LHEEx': -71.2924499511719,
            'LKNEy': 0.0,
            'LPSIx': -134.874649047852,
            'LPSIy': 66.1733016967773,
            'LTHIy': 91.1664733886719,
            'LTHIz': -246.724578857422,
            'LTIBy': 86.1824417114258,
            'LTIBz': -241.08772277832,
            'LTOEx': 112.053565979004,
            'LWRx': 37.3928489685059,
            'LWRy': 0.0,
            'LeftAnkleAbAdd': 0.0,
            'LeftAnkleWidth': 90.0,
            'LeftAsisTrocanterDistance': 0.0,
            'LeftClavicleLength': 169.407562255859,
            'LeftElbowWidth': 80.0,
            'LeftFemurLength': 401.595642089844,
            'LeftFootLength': 176.388000488281,
            'LeftHandLength': 86.4382247924805,
            'LeftHandThickness': 17.0,
            'LeftHumerusLength': 311.366516113281,
            'LeftKneeWidth': 120.0,
            'LeftLegLength': 1000.0,
            'LeftRadiusLength': 264.315307617188,
            'LeftShankRotation': 0.0,
            'LeftShoulderOffset': 40.0,
            'LeftSoleDelta': 0.0,
            'LeftStaticPlantFlex': 0.137504011392593,
            'LeftStaticRotOff': 0.0358467921614647,
            'LeftThighRotation': 0.0,
            'LeftTibiaLength': 432.649719238281,
            'LeftTibialTorsion': 0.0,
            'LeftWristWidth': 60.0,
            'MeanLegLength': 0.0,
            'PelvisLength': 0.0,
            'RANKy': 0.0,
            'RASIx': 0.0,
            'RASIz': 0.0,
            'RBAKx': -217.971115112305,
            'RBAKy': -97.8660354614258,
            'RBAKz': -101.454940795898,
            'RBHDx': -159.32258605957,
            'RELBy': 0.0,
            'RFINy': 0.0,
            'RFOOy': 2.1107816696167,
            'RFOOz': -23.4012489318848,
            'RHEEx': -52.7204742431641,
            'RKNEy': 0.0,
            'RPSIx': -128.248474121094,
            'RPSIy': -77.4204406738281,
            'RTHIy': -93.3007659912109,
            'RTHIz': -134.734924316406,
            'RTIBy': -77.5902252197266,
            'RTIBz': -201.939865112305,
            'RTOEx': 129.999603271484,
            'RWRx': 35.0017356872559,
            'RWRy': 0.0,
            'RightAnkleAbAdd': 0.0,
            'RightAnkleWidth': 90.0,
            'RightAsisTrocanterDistance': 0.0,
            'RightClavicleLength': 172.908142089844,
            'RightElbowWidth': 80.0,
            'RightFemurLength': 397.317260742188,
            'RightFootLength': 175.794006347656,
            'RightHandLength': 87.4593048095703,
            'RightHandThickness': 17.0,
            'RightHumerusLength': 290.563262939453,
            'RightKneeWidth': 120.0,
            'RightLegLength': 1000.0,
            'RightRadiusLength': 264.853607177734,
            'RightShankRotation': 0.0,
            'RightShoulderOffset': 40.0,
            'RightSoleDelta': 0.0,
            'RightStaticPlantFlex': 0.17637075483799,
            'RightStaticRotOff': 0.03440235927701,
            'RightThighRotation': 0.0,
            'RightTibiaLength': 443.718109130859,
            'RightTibialTorsion': 0.0,
            'RightWristWidth': 60.0,
            'STRNz': -207.033920288086,
            'T10x': -205.628646850586,
            'T10y': -7.51900339126587,
            'T10z': -261.275146484375,
            'Theta': 0.500000178813934,
            'ThorOx': 1.28787481784821,
            'ThorOy': 0.0719171389937401,
            'ThorOz': 499.705780029297
        }

        #Test that loadVSK correctly returned as a dictionary
        assert isinstance(result_vsk, dict)
        #Test accurate loading
        assert result_vsk == expected_result
Exemplo n.º 10
0
    def test_loadVSK_list(self):
        """
        This function tests pycgmIO.loadVSK(filename, dict=True),
        where filename is the vsk file to be loaded and dict is a 
        bool indicating whether to return the vsk as a dictionary or list of
        [keys, values].

        RoboSM.vsk in SampleData is used to test the output.

        We test returning as a list.
        """
        result_vsk = pycgmIO.loadVSK(self.filename_RoboSM_vsk, dict=True)
        result_keys = result_vsk[0]
        result_values = result_vsk[1]
        expected_keys = [
            'Bodymass', 'Height', 'InterAsisDistance', 'LeftLegLength',
            'LeftAsisTrocanterDistance', 'LeftKneeWidth', 'LeftAnkleWidth',
            'LeftTibialTorsion', 'LeftSoleDelta', 'LeftThighRotation',
            'LeftShankRotation', 'LeftStaticPlantFlex', 'LeftStaticRotOff',
            'LeftAnkleAbAdd', 'LeftShoulderOffset', 'LeftElbowWidth',
            'LeftWristWidth', 'LeftHandThickness', 'RightLegLength',
            'RightAsisTrocanterDistance', 'RightKneeWidth', 'RightAnkleWidth',
            'RightTibialTorsion', 'RightSoleDelta', 'RightThighRotation',
            'RightShankRotation', 'RightStaticPlantFlex', 'RightStaticRotOff',
            'RightAnkleAbAdd', 'RightShoulderOffset', 'RightElbowWidth',
            'RightWristWidth', 'RightHandThickness', 'MeanLegLength', 'C',
            'Theta', 'Beta', 'HJCy', 'PelvisLength', 'LASIx', 'LASIz', 'RASIx',
            'RASIz', 'ASISx', 'ASISz', 'LKNEy', 'LANKy', 'RKNEy', 'RANKy',
            'LELBy', 'LWRy', 'LFINy', 'RELBy', 'RWRy', 'RFINy', 'HeadOffset',
            'HEADy', 'LBHDx', 'BHDy', 'RBHDx', 'HeadOx', 'HeadOy', 'HeadOz',
            'C7x', 'C7z', 'T10x', 'T10y', 'T10z', 'STRNz', 'RBAKx', 'RBAKy',
            'RBAKz', 'ThorOx', 'ThorOy', 'ThorOz', 'LeftClavicleLength',
            'LeftHumerusLength', 'LeftRadiusLength', 'LeftHandLength', 'LWRx',
            'RightClavicleLength', 'RightHumerusLength', 'RightRadiusLength',
            'RightHandLength', 'RWRx', 'ASISy', 'LPSIx', 'LPSIy', 'RPSIx',
            'RPSIy', 'LeftFemurLength', 'LeftTibiaLength', 'LeftFootLength',
            'LTHIy', 'LTHIz', 'LTIBy', 'LTIBz', 'LFOOy', 'LFOOz', 'LHEEx',
            'LTOEx', 'RightFemurLength', 'RightTibiaLength', 'RightFootLength',
            'RTHIy', 'RTHIz', 'RTIBy', 'RTIBz', 'RFOOy', 'RFOOz', 'RHEEx',
            'RTOEx'
        ]

        expected_values = [
            72.0, 1730.0, 281.118011474609, 1000.0, 0.0, 120.0, 90.0, 0.0, 0.0,
            0.0, 0.0, 0.137504011392593, 0.0358467921614647, 0.0, 40.0, 80.0,
            60.0, 17.0, 1000.0, 0.0, 120.0, 90.0, 0.0, 0.0, 0.0, 0.0,
            0.17637075483799, 0.03440235927701, 0.0, 40.0, 80.0, 60.0, 17.0,
            0.0, 0.0, 0.500000178813934, 0.314000427722931, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.290628731250763, 63.3674736022949, -171.985321044922,
            65.2139663696289, -159.32258605957, 0.167465895414352,
            0.0252241939306259, 700.027526855469, -160.832626342773,
            35.1444931030273, -205.628646850586, -7.51900339126587,
            -261.275146484375, -207.033920288086, -217.971115112305,
            -97.8660354614258, -101.454940795898, 1.28787481784821,
            0.0719171389937401, 499.705780029297, 169.407562255859,
            311.366516113281, 264.315307617188, 86.4382247924805,
            37.3928489685059, 172.908142089844, 290.563262939453,
            264.853607177734, 87.4593048095703, 35.0017356872559,
            140.533599853516, -134.874649047852, 66.1733016967773,
            -128.248474121094, -77.4204406738281, 401.595642089844,
            432.649719238281, 176.388000488281, 91.1664733886719,
            -246.724578857422, 86.1824417114258, -241.08772277832,
            -3.58954524993896, -15.6271200180054, -71.2924499511719,
            112.053565979004, 397.317260742188, 443.718109130859,
            175.794006347656, -93.3007659912109, -134.734924316406,
            -77.5902252197266, -201.939865112305, 2.1107816696167,
            -23.4012489318848, -52.7204742431641, 129.999603271484
        ]

        #Test that loadVSK correctly returned as a list
        assert isinstance(result_vsk, list)
        #Test that len(keys) is the same as len(values)
        assert len(result_keys) == len(result_values)
        #Test accurate loading
        assert expected_keys == result_keys
        assert expected_values == result_values