def main(): plt.close("all") parser = argparse.ArgumentParser(description='CGM plotMAP') parser.add_argument( '-nd', '--normativeData', type=str, help='normative Data set (Schwartz2008 or Pinzone2014)', default="Schwartz2008") parser.add_argument( '-ndm', '--normativeDataModality', type=str, help= "if Schwartz2008 [VerySlow,SlowFree,Fast,VeryFast] - if Pinzone2014 [CentreOne,CentreTwo]", default="Free") parser.add_argument('-ps', '--pointSuffix', type=str, help='suffix of model outputs') args = parser.parse_args() NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if not NEXUS_PYTHON_CONNECTED: raise Exception("Vicon Nexus is not running") #-----------------------SETTINGS--------------------------------------- pointSuffix = args.pointSuffix #-----------------------SETTINGS--------------------------------------- normativeData = { "Author": args.normativeData, "Modality": args.normativeDataModality } if normativeData["Author"] == "Schwartz2008": chosenModality = normativeData["Modality"] elif normativeData["Author"] == "Pinzone2014": chosenModality = normativeData["Modality"] nds = normativeDatasets.NormativeData(normativeData["Author"], chosenModality) #--------------------------Data Location and subject------------------------------------- if eclipse.getCurrentMarkedNodes() is not None: LOGGER.logger.info( "[pyCGM2] - Script worked with marked node of Vicon Eclipse") # --- acquisition file and path---- DATA_PATH, modelledFilenames = eclipse.getCurrentMarkedNodes() ECLIPSE_MODE = True if not ECLIPSE_MODE: LOGGER.logger.info( "[pyCGM2] - Script works with the loaded c3d in vicon Nexus") # --- acquisition file and path---- DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt + ".c3d" LOGGER.logger.info("data Path: " + DATA_PATH) LOGGER.logger.info("file: " + modelledFilename) # ----- Subject ----- # need subject to find input files subject = nexusTools.getActiveSubject(NEXUS) LOGGER.logger.info("Subject name : " + subject) if not ECLIPSE_MODE: # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, modelledFilenameNoExt, subject) acq = nacf.build() # --------------------------PROCESSING -------------------------------- analysisInstance = analysis.makeAnalysis(DATA_PATH, [modelledFilename], type="Gait", kineticLabelsDict=None, emgChannels=None, pointLabelSuffix=pointSuffix, btkAcqs=[acq], subjectInfo=None, experimentalInfo=None, modelInfo=None) outputName = modelledFilename else: analysisInstance = analysis.makeAnalysis(DATA_PATH, type="Gait", kineticLabelsDict=None, emgChannels=None, pointLabelSuffix=pointSuffix, subjectInfo=None, experimentalInfo=None, modelInfo=None) outputName = "Eclipse-MAP" plot.plot_MAP(DATA_PATH, analysisInstance, nds, exportPdf=True, outputName=outputName, pointLabelSuffix=pointSuffix)
def main(): parser = argparse.ArgumentParser(description='CGM2.5 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('--noIk', action='store_true', help='cancel inverse kinematic') parser.add_argument('--resetMP', action='store_true', help='reset optional mass parameters') parser.add_argument('--forceLHJC', nargs='+') parser.add_argument('--forceRHJC', nargs='+') 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 ------------------------------ # ( in user/AppData) if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM2_5-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH, "CGM2_5-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER, "CGM2_5-pyCGM2.settings") argsManager = CgmArgsManager.argsManager_cgm(settings, args) leftFlatFoot = argsManager.getLeftFlatFoot() rightFlatFoot = argsManager.getRightFlatFoot() headFlat = argsManager.getHeadFlat() markerDiameter = argsManager.getMarkerDiameter() pointSuffix = argsManager.getPointSuffix("cgm2.5") ik_flag = argsManager.enableIKflag() hjcMethod = settings["Calibration"]["HJC"] lhjc = argsManager.forceHjc("left") rhjc = argsManager.forceHjc("right") if lhjc is not None: hjcMethod["Left"] = lhjc if rhjc is not None: hjcMethod["Right"] = rhjc # --------------------------LOADING------------------------------ 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 ----------------------------------- # Notice : Work with ONE subject by session subjects = NEXUS.GetSubjectNames() subject = nexusTools.getActiveSubject(NEXUS) Parameters = NEXUS.GetSubjectParamNames(subject) required_mp, optional_mp = nexusUtils.getNexusSubjectMp( NEXUS, subject, resetFlag=args.resetMP) # --------------------------SESSION INFOS ----------------------------- # --------------------------SESSIONS INFOS ----------------------------------- mpInfo, mpFilename = files.getMpFileContent(DATA_PATH, "mp.pyCGM2", subject) # translators management translators = files.getTranslators(DATA_PATH, "CGM2_5.translators") if not translators: translators = settings["Translators"] # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, calibrateFilenameLabelledNoExt, subject) acq = nacf.build() # --------------------------CONFIG ------------------------------------ model, finalAcqStatic, detectAnomaly = cgm2_5.calibrate( DATA_PATH, calibrateFilenameLabelled, translators, settings, required_mp, optional_mp, ik_flag, leftFlatFoot, rightFlatFoot, headFlat, markerDiameter, hjcMethod, pointSuffix, forceBtkAcq=acq, anomalyException=args.anomalyException) # ----------------------SAVE------------------------------------------- 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, finalAcqStatic, subject, pointSuffix, staticProcessing=True).run() # ========END of the nexus OPERATION if run from Nexus ========= else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(): parser = argparse.ArgumentParser(description='EMG-plot_temporalEMG') parser.add_argument('-bpf', '--BandpassFrequencies', nargs='+', help='bandpass filter') parser.add_argument('-ecf', '--EnvelopLowpassFrequency', type=int, help='cutoff frequency for emg envelops') parser.add_argument('-r', '--raw', action='store_true', help='rectified data') parser.add_argument('-ina', '--ignoreNormalActivity', action='store_true', help='do not display normal activity') args = parser.parse_args() NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if NEXUS_PYTHON_CONNECTED: # run Operation # --- acquisition file and path---- DATA_PATH, inputFileNoExt = NEXUS.GetTrialName() inputFile = inputFileNoExt + ".c3d" #--------------------------settings------------------------------------- if os.path.isfile(DATA_PATH + "emg.settings"): emgSettings = files.openFile(DATA_PATH, "emg.settings") LOGGER.logger.warning( "[pyCGM2]: emg.settings detected in the data folder") else: emgSettings = None manager = EmgManager.EmgConfigManager( None, localInternalSettings=emgSettings) manager.contruct() # ----------------------INPUTS------------------------------------------- bandPassFilterFrequencies = manager.BandpassFrequencies #emgSettings["Processing"]["BandpassFrequencies"] if args.BandpassFrequencies is not None: if len(args.BandpassFrequencies) != 2: raise Exception( "[pyCGM2] - bad configuration of the bandpass frequencies ... set 2 frequencies only" ) else: bandPassFilterFrequencies = [ float(args.BandpassFrequencies[0]), float(args.BandpassFrequencies[1]) ] LOGGER.logger.info( "Band pass frequency set to %i - %i instead of 20-200Hz", bandPassFilterFrequencies[0], bandPassFilterFrequencies[1]) envelopCutOffFrequency = manager.EnvelopLowpassFrequency #emgSettings["Processing"]["EnvelopLowpassFrequency"] if args.EnvelopLowpassFrequency is not None: envelopCutOffFrequency = args.EnvelopLowpassFrequency LOGGER.logger.info("Cut-off frequency set to %i instead of 6Hz ", envelopCutOffFrequency) rectifyBool = False if args.raw else True # --------------------------SUBJECT ------------------------------------ subjects = NEXUS.GetSubjectNames() subject = nexusTools.getActiveSubject(NEXUS) # btk Acquisition nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, inputFileNoExt, subject) acq = nacf.build() # --------------emg Processing-------------- EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES = manager.getEmgConfiguration( ) emg.processEMG_fromBtkAcq( acq, EMG_LABELS, highPassFrequencies=bandPassFilterFrequencies, envelopFrequency=envelopCutOffFrequency ) # high pass then low pass for all c3ds plot.plotTemporalEMG(DATA_PATH, inputFile, EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES, exportPdf=True, rectify=rectifyBool, btkAcq=acq, ignoreNormalActivity=args.ignoreNormalActivity) else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(): parser = argparse.ArgumentParser(description='CGM1.1 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() 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_cgm(settings,args) markerDiameter = argsManager.getMarkerDiameter() pointSuffix = argsManager.getPointSuffix("cgm1_1") 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.1": raise Exception ("%s-pyCGM2.model file was not calibrated from the CGM1.1 calibration pipeline"%model.version) # --------------------------SESSION INFOS ------------------------------------ # translators management translators = files.getTranslators(DATA_PATH,"CGM1_1.translators") if not translators: translators = settings["Translators"] # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter(DATA_PATH,reconstructFilenameLabelledNoExt,subject) acq = nacf.build() #force plate assignement from Nexus mfpa = nexusTools.getForcePlateAssignment(NEXUS) # --------------------------MODELLING PROCESSING ----------------------- acqGait = cgm1_1.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"]) # ========END of the nexus OPERATION if run from Nexus ========= else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(): parser = argparse.ArgumentParser(description='CGM1.1 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') 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_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")
def main(): parser = argparse.ArgumentParser(description='2Dof Knee Calibration') parser.add_argument('-s','--side', type=str, help="Side : Left or Right") parser.add_argument('-b','--beginFrame', type=int, help="begin frame") parser.add_argument('-e','--endFrame', type=int, help="end frame") args = parser.parse_args() NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if NEXUS_PYTHON_CONNECTED: # run Operation DATA_PATH, reconstructedFilenameLabelledNoExt = NEXUS.GetTrialName() reconstructFilenameLabelled = reconstructedFilenameLabelledNoExt+".c3d" LOGGER.logger.info( "data Path: "+ DATA_PATH ) LOGGER.logger.info( "reconstructed file: "+ reconstructFilenameLabelled) # --------------------------SUBJECT ----------------------------------- # Notice : Work with ONE subject by session subjects = NEXUS.GetSubjectNames() subject = nexusTools.getActiveSubject(NEXUS) LOGGER.logger.info( "Subject name : " + subject ) # --------------------pyCGM2 MODEL - INIT ------------------------------ model = files.loadModel(DATA_PATH,subject) LOGGER.logger.info("loaded model : %s" %(model.version )) if model.version == "CGM1.0": 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") elif model.version == "CGM1.1": 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") elif model.version == "CGM2.1": if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM2_1-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,"CGM2_1-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_1-pyCGM2.settings") elif model.version == "CGM2.2": if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM2_2-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,"CGM2_2-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_2-pyCGM2.settings") elif model.version == "CGM2.3": if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM2_3-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,"CGM2_3-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_3-pyCGM2.settings") elif model.version in ["CGM2.4"]: if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM2_4-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,"CGM2_4-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_4-pyCGM2.settings") elif model.version in ["CGM2.5"]: if os.path.isfile(pyCGM2.PYCGM2_APPDATA_PATH + "CGM2_5-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,"CGM2_5-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_5-pyCGM2.settings") else: raise Exception ("model version not found [contact admin]") # --------------------------SESSION INFOS ------------------------------------ mpInfo,mpFilename = files.getMpFileContent(DATA_PATH,"mp.pyCGM2",subject) # translators management if model.version in ["CGM1.0"]: translators = files.getTranslators(DATA_PATH,"CGM1.translators") elif model.version in ["CGM1.1"]: translators = files.getTranslators(DATA_PATH,"CGM1_1.translators") elif model.version in ["CGM2.1"]: translators = files.getTranslators(DATA_PATH,"CGM2_1.translators") elif model.version in ["CGM2.2"]: translators = files.getTranslators(DATA_PATH,"CGM2_2.translators") elif model.version in ["CGM2.3"]: translators = files.getTranslators(DATA_PATH,"CGM2_3.translators") elif model.version in ["CGM2.4"]: translators = files.getTranslators(DATA_PATH,"CGM2_4.translators") elif model.version in ["CGM2.5"]: translators = files.getTranslators(DATA_PATH,"CGM2_5.translators") if not translators: translators = settings["Translators"] # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter(DATA_PATH,reconstructedFilenameLabelledNoExt,subject) acq = nacf.build() # --------------------------MODEL PROCESSING---------------------------- model,acqFunc,side = kneeCalibration.calibration2Dof(model, DATA_PATH,reconstructFilenameLabelled,translators, args.side,args.beginFrame,args.endFrame,None,forceBtkAcq=acq) # ----------------------SAVE------------------------------------------- files.saveModel(model,DATA_PATH,subject) LOGGER.logger.warning("model updated with a %s knee calibrated with 2Dof method" %(side)) # save mp files.saveMp(mpInfo,model,DATA_PATH,mpFilename) # ----------------------VICON INTERFACE------------------------------------------- #--- update mp nexusUtils.updateNexusSubjectMp(NEXUS,model,subject) if side == "Left": nexusTools.appendBones(NEXUS,subject,acqFunc,"LFE0", model.getSegment("Left Thigh"),OriginValues = acqFunc.GetPoint("LKJC").GetValues() ) elif side == "Right": nexusTools.appendBones(NEXUS,subject,acqFunc,"RFE0", model.getSegment("Right Thigh"),OriginValues = acqFunc.GetPoint("RKJC").GetValues() ) # --------------------------NEW MOTION FILTER - DISPLAY BONES--------- scp=modelFilters.StaticCalibrationProcedure(model) if model.version in ["CGM1.0","CGM1.1","CGM2.1","CGM2.2"]: modMotion=modelFilters.ModelMotionFilter(scp,acqFunc,model,enums.motionMethod.Determinist) modMotion.compute() elif model.version in ["CGM2.3","CGM2.4"]: proximalSegmentLabel=str(side+" Thigh") distalSegmentLabel=str(side+" Shank") # Motion modMotion=modelFilters.ModelMotionFilter(scp,acqFunc,model,enums.motionMethod.Sodervisk) modMotion.segmentalCompute([proximalSegmentLabel,distalSegmentLabel]) # -- add nexus Bones if side == "Left": nexusTools.appendBones(NEXUS,subject,acqFunc,"LFE1", model.getSegment("Left Thigh"),OriginValues = acqFunc.GetPoint("LKJC").GetValues() ) LOGGER.logger.warning("offset %s" %(str(model.mp_computed["LeftKneeFuncCalibrationOffset"] ))) elif side == "Right": nexusTools.appendBones(NEXUS,subject,acqFunc,"RFE1", model.getSegment("Right Thigh"),OriginValues = acqFunc.GetPoint("RKJC").GetValues() ) LOGGER.logger.warning("offset %s" %(str(model.mp_computed["RightKneeFuncCalibrationOffset"] ))) else: raise Exception("NO Nexus connection. Turn on Nexus")
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 + "CGM2_2-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH,"CGM2_2-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER,"CGM2_2-pyCGM2.settings") # --------------------------CONFIG ------------------------------------ argsManager = CgmArgsManager.argsManager_cgm(settings,args) markerDiameter = argsManager.getMarkerDiameter() pointSuffix = argsManager.getPointSuffix("cgm2.2") momentProjection = argsManager.getMomentProjection() # --------------------------LOADING ------------------------------------ DATA_PATH, reconstructFilenameLabelledNoExt = NEXUS.GetTrialName() reconstructFilenameLabelled = reconstructFilenameLabelledNoExt+".c3d" logging.info( "data Path: "+ DATA_PATH ) logging.info( "calibration file: "+ reconstructFilenameLabelled) # --------------------------SUBJECT ------------------------------------ subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS,subjects) logging.info( "Subject name : " + subject ) # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH,subject) # check model logging.info("loaded model : %s" %(model.version)) if model.version != "CGM2.2": raise Exception ("%s-pyCGM2.model file was not calibrated from the CGM2.2 calibration pipeline"%subject) # --------------------------SESSION INFOS ------------------------------------ translators = files.getTranslators(DATA_PATH,"CGM2_2.translators") if not translators: translators = settings["Translators"] # ikweight ikWeight = files.getIKweightSet(DATA_PATH,"CGM2_2.ikw") if not ikWeight: ikWeight = settings["Fitting"]["Weight"] #force plate assignement from Nexus mfpa = nexusTools.getForcePlateAssignment(NEXUS) nacf = nexusFilters.NexusConstructAcquisitionFilter(DATA_PATH,reconstructFilenameLabelledNoExt,subject) acq = nacf.build() # --------------------------MODELLING PROCESSING ----------------------- acqIK = cgm2_2.fitting(model,DATA_PATH, reconstructFilenameLabelled, translators,settings, markerDiameter, pointSuffix, mfpa, momentProjection, forceBtkAcq=acq) # ----------------------DISPLAY ON VICON------------------------------- nexusFilters.NexusModelFilter(NEXUS,model,acqIK,subject,pointSuffix).run() nexusTools.createGeneralEvents(NEXUS,subject,acqIK,["Left-FP","Right-FP"]) # ========END of the nexus OPERATION if run from Nexus ========= else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(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")
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-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" 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.translators") if not translators: translators = settings["Translators"] # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter(DATA_PATH,calibrateFilenameLabelledNoExt,subject) acq = nacf.build() # --------------------------MODELLING PROCESSING ----------------------- model,acqStatic = cgm1.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()
def main(): parser = argparse.ArgumentParser(description='CGM2-2 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') parser.add_argument('-a', '--accuracy', type=float, help='Inverse Kinematics accuracy') parser.add_argument('-ae', '--anomalyException', action='store_true', help='stop if anomaly detected ') parser.add_argument('-fi', '--frameInit', type=int, help='first frame to process') parser.add_argument('-fe', '--frameEnd', type=int, help='last frame to process') 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 + "CGM2_2-pyCGM2.settings"): settings = files.openFile(pyCGM2.PYCGM2_APPDATA_PATH, "CGM2_2-pyCGM2.settings") else: settings = files.openFile(pyCGM2.PYCGM2_SETTINGS_FOLDER, "CGM2_2-pyCGM2.settings") # --------------------------CONFIG ------------------------------------ argsManager = CgmArgsManager.argsManager_cgm(settings, args) markerDiameter = argsManager.getMarkerDiameter() pointSuffix = argsManager.getPointSuffix("cgm2.2") momentProjection = argsManager.getMomentProjection() ikAccuracy = argsManager.getIkAccuracy() # --------------------------LOADING ------------------------------------ DATA_PATH, reconstructFilenameLabelledNoExt = NEXUS.GetTrialName() reconstructFilenameLabelled = reconstructFilenameLabelledNoExt + ".c3d" LOGGER.logger.info("data Path: " + DATA_PATH) LOGGER.set_file_handler(DATA_PATH + "pyCGM2-Fitting.log") LOGGER.logger.info("calibration file: " + reconstructFilenameLabelled) # --------------------------SUBJECT ------------------------------------ subjects = NEXUS.GetSubjectNames() subject = nexusTools.getActiveSubject(NEXUS) LOGGER.logger.info("Subject name : " + subject) # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH, subject) # -------------------------- MP ------------------------------------ # allow alteration of thigh offset model.mp_computed[ "LeftThighRotationOffset"] = NEXUS.GetSubjectParamDetails( subject, "LeftThighRotation")[0] model.mp_computed[ "RightThighRotationOffset"] = NEXUS.GetSubjectParamDetails( subject, "RightThighRotation")[0] # check model LOGGER.logger.info("loaded model : %s" % (model.version)) if model.version != "CGM2.2": raise Exception( "%s-pyCGM2.model file was not calibrated from the CGM2.2 calibration pipeline" % subject) # --------------------------SESSION INFOS ------------------------------------ translators = files.getTranslators(DATA_PATH, "CGM2_2.translators") if not translators: translators = settings["Translators"] # ikweight ikWeight = files.getIKweightSet(DATA_PATH, "CGM2_2.ikw") if not ikWeight: ikWeight = settings["Fitting"]["Weight"] #force plate assignement from Nexus mfpa = nexusTools.getForcePlateAssignment(NEXUS) nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, reconstructFilenameLabelledNoExt, subject) acq = nacf.build() # --------------------------MODELLING PROCESSING ----------------------- acqIK, detectAnomaly = cgm2_2.fitting( model, DATA_PATH, reconstructFilenameLabelled, translators, settings, markerDiameter, pointSuffix, mfpa, momentProjection, forceBtkAcq=acq, ikAccuracy=ikAccuracy, anomalyException=args.anomalyException, frameInit=args.frameInit, frameEnd=args.frameEnd) # ----------------------DISPLAY ON VICON------------------------------- nexusFilters.NexusModelFilter(NEXUS, model, acqIK, subject, pointSuffix).run() nexusTools.createGeneralEvents(NEXUS, subject, acqIK, ["Left-FP", "Right-FP"]) # ========END of the nexus OPERATION if run from Nexus ========= else: raise Exception("NO Nexus connection. Turn on Nexus")