コード例 #1
0
def main(args):
    DATA_PATH = os.getcwd()+"\\"

    # User Settings
    if os.path.isfile(DATA_PATH + args.userFile):
        userSettings = files.openFile(DATA_PATH,args.userFile)
    else:
        raise Exception ("user setting file not found")

    # internal (expert) Settings
    if args.expertFile:
        if os.path.isfile(DATA_PATH + args.expertFile):
            internalSettings = files.openFile(DATA_PATH,args.expertFile)
        else:
            raise Exception ("expert setting file not found")
    else:
        internalSettings = None

    # translators
    if os.path.isfile(DATA_PATH + "CGM1_1.translators"):
        translators = files.openFile(DATA_PATH,"CGM1_1.translators")
    else:
        translators = None


    # --- Manager ----
    manager = ModelManager.CGM1_1ConfigManager(userSettings,localInternalSettings=internalSettings,localTranslators=translators)
    manager.contruct()
    finalSettings = manager.getFinalSettings()
    files.prettyDictPrint(finalSettings)


    logging.info("=============Calibration=============")
    model,finalAcqStatic = cgm1_1.calibrate(DATA_PATH,
        manager.staticTrial,
        manager.translators,
        manager.requiredMp,
        manager.optionalMp,
        manager.leftFlatFoot,
        manager.rightFlatFoot,
        manager.markerDiameter,
        manager.pointSuffix,
        displayCoordinateSystem=True)



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

    manager.updateMp(model)
    #files.prettyDictPrint(manager.finalSettings)

    logging.info("=============Fitting=============")
    for trial in manager.dynamicTrials:
        mfpa = None if trial["Mfpa"] == "Auto" else trial["Mfpa"]
        reconstructFilenameLabelled = trial["File"]

        acqGait = cgm1_1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
            manager.translators,
            manager.markerDiameter,
            manager.pointSuffix,
            mfpa,
            manager.momentProjection,
            displayCoordinateSystem=True)

        btkTools.smartWriter(acqGait, str(DATA_PATH+reconstructFilenameLabelled))#[:-4]+"-pyCGM2modelled.c3d"))
        logging.info("---->dynamic trial (%s) processed" %(reconstructFilenameLabelled))

    logging.info("=============Writing of final Settings=============")
    i = 0
    while os.path.exists("CGM1.1 [%s].completeSettings" % i):
        i += 1
    filename = "CGM1.1 [" + str(i)+"].completeSettings"
    files.saveJson(DATA_PATH, filename, finalSettings)
    logging.info("---->complete settings (%s) exported" %(filename))


    raw_input("Press return to exit..")
コード例 #2
0
def main(args):
    DATA_PATH = os.getcwd() + "\\"

    # User Settings
    if os.path.isfile(DATA_PATH + args.userFile):
        userSettings = files.openFile(DATA_PATH, args.userFile)
    else:
        raise Exception("user setting file not found")

    # internal (expert) Settings
    if args.expertFile:
        if os.path.isfile(DATA_PATH + args.expertFile):
            internalSettings = files.openFile(DATA_PATH, args.expertFile)
        else:
            raise Exception("expert setting file not found")
    else:
        internalSettings = None

    # --- Manager ----
    manager = EmgManager.EmgConfigManager(
        userSettings, localInternalSettings=internalSettings)
    manager.contruct()
    finalSettings = manager.getFinalSettings()
    files.prettyDictPrint(finalSettings)

    # reconfiguration of emg settings as lists
    EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES = manager.getEmgConfiguration(
    )

    #----- rectified view -------
    rectTrials = manager.temporal_trials
    analysis.processEMG(
        DATA_PATH,
        rectTrials,
        EMG_LABELS,
        highPassFrequencies=manager.BandpassFrequencies,
        envelopFrequency=manager.EnvelopLowpassFrequency,
        fileSuffix=None)  # high pass then low pass for all c3ds

    for trial in rectTrials:
        plot.plotTemporalEMG(DATA_PATH,
                             trial,
                             EMG_LABELS,
                             EMG_MUSCLES,
                             EMG_CONTEXT,
                             NORMAL_ACTIVITIES,
                             exportPdf=True,
                             rectify=manager.rectifyFlag)

    #----- Gait normalized envelop -------
    envTrials = manager.gaitNormalized_trials
    analysis.processEMG(
        DATA_PATH,
        envTrials,
        EMG_LABELS,
        highPassFrequencies=manager.BandpassFrequencies,
        envelopFrequency=manager.EnvelopLowpassFrequency,
        fileSuffix=None)  # high pass then low pass for all c3ds

    emgAnalysisInstance = analysis.makeEmgAnalysis(DATA_PATH, envTrials,
                                                   EMG_LABELS, None, None)

    filename = manager.title

    if not manager.consistencyFlag:
        plot.plotDescriptiveEnvelopEMGpanel(DATA_PATH,
                                            emgAnalysisInstance,
                                            EMG_LABELS,
                                            EMG_MUSCLES,
                                            EMG_CONTEXT,
                                            NORMAL_ACTIVITIES,
                                            normalized=False,
                                            exportPdf=True,
                                            outputName=filename)
    else:
        plot.plotConsistencyEnvelopEMGpanel(DATA_PATH,
                                            emgAnalysisInstance,
                                            EMG_LABELS,
                                            EMG_MUSCLES,
                                            EMG_CONTEXT,
                                            NORMAL_ACTIVITIES,
                                            normalized=False,
                                            exportPdf=True,
                                            outputName=filename)

    logging.info("=============Writing of final Settings=============")
    files.saveJson(DATA_PATH, str(filename + "-EMG.completeSettings"),
                   finalSettings)
    logging.info("---->complete settings (%s) exported" %
                 (str(filename + "-EMG.completeSettings")))

    raw_input("Press return to exit..")