示例#1
0
def main(args):

    NEXUS = ViconNexus.ViconNexus()
    NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected()

    if NEXUS_PYTHON_CONNECTED:  # run Operation

        # --------------------------GLOBAL SETTINGS ------------------------------------
        # global setting ( in user/AppData)
        if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH +
                          "CGM1_1-pyCGM2.settings"):
            settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,
                                      "CGM1_1-pyCGM2.settings")
        else:
            settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,
                                      "CGM1_1-pyCGM2.settings")

        # --------------------------CONFIG ------------------------------------
        argsManager = CgmArgsManager.argsManager_cgm1(settings, args)
        leftFlatFoot = argsManager.getLeftFlatFoot()
        rightFlatFoot = argsManager.getRightFlatFoot()
        headFlat = argsManager.getHeadFlat()
        markerDiameter = argsManager.getMarkerDiameter()
        pointSuffix = argsManager.getPointSuffix("cgm1_1")

        # --------------------------LOADING ------------------------------------
        DATA_PATH, calibrateFilenameLabelledNoExt = NEXUS.GetTrialName()

        calibrateFilenameLabelled = calibrateFilenameLabelledNoExt + ".c3d"

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

        # --------------------------SUBJECT ------------------------------------
        subjects = NEXUS.GetSubjectNames()
        subject = nexusTools.checkActivatedSubject(NEXUS, subjects)
        Parameters = NEXUS.GetSubjectParamNames(subject)

        required_mp, optional_mp = nexusUtils.getNexusSubjectMp(
            NEXUS, subject, resetFlag=args.resetMP)
        # -------------------------- INFOS ------------------------------------
        mpInfo, mpFilename = files.getMpFileContent(DATA_PATH, "mp.pyCGM2",
                                                    subject)

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

        # btkAcq builder
        nacf = nexusFilters.NexusConstructAcquisitionFilter(
            DATA_PATH, calibrateFilenameLabelledNoExt, subject)
        acq = nacf.build()

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

        # ----------------------SAVE-------------------------------------------
        #pyCGM2.model
        files.saveModel(model, DATA_PATH, subject)

        # save mp
        files.saveMp(mpInfo, model, DATA_PATH, mpFilename)

        # ----------------------DISPLAY ON VICON-------------------------------
        nexusUtils.updateNexusSubjectMp(NEXUS, model, subject)
        nexusFilters.NexusModelFilter(NEXUS,
                                      model,
                                      acqStatic,
                                      subject,
                                      pointSuffix,
                                      staticProcessing=True).run()

        # ========END of the nexus OPERATION if run from Nexus  =========

    else:
        raise Exception("NO Nexus connection. Turn on Nexus")
示例#2
0
def main():

    NEXUS = ViconNexus.ViconNexus()
    NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected()

    parser = argparse.ArgumentParser(description='CGM1 Fitting')
    parser.add_argument(
        '--proj',
        type=str,
        help='Moment Projection. Choice : Distal, Proximal, Global')
    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')

    args = parser.parse_args()

    if NEXUS_PYTHON_CONNECTED:  # run Operation
        # --------------------------GLOBAL SETTINGS ------------------------------------
        # global setting ( in user/AppData)
        if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM1-pyCGM2.settings"):
            settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,
                                      "CGM1-pyCGM2.settings")
        else:
            settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,
                                      "CGM1-pyCGM2.settings")

        # --------------------------CONFIG ------------------------------------
        argsManager = CgmArgsManager.argsManager_cgm1(settings, args)
        markerDiameter = argsManager.getMarkerDiameter()
        pointSuffix = argsManager.getPointSuffix("cgm1")
        momentProjection = argsManager.getMomentProjection()

        DATA_PATH, reconstructFilenameLabelledNoExt = NEXUS.GetTrialName()

        reconstructFilenameLabelled = reconstructFilenameLabelledNoExt + ".c3d"
        logging.info("data Path: " + DATA_PATH)
        logging.info("calibration file: " + reconstructFilenameLabelled)

        # --------------------------SUBJECT ------------------------------------
        # Notice : Work with ONE subject by session
        subjects = NEXUS.GetSubjectNames()
        subject = nexusTools.checkActivatedSubject(NEXUS, subjects)
        logging.info("Subject name : " + subject)

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

        # --------------------------CHECKING -----------------------------------
        # check model is the CGM1
        logging.info("loaded model : %s" % (model.version))
        if model.version != "CGM1.0":
            raise Exception(
                "%s-pyCGM2.model file was not calibrated from the CGM1.0 calibration pipeline"
                % model.version)

        # --------------------------SESSION INFOS ------------------------------------

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

        #force plate assignement from Nexus
        mfpa = nexusTools.getForcePlateAssignment(NEXUS)

        # btkAcq builder
        nacf = nexusFilters.NexusConstructAcquisitionFilter(
            DATA_PATH, reconstructFilenameLabelledNoExt, subject)
        acq = nacf.build()
        # --------------------------MODELLING PROCESSING -----------------------
        acqGait = cgm1.fitting(model,
                               DATA_PATH,
                               reconstructFilenameLabelled,
                               translators,
                               markerDiameter,
                               pointSuffix,
                               mfpa,
                               momentProjection,
                               forceBtkAcq=acq)

        # ----------------------SAVE-------------------------------------------
        # Todo: pyCGM2 model :  cpickle doesn t work. Incompatibility with Swig. ( see about BTK wrench)

        # ----------------------DISPLAY ON VICON-------------------------------
        nexusFilters.NexusModelFilter(NEXUS, model, acqGait, subject,
                                      pointSuffix).run()
        nexusTools.createGeneralEvents(NEXUS, subject, acqGait,
                                       ["Left-FP", "Right-FP"])

    else:
        raise Exception("NO Nexus connection. Turn on Nexus")
示例#3
0
def main():

    parser = argparse.ArgumentParser(description='CGM1 Calibration')
    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('-hf', '--headFlat', type=int, help='head flat 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('-ae',
                        '--anomalyException',
                        action='store_true',
                        help='stop if anomaly detected ')

    args = parser.parse_args()

    NEXUS = ViconNexus.ViconNexus()
    NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected()

    if NEXUS_PYTHON_CONNECTED:  # run Operation

        # --------------------------GLOBAL SETTINGS ------------------------------------
        # global setting ( in user/AppData)
        if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM1-pyCGM2.settings"):
            settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,
                                      "CGM1-pyCGM2.settings")
        else:
            settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,
                                      "CGM1-pyCGM2.settings")
        # --------------------------CONFIG ------------------------------------
        argsManager = CgmArgsManager.argsManager_cgm1(settings, args)
        leftFlatFoot = argsManager.getLeftFlatFoot()
        rightFlatFoot = argsManager.getRightFlatFoot()
        headFlat = argsManager.getHeadFlat()
        markerDiameter = argsManager.getMarkerDiameter()
        pointSuffix = argsManager.getPointSuffix("cgm1")

        DATA_PATH, calibrateFilenameLabelledNoExt = NEXUS.GetTrialName()

        calibrateFilenameLabelled = calibrateFilenameLabelledNoExt + ".c3d"

        LOGGER.logger.info("data Path: " + DATA_PATH)
        LOGGER.set_file_handler(DATA_PATH + "pyCGM2-Calibration.log")
        LOGGER.logger.info("calibration file: " + calibrateFilenameLabelled)

        # --------------------------SUBJECT ------------------------------------
        subjects = NEXUS.GetSubjectNames()
        subject = nexusTools.getActiveSubject(
            NEXUS)  #checkActivatedSubject(NEXUS,subjects)
        Parameters = NEXUS.GetSubjectParamNames(subject)

        required_mp, optional_mp = nexusUtils.getNexusSubjectMp(
            NEXUS, subject, resetFlag=args.resetMP)

        # -------------------------- INFOS ------------------------------------
        mpInfo, mpFilename = files.getMpFileContent(DATA_PATH, "mp.pyCGM2",
                                                    subject)

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

        # btkAcq builder
        nacf = nexusFilters.NexusConstructAcquisitionFilter(
            DATA_PATH, calibrateFilenameLabelledNoExt, subject)
        acq = nacf.build()

        # --------------------------MODELLING PROCESSING -----------------------
        model, acqStatic, detectAnomaly = cgm1.calibrate(
            DATA_PATH,
            calibrateFilenameLabelled,
            translators,
            required_mp,
            optional_mp,
            leftFlatFoot,
            rightFlatFoot,
            headFlat,
            markerDiameter,
            pointSuffix,
            forceBtkAcq=acq,
            anomalyException=args.anomalyException)

        # ----------------------SAVE-------------------------------------------
        #pyCGM2.model
        files.saveModel(model, DATA_PATH, subject)

        # save mp
        files.saveMp(mpInfo, model, DATA_PATH, mpFilename)

        # ----------------------DISPLAY ON VICON-------------------------------
        nexusUtils.updateNexusSubjectMp(NEXUS, model, subject)
        nexusFilters.NexusModelFilter(NEXUS,
                                      model,
                                      acqStatic,
                                      subject,
                                      pointSuffix,
                                      staticProcessing=True).run()