Esempio n. 1
0
 def optionalMp(self):
     if self._vsk is None:
         return  self._userSettings["MP"]["Optional"]
     else:
         required_mp,optional_mp = vskTools.getFromVskSubjectMp(self._vsk, resetFlag=True)
         self._userSettings["MP"]["Optional"].update(optional_mp)
         return optional_mp
Esempio n. 2
0
    def test_CGM24_FullBody_noOptions_uncorrectLowerLimbMarker(self):
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "Scenarii\\different static and dynamic marker set\\CGM24-fullBody\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH +  staticFilename)


        markerDiameter=14
        leftFlatFoot = False
        rightFlatFoot = False
        headStraight = False
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "PN07.vsk")
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True)

        settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_4-pyCGM2.settings")
        hjcMethod = settings["Calibration"]["HJC"]

        translators = files.getTranslators(DATA_PATH,"CGM2_4.translators")
        # if not translators:  translators = settings["Translators"]


        model,finalAcqStatic = cgm2_4.calibrate(DATA_PATH,
            staticFilename,
            translators,
            settings,
            required_mp,
            optional_mp,
            False,
            leftFlatFoot,
            rightFlatFoot,
            headStraight,
            markerDiameter,
            hjcMethod,
            pointSuffix,
            displayCoordinateSystem=True)

        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        logging.info("Static Calibration -----> Done")

        gaitFilename="gait1_noLASI.c3d"

        mfpa = None
        reconstructFilenameLabelled = gaitFilename

        acqGait = cgm2_4.fitting(model,DATA_PATH, reconstructFilenameLabelled,
            translators,
            settings,
            False,
            markerDiameter,
            pointSuffix,
            mfpa,
            enums.MomentProjection.Proximal,
            displayCoordinateSystem=True)

        assert model.m_bodypart  == enums.BodyPart.UpperLimb
Esempio n. 3
0
    def test_sample0(self):

        DATA_PATH = MAIN_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\CGM1\\fullBody-native-noOptions\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH + staticFilename)

        markerDiameter = 14
        leftFlatFoot = False
        rightFlatFoot = False
        headStraight = False
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk")
        required_mp, optional_mp = vskTools.getFromVskSubjectMp(vsk,
                                                                resetFlag=True)

        # calibration according CGM1
        model, finalAcqStatic = cgm1.calibrate(DATA_PATH,
                                               staticFilename,
                                               None,
                                               required_mp,
                                               optional_mp,
                                               leftFlatFoot,
                                               rightFlatFoot,
                                               headStraight,
                                               markerDiameter,
                                               pointSuffix,
                                               displayCoordinateSystem=True)

        # no fitting operation, only checking of forceplateAssembly
        gaitFilename = "gait1.c3d"
        acqGait = btkTools.smartReader(DATA_PATH + gaitFilename)
        mfpa = None

        mappedForcePlate = forceplates.matchingFootSideOnForceplate(acqGait,
                                                                    mfpa=mfpa)
        forceplates.addForcePlateGeneralEvents(acqGait, mappedForcePlate)
        logging.warning("Manual Force plate assignment : %s" %
                        mappedForcePlate)

        # assembly foot and force plate
        modelFilters.ForcePlateAssemblyFilter(
            model,
            acqGait,
            mappedForcePlate,
            leftSegmentLabel="Left Foot",
            rightSegmentLabel="Right Foot").compute(
                pointLabelSuffix=pointSuffix)

        testingUtils.plotComparisonOfPoint(acqGait, "RGroundReactionForce",
                                           "test")
        testingUtils.plotComparisonOfPoint(acqGait, "RGroundReactionMoment",
                                           "test")
Esempio n. 4
0
    def test_FullBody_noOptions(self):
        DATA_PATH = MAIN_PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\uncropped data\\cgm1\\"
        staticFilename = "static.c3d"

        DATA_PATH_OUT = pyCGM2.TEST_DATA_PATH_OUT+"LowLevel\\uncropped data\\cgm1\\"
        files.createDir(DATA_PATH_OUT)

        markerDiameter=14
        leftFlatFoot = True
        rightFlatFoot = True
        headStraight = True
        pointSuffix = ""

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk")
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True)

        model,finalAcqStatic = cgm1.calibrate(DATA_PATH,
            staticFilename,
            None,
            required_mp,
            optional_mp,
            leftFlatFoot,
            rightFlatFoot,
            headStraight,
            markerDiameter,
            pointSuffix,
            displayCoordinateSystem=True)

        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        # logging.info("Static Calibration -----> Done")

        gaitFilename="gait1.c3d"

        acqGait0 = btkTools.smartReader(DATA_PATH +  gaitFilename)
        trackingMarkers = model.getTrackingMarkers(acqGait0)
        validFrames,vff,vlf = btkTools.findValidFrames(acqGait0,trackingMarkers)


        mfpa = None
        reconstructFilenameLabelled = gaitFilename


        acqGait = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
            None,
            markerDiameter,
            pointSuffix,
            mfpa,
            enums.MomentProjection.Proximal,
            displayCoordinateSystem=True)

        btkTools.smartWriter(acqGait, DATA_PATH_OUT+"//gait1-processed.c3d")
Esempio n. 5
0
    def test_CGM1_FullBody_noOptions_uncorrectUpperLimbMarker(self):
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "Scenarii\different static and dynamic marker set\CGM1-fullBody\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH + staticFilename)

        markerDiameter = 14
        leftFlatFoot = False
        rightFlatFoot = False
        headStraight = False
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk")
        required_mp, optional_mp = vskTools.getFromVskSubjectMp(vsk,
                                                                resetFlag=True)

        model, finalAcqStatic, error = cgm1.calibrate(
            DATA_PATH,
            staticFilename,
            None,
            required_mp,
            optional_mp,
            leftFlatFoot,
            rightFlatFoot,
            headStraight,
            markerDiameter,
            pointSuffix,
            displayCoordinateSystem=True)

        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        LOGGER.logger.info("Static Calibration -----> Done")

        # case 1 -  one marker on the upper limb misses
        gaitFilename = "gait1_noRFIN.c3d"
        mfpa = None
        reconstructFilenameLabelled = gaitFilename

        acqGait, error = cgm1.fitting(model,
                                      DATA_PATH,
                                      reconstructFilenameLabelled,
                                      None,
                                      markerDiameter,
                                      pointSuffix,
                                      mfpa,
                                      enums.MomentProjection.Proximal,
                                      displayCoordinateSystem=True)

        assert model.m_bodypart == enums.BodyPart.FullBody
Esempio n. 6
0
    def test_CGM1_FullBody_noOptions_noFP(self):
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\CGM1\\fullBody-native-noOptions - noFP\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH +  staticFilename)


        markerDiameter=14
        leftFlatFoot = False
        rightFlatFoot = False
        headStraight = False
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk")
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True)

        model,finalAcqStatic = cgm1.calibrate(DATA_PATH,
            staticFilename,
            None,
            required_mp,
            optional_mp,
            leftFlatFoot,
            rightFlatFoot,
            headStraight,
            markerDiameter,
            pointSuffix,
            displayCoordinateSystem=True)


        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        # logging.info("Static Calibration -----> Done")

        gaitFilename="gait1.c3d"

        mfpa = None
        reconstructFilenameLabelled = gaitFilename

        acqGait = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
            None,
            markerDiameter,
            pointSuffix,
            mfpa,
            enums.MomentProjection.Proximal,
            displayCoordinateSystem=True)

        btkTools.smartWriter(acqGait, "gait1-pyCGM2modelled.c3d")
Esempio n. 7
0
        calibrateFilenameLabelled = args.trial

    logging.info( "data Path: "+ DATA_PATH )
    logging.info( "calibration file: "+ calibrateFilenameLabelled)


    # --------------------------SUBJECT ------------------------------------
    #  translators management
    translators = files.getTranslators(DATA_PATH,"CGM1.translators")
    if not translators: translators = settings["Translators"]

    # --------------------------SUBJECT ------------------------------------
    if os.path.isfile(DATA_PATH+subject+".vsk"):
        logging.info("vsk file found")
        vsk = vskTools.Vsk(str(DATA_PATH + subject+".vsk"))
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=args.resetMP)
        mpInfo,mpFilename = files.getJsonFileContent(DATA_PATH,"mp.pyCGM2",subject)
    else:
        logging.info("no vsk found")
        mpInfo,mpFilename = files.getJsonFileContent(DATA_PATH,"mp.pyCGM2",subject)
        required_mp,optional_mp = files.getMp(mpInfo, resetFlag=args.resetMP)

    #---------------------------------------------------------------------------
    # --------------------------MODELLING PROCESSING ---------------------------
    model,acqStatic = cgm1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
                  leftFlatFoot,rightFlatFoot,markerDiameter,
                  pointSuffix)

    #---------------------------------------------------------------------------
    #---------------------------------------------------------------------------
Esempio n. 8
0
    def test_FullBody_noOptions_global(self):
        DATA_PATH = MAIN_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\\CGM1\\LowerLimb-medMed_Yprogression\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH + staticFilename)

        markerDiameter = 14
        leftFlatFoot = False
        rightFlatFoot = False
        headStraight = False
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "Subject.vsk")
        required_mp, optional_mp = vskTools.getFromVskSubjectMp(vsk,
                                                                resetFlag=True)

        model, finalAcqStatic = cgm1.calibrate(DATA_PATH,
                                               staticFilename,
                                               None,
                                               required_mp,
                                               optional_mp,
                                               leftFlatFoot,
                                               rightFlatFoot,
                                               headStraight,
                                               markerDiameter,
                                               pointSuffix,
                                               displayCoordinateSystem=True)

        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        # logging.info("Static Calibration -----> Done")

        gaitFilename = "gait1.Global.c3d"

        mfpa = "RLX"
        reconstructFilenameLabelled = gaitFilename

        acqGait = cgm1.fitting(model,
                               DATA_PATH,
                               reconstructFilenameLabelled,
                               None,
                               markerDiameter,
                               pointSuffix,
                               mfpa,
                               enums.MomentProjection.Global,
                               displayCoordinateSystem=True)

        testingUtils.plotComparison_ForcePanel(acqGait, None, "test", "Left")
        testingUtils.plotComparison_ForcePanel(acqGait, None, "test", "Right")

        gaitFilename = "gait2.Global.c3d"

        mfpa = "XLR"
        reconstructFilenameLabelled = gaitFilename

        acqGait = cgm1.fitting(model,
                               DATA_PATH,
                               reconstructFilenameLabelled,
                               None,
                               markerDiameter,
                               pointSuffix,
                               mfpa,
                               enums.MomentProjection.Global,
                               displayCoordinateSystem=True)

        testingUtils.plotComparison_ForcePanel(acqGait, None, "test", "Left")
        testingUtils.plotComparison_ForcePanel(acqGait, None, "test", "Right")
Esempio n. 9
0
    def test_issue_signAbdAddOffset(self):

        DATA_PATH = pyCGM2.TEST_DATA_PATH + "Issues\\StephenM\\signedAbdAdd-KadMed\\"
        staticFilename = "Static.c3d"
        acqStatic = btkTools.smartReader(str(DATA_PATH + staticFilename))

        markerDiameter = 14
        leftFlatFoot = True
        rightFlatFoot = True
        headStraight = True
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "Nick.vsk")
        required_mp, optional_mp = vskTools.getFromVskSubjectMp(vsk,
                                                                resetFlag=True)
        # required_mp={
        # 'Bodymass'   : 65.0,
        # 'LeftLegLength' : 800.0,
        # 'RightLegLength' : 800.0 ,
        # 'LeftKneeWidth' : 120.0,
        # 'RightKneeWidth' : 120.0,
        # 'LeftAnkleWidth' : 100.0,
        # 'RightAnkleWidth' : 100.0,
        # 'LeftSoleDelta' : 0,
        # 'RightSoleDelta' : 0,
        # 'LeftShoulderOffset'   : 40,
        # 'LeftElbowWidth' : 74,
        # 'LeftWristWidth' : 55 ,
        # 'LeftHandThickness' : 34 ,
        # 'RightShoulderOffset'   : 40,
        # 'RightElbowWidth' : 74,
        # 'RightWristWidth' : 55 ,
        # 'RightHandThickness' : 34}
        #
        # optional_mp={
        # 'InterAsisDistance'   :  0,#0,
        # 'LeftAsisTrocanterDistance' :  0,#0,
        # 'LeftTibialTorsion' :  0,#0,
        # 'LeftThighRotation' :  0,#0,
        # 'LeftShankRotation' : 0,#0,ipdb
        # 'RightAsisTrocanterDistance' : 0,#0,
        # 'RightTibialTorsion' :  0,#0,
        # 'RightThighRotation' :  0,#0,
        # 'RightShankRotation' : 0}

        model, finalAcqStatic = cgm1.calibrate(DATA_PATH,
                                               staticFilename,
                                               None,
                                               required_mp,
                                               optional_mp,
                                               leftFlatFoot,
                                               rightFlatFoot,
                                               headStraight,
                                               markerDiameter,
                                               pointSuffix,
                                               displayCoordinateSystem=True)

        testingUtils.test_offset(
            model.mp_computed["LeftThighRotationOffset"],
            acqStatic,
            "LThighRotation",
            decimal=1)  # not enought accurate but unsignificant
        testingUtils.test_offset(model.mp_computed["RightThighRotationOffset"],
                                 acqStatic,
                                 "RThighRotation",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["LeftShankRotationOffset"],
                                 acqStatic,
                                 "LShankRotation",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["RightShankRotationOffset"],
                                 acqStatic,
                                 "RShankRotation",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["LeftTibialTorsionOffset"],
                                 acqStatic,
                                 "LTibialTorsion",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["RightTibialTorsionOffset"],
                                 acqStatic,
                                 "RTibialTorsion",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["LeftAnkleAbAddOffset"],
                                 acqStatic,
                                 "LAnkleAbAdd",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["RightAnkleAbAddOffset"],
                                 acqStatic,
                                 "RAnkleAbAdd",
                                 decimal=1)
        testingUtils.test_offset(
            model.mp_computed["LeftStaticPlantFlexOffset"],
            acqStatic,
            "LStaticPlantFlex",
            decimal=1)
        testingUtils.test_offset(
            model.mp_computed["RightStaticPlantFlexOffset"],
            acqStatic,
            "RStaticPlantFlex",
            decimal=1)
        testingUtils.test_offset(model.mp_computed["LeftStaticRotOffset"],
                                 acqStatic,
                                 "LStaticRotOff",
                                 decimal=1)
        testingUtils.test_offset(model.mp_computed["RightStaticRotOffset"],
                                 acqStatic,
                                 "RStaticRotOff",
                                 decimal=1)
Esempio n. 10
0
    def test_issue_jointForce_CGM24(self):
        """
        synopsis : inverted sign of the x-component of the joint force with CGM1.1 to CGM2.4
        """

        DATA_PATH = MAIN_PATH = pyCGM2.TEST_DATA_PATH + "Issues\\StephenM\\sign_jointForce_CGM24\\"
        staticFilename = "FullBody CGM2 data Cal 01.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH + staticFilename)

        markerDiameter = 14
        leftFlatFoot = False
        rightFlatFoot = False
        headStraight = False
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "Nick.vsk")
        required_mp, optional_mp = vskTools.getFromVskSubjectMp(vsk,
                                                                resetFlag=True)

        settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,
                                  "CGM2_4-pyCGM2.settings")

        model, finalAcqStatic = cgm2_4.calibrate(DATA_PATH,
                                                 staticFilename,
                                                 None,
                                                 settings,
                                                 required_mp,
                                                 optional_mp,
                                                 True,
                                                 leftFlatFoot,
                                                 rightFlatFoot,
                                                 headStraight,
                                                 markerDiameter, {
                                                     "Left": "Hara",
                                                     "Right": "Hara"
                                                 },
                                                 pointSuffix,
                                                 displayCoordinateSystem=True)

        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        # logging.info("Static Calibration -----> Done")

        gaitFilename = "Capture 02.Distal.c3d"

        mfpa = "R"
        reconstructFilenameLabelled = gaitFilename

        acqGait = cgm2_4.fitting(model,
                                 DATA_PATH,
                                 reconstructFilenameLabelled,
                                 None,
                                 settings,
                                 True,
                                 markerDiameter,
                                 pointSuffix,
                                 mfpa,
                                 enums.MomentProjection.Distal,
                                 displayCoordinateSystem=True)

        testingUtils.plotComparisonOfPoint(acqGait,
                                           "RAnkleForce",
                                           "test",
                                           title="RAnkleForce PiG - CGM24")
        testingUtils.plotComparisonOfPoint(acqGait,
                                           "RKneeForce",
                                           "test",
                                           title="RKneeForce PiG - CGM24")
        testingUtils.plotComparisonOfPoint(acqGait,
                                           "RHipForce",
                                           "test",
                                           title="RHipForce PiG - CGM24")
Esempio n. 11
0
    def test_FullBody_noOptions(self):
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\CGM1\\fullBody-native-Options\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(DATA_PATH +  staticFilename)


        markerDiameter=14
        leftFlatFoot = True
        rightFlatFoot = True
        headStraight = True
        pointSuffix = "test"

        vskFile = vskTools.getVskFiles(DATA_PATH)
        vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk")
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True)

        model,finalAcqStatic,error = cgm1.calibrate(DATA_PATH,
            staticFilename,
            None,
            required_mp,
            optional_mp,
            leftFlatFoot,
            rightFlatFoot,
            headStraight,
            markerDiameter,
            pointSuffix,
            displayCoordinateSystem=True)


        testingUtils.test_offset(model.mp_computed["LeftThighRotationOffset"],acqStatic,"LThighRotation", decimal=3)
        testingUtils.test_offset(model.mp_computed["RightThighRotationOffset"],acqStatic,"RThighRotation", decimal=3)
        testingUtils.test_offset(model.mp_computed["LeftShankRotationOffset"],acqStatic,"LShankRotation", decimal=3)
        testingUtils.test_offset(model.mp_computed["RightShankRotationOffset"],acqStatic,"RShankRotation", decimal=3)
        testingUtils.test_offset(model.mp_computed["LeftTibialTorsionOffset"],acqStatic,"LTibialTorsion", decimal=3)
        testingUtils.test_offset(model.mp_computed["RightTibialTorsionOffset"],acqStatic,"RTibialTorsion", decimal=3)
        testingUtils.test_offset(model.mp_computed["LeftAnkleAbAddOffset"],acqStatic,"LAnkleAbAdd", decimal=3)
        testingUtils.test_offset(model.mp_computed["RightAnkleAbAddOffset"],acqStatic,"RAnkleAbAdd", decimal=3)
        testingUtils.test_offset(model.mp_computed["LeftStaticPlantFlexOffset"],acqStatic,"LStaticPlantFlex", decimal=3)
        testingUtils.test_offset(model.mp_computed["RightStaticPlantFlexOffset"],acqStatic,"RStaticPlantFlex", decimal=3)
        testingUtils.test_offset(model.mp_computed["LeftStaticRotOffset"],acqStatic,"LStaticRotOff", decimal=3)
        testingUtils.test_offset(model.mp_computed["RightStaticRotOffset"],acqStatic,"RStaticRotOff", decimal=3)


        np.testing.assert_equal(model.getSegment("Left Thigh").getReferential("TF").static.getNode_byLabel("LHJC").m_desc ,"Davis")
        np.testing.assert_equal(model.getSegment("Right Thigh").getReferential("TF").static.getNode_byLabel("RHJC").m_desc ,"Davis")
        np.testing.assert_equal(model.getSegment("Left Thigh").getReferential("TF").static.getNode_byLabel("LKJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Right Thigh").getReferential("TF").static.getNode_byLabel("RKJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Left Shank").getReferential("TF").static.getNode_byLabel("LKJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Right Shank").getReferential("TF").static.getNode_byLabel("RKJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Left Shank").getReferential("TF").static.getNode_byLabel("LAJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Right Shank").getReferential("TF").static.getNode_byLabel("RAJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Left Foot").getReferential("TF").static.getNode_byLabel("LAJC").m_desc ,"Chord")
        np.testing.assert_equal(model.getSegment("Right Foot").getReferential("TF").static.getNode_byLabel("RAJC").m_desc ,"Chord")


        testingUtils.test_point(finalAcqStatic,"LPelvisAngles","LPelvisAngles_test",decimal = 3)
        testingUtils.test_point(finalAcqStatic,"RPelvisAngles","RPelvisAngles_test",decimal = 3)
        testingUtils.test_point(finalAcqStatic,"LHipAngles","LHipAngles_test",decimal = 3)
        testingUtils.test_point(finalAcqStatic,"LKneeAngles","LKneeAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"LAnkleAngles","LAnkleAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RHipAngles","RHipAngles_test",decimal = 3)
        testingUtils.test_point(finalAcqStatic,"RKneeAngles","RKneeAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RAnkleAngles","RAnkleAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"LFootProgressAngles","LFootProgressAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RFootProgressAngles","RFootProgressAngles_test",decimal = 2)

        testingUtils.test_point(finalAcqStatic,"LThoraxAngles","LThoraxAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RThoraxAngles","RThoraxAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"LSpineAngles","LSpineAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RSpineAngles","RSpineAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"LShoulderAngles","LShoulderAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RShoulderAngles","RShoulderAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"LElbowAngles","LElbowAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"RElbowAngles","RElbowAngles_test",decimal = 2)
        testingUtils.test_point(finalAcqStatic,"LHeadAngles","LHeadAngles_test",decimal = 3)
        testingUtils.test_point(finalAcqStatic,"RHeadAngles","RHeadAngles_test",decimal = 3)


        # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d"))
        # LOGGER.logger.info("Static Calibration -----> Done")

        gaitFilename="gait1.c3d"

        mfpa = None
        reconstructFilenameLabelled = gaitFilename

        acqGait,error = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
            None,
            markerDiameter,
            pointSuffix,
            mfpa,
            enums.MomentProjection.Proximal,
            displayCoordinateSystem=True)

        testingUtils.test_point(acqGait,"LPelvisAngles","LPelvisAngles_test",decimal = 3)
        testingUtils.test_point(acqGait,"RPelvisAngles","RPelvisAngles_test",decimal = 3)
        testingUtils.test_point(acqGait,"LHipAngles","LHipAngles_test",decimal = 3)
        testingUtils.test_point(acqGait,"LKneeAngles","LKneeAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"LAnkleAngles","LAnkleAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RHipAngles","RHipAngles_test",decimal = 3)
        testingUtils.test_point(acqGait,"RKneeAngles","RKneeAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RAnkleAngles","RAnkleAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"LFootProgressAngles","LFootProgressAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RFootProgressAngles","RFootProgressAngles_test",decimal = 2)

        testingUtils.test_point(acqGait,"LThoraxAngles","LThoraxAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RThoraxAngles","RThoraxAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"LSpineAngles","LSpineAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RSpineAngles","RSpineAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"LShoulderAngles","LShoulderAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RShoulderAngles","RShoulderAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"LElbowAngles","LElbowAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"RElbowAngles","RElbowAngles_test",decimal = 2)
        testingUtils.test_point(acqGait,"LHeadAngles","LHeadAngles_test",decimal = 3)
        testingUtils.test_point(acqGait,"RHeadAngles","RHeadAngles_test",decimal = 3)
        # testingUtils.test_point(acqGait,"LWristAngles","LWristAngles_test",decimal = 3) fail on z!
        # testingUtils.test_point(acqGait,"RWristAngles","RWristAngles_test",decimal = 3) fail on Z!
        # testingUtils.test_point(acqGait,"CentreOfMass","CentreOfMass_test",decimal = 3)

        btkTools.smartAppendPoint(acqGait,"headCOM_py",model.getSegment("Head").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"ThoraxCOM_py",model.getSegment("Thorax").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"LhumCOM_py",model.getSegment("Left UpperArm").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"LforeCom_py",model.getSegment("Left ForeArm").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"LhandCom_py",model.getSegment("Left Hand").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"RhumCOM_py",model.getSegment("Right UpperArm").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"RforeCom_py",model.getSegment("Right ForeArm").getComTrajectory())
        btkTools.smartAppendPoint(acqGait,"RhandCom_py",model.getSegment("Right Hand").getComTrajectory())
Esempio n. 12
0
def modelling(manager,DATA_PATH,DATA_PATH_OUT,vskFile=None):
    modelVersion = manager.getModelVersion()
    logging.info("model version : %s" %(modelVersion))

    # --------------------------MODELLING ------------------------------------

    # manage global settings and translators
    if modelVersion == "CGM1.0":
        translatorFiles=  "CGM1.translators"
        globalPyCGM2settingFile = "CGM1-pyCGM2.settings"
    elif modelVersion == "CGM1.1":
        translatorFiles=  "CGM1_1.translators"
        globalPyCGM2settingFile = "CGM1_1-pyCGM2.settings"
    elif modelVersion == "CGM2.1":
        translatorFiles=  "CGM2_1.translators"
        globalPyCGM2settingFile = "CGM2_1-pyCGM2.settings"
    elif modelVersion == "CGM2.2":
        translatorFiles=  "CGM2_2.translators"
        globalPyCGM2settingFile = "CGM2_2-pyCGM2.settings"
    elif modelVersion == "CGM2.2e":
        translatorFiles=  "CGM2_2.translators"
        globalPyCGM2settingFile = "CGM2_2-Expert-pyCGM2.settings"
    elif modelVersion == "CGM2.3":
        translatorFiles=  "CGM2_3.translators"
        globalPyCGM2settingFile = "CGM2_3-pyCGM2.settings"
    elif modelVersion == "CGM2.3e":
        translatorFiles=  "CGM2_3.translators"
        globalPyCGM2settingFile = "CGM2_3-Expert-pyCGM2.settings"
    elif modelVersion == "CGM2.4":
        translatorFiles=  "CGM2_4.translators"
        globalPyCGM2settingFile = "CGM2_4-pyCGM2.settings"
    elif modelVersion == "CGM2.4e":
        translatorFiles=  "CGM2_4.translators"
        globalPyCGM2settingFile = "CGM2_4-Expert-pyCGM2.settings"

    else:
        raise Exception( "model version not known")

    settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,globalPyCGM2settingFile)
    translators = files.getTranslators(DATA_PATH,translatorFiles)
    if not translators: translators = settings["Translators"]

    # mp file
    if vskFile is None:
        logging.info("mp from pipeline file")
        required_mp,optional_mp = manager.getMP()
    else:
        logging.warning("mp from vsk file")
        vsk = vskTools.Vsk(str(DATA_PATH + vskFile))
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True)


    fileSuffix = manager.getFileSuffix()
    pointSuffix = manager.getPointSuffix()
    ik_flag = manager.isIkFitting()

    #------calibration--------
    leftFlatFoot = manager.getLeftFlatFoot()
    rightFlatFoot = manager.getRightFlatFoot()
    markerDiameter = manager.getMarkerDiameter()
    calibrateFilenameLabelled = manager.getStaticTial()

    if modelVersion == "CGM1.0":
        model,finalAcqStatic = cgm1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
               leftFlatFoot,rightFlatFoot,markerDiameter,
               pointSuffix)
    elif modelVersion == "CGM1.1":
        model,finalAcqStatic = cgm1_1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
               leftFlatFoot,rightFlatFoot,markerDiameter,
               pointSuffix)
    elif modelVersion == "CGM2.1":

        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
                      leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                      pointSuffix)

    elif modelVersion == "CGM2.2":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_2.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                          required_mp,optional_mp,
                          True,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                          pointSuffix)

    elif modelVersion == "CGM2.2e":
        hjcMethods =  manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_2e.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                          required_mp,optional_mp,
                          True,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                          pointSuffix)

    elif modelVersion == "CGM2.3":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_3.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    elif modelVersion == "CGM2.3e":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_3e.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    elif modelVersion == "CGM2.4":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_4.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    elif modelVersion == "CGM2.4e":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_4e.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    btkTools.smartWriter(finalAcqStatic, str(DATA_PATH_OUT+"calibrated.c3d"))
    logging.info("Static Calibration -----> Done")

    # knee calibration
    leftEnable = manager.isKneeCalibrationEnable("Left")
    rightEnable = manager.isKneeCalibrationEnable("Right")

    if leftEnable:
        method, trial,begin,end,jointRange = manager.getKneeCalibration("Left")
        if method == "Calibration2Dof":
            model,acqFunc,side = kneeCalibration.calibration2Dof(model,
                DATA_PATH,trial,translators,
                "Left",begin,end,jointRange)

            logging.info("Left knee Calibration (Calibration2Dof) -----> Done")
        elif method == "SARA":
            model,acqFunc,side = kneeCalibration.sara(model,
                DATA_PATH,trial,translators,
                "Left",begin,end)
            logging.info("Left knee Calibration (SARA) -----> Done")
    if rightEnable:
        method, trial,begin,end,jointRange = manager.getKneeCalibration("Right")
        if method == "Calibration2Dof":
            model,acqFunc,side = kneeCalibration.calibration2Dof(model,
                DATA_PATH,trial,translators,
                "Right",begin,end,jointRange)
            logging.info("Right knee Calibration (Calibration2Dof) -----> Done")
        elif method == "SARA":
            model,acqFunc,side = kneeCalibration.sara(model,
                DATA_PATH,trial,translators,
                "Right",begin,end)
            logging.info("Right knee Calibration (SARA) -----> Done")

    # update mp
    manager.updateMp(model)
    # save settings
    if manager.m_pipelineFile is not None:
        manager.save(DATA_PATH,str( manager.m_pipelineFile+"-saved"))
        logging.info("pipeline file -----> Save")

    # Fitting
    trials = manager.getFittingTrials()
    momentProjection = manager.getMomentProjection()

    if modelVersion not in ["CGM1.0", "CGM1.1", "CGM2.1"]:
        ikwf = manager.getIkWeightFile()
        if ikwf is not None:
            ikWeight = files.openJson(DATA_PATH,ikwf)
            settings["Fitting"]["Weight"]=ikWeight["Weight"]


    for trial in trials:
        mfpa = None if trial["Mfpa"] == "Auto" else trial["Mfpa"]

        reconstructFilenameLabelled = trial["File"]


        if modelVersion == "CGM1.0":
            acqGait = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                translators,
                markerDiameter,
                pointSuffix,
                mfpa,momentProjection)
        elif modelVersion == "CGM1.1":
            acqGait = cgm1_1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                translators,
                markerDiameter,
                pointSuffix,
                mfpa,momentProjection)

        elif modelVersion == "CGM2.1":
            acqGait = cgm2_1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                translators,
                markerDiameter,
                pointSuffix,
                mfpa,momentProjection)

        elif modelVersion == "CGM2.2":
            acqGait = cgm2_2.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.2e":
            acqGait = cgm2_2e.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.3":
            acqGait = cgm2_3.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.3e":
            acqGait = cgm2_3e.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.4":
            acqGait = cgm2_4.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.4e":
            acqGait = cgm2_4e.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        logging.info("Fitting -----> Done")


        if fileSuffix is not None:
            c3dFilename = str(reconstructFilenameLabelled[:-4]+"-modelled-"+fileSuffix+".c3d")
        else:
            c3dFilename = str(reconstructFilenameLabelled[:-4]+"-modelled.c3d")

        btkTools.smartWriter(acqGait, str(DATA_PATH_OUT+c3dFilename))
        logging.info("c3d file (%s) generated" %(c3dFilename) )