def main(): plt.close("all") parser = argparse.ArgumentParser(description='CGM plot temporal Kinetics') 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 NEXUS_PYTHON_CONNECTED: pointSuffix = args.pointSuffix # --------------------------INPUTS ------------------------------------ DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("file: " + modelledFilename) # ----- Subject ----- # need subject to find input files subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS, subjects) logging.info("Subject name : " + subject) # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH, subject) modelVersion = model.version # ----- construction of the openMA root instance ----- trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, modelledFilenameNoExt, subject) openmaTrial = trialConstructorFilter.build() # --------------------pyCGM2 MODEL ------------------------------ if model.m_bodypart in [ enums.BodyPart.LowerLimb, enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plotTemporalKinetic(DATA_PATH, modelledFilename, "LowerLimb", pointLabelSuffix=pointSuffix, exportPdf=True, openmaTrial=openmaTrial) # if model.m_bodypart in [enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody]: # plot.plotTemporalKinetic(DATA_PATH, modelledFilename,"Trunk", pointLabelSuffix=pointSuffix,exportPdf=True) # if model.m_bodypart in [enums.BodyPart.UpperLimb, enums.BodyPart.FullBody]: # pass # TODO plot upperlimb panel else: raise Exception("NO Nexus connection. Turn on Nexus")
def test_loadAndSaveModel(self): model = files.loadModel( pyCGM2.TEST_DATA_PATH + "\\LowLevel\\IO\\Hänibàl_files\\", "PIG-KAD") assert model != False files.saveModel( model, pyCGM2.TEST_DATA_PATH + "\\LowLevel\\IO\\Hänibàl_files\\", "testModelOut")
def main(): plt.close("all") parser = argparse.ArgumentParser(description='CGM plot stp') parser.add_argument('-ps', '--pointSuffix', type=str, help='suffix added to pyCGM2 outputs') args = parser.parse_args() NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if NEXUS_PYTHON_CONNECTED: pointSuffix = args.pointSuffix # --------------------------INPUTS ------------------------------------ DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("file: " + modelledFilename) # ----- Subject ----- # need subject to find input files subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS, subjects) logging.info("Subject name : " + subject) # ----- construction of the openMA root instance ----- trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, modelledFilenameNoExt, subject) openmaTrial = trialConstructorFilter.build() # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH, subject) modelVersion = model.version # --------------------------PROCESSING -------------------------------- analysisInstance = analysis.makeAnalysis( DATA_PATH, [modelledFilename], pointLabelSuffix=pointSuffix, openmaTrials=[openmaTrial] ) # analysis structure gathering Time-normalized Kinematic and kinetic CGM outputs plot.plot_spatioTemporal(DATA_PATH, analysisInstance, exportPdf=True, outputName=modelledFilename) else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(): parser = argparse.ArgumentParser(description='CGM2-3 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('--noIk', action='store_true', help='cancel inverse kinematic') 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_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") # --------------------------CONFIG ------------------------------------ argsManager = CgmArgsManager.argsManager_cgm(settings, args) markerDiameter = argsManager.getMarkerDiameter() pointSuffix = argsManager.getPointSuffix("cgm2.3") momentProjection = argsManager.getMomentProjection() ik_flag = argsManager.enableIKflag 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 ----------------------------------- # Notice : Work with ONE subject by session 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] # --------------------------CHECKING ----------------------------------- # check model LOGGER.logger.info("loaded model : %s" % (model.version)) if model.version != "CGM2.3": raise Exception( "%s-pyCGM2.model file was not calibrated from the CGM2.3 calibration pipeline" % subject) # --------------------------SESSION INFOS ------------------------------------ # translators management translators = files.getTranslators(DATA_PATH, "CGM2_3.translators") if not translators: translators = settings["Translators"] # ikweight ikWeight = files.getIKweightSet(DATA_PATH, "CGM2_3.ikw") if not ikWeight: ikWeight = settings["Fitting"]["Weight"] #force plate assignement from Nexus mfpa = nexusTools.getForcePlateAssignment(NEXUS) # btkAcquisition nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, reconstructFilenameLabelledNoExt, subject) acq = nacf.build() # --------------------------MODELLING PROCESSING ----------------------- finalAcqGait, detectAnomaly = cgm2_3.fitting( model, DATA_PATH, reconstructFilenameLabelled, translators, settings, ik_flag, markerDiameter, pointSuffix, mfpa, momentProjection, forceBtkAcq=acq, ikAccuracy=ikAccuracy, anomalyException=args.anomalyException, frameInit=args.frameInit, frameEnd=args.frameEnd) # ----------------------DISPLAY ON VICON------------------------------- nexusFilters.NexusModelFilter(NEXUS, model, finalAcqGait, subject, pointSuffix).run() nexusTools.createGeneralEvents(NEXUS, subject, finalAcqGait, ["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): NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if NEXUS_PYTHON_CONNECTED: # run Operation # --------------------------PATH + FILE ------------------------------------ DATA_PATH, reconstructedFilenameLabelledNoExt = NEXUS.GetTrialName() reconstructFilenameLabelled = reconstructedFilenameLabelledNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("reconstructed 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) logging.info("loaded model : %s" % (model.version)) # --------------------------CONFIG ------------------------------------ # --------------------CHECKING ------------------------------ if model.version in ["CGM1.0", "CGM1.1", "CGM2.1", "CGM2.2"]: raise Exception( "Can t use SARA method with your model %s [minimal version : CGM2.3]" % (model.version)) 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 ["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.sara( model, DATA_PATH, reconstructFilenameLabelled, translators, args.side, args.beginFrame, args.endFrame, forceBtkAcq=acq) # ----------------------SAVE------------------------------------------- files.saveModel(model, DATA_PATH, subject) logging.warning( "model updated with a %s knee calibrated with SARA method" % (side)) # save mp files.saveMp(mpInfo, model, DATA_PATH, mpFilename) # ----------------------VICON INTERFACE------------------------------------------- #--- update mp nexusUtils.updateNexusSubjectMp(NEXUS, model, subject) # -- add nexus Bones 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()) proximalSegmentLabel = str(side + " Thigh") distalSegmentLabel = str(side + " Shank") # add modelled markers meanOr_inThigh = model.getSegment(proximalSegmentLabel).getReferential( "TF").getNodeTrajectory("KJC_Sara") meanAxis_inThigh = model.getSegment( proximalSegmentLabel).getReferential("TF").getNodeTrajectory( "KJC_SaraAxis") btkTools.smartAppendPoint(acqFunc, side + "_KJC_Sara", meanOr_inThigh) btkTools.smartAppendPoint(acqFunc, side + "_KJC_SaraAxis", meanAxis_inThigh) nexusTools.appendModelledMarkerFromAcq(NEXUS, subject, side + "_KJC_Sara", acqFunc) nexusTools.appendModelledMarkerFromAcq(NEXUS, subject, side + "_KJC_SaraAxis", acqFunc) #---Second model motion filter # consider new anatomical frame scp = modelFilters.StaticCalibrationProcedure(model) modMotion = modelFilters.ModelMotionFilter( scp, acqFunc, model, enums.motionMethod.Sodervisk) modMotion.segmentalCompute([proximalSegmentLabel, distalSegmentLabel]) # projection of the Sara axis in the transversale plane # -- add nexus Bones if side == "Left": nexusTools.appendBones( NEXUS, subject, acqFunc, "LFE1", model.getSegment("Left Thigh"), OriginValues=acqFunc.GetPoint("LKJC").GetValues()) print model.mp_computed["LeftKneeFuncCalibrationOffset"] logging.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()) logging.warning( "offset %s" % (str(model.mp_computed["RightKneeFuncCalibrationOffset"]))) print 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: #-----------------------SETTINGS--------------------------------------- pointSuffix = args.pointSuffix normativeData = { "Author": args.normativeData, "Modality": args.normativeDataModality } if normativeData["Author"] == "Schwartz2008": chosenModality = normativeData["Modality"] nds = normativeDatasets.Schwartz2008( chosenModality ) # modalites : "Very Slow" ,"Slow", "Free", "Fast", "Very Fast" elif normativeData["Author"] == "Pinzone2014": chosenModality = normativeData["Modality"] nds = normativeDatasets.Pinzone2014( chosenModality) # modalites : "Center One" ,"Center Two" consistencyFlag = True if args.consistency else False # --------------------------INPUTS ------------------------------------ DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("file: " + modelledFilename) # ----- Subject ----- # need subject to find input files subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS, subjects) logging.info("Subject name : " + subject) # ----- construction of the openMA root instance ----- trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, modelledFilenameNoExt, subject) openmaTrial = trialConstructorFilter.build() # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH, subject) modelVersion = model.version # --------------------------PROCESSING -------------------------------- analysisInstance = analysis.makeAnalysis( DATA_PATH, [modelledFilename], pointLabelSuffix=pointSuffix, openmaTrials=[openmaTrial] ) # analysis structure gathering Time-normalized Kinematic and kinetic CGM outputs if not consistencyFlag: if model.m_bodypart in [ enums.BodyPart.LowerLimb, enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plot_DescriptiveKinetic(DATA_PATH, analysisInstance, "LowerLimb", nds, pointLabelSuffix=pointSuffix, exportPdf=True, outputName=modelledFilename) else: if model.m_bodypart in [ enums.BodyPart.LowerLimb, enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plot_ConsistencyKinetic(DATA_PATH, analysisInstance, "LowerLimb", nds, pointLabelSuffix=pointSuffix, exportPdf=True, outputName=modelledFilename) else: raise Exception("NO Nexus connection. Turn on Nexus")
DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt+".c3d" logging.info( "data Path: "+ DATA_PATH ) logging.info( "file: "+ modelledFilename) # ----- Subject ----- # need subject to find input files subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS,subjects) logging.info( "Subject name : " + subject ) # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH,subject) modelVersion = model.version # --------------------SESSION INFOS ------------------------------ # -----infos-------- modelInfo = None #if infoSettings["Modelling"]["Model"]=={} else infoSettings["Modelling"]["Model"] subjectInfo = None #if infoSettings["Processing"]["Subject"]=={} else infoSettings["Processing"]["Subject"] experimentalInfo = None #if infoSettings["Processing"]["Experimental conditions"]=={} else infoSettings["Processing"]["Experimental conditions"] # --------------------------PROCESSING -------------------------------- cgmProcessing.gaitProcessing(DATA_PATH,modelledFilename,modelVersion, modelInfo, subjectInfo, experimentalInfo, normativeData, pointSuffix, outputFilename = modelledFilenameNoExt,
def main(): parser = argparse.ArgumentParser(description='CGM2-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 + "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") # --------------------------CONFIG ------------------------------------ argsManager = CgmArgsManager.argsManager_cgm(settings, args) markerDiameter = argsManager.getMarkerDiameter() pointSuffix = argsManager.getPointSuffix("cgm2.1") 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.1": raise Exception( "%s-pyCGM2.model file was not calibrated from the CGM2.1 calibration pipeline" % subject) # --------------------------SESSION INFOS ------------------------------------ # translators management translators = files.getTranslators(DATA_PATH, "CGM2_1.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 = cgm2_1.fitting(model, DATA_PATH, reconstructFilenameLabelled, translators, markerDiameter, pointSuffix, mfpa, momentProjection, forceBtkAcq=acq) # ----------------------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(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(): 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 NEXUS_PYTHON_CONNECTED: #-----------------------SETTINGS--------------------------------------- pointSuffix = args.pointSuffix normativeData = { "Author": args.normativeData, "Modality": args.normativeDataModality } if normativeData["Author"] == "Schwartz2008": chosenModality = normativeData["Modality"] nds = normativeDatasets.Schwartz2008( chosenModality ) # modalites : "Very Slow" ,"Slow", "Free", "Fast", "Very Fast" elif normativeData["Author"] == "Pinzone2014": chosenModality = normativeData["Modality"] nds = normativeDatasets.Pinzone2014( chosenModality) # modalites : "Center One" ,"Center Two" # --------------------------INPUTS ------------------------------------ DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("file: " + modelledFilename) # ----- Subject ----- # need subject to find input files subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS, subjects) logging.info("Subject name : " + subject) # ----- construction of the openMA root instance ----- trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, modelledFilenameNoExt, subject) openmaTrial = trialConstructorFilter.build() # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH, subject) modelVersion = model.version # --------------------------PROCESSING -------------------------------- analysisInstance = analysis.makeAnalysis( DATA_PATH, [modelledFilename], None, None, None, pointLabelSuffix=pointSuffix, openmaTrials=[openmaTrial] ) # analysis structure gathering Time-normalized Kinematic and kinetic CGM outputs plot.plot_MAP(DATA_PATH, analysisInstance, nds, exportPdf=True, outputName=modelledFilename, pointLabelSuffix=pointSuffix) else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(): plt.close("all") parser = argparse.ArgumentParser( description='CGM plot Normalized Kinematics') 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') parser.add_argument('-c', '--consistency', action='store_true', help='consistency plots') args = parser.parse_args() NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if NEXUS_PYTHON_CONNECTED: #-----------------------SETTINGS--------------------------------------- normativeData = { "Author": args.normativeData, "Modality": args.normativeDataModality } if normativeData["Author"] == "Schwartz2008": chosenModality = normativeData["Modality"] nds = normativeDatasets.Schwartz2008( chosenModality ) # modalites : "Very Slow" ,"Slow", "Free", "Fast", "Very Fast" elif normativeData["Author"] == "Pinzone2014": chosenModality = normativeData["Modality"] nds = normativeDatasets.Pinzone2014( chosenModality) # modalites : "Center One" ,"Center Two" consistencyFlag = True if args.consistency else False pointSuffix = args.pointSuffix # --------------------------INPUTS ------------------------------------ DATA_PATH, modelledFilenameNoExt = NEXUS.GetTrialName() modelledFilename = modelledFilenameNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("file: " + modelledFilename) # ----- Subject ----- # need subject to find input files subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS, subjects) logging.info("Subject name : " + subject) # --------------------pyCGM2 MODEL ------------------------------ model = files.loadModel(DATA_PATH, subject) modelVersion = model.version # ----- construction of the openMA root instance ----- trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, modelledFilenameNoExt, subject) openmaTrial = trialConstructorFilter.build() # --------------------------PROCESSING -------------------------------- analysisInstance = analysis.makeAnalysis(DATA_PATH, [modelledFilename], pointLabelSuffix=pointSuffix, openmaTrials=[openmaTrial]) if not consistencyFlag: if model.m_bodypart in [ enums.BodyPart.LowerLimb, enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plot_DescriptiveKinematic(DATA_PATH, analysisInstance, "LowerLimb", nds, pointLabelSuffix=pointSuffix, exportPdf=True, outputName=modelledFilename) #plot_DescriptiveKinematic(DATA_PATH,analysis,bodyPart,normativeDataset,pointLabelSuffix=None,type="Gait",exportPdf=False,outputName=None): if model.m_bodypart in [ enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plot_DescriptiveKinematic(DATA_PATH, analysisInstance, "Trunk", nds, pointLabelSuffix=pointSuffix, exportPdf=True, outputName=modelledFilename) if model.m_bodypart in [ enums.BodyPart.UpperLimb, enums.BodyPart.FullBody ]: pass # TODO plot upperlimb panel else: if model.m_bodypart in [ enums.BodyPart.LowerLimb, enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plot_ConsistencyKinematic(DATA_PATH, analysisInstance, "LowerLimb", nds, pointLabelSuffix=pointSuffix, exportPdf=True, outputName=modelledFilename) if model.m_bodypart in [ enums.BodyPart.LowerLimbTrunk, enums.BodyPart.FullBody ]: plot.plot_ConsistencyKinematic(DATA_PATH, analysisInstance, "Trunk", nds, pointLabelSuffix=pointSuffix, exportPdf=True, outputName=modelledFilename) if model.m_bodypart in [ enums.BodyPart.UpperLimb, enums.BodyPart.FullBody ]: pass # TODO plot upperlimb panel 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")