Beispiel #1
0
def getNormalBurstActivity_fromCycles(muscle, ff, begin, fo, end, apf):
    """
        detection des zones d"activité normal emg
         voici les on pour l"emg
        #            on1=beg
        #            on2=beg+(12/NORMAL_STANCE_PHASE)*(fo-beg)
        #            on3=beg+(48/NORMAL_STANCE_PHASE)*(fo-beg)
        #            on4=fo+((70-NORMAL_STANCE_PHASE)/(100.0-NORMAL_STANCE_PHASE))*(end-fo)
        #            on5=fo+((93-NORMAL_STANCE_PHASE)/(100.0-NORMAL_STANCE_PHASE))*(end-fo)
        #            on6=fo+((100-NORMAL_STANCE_PHASE)/(100.0-NORMAL_STANCE_PHASE))*(end-fo)

        # valeurs normales issues d"une livre EMG analys
        """

    normalActivations = files.openJson(
        pyCGM2.NORMATIVE_DATABASE_PATH + "emg\\", "normalActivation.json")

    NORMAL_STANCE_PHASE = normalActivations["NORMAL_STANCE_PHASE"]
    TABLE = normalActivations["Activation"]

    beg = (begin - ff) * apf
    fo = (fo - ff) * apf
    end = (end - ff) * apf

    if muscle in TABLE.keys():
        list_beginBurst = []
        list_burstDuration = []

        for i, j in zip(range(0, 6, 2), range(1, 6, 2)):
            if TABLE[muscle][i] != "na" and TABLE[muscle][j] != "na":
                if TABLE[muscle][i] < NORMAL_STANCE_PHASE:
                    beginBurst = beg + (TABLE[muscle][i] /
                                        NORMAL_STANCE_PHASE) * (fo - beg)
                else:
                    beginBurst = fo + (
                        (TABLE[muscle][i] - NORMAL_STANCE_PHASE) /
                        (100.0 - NORMAL_STANCE_PHASE)) * (end - fo)

                if TABLE[muscle][j] < NORMAL_STANCE_PHASE:
                    endBurst = beg + (TABLE[muscle][j] /
                                      NORMAL_STANCE_PHASE) * (fo - beg)
                else:
                    endBurst = fo + (
                        (TABLE[muscle][j] - NORMAL_STANCE_PHASE) /
                        (100.0 - NORMAL_STANCE_PHASE)) * (end - fo)

                list_beginBurst.append(beginBurst)
                list_burstDuration.append(endBurst - beginBurst)

    else:
        list_beginBurst = [0]
        list_burstDuration = [0]

    return list_beginBurst, list_burstDuration
Beispiel #2
0
    def CGM2_4_Calibration2Dof_test(cls):
        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\Knee Calibration\\"
        staticFilename = "static.c3d"

        funcFilename = "functional.c3d"
        gaitFilename = "gait trial 01.c3d"

        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,
                                  "CGM2_4-pyCGM2.settings")
        translators = settings["Translators"]

        markerDiameter = 14
        mp = {
            'Bodymass': 69.0,
            'LeftLegLength': 930.0,
            'RightLegLength': 930.0,
            'LeftKneeWidth': 94.0,
            'RightKneeWidth': 64.0,
            'LeftAnkleWidth': 67.0,
            'RightAnkleWidth': 62.0,
            'LeftSoleDelta': 0,
            'RightSoleDelta': 0,
            "LeftToeOffset": 0,
            "RightToeOffset": 0,
        }

        acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename))

        model = cgm2.CGM2_4()
        model.configure()

        model.addAnthropoInputParameters(mp)

        # --store calibration parameters--
        model.setStaticFilename(staticFilename)
        model.setCalibrationProperty("leftFlatFoot", True)
        model.setCalibrationProperty("rightFlatFoot", True)
        model.setCalibrationProperty("markerDiameter", 14)

        # test -  no joint Range
        model, acqFunc, side = kneeCalibration.calibration2Dof(
            model, MAIN_PATH, funcFilename, translators, "Left", 831, 1280,
            None)
        # test with joint range of [20-90]
        model, acqFunc, side = kneeCalibration.calibration2Dof(
            model, MAIN_PATH, funcFilename, translators, "Left", 831, 1280,
            [20, 90])
Beispiel #3
0
    parser.add_argument('-l','--leftFlatFoot', type=int, help='left flat foot option')
    parser.add_argument('-r','--rightFlatFoot',type=int,  help='right flat foot option')
    parser.add_argument('-md','--markerDiameter', type=float, help='marker diameter')
    parser.add_argument('-ps','--pointSuffix', type=str, help='suffix of model outputs')
    parser.add_argument('--check', action='store_true', help='force model output suffix' )
    parser.add_argument('--resetMP', action='store_true', help='reset optional mass parameters')

    parser.add_argument('-fs','--fileSuffix', type=str, help='suffix of output file')

    parser.add_argument('--DEBUG', action='store_true', help='debug model')
    args = parser.parse_args()

    # --------------------------GLOBAL SETTINGS ------------------------------------
    # global setting ( in user/AppData)
    settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,"CGM1-pyCGM2.settings")

    # --------------------------CONFIG ------------------------------------
    subject = args.subject

    argsManager = CgmArgsManager.argsManager_cgm1(settings,args)
    leftFlatFoot = argsManager.getLeftFlatFoot()
    rightFlatFoot = argsManager.getRightFlatFoot()
    markerDiameter = argsManager.getMarkerDiameter()
    pointSuffix = argsManager.getPointSuffix("cgm1")

    # --------------------------LOADING ------------------------------------
    if args.DEBUG:
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1\\native\\"
        calibrateFilenameLabelled = "static.c3d"
        subject = "MRI-US-01 - Pig"
Beispiel #4
0
    def jsontest(cls):
        DATA_PATH = "C:\\Users\\HLS501\\Documents\\Programming\\API\\pyCGM2\\pyCGM2\\SessionSettings\\"
        jsonConfigFile = "pipeline.pyCGM2"

        struct = files.openJson(DATA_PATH,jsonConfigFile )
Beispiel #5
0
        reconstructFilenameLabelled = args.trial

    logging.info("data Path: " + DATA_PATH)
    logging.info("reconstructed file: " + reconstructFilenameLabelled)

    # --------------------pyCGM2 MODEL - INIT ------------------------------
    model = files.loadModel(DATA_PATH, subject)

    logging.info("loaded model : %s" % (model.version))

    if model.version in ["CGM1.0", "CGM1.1", "CGM2.1", "CGM2.2", "CGM2.2e"]:
        raise Exception(
            "Can t use SARA method with your model %s [minimal version : CGM2.3]"
            % (model.version))
    elif model.version == "CGM2.3":
        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,
                                  "CGM2_3-pyCGM2.settings")
    elif model.version == "CGM2.3e":
        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,
                                  "CGM2_3-Expert-pyCGM2.settings")
    elif model.version == "CGM2.4":
        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,
                                  "CGM2_4-pyCGM2.settings")
    elif model.version == "CGM2.4e":
        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,
                                  "CGM2_4-Expert-pyCGM2.settings")
    else:
        raise Exception("model version not found [contact admin]")

    # --------------------------SESSION INFOS ------------------------------------
    mpInfo, mpFilename = files.getJsonFileContent(DATA_PATH, "mp.pyCGM2",
                                                  subject)
Beispiel #6
0
                        action='store_true',
                        help='force model output suffix')
    parser.add_argument('-ikwf',
                        '--ikWeightFile',
                        type=str,
                        help='file of ik weight setting')
    parser.add_argument('-fs',
                        '--fileSuffix',
                        type=str,
                        help='suffix of output file')
    parser.add_argument('--DEBUG', action='store_true', help='debug model')
    args = parser.parse_args()

    # --------------------------GLOBAL SETTINGS ------------------------------------
    # global setting ( in user/AppData)
    settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,
                              "CGM2_2-pyCGM2.settings")

    # --------------------------CONFIG ------------------------------------
    subject = args.subject

    argsManager = CgmArgsManager.argsManager_cgm(settings, args)
    markerDiameter = argsManager.getMarkerDiameter()
    pointSuffix = argsManager.getPointSuffix("cgm2_2")
    momentProjection = argsManager.getMomentProjection()
    mfpa = argsManager.getManualForcePlateAssign()
    ikwf = argsManager.getIkWeightFile()

    # --------------------------LOADING ------------------------------------
    if args.DEBUG:
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.2\\native\\"
        reconstructFilenameLabelled = "Gait trial.c3d"
Beispiel #7
0
    def KadMed_TrueEquinus_leftSkinMarkers(cls):
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\kad-med-TrueEquinus-leftSkinMarkers\\"
        staticFilename = "static.c3d"


        markerDiameter=14
        required_mp={
        'Bodymass'   : 36.9,
        'LeftLegLength' : 665.0,
        'RightLegLength' : 655.0 ,
        'LeftKneeWidth' : 102.7,
        'RightKneeWidth' : 100.2,
        'LeftAnkleWidth' : 64.5,
        'RightAnkleWidth' : 63.0,
        'LeftSoleDelta' : 0,
        'RightSoleDelta' : 0,
        }

        optional_mp={
        'InterAsisDistance'   : 0,
        'LeftAsisTrocanterDistance' : 0,
        'LeftThighRotation' : 0,
        'LeftShankRotation' : 0 ,
        'LeftTibialTorsion' : 0,
        'RightAsisTrocanterDistance' : 0,
        'RightThighRotation' : 0,
        'RightShankRotation' : 0,
        'RightTibialTorsion' : 0
        }


        
        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,"CGM1_1-pyCGM2.settings")
        translators = settings["Translators"]

        pointSuffix = "cgm1_6dof"

        model,acqStatic = cgm1.calibrate(DATA_PATH,staticFilename,translators,
                                   required_mp,optional_mp,
                                   False,False,markerDiameter,
                                   pointSuffix)

        mcsp = modelFilters.ModelCoordinateSystemProcedure(model)
        mcsf = modelFilters.CoordinateSystemDisplayFilter(mcsp,model,acqStatic)
        mcsf.setStatic(False)
        mcsf.display()
        btkTools.smartWriter(acqStatic,"CGM1-KadMed-TrueEquinus-leftSkin-static.c3d")


        #motion
        gaitFilename="gait trial 01.c3d"
        mfpa  = None
        momentProjection=enums.MomentProjection.Distal

        acqGait = cgm1.fitting(model,DATA_PATH, gaitFilename,
                 translators,
                 markerDiameter,
                 pointSuffix,
                 mfpa,
                 momentProjection)


        mcsp = modelFilters.ModelCoordinateSystemProcedure(model)
        mcsf = modelFilters.CoordinateSystemDisplayFilter(mcsp,model,acqGait)
        mcsf.setStatic(False)
        mcsf.display()

        #mcsp = modelFilters.ModelCoordinateSystemProcedure(model)
        #modelFilters.CoordinateSystemDisplayFilter(mcsp,model,acqGait).display()


        btkTools.smartWriter(acqGait, "CGM1-KadMed-TrueEquinus-leftSkin-gait.c3d")


        # testings
        offsetTesting(acqStatic,model,display = True, unitTesting=True)
        testJointCentres(acqGait)
        testRelativesAngles(acqGait,pointSuffix)
Beispiel #8
0
def calculation_kindyn(filenames_stat, filenames_dyn, there_is_knee_optim):

    # Definition des différents répertoires
    DATA_PATH = os.path.split(filenames_stat)[0] + '\\'
    DATA_PATH_OUT = os.path.join(DATA_PATH, 'Post_CGM2_1')
    if not os.path.isdir(DATA_PATH_OUT):
        os.mkdir(DATA_PATH_OUT)
    DATA_PATH_OUT = os.path.join(DATA_PATH, 'Post_CGM2_1') + '\\'
    calibrateFilenameLabelled = str(os.path.split(filenames_stat)[1])

    # Setting pour la toolbox pycgm2
    args = Namespace()
    args.leftFlatFoot = None
    args.rightFlatFoot = None
    args.markerDiameter = None
    args.pointSuffix = None
    args.fileSuffix = None
    args.mfpa = None
    args.proj = None
    args.check = True

    # --------------------------GLOBAL SETTINGS ------------------------------------
    # global setting ( in user/AppData)
    settings = files.openJson(pyCGM2.CONFIG.PYCGM2_APPDATA_PATH,
                              "CGM2_1-pyCGM2.settings")

    fileSuffix = None
    # settings overloading
    argsManager = cgmUtils.argsManager_cgm(settings, args)
    # leftFlatFoot = argsManager.getLeftFlatFoot()
    # rightFlatFoot = argsManager.getRightFlatFoot()
    leftFlatFoot = 0
    rightFlatFoot = 0
    markerDiameter = argsManager.getMarkerDiameter()
    markerDiameter = 12
    pointSuffix = argsManager.getPointSuffix("cgm2_1")
    momentProjection = argsManager.getMomentProjection()
    # mfpa = argsManager.getManualForcePlateAssign()

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

    # Choix de la methode de Hanche
    hjcMethod = settings["Calibration"]["HJC"]

    # Extraction des meta data
    required_mp, optional_mp = extract_metaData_pycgm2(filenames_stat)

    # Statique
    model, acqStatic = cgm2_1.calibrate(DATA_PATH, calibrateFilenameLabelled,
                                        translators, required_mp, optional_mp,
                                        leftFlatFoot, rightFlatFoot,
                                        markerDiameter, hjcMethod, pointSuffix)

    for ind_file, filename in enumerate(filenames_dyn):
        plateforme_mpa = ''
        name_enf = extraction_name_enf(filename)
        # on fait une copy du fichier ENF pour pouvoir utiliser la génération de rapport
        copy2(name_enf, DATA_PATH_OUT)
        [FP1, FP2] = extraction_enf(filename)

        if FP1 == 'right':
            plateforme_mpa += 'R'
        elif FP1 == 'left':
            plateforme_mpa += 'L'
        else:
            plateforme_mpa += 'X'

        if FP2 == 'right':
            plateforme_mpa += 'R'
        elif FP2 == 'left':
            plateforme_mpa += 'L'
        else:
            plateforme_mpa += 'X'

        reconstructFilenameLabelled = os.path.split(filename)[1]
        # Fitting
        # Pour le premier fichier on 'décore' le modèle pour pouvoir faire
        # la méthode de dynakad (il faut que le modele ait été utilisé en dynamique)
        if ind_file == 0 and there_is_knee_optim:
            # acqGait = cgm2_1.fitting(model, DATA_PATH, reconstructFilenameLabelled,
            #                         translators,
            #                         markerDiameter,
            #                         pointSuffix,
            #                         plateforme_mpa, momentProjection)
            first_frame = None
            last_frame = None
            model, acqFunc_L, side_L = kneeCalibration.calibration2Dof(
                model, DATA_PATH, reconstructFilenameLabelled, translators,
                'Left', first_frame, last_frame)
            print(model.mp_computed["RightKneeFuncCalibrationOffset"])
            print(model.mp_computed["LeftKneeFuncCalibrationOffset"])

            model, acqFunc_R, side_R = kneeCalibration.calibration2Dof(
                model, DATA_PATH, reconstructFilenameLabelled, translators,
                'Right', first_frame, last_frame)
            print(model.mp_computed["RightKneeFuncCalibrationOffset"])
            print(model.mp_computed["LeftKneeFuncCalibrationOffset"])
            # modelDecorator.KneeCalibrationDecorator(model).calibrate2dof('Left', index_1=0)
            # modelDecorator.KneeCalibrationDecorator(model).calibrate2dof('Right', index_1=0)

        acqGait = cgm2_1.fitting(model, DATA_PATH, reconstructFilenameLabelled,
                                 translators, markerDiameter, pointSuffix,
                                 plateforme_mpa, momentProjection)
        # writer
        if fileSuffix is not None:
            c3dFilename = str(reconstructFilenameLabelled[:-4] + "-modelled-" +
                              fileSuffix + ".c3d")
        else:
            c3dFilename = str(reconstructFilenameLabelled)

        btkTools.smartWriter(acqGait, str(DATA_PATH_OUT + c3dFilename))
        logging.info("c3d file (%s) generated" % (c3dFilename))
    return DATA_PATH_OUT
Beispiel #9
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) )