def temporalPlotPanel(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "EMG\\SampleNantes\\" gaitTrial = "gait.c3d" restTrial = "repos.c3d" EMG_LABELS = ['EMG1', 'EMG2', 'EMG3', 'EMG4'] acq = btkTools.smartReader(DATA_PATH + gaitTrial) bf = emgFilters.BasicEmgProcessingFilter(acq, EMG_LABELS) bf.setHighPassFrequencies(20.0, 200.0) bf.run() btkTools.smartWriter(acq, "testBasicPlot.c3d") trial = trialTools.smartTrialReader(None, "testBasicPlot.c3d") # # viewer kv = emgPlotViewers.TemporalEmgPlotViewer(trial) kv.setEmgs([["EMG1", "Left"], ["EMG2", "Right"], ["EMG3", "Left"], ["EMG4", "Right"]]) kv.setNormalActivationLabels(["RECFEM", "RECFEM", None, "VASLAT"]) kv.setEmgRectify(True) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot() plt.show()
def noX2d_manualCropping(cls): NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() #DATA_PATH, filenameNoExt = NEXUS.GetTrialName() DATA_PATH = "C:\\Users\\HLS501\\Documents\\VICON DATA\\pyCGM2-Data\\NexusAPI\\BtkAcquisitionCreator\\sample3\\" filenameNoExt = "capture 01" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) NEXUS.SetTrialRegionOfInterest(350, 500) subject = NEXUS.GetSubjectNames()[0] acqConstructorFilter = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, filenameNoExt, subject) acq = acqConstructorFilter.build() acq0 = btkTools.smartReader(str(DATA_PATH + "Capture 01-cropped.c3d")) #ipdb.set_trace() plt.plot(acq.GetPoint("LTHI").GetValues(), "-r") plt.plot(acq0.GetPoint("LTHI").GetValues(), "-ob") plt.show() np.testing.assert_array_almost_equal(acq.GetPoint("LTHI").GetValues(), acq0.GetPoint("LTHI").GetValues(), decimal=2) #np.testing.assert_array_almost_equal(acq.GetAnalog("Force.Fx1").GetValues(),acq0.GetAnalog("Force.Fx1").GetValues(),decimal=2) btkTools.smartWriter(acq, "noX2d_cropInteractive.c3d")
def temporalPlotSingleEmg(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "EMG\\SampleNantes\\" gaitTrial = "gait.c3d" restTrial = "repos.c3d" EMG_LABELS = ['EMG1'] acq = btkTools.smartReader(DATA_PATH + gaitTrial) bf = emgFilters.BasicEmgProcessingFilter(acq, EMG_LABELS) bf.setHighPassFrequencies(20.0, 200.0) bf.run() btkTools.smartWriter(acq, "testBasicPlot.c3d") trial = trialTools.smartTrialReader(None, "testBasicPlot.c3d") fig = plt.figure() ax = plt.gca() plot.temporalPlot(ax, trial, "EMG1_Rectify", 0, color="blue", title="test", xlabel="frame", ylabel="emg", ylim=None, legendLabel=None, customLimits=None) plot.addTemporalNormalActivationLayer(ax, trial, "RECFEM", "Left") plt.show()
def croppedC3d(cls): NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() DATA_PATH = "C:\\Users\\HLS501\\Documents\\VICON DATA\\pyCGM2-Data\\NexusAPI\\BtkAcquisitionCreator\\sample_NOx2d\\" filenameNoExt = "gait_cropped" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) subject = NEXUS.GetSubjectNames()[0] acqConstructorFilter = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, filenameNoExt, subject) acq = acqConstructorFilter.build() btkTools.smartWriter(acq, "TestsNOX2d_croppedC3d.c3d") acq0 = btkTools.smartReader(str(DATA_PATH + filenameNoExt + ".c3d")) # plotPoint(acq,acq0,"LTHI") # plotAnalog(acq,acq0,"Force.Fz1") # plotAnalog(acq,acq0,"Force.Fz2") # plotAnalog(acq,acq0,"Force.Fz3") np.testing.assert_array_almost_equal(acq.GetPoint("LTHI").GetValues(), acq0.GetPoint("LTHI").GetValues(), decimal=2) np.testing.assert_array_almost_equal( acq.GetAnalog("Force.Fz1").GetValues(), acq0.GetAnalog("Force.Fz1").GetValues(), decimal=2) np.testing.assert_array_almost_equal( acq.GetAnalog("Force.Fz2").GetValues(), acq0.GetAnalog("Force.Fz2").GetValues(), decimal=2) np.testing.assert_array_almost_equal( acq.GetAnalog("Force.Fz3").GetValues(), acq0.GetAnalog("Force.Fz3").GetValues(), decimal=2)
def main(args): DATA_PATH = os.getcwd() + "\\" file = args.file[0] if not os.path.isfile(file): raise Exception("the file (%s) doesn t exist" % (file)) modelledTrials = [file] for trial in modelledTrials: logging.info("[pyCGM2]: Zeni Event Detection on trial %s" % (str(trial))) acqGait = btkTools.smartReader(str(DATA_PATH + trial)) acqGait.ClearEvents() # ----------------------EVENT DETECTOR------------------------------- evp = events.ZeniProcedure() evp.setFootStrikeOffset(args.footStrikeOffset) evp.setFootOffOffset(args.footOffOffset) # event filter evf = events.EventFilter(evp, acqGait) evf.detect() btkTools.smartWriter(acqGait, str(DATA_PATH + trial)) logging.info("[pyCGM2]: Zeni Event Detection on trial %s ----> Done" % (str(trial))) if args.MokkaCheck: cmd = "Mokka.exe \"%s\"" % (str(DATA_PATH + trial)) os.system(cmd)
def test_temporalPlotPanel(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"GaitData\\EMG\\Hånnibøl Lecter-nerve block\\" gaitTrial = "PRE-gait trial 01.c3d" restTrial = "PRE-repos.c3d" DATA_PATH_OUT = pyCGM2.TEST_DATA_PATH_OUT+"GaitData\\EMG\\Hånnibøl Lecter-nerve block\\" files.createDir(DATA_PATH_OUT) EMG_LABELS=['EMG1','EMG2','EMG3','EMG4'] acq = btkTools.smartReader(DATA_PATH +gaitTrial) bf = emgFilters.BasicEmgProcessingFilter(acq,EMG_LABELS) bf.setHighPassFrequencies(20.0,200.0) bf.run() btkTools.smartWriter(acq,DATA_PATH_OUT+"test_temporalPlotPanel.c3d") trial =trialTools.smartTrialReader(DATA_PATH_OUT,"test_temporalPlotPanel.c3d") # # viewer kv = emgPlotViewers.TemporalEmgPlotViewer(trial) kv.setEmgs([["EMG1","Left","RF"],["EMG2","Right","RF"],["EMG3","Left","vaste"],["EMG4","Right","vaste"]]) kv.setNormalActivationLabels(["RECFEM","RECFEM",None,"VASLAT"]) kv. setEmgRectify(True) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setExport(DATA_PATH_OUT,"hän-test_temporalPlotPanel","png") pf.plot()
def analysisAdvancedEMG(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\analysis\\gaitEMG\\" inputFile = ["pre.c3d","post.c3d"] EMG_LABELS = ["EMG1","EMG2"] # for file in inputFile: acq = btkTools.smartReader(DATA_PATH+file) pyCGM2.Lib.analysis.processEMG_fromBtkAcq(acq, EMG_LABELS, highPassFrequencies=[20,200],envelopFrequency=6.0) btkTools.smartWriter(acq,DATA_PATH+file[:-4]+"-emgProcessed.c3d") inputFileProcessed = [file[:-4]+"-emgProcessed.c3d" for file in inputFile] emgAnalysis = pyCGM2.Lib.analysis.makeEmgAnalysis(DATA_PATH, inputFileProcessed, EMG_LABELS,None, None) exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(emgAnalysis) exportFilter.export("testAdvancedEMG", path=DATA_PATH,excelFormat = "xls",mode="Advanced") # exportFilter = exporter.AnalysisExportFilter() # exportFilter.setAnalysisInstance(emgAnalysis) # exportFilter.export("testAdvancedEMG.json", path=DATA_PATH) exportFilter = exporter.AnalysisC3dExportFilter() exportFilter.setAnalysisInstance(emgAnalysis) exportFilter.export("testAdvanced", path=DATA_PATH)
def noIK_6dof(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\fullBody\\" staticFilename = "PN01OP01S01STAT.c3d" gaitFilename = "PN01OP01S01STAT.c3d" markerDiameter = 14 mp = { 'Bodymass': 83.0, 'LeftLegLength': 874.0, 'RightLegLength': 876.0, 'LeftKneeWidth': 106.0, 'RightKneeWidth': 103.0, 'LeftAnkleWidth': 74.0, 'RightAnkleWidth': 72.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) translators = files.getTranslators(MAIN_PATH, "CGM2_4.translators") acqStatic = btkTools.applyTranslators(acqStatic, translators) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() print "----" print model.getSegment("Left Shank").getReferential( "TF").relativeMatrixAnatomic print "----" # # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # # # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) acqGait = btkTools.applyTranslators(acqGait, translators) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, enums.motionMethod.Sodervisk) modMotion.compute() btkTools.smartWriter(acqGait, "cgm24_noIK6dof_staticMotion.c3d")
def basicCGM1_manualTibialTorsion(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\basic-tibialTorsion\\" staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model=cgm.CGM1 model.configure() markerDiameter=14 mp={ 'Bodymass' : 71.0, 'LeftLegLength' : 860.0, 'RightLegLength' : 865.0 , 'LeftKneeWidth' : 102.0, 'RightKneeWidth' : 103.4, 'LeftAnkleWidth' : 75.3, 'RightAnkleWidth' : 72.9, 'LeftSoleDelta' : 0, 'RightSoleDelta' : 0, } optional_mp={ 'LeftTibialTorsion' : -30.0, 'RightTibialTorsion' : -30.0 } model.addAnthropoInputParameters(mp,optional=optional_mp) # -----------CGM STATIC CALIBRATION-------------------- scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model, viconCGM1compatible=True).compute() # TESTS ------------------------------------------------ # offset testing offsetTesting(acqStatic,model,display = True, unitTesting=True) # nodes # np.testing.assert_equal(model.getSegment("Left Thigh").getReferential("TF").static.getNode_byLabel("LKJC").m_desc ,"Chord") # np.testing.assert_equal(model.getSegment("Right Thigh").getReferential("TF").static.getNode_byLabel("RKJC").m_desc ,"Chord") # # np.testing.assert_equal(model.getSegment("Left Shank").getReferential("TF").static.getNode_byLabel("LKJC").m_desc ,"Chord") # np.testing.assert_equal(model.getSegment("Right Shank").getReferential("TF").static.getNode_byLabel("RKJC").m_desc ,"Chord") np.testing.assert_equal(model.m_useRightTibialTorsion,True ) np.testing.assert_equal(model.m_useLeftTibialTorsion,True ) # joint centres np.testing.assert_almost_equal(acqStatic.GetPoint("LFEP").GetValues().mean(axis=0),acqStatic.GetPoint("LHJC").GetValues().mean(axis=0),decimal = 3) np.testing.assert_almost_equal(acqStatic.GetPoint("RFEP").GetValues().mean(axis=0),acqStatic.GetPoint("RHJC").GetValues().mean(axis=0),decimal = 3) np.testing.assert_almost_equal(acqStatic.GetPoint("LFEO").GetValues().mean(axis=0),acqStatic.GetPoint("LKJC").GetValues().mean(axis=0),decimal = 3) np.testing.assert_almost_equal(acqStatic.GetPoint("RFEO").GetValues().mean(axis=0),acqStatic.GetPoint("RKJC").GetValues().mean(axis=0),decimal = 3) np.testing.assert_almost_equal(acqStatic.GetPoint("LTIO").GetValues().mean(axis=0),acqStatic.GetPoint("LAJC").GetValues().mean(axis=0),decimal = 3) np.testing.assert_almost_equal(acqStatic.GetPoint("RTIO").GetValues().mean(axis=0),acqStatic.GetPoint("RAJC").GetValues().mean(axis=0),decimal = 3) btkTools.smartWriter(acqStatic, "outStatic_advancedCGM1_kad_manualTibial.c3d")
def test_temporalPlotSingleEmg(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"GaitData\\EMG\\Hånnibøl Lecter-nerve block\\" gaitTrial = "PRE-gait trial 01.c3d" restTrial = "PRE-repos.c3d" DATA_PATH_OUT = pyCGM2.TEST_DATA_PATH_OUT+"GaitData\\EMG\\Hånnibøl Lecter-nerve block\\" files.createDir(DATA_PATH_OUT) EMG_LABELS=['EMG1'] acq = btkTools.smartReader(DATA_PATH +gaitTrial) bf = emgFilters.BasicEmgProcessingFilter(acq,EMG_LABELS) bf.setHighPassFrequencies(20.0,200.0) bf.run() btkTools.smartWriter(acq,DATA_PATH_OUT+"test_temporalPlotSingleEmg.c3d") trial =trialTools.smartTrialReader(DATA_PATH_OUT,"test_temporalPlotSingleEmg.c3d") fig = plt.figure() ax = plt.gca() plot.temporalPlot(ax,trial,"EMG1_Rectify",0, color="blue", title="test", xlabel="frame", ylabel="emg",ylim=None,legendLabel=None, customLimits=None) plot.addTemporalNormalActivationLayer(ax,trial,"RECFEM","Left")
def cgm24(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\markerDecomposition\\CGM24decomposeTracking\\" # staticFilename = "PN01OP01S01STAT.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model=cgm2.CGM2_4LowerLimbs() model.setVersion("CGM2.4e") model.configure() markerDiameter=14 mp={ 'Bodymass' : 83.0, 'LeftLegLength' : 874.0, 'RightLegLength' : 876.0 , 'LeftKneeWidth' : 106.0, 'RightKneeWidth' : 103.0, 'LeftAnkleWidth' : 74.0, 'RightAnkleWidth' : 72.0, 'LeftSoleDelta' : 0, 'RightSoleDelta' : 0, } model.addAnthropoInputParameters(mp) # CALIBRATION scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model, leftFlatFoot = 1, rightFlatFoot = 1, markerDiameter=markerDiameter, ).compute() modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="left") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="left") modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="right") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="right") modelDecorator.HipJointCenterDecorator(model).hara(side = "Both") scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model, leftFlatFoot = 1, rightFlatFoot = 1, markerDiameter=markerDiameter, ).compute() # --- Test 1 Motion Axe X ------- gaitFilename="PN01OP01S01SS01.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,pyCGM2Enums.motionMethod.Sodervisk ) modMotion.compute() mtf = modelFilters.TrackingMarkerDecompositionFilter(model,acqGait) mtf.decompose() btkTools.smartWriter(acqGait, "cgm24-decompose.c3d")
def prepare_folder_and_run_event_detection(sessionXML, work_folder, processed_folder): utils.create_directory_if_needed(processed_folder) staticMeasurement = utils.find_static(sessionXML) filename = qtmTools.getFilename(staticMeasurement) calibrated_file_path = os.path.join(processed_folder, filename) if not os.path.isfile(calibrated_file_path): shutil.copyfile(os.path.join(work_folder, filename), calibrated_file_path) logging.info( "qualisys exported c3d file [%s] copied to processed folder" % (filename)) dynamicMeasurements = qtmTools.findDynamic(sessionXML) for dynamicMeasurement in dynamicMeasurements: filename = qtmTools.getFilename(dynamicMeasurement) no_events_file_path = os.path.join(work_folder, filename) processed_file_path = os.path.join(processed_folder, filename) if not os.path.isfile(processed_file_path): shutil.copyfile(no_events_file_path, processed_file_path) logging.info( "qualisys exported c3d file [%s] copied to processed folder" % (filename)) acq = btkTools.smartReader(processed_file_path) if "5" in btkTools.smartGetMetadata(acq, "FORCE_PLATFORM", "TYPE"): forceplates.correctForcePlateType5(acq) acq, state = eventDetector.zeni(acq) btkTools.smartWriter(acq, processed_file_path)
def test_btkWriter(self): filename = pyCGM2.TEST_DATA_PATH + "LowLevel\\IO\\Hånnibøl_c3d\\static.c3d" acq = btkTools.smartReader(filename, translators=None) filenameOUT = pyCGM2.TEST_DATA_PATH_OUT + "LowLevel\\IO\\Hånnibøl_c3d\\static.c3d" files.createDir(pyCGM2.TEST_DATA_PATH_OUT + "LowLevel\\IO\\Hånnibøl_c3d") btkTools.smartWriter(acq, filenameOUT)
def exportC3d(self, filenameNoExt=None): if filenameNoExt is None: btkTools.smartWriter( self.m_acq, self.m_dataPath + self.m_filenameNoExt + ".c3d") else: btkTools.smartWriter(self.m_acq, self.m_dataPath + filenameNoExt + ".c3d")
def noIK_6dof_Garches(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "Datasets Tests\\didier\\08_02_18_Vincent Pere\\" staticFilename = "08_02_18_Vincent_Pere_Statique_000_MOKKA.c3d" gaitFilename = "08_02_18_Vincent_Pere_Statique_000_MOKKA.c3d" markerDiameter = 14 mp = { 'Bodymass': 70.0, 'LeftLegLength': 890.0, 'RightLegLength': 890.0, 'LeftKneeWidth': 150.0, 'RightKneeWidth': 150.0, 'LeftAnkleWidth': 88.0, 'RightAnkleWidth': 99.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() print "----" print model.getSegment("Left Shank").getReferential( "TF").relativeMatrixAnatomic print "----" # # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # # # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, enums.motionMethod.Sodervisk) modMotion.compute() btkTools.smartWriter(acqGait, "cgm24_noIK6dof_staticMotion_Garches.c3d")
def twoPF_FP1left_FP2right(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\forceplates\\FootAssignementAutoamticGeneralEvent\\" # --- Motion 1 gaitFilename = "MRI-US-01, 2008-08-08, 3DGA 13.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) #forceplates.appendForcePlateCornerAsMarker(acqGait) mappedForcePlate = forceplates.matchingFootSideOnForceplate(acqGait) forceplates.addForcePlateGeneralEvents(acqGait, "LR") btkTools.smartWriter(acqGait, str(MAIN_PATH + "twoPF_FP1left_FP2right.c3d")) modelledFilenames = ["twoPF_FP1left_FP2right.c3d"] #---- GAIT CYCLES FILTER PRELIMARIES #-------------------------------------------------------------------------- # distinguishing trials for kinematic and kinetic processing # - kinematic Trials kinematicTrials = [] kinematicFilenames = [] for kinematicFilename in modelledFilenames: kinematicFileNode = ma.io.read(str(MAIN_PATH + kinematicFilename)) kinematicTrial = kinematicFileNode.findChild(ma.T_Trial) trialTools.sortedEvents(kinematicTrial) longitudinalAxis, forwardProgression, globalFrame = trialTools.findProgression( kinematicTrial, "LHEE") kinematicTrials.append(kinematicTrial) kinematicFilenames.append(kinematicFilename) # - kinetic Trials ( check if kinetic events) kineticTrials, kineticFilenames, flag_kinetics = trialTools.automaticKineticDetection( MAIN_PATH, modelledFilenames) #---- GAIT CYCLES FILTER #-------------------------------------------------------------------------- cycleBuilder = cycle.GaitCyclesBuilder( spatioTemporalTrials=kinematicTrials, kinematicTrials=kinematicTrials, kineticTrials=kineticTrials, emgTrials=None) cyclefilter = cycle.CyclesFilter() cyclefilter.setBuilder(cycleBuilder) cycles = cyclefilter.build() # TESTING np.testing.assert_equal(len(cycles.kineticCycles), 2) np.testing.assert_equal(cycles.kineticCycles[0].context, "Left") np.testing.assert_equal(cycles.kineticCycles[0].begin, 253) np.testing.assert_equal(cycles.kineticCycles[1].context, "Right") np.testing.assert_equal(cycles.kineticCycles[1].begin, 201)
def calibration_FlatFoot(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\medial\\" staticFilename = "static.c3d" markerDiameter = 14 mp = { 'Bodymass': 69.0, 'LeftLegLength': 930.0, 'RightLegLength': 930.0, 'LeftKneeWidth': 94.0, 'RightKneeWidth': 64.0, 'LeftAnkleWidth': 67.0, 'RightAnkleWidth': 62.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter(scp, acqStatic, model, markerDiameter=markerDiameter, leftFlatFoot=True, rightFlatFoot=True).compute() # display CS csp = modelFilters.ModelCoordinateSystemProcedure(model) csf = modelFilters.CoordinateSystemDisplayFilter(csp, model, acqStatic) csf.setStatic(True) csf.display() btkTools.smartWriter(acqStatic, "cgm2.4_FlatFoot.c3d")
def calibration_GarchesFlatFoot(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "Datasets Tests\\didier\\08_02_18_Vincent Pere\\" staticFilename = "08_02_18_Vincent_Pere_Statique_000_MOKKA.c3d" markerDiameter = 14 mp = { 'Bodymass': 70.0, 'LeftLegLength': 890.0, 'RightLegLength': 890.0, 'LeftKneeWidth': 150.0, 'RightKneeWidth': 150.0, 'LeftAnkleWidth': 88.0, 'RightAnkleWidth': 99.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter(scp, acqStatic, model, markerDiameter=markerDiameter, leftFlatFoot=True, rightFlatFoot=True).compute() # display CS csp = modelFilters.ModelCoordinateSystemProcedure(model) csf = modelFilters.CoordinateSystemDisplayFilter(csp, model, acqStatic) csf.setStatic(True) csf.display() btkTools.smartWriter(acqStatic, "cgm2.4_GarchesFlatFoot.c3d")
def processC3d(self): for c3d in self.m_c3ds: filenameOut = c3d[:-4] + "_" + self.m_fileSuffix+".c3d" if self.m_fileSuffix is not None else c3d acq = btkTools.smartReader((self.m_c3dPath+c3d)) values = acq.GetAnalog(utils.str(self.m_label)).GetValues() valuesNorm = values / self.m_threshold btkTools.smartAppendAnalog(acq,self.m_label+"_Norm",valuesNorm, desc= "Normalization)") btkTools.smartWriter(acq, (self.m_c3dPath+filenameOut))
def test_correctForcePlateType5(self): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\ForcePlate\\ForcePlateTypeManagement\\" DATA_PATH_OUT = pyCGM2.TEST_DATA_PATH_OUT + "LowLevel\\ForcePlate\\ForcePlateTypeManagement\\" files.createDir(DATA_PATH_OUT) btkAcq = btkTools.smartReader(MAIN_PATH + "HUG_gait_type5.c3d") forceplates.correctForcePlateType5(btkAcq) btkTools.smartWriter(btkAcq, DATA_PATH_OUT + "HUG_gait_type5.c3d")
def basicCGM1_bodyBuilderFoot(cls): """ goal : know effet on Foot kinematics of a foot referential built according ta sequence metionned in some bodybuilder code: LFoot = [LTOE,LAJC-LTOE,LAJC-LKJC,zyx] """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\basic\\" staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model=cgm.CGM1LowerLimbs() model.configure() mp={ 'Bodymass' : 71.0, 'LeftLegLength' : 860.0, 'RightLegLength' : 865.0 , 'LeftKneeWidth' : 102.0, 'RightKneeWidth' : 103.4, 'LeftAnkleWidth' : 75.3, 'RightAnkleWidth' : 72.9, 'LeftSoleDelta' : 0, 'RightSoleDelta' : 0, } model.addAnthropoInputParameters(mp) scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model, useBodyBuilderFoot=True).compute() # ------ Test 1 Motion Axe X ------- gaitFilename="MRI-US-01, 2008-08-08, 3DGA 14.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) # Motion FILTER # optimisation segmentaire et calibration fonctionnel modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,pyCGM2Enums.motionMethod.Determinist) modMotion.compute() # relative angles modelFilters.ModelJCSFilter(model,acqGait).compute(description="vectoriel", pointLabelSuffix="cgm1_6dof") # absolute angles longitudinalAxis,forwardProgression,globalFrame = btkTools.findProgressionAxisFromPelvicMarkers(acqGait,["LASI","LPSI","RASI","RPSI"]) modelFilters.ModelAbsoluteAnglesFilter(model,acqGait, segmentLabels=["Left Foot","Right Foot","Pelvis"], angleLabels=["LFootProgress", "RFootProgress","Pelvis"], eulerSequences=["TOR","TOR", "TOR"], globalFrameOrientation = globalFrame, forwardProgression = forwardProgression).compute(pointLabelSuffix="cgm1_6dof") btkTools.smartWriter(acqGait, "testuseBodyBuilderFoot.c3d")
def advancedCGM11_KneeMedKad_TrueEquinus(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\kad-med-TrueEquinus\\" staticFilename = "static.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm.CGM1 model.configure() markerDiameter = 14 mp = { 'Bodymass': 36.9, 'LeftLegLength': 665.0, 'RightLegLength': 655.0, 'LeftKneeWidth': 102.7, 'RightKneeWidth': 100.2, 'LeftAnkleWidth': 64.5, 'RightAnkleWidth': 63.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } optional_mp = { 'InterAsisDistance': 0, 'LeftAsisTrocanterDistance': 0, 'LeftThighRotation': 0, 'LeftShankRotation': 0, 'LeftTibialTorsion': 0, 'RightAsisTrocanterDistance': 0, 'RightThighRotation': 0, 'RightShankRotation': 0, 'RightTibialTorsion': 0 } model.addAnthropoInputParameters(mp, optional=optional_mp) # -----------CGM STATIC CALIBRATION-------------------- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.Kad(model, acqStatic).compute() modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, side="both") modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() btkTools.smartWriter(acqStatic, "Kad-med-TrueEquinus.c3d")
def test_FullBody_noOptions(self): DATA_PATH = MAIN_PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\uncropped data\\cgm1\\" staticFilename = "static.c3d" DATA_PATH_OUT = pyCGM2.TEST_DATA_PATH_OUT+"LowLevel\\uncropped data\\cgm1\\" files.createDir(DATA_PATH_OUT) markerDiameter=14 leftFlatFoot = True rightFlatFoot = True headStraight = True pointSuffix = "" vskFile = vskTools.getVskFiles(DATA_PATH) vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk") required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True) model,finalAcqStatic = cgm1.calibrate(DATA_PATH, staticFilename, None, required_mp, optional_mp, leftFlatFoot, rightFlatFoot, headStraight, markerDiameter, pointSuffix, displayCoordinateSystem=True) # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d")) # logging.info("Static Calibration -----> Done") gaitFilename="gait1.c3d" acqGait0 = btkTools.smartReader(DATA_PATH + gaitFilename) trackingMarkers = model.getTrackingMarkers(acqGait0) validFrames,vff,vlf = btkTools.findValidFrames(acqGait0,trackingMarkers) mfpa = None reconstructFilenameLabelled = gaitFilename acqGait = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled, None, markerDiameter, pointSuffix, mfpa, enums.MomentProjection.Proximal, displayCoordinateSystem=True) btkTools.smartWriter(acqGait, DATA_PATH_OUT+"//gait1-processed.c3d")
def advancedCGM11_KneeMedKad(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\CGM1.1\medial\\" staticFilename = "static-all.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm.CGM1 model.configure() markerDiameter = 14 mp = { 'Bodymass': 71.0, 'LeftLegLength': 860.0, 'RightLegLength': 865.0, 'LeftKneeWidth': 102.0, 'RightKneeWidth': 103.4, 'LeftAnkleWidth': 75.3, 'RightAnkleWidth': 72.9, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } optional_mp = { 'InterAsisDistance': 0, 'LeftAsisTrocanterDistance': 0, 'LeftThighRotation': 0, 'LeftShankRotation': 0, 'LeftTibialTorsion': -10, 'RightAsisTrocanterDistance': 0, 'RightThighRotation': 0, 'RightShankRotation': 0, 'RightTibialTorsion': 15 } model.addAnthropoInputParameters(mp, optional=optional_mp) # -----------CGM STATIC CALIBRATION-------------------- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.KneeCalibrationDecorator(model).midCondyles_KAD( acqStatic) #modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, side="both") modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() btkTools.smartWriter(acqStatic, "advancedCGM11_KneeMedKad.c3d")
def cgm1(cls): """ GOAL : compare Joint centres and foot Offset """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\markerDecomposition\\CGM1decomposeTracking\\" # staticFilename = "static.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm.CGM1LowerLimbs() model.configure() markerDiameter = 14 mp = { 'Bodymass': 36.9, 'LeftLegLength': 665, 'RightLegLength': 655.0, 'LeftKneeWidth': 102.7, 'RightKneeWidth': 100.2, 'LeftAnkleWidth': 64.5, 'RightAnkleWidth': 63.4, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } model.addAnthropoInputParameters(mp) # CALIBRATION scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() print model.m_useRightTibialTorsion # --- Test 1 Motion Axe X ------- gaitFilename = "gait trial 01.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, pyCGM2Enums.motionMethod.Determinist, useForMotionTest=True) modMotion.compute() mtf = modelFilters.TrackingMarkerDecompositionFilter(model, acqGait) mtf.decompose() btkTools.smartWriter(acqGait, "cgm1-decompose.c3d")
def detection(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\event detection\\events\\" # --- Motion 1 gaitFilename = "gait-noEvents.c3d" acq = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) evp = events.ZeniProcedure() evf = events.EventFilter(evp, acq) evf.detect() btkTools.smartWriter("testEvent0.c3d", acq)
def processEMG(DATA_PATH, gaitTrials, emgChannels, highPassFrequencies=[20, 200], envelopFrequency=6.0, fileSuffix=None): """ processEMG_fromC3dFiles : filters emg channels from a list of c3d files :param DATA_PATH [String]: path to your folder :param gaitTrials [string List]:c3d files with emg signals :param emgChannels [string list]: label of your emg channels **optional** :param highPassFrequencies [list of float]: boundaries of the bandpass filter :param envelopFrequency [float]: cut-off frequency for creating an emg envelop :param fileSuffix [string]: suffix added to your ouput c3d files """ if fileSuffix is None: fileSuffix = "" for gaitTrial in gaitTrials: acq = btkTools.smartReader(DATA_PATH + gaitTrial) flag = False for channel in emgChannels: if not btkTools.isAnalogExist(acq, channel): logging.error("channel [%s] not detected in the c3d [%s]" % (channel, gaitTrial)) flag = True if flag: raise Exception( "[pyCGM2] One label has not been detected as analog. see above" ) bf = emgFilters.BasicEmgProcessingFilter(acq, emgChannels) bf.setHighPassFrequencies(highPassFrequencies[0], highPassFrequencies[1]) bf.run() envf = emgFilters.EmgEnvelopProcessingFilter(acq, emgChannels) envf.setCutoffFrequency(envelopFrequency) envf.run() outFilename = gaitTrial if fileSuffix == "" else gaitTrial + "_" + fileSuffix btkTools.smartWriter(acq, DATA_PATH + outFilename)
def test_CGM1_FullBody_noOptions_noFP(self): DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\CGM1\\fullBody-native-noOptions - noFP\\" staticFilename = "static.c3d" acqStatic = btkTools.smartReader(DATA_PATH + staticFilename) markerDiameter=14 leftFlatFoot = False rightFlatFoot = False headStraight = False pointSuffix = "test" vskFile = vskTools.getVskFiles(DATA_PATH) vsk = vskTools.Vsk(DATA_PATH + "New Subject.vsk") required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True) model,finalAcqStatic = cgm1.calibrate(DATA_PATH, staticFilename, None, required_mp, optional_mp, leftFlatFoot, rightFlatFoot, headStraight, markerDiameter, pointSuffix, displayCoordinateSystem=True) # btkTools.smartWriter(finalAcqStatic, str( staticFilename[:-4]+"-pyCGM2modelled.c3d")) # logging.info("Static Calibration -----> Done") gaitFilename="gait1.c3d" mfpa = None reconstructFilenameLabelled = gaitFilename acqGait = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled, None, markerDiameter, pointSuffix, mfpa, enums.MomentProjection.Proximal, displayCoordinateSystem=True) btkTools.smartWriter(acqGait, "gait1-pyCGM2modelled.c3d")
def cgm1_sacrum(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\Translators\\cgm1-sacr\\" staticFilename = "static.c3d" translators = files.getTranslators(MAIN_PATH, translatorType="CGM1.translators") acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) acqStatic2 = btkTools.applyTranslators(acqStatic, translators) btkTools.smartWriter(acqStatic2, "staticCGM1Sacrum.c3d") np.testing.assert_equal( acqStatic2.GetPoint("LPSI").GetValues(), acqStatic.GetPoint("SACR").GetValues()) np.testing.assert_equal( acqStatic2.GetPoint("RPSI").GetValues(), acqStatic.GetPoint("SACR").GetValues())
def fit_model_to_measurements(model, model_type, model_manager, data_path, point_suffix): processing_module = get_processing_module_alias(model_type) for dynamic_measurement in model_manager.dynamicTrials: fitting_settings = get_model_fitting_settings(model_type, dynamic_measurement, model, data_path, model_manager, point_suffix) filename = qtmTools.getFilename(dynamic_measurement) logging.info("----Processing of [%s]-----" % filename) file_path = os.path.join(data_path, filename) filter_data(file_path, dynamic_measurement) acqGait = processing_module.fitting(*fitting_settings) btkTools.smartWriter(acqGait, file_path)