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 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 test_ForcePlateType5(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_origin.c3d") btkAcq_correct = btkTools.smartReader(MAIN_PATH + "HUG_gait_type5_convert.c3d") flabels = [ "Force.Fx0", "Force.Fx1", "Force.Fy0", "Force.Fy1", "Force.Fz0", "Force.Fz1" ] mlabels = [ "Moment.Mx0", "Moment.Mx1", "Moment.My0", "Moment.My1", "Moment.Mz0", "Moment.Mz1" ] for label in flabels: np.testing.assert_almost_equal( btkAcq.GetAnalog(label).GetValues(), btkAcq_correct.GetAnalog(label).GetValues(), decimal=2) for label in mlabels: np.testing.assert_almost_equal( btkAcq.GetAnalog(label).GetValues(), btkAcq_correct.GetAnalog(label).GetValues(), decimal=2)
def test_gaitEventsAnomalies(self): filename = pyCGM2.TEST_DATA_PATH + "/LowLevel/anomalies/gaitEvents/gait Trial 01-noAnomalies.c3d" acq = btkTools.smartReader(filename) madp = AnomalyDetectionProcedure.GaitEventAnomalyProcedure() adf = AnomalyFilter.AnomalyDetectionFilter(acq, filename, madp) adf.run() filename = pyCGM2.TEST_DATA_PATH + "/LowLevel/anomalies/gaitEvents/gait Trial 01-noEvents.c3d" acq = btkTools.smartReader(filename) madp = AnomalyDetectionProcedure.GaitEventAnomalyProcedure() adf = AnomalyFilter.AnomalyDetectionFilter( acq, filename[filename.rfind("/") + 1:], madp) adf.run() filename = pyCGM2.TEST_DATA_PATH + "/LowLevel/anomalies/gaitEvents/gait Trial 01-LeftDoubleFS_anomalies.c3d" acq = btkTools.smartReader(filename) madp = AnomalyDetectionProcedure.GaitEventAnomalyProcedure() adf = AnomalyFilter.AnomalyDetectionFilter( acq, filename[filename.rfind("/") + 1:], madp) adf.run() filename = pyCGM2.TEST_DATA_PATH + "/LowLevel/anomalies/gaitEvents/gait Trial 01-LeftDoubleFO_anomalies.c3d" acq = btkTools.smartReader(filename) madp = AnomalyDetectionProcedure.GaitEventAnomalyProcedure() adf = AnomalyFilter.AnomalyDetectionFilter( acq, filename[filename.rfind("/") + 1:], madp) adf.run()
def test_progressionFrameIssue(self): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "\\Issues\\BrianH\\progressionFrame Issue\\" gaitFilename = "walk09.c3d" acq = btkTools.smartReader(MAIN_PATH + gaitFilename) valSACR = acq.GetPoint(utils.str("SACR")).GetValues() btkTools.smartAppendPoint(acq, "RPSI", valSACR, desc="") btkTools.smartAppendPoint(acq, "LPSI", valSACR, desc="") pfp = progressionFrame.PelvisProgressionFrameProcedure() pff = progressionFrame.ProgressionFrameFilter(acq, pfp) pff.compute() np.testing.assert_equal(pff.outputs["progressionAxis"], "X") np.testing.assert_equal(pff.outputs["forwardProgression"], True) gaitFilename = "walk11.c3d" acq = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) valSACR = acq.GetPoint(utils.str("SACR")).GetValues() btkTools.smartAppendPoint(acq, "RPSI", valSACR, desc="") btkTools.smartAppendPoint(acq, "LPSI", valSACR, desc="") pfp = progressionFrame.PelvisProgressionFrameProcedure() pff = progressionFrame.ProgressionFrameFilter(acq, pfp) pff.compute() np.testing.assert_equal(pff.outputs["progressionAxis"], "X") np.testing.assert_equal(pff.outputs["forwardProgression"], True)
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 test_sample0(self): DATA_PATH = MAIN_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\CGM1\\fullBody-native-noOptions\\" 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) # calibration according CGM1 model, finalAcqStatic = cgm1.calibrate(DATA_PATH, staticFilename, None, required_mp, optional_mp, leftFlatFoot, rightFlatFoot, headStraight, markerDiameter, pointSuffix, displayCoordinateSystem=True) # no fitting operation, only checking of forceplateAssembly gaitFilename = "gait1.c3d" acqGait = btkTools.smartReader(DATA_PATH + gaitFilename) mfpa = None mappedForcePlate = forceplates.matchingFootSideOnForceplate(acqGait, mfpa=mfpa) forceplates.addForcePlateGeneralEvents(acqGait, mappedForcePlate) logging.warning("Manual Force plate assignment : %s" % mappedForcePlate) # assembly foot and force plate modelFilters.ForcePlateAssemblyFilter( model, acqGait, mappedForcePlate, leftSegmentLabel="Left Foot", rightSegmentLabel="Right Foot").compute( pointLabelSuffix=pointSuffix) testingUtils.plotComparisonOfPoint(acqGait, "RGroundReactionForce", "test") testingUtils.plotComparisonOfPoint(acqGait, "RGroundReactionMoment", "test")
def CGM1_UpperLimb(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\full-PiG\\" staticFilename = "PN01NORMSTAT.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model=cgm.CGM1() model.configure(bodyPart=enums.BodyPart.UpperLimb) markerDiameter=14 mp={ 'LeftShoulderOffset' : 50, 'LeftElbowWidth' : 91, 'LeftWristWidth' : 56 , 'LeftHandThickness' : 28 , 'RightShoulderOffset' : 45, 'RightElbowWidth' : 90, 'RightWristWidth' : 55 , 'RightHandThickness' : 30 } model.addAnthropoInputParameters(mp) # -----------CGM STATIC CALIBRATION-------------------- scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model,headFlat= True).compute() csp = modelFilters.ModelCoordinateSystemProcedure(model) # --- motion ---- gaitFilename="PN01NORMSS01.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,enums.motionMethod.Determinist) modMotion.compute() csdf = modelFilters.CoordinateSystemDisplayFilter(csp,model,acqGait) csdf.setStatic(False) csdf.display() # thorax R_thorax= model.getSegment("Thorax").anatomicalFrame.motion[10].getRotation() R_thorax_vicon = getViconRmatrix(10, acqGait, "TRXO", "TRXA", "TRXL", "XZY") np.testing.assert_almost_equal( R_thorax, R_thorax_vicon, decimal =3) # head R_head= model.getSegment("Head").anatomicalFrame.motion[10].getRotation() R_head_vicon = getViconRmatrix(10, acqGait, "HEDO", "HEDA", "HEDL", "XZY") np.testing.assert_almost_equal( R_head, R_head_vicon, decimal =2)
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 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 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 gapFilterTest(cls): DATA_PATH = "C:\\Users\\HLS501\\Documents\\VICON DATA\\pyCGM2-Data\\operations\\gapFilling\\gaitWithGaps_noX2d\\" acq = btkTools.smartReader(str(DATA_PATH + "gait_GAP.c3d")) acq_filled = btkTools.smartReader( str(DATA_PATH + "gait_GAP.-moGap.c3d")) gfp = gapFilling.LowDimensionalKalmanFilterProcedure() gff = gapFilling.GapFillingFilter(gfp, acq) gff.fill() filledAcq = gff.getFilledAcq() filledMarkers = gff.getFilledMarkers() for marker in filledMarkers: plt.plot(filledAcq.GetPoint(marker).GetValues(), "or") plt.plot(acq_filled.GetPoint(marker).GetValues(), "-g") plt.show()
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 test_temporalEmgPlot(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) #--------------------------settings------------------------------------- if os.path.isfile(DATA_PATH + "emg.settings"): emgSettings = files.openFile(DATA_PATH,"emg.settings") logging.warning("[pyCGM2]: emg.settings detected in the data folder") else: emgSettings = None manager = EmgManager.EmgConfigManager(None,localInternalSettings=emgSettings) manager.contruct() EMG_LABELS,EMG_MUSCLES,EMG_CONTEXT,NORMAL_ACTIVITIES = manager.getEmgConfiguration() rectifyBool=True acq = btkTools.smartReader(DATA_PATH+gaitTrial) analysis.processEMG_fromBtkAcq(acq, EMG_LABELS, highPassFrequencies=[20,200], envelopFrequency=6.0) openmaTrial = trialTools.convertBtkAcquisition(acq) plot.plotTemporalEMG(DATA_PATH,gaitTrial, EMG_LABELS,EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES,exportPdf=False,rectify=rectifyBool,openmaTrial=openmaTrial)
def gaitTrialProgressionY_forward_lateralX(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\progression\\" gaitFilename = "gait_Y_forward.c3d" acq = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) valSACR = (acq.GetPoint("LPSI").GetValues() + acq.GetPoint("RPSI").GetValues()) / 2.0 btkTools.smartAppendPoint(acq, "SACR", valSACR, desc="") valMidAsis = (acq.GetPoint("LASI").GetValues() + acq.GetPoint("RASI").GetValues()) / 2.0 btkTools.smartAppendPoint(acq, "midASIS", valMidAsis, desc="") validFrames, vff, vlf = btkTools.findValidFrames( acq, ["LPSI", "LASI", "RPSI"]) longitudinalAxis, forwardProgression, globalFrame = btkTools.findProgression( acq, "LASI") np.testing.assert_equal(longitudinalAxis, "Y") np.testing.assert_equal(forwardProgression, True) np.testing.assert_equal(globalFrame, "YXZ")
def test_interactiveCropping_fromCropped(self): NEXUS = ViconNexus.ViconNexus() DATA_PATH = pyCGM2.TEST_DATA_PATH + "NexusAPI\\BtkAcquisitionCreator\\sample_NOx2d\\" filenameNoExt = "gait_cropped" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) NEXUS.SetTrialRegionOfInterest(300, 400) subject = nexusTools.getActiveSubject(NEXUS) # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, filenameNoExt, subject) acq = nacf.build() acq0 = btkTools.smartReader( str(DATA_PATH + "forCheckingInteractiveCropped\\gait_cropped - 300-400.c3d")) 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 test_threePF_mfpaSupNumberForcePlates(self): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\ForcePlate\\ForcePlateAssignment\\" # --- Motion 1 gaitFilename = "walking_Y_3pf.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) #forceplates.appendForcePlateCornerAsMarker(acqGait) correctAssigmenent = "RLR" assignedMappedForcePlate1 = forceplates.matchingFootSideOnForceplate( acqGait, mfpa="XXXXXX") assert assignedMappedForcePlate1 == "XXX" assignedMappedForcePlate2 = forceplates.matchingFootSideOnForceplate( acqGait, mfpa="XXALR") assert assignedMappedForcePlate2 == "XXR" assignedMappedForcePlate3 = forceplates.matchingFootSideOnForceplate( acqGait, mfpa="AAALR") assert assignedMappedForcePlate3 == "RLR" assignedMappedForcePlate4 = forceplates.matchingFootSideOnForceplate( acqGait, mfpa="AXAXXX") assert assignedMappedForcePlate4 == "RXR"
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 test_functions(self): filename = pyCGM2.TEST_DATA_PATH + "LowLevel\\IO\\Hånnibøl_c3d\\gait1.c3d" acq = btkTools.smartReader(filename, translators=None) btkTools.GetMarkerNames(acq) btkTools.findNearestMarker(acq, 0, "LASI") btkTools.GetAnalogNames(acq) btkTools.isGap(acq, "LASI") btkTools.findMarkerGap(acq) btkTools.isPointExist(acq, "LASI") btkTools.isPointsExist(acq, ["LASI", "RASI"]) btkTools.clearPoints(acq, ["LASI", "RASI"]) btkTools.checkFirstAndLastFrame(acq, "LASI") btkTools.isGap_inAcq(acq, ["LASI", "RASI"]) btkTools.findValidFrames(acq, ["LASI", "RASI"]) btkTools.checkMultipleSubject(acq) btkTools.checkMarkers(acq, ["LASI", "RASI"]) btkTools.clearEvents(acq, ["Foot Strike"]) btkTools.modifyEventSubject(acq, "Hän") btkTools.modifySubject(acq, "Han") btkTools.getVisibleMarkersAtFrame(acq, ["LASI", "RASI"], 0) btkTools.isAnalogExist(acq, "emg-Hän") btkTools.createZeros(acq, ["LASI", "RASI"]) btkTools.constructEmptyMarker(acq, "zéros", desc="Hän") btkTools.getStartEndEvents(acq, "Left") btkTools.changeSubjectName(acq, "Hän") btkTools.smartGetMetadata(acq, "SUBJECTS", "USED") btkTools.smartSetMetadata(acq, "SUBJECTS", "USED", 0, "Hän")
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 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 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 gaitTrialProgressionY_backward_lateralX_static(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\progression\\" gaitFilename="static_Y_backward.c3d" acq = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) valSACR=(acq.GetPoint("LPSI").GetValues() + acq.GetPoint("RPSI").GetValues()) / 2.0 btkTools.smartAppendPoint(acq,"SACR",valSACR,desc="") valMidAsis=(acq.GetPoint("LASI").GetValues() + acq.GetPoint("RASI").GetValues()) / 2.0 btkTools.smartAppendPoint(acq,"midASIS",valMidAsis,desc="") longitudinalAxis,forwardProgression,globalFrame = btkTools.findProgressionAxisFromPelvicMarkers(acq,["LASI","LPSI","RASI","RPSI"]) np.testing.assert_equal( longitudinalAxis,"Y") np.testing.assert_equal( forwardProgression,False) np.testing.assert_equal( globalFrame,"YXZ") longitudinalAxis2,forwardProgression2,globalFrame2 = btkTools.findProgressionAxisFromLongAxis(acq,"LPSI","LASI") np.testing.assert_equal( longitudinalAxis2,"Y") np.testing.assert_equal( forwardProgression2,False) np.testing.assert_equal( globalFrame2,"YXZ")
def test_gaitTrialProgressionY_forward_lateralX(self): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\ProgressionFrame\\sample 1\\" gaitFilename = "gait_Y_forward.c3d" acq = btkTools.smartReader(MAIN_PATH + gaitFilename) pfp = progressionFrame.PelvisProgressionFrameProcedure() pff = progressionFrame.ProgressionFrameFilter(acq, pfp) pff.compute() np.testing.assert_equal(pff.outputs["progressionAxis"], "Y") np.testing.assert_equal(pff.outputs["forwardProgression"], True) np.testing.assert_equal(pff.outputs["globalFrame"], "YXZ") valSACR = (acq.GetPoint(utils.str("LPSI")).GetValues() + acq.GetPoint(utils.str("RPSI")).GetValues()) / 2.0 btkTools.smartAppendPoint(acq, "SACR", valSACR, desc="") pfp = progressionFrame.PelvisProgressionFrameProcedure( backMarkers=["SACR"]) pff = progressionFrame.ProgressionFrameFilter(acq, pfp) pff.compute() np.testing.assert_equal(pff.outputs["progressionAxis"], "Y") np.testing.assert_equal(pff.outputs["forwardProgression"], True) np.testing.assert_equal(pff.outputs["globalFrame"], "YXZ")
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 test_markerFiltering_gaps(self): PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\filtering\\" acq = btkTools.smartReader(PATH + "verif0.c3d") marker = "LFHD" # artificial gap for i in range(0, 10): acq.GetPoint(marker).SetValue(i, 1, 0) for i in range(100, 150): acq.GetPoint(marker).SetValue(i, 1, 0) array0 = acq.GetPoint(marker).GetValues()[:, 1] signal_processing.markerFiltering(acq, [marker], zerosFiltering=True, order=4, fc=6.0) array1 = acq.GetPoint(marker).GetValues()[:, 1] plt.plot(array0, '-b') plt.plot(array1, '-r') 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 test_noCroppedC3d(self): NEXUS = ViconNexus.ViconNexus() DATA_PATH = pyCGM2.TEST_DATA_PATH + "NexusAPI\\BtkAcquisitionCreator\\sample_withx2d\\" filenameNoExt = "gait_noCropped" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) subject = nexusTools.getActiveSubject(NEXUS) # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter( DATA_PATH, filenameNoExt, subject) acq = nacf.build() acq0 = btkTools.smartReader(str(DATA_PATH + filenameNoExt + ".c3d")) 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 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 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)