def test_descriptiveKinematicPlotPanel_savePngAndPdf(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d","gait Trial 02.c3d"] DATA_PATH_OUT = pyCGM2.TEST_DATA_PATH_OUT+"GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" files.createDir(DATA_PATH_OUT) modelInfo=None subjectInfo=None experimentalInfo=None analysisInstance = analysis.makeAnalysis(DATA_PATH,modelledFilenames) # viewer kv = plotViewers.NormalizedKinematicsPlotViewer(analysisInstance) kv.setConcretePlotFunction(plot.descriptivePlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setExport(DATA_PATH_OUT,"test_descriptiveKinematicPlotPanel","png") pf.plot() # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setExport(DATA_PATH_OUT,"test_descriptiveKinematicPlotPanel","pdf") pf.plot()
def test_lowLevel_temporalEmgPlot_4channels(self): DATA_PATH, modelledFilenames,acq = dataTest2() fig = plt.figure() EMG_LABELS=['Voltage.EMG1','Voltage.EMG2','Voltage.EMG3','Voltage.EMG4'] bf = emgFilters.BasicEmgProcessingFilter(acq,EMG_LABELS) bf.setHighPassFrequencies(20.0,200.0) bf.run() # # viewer kv = emgPlotViewers.TemporalEmgPlotViewer(acq) kv.setEmgs([["Voltage.EMG1","Left","RF"],["Voltage.EMG2","Right","RF"], ["Voltage.EMG3","Left","vaste"],["Voltage.EMG4","Right","vaste"]]) kv.setNormalActivationLabels(["RECFEM","RECFEM",None,"VASLAT"]) kv. setEmgRectify(True) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) fig = pf.plot() # plt.show() if SHOW: plt.show() return fig
def test_gaitMeanOnlyKineticPlotPanel(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d","gait Trial 02.c3d"] #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysis1 = analysis.makeAnalysis(DATA_PATH,modelledFilenames) analysis2 = analysis.makeAnalysis(DATA_PATH,modelledFilenames) kv = ComparisonPlotViewers.KineticsPlotComparisonViewer([analysis1,analysis2],"Right", ["ana1","ana2"]) kv.setConcretePlotFunction(plot.gaitMeanPlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot()
def test_singleAnalysis(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d", "gait Trial 02.c3d"] #---- Analysis #-------------------------------------------------------------------------- modelInfo = None subjectInfo = None experimentalInfo = None analysisInstance = analysis.makeAnalysis(DATA_PATH, modelledFilenames) ndp = normativeDatasets.Schwartz2008("Free") gps = scores.CGM1_GPS() scf = scores.ScoreFilter(gps, analysisInstance, ndp) scf.compute() # viewer kv = plotViewers.GpsMapPlotViewer(analysisInstance) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot()
def test_gaitConsistencyKinematicPlotPanel(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d","gait Trial 02.c3d"] #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysisInstance = analysis.makeAnalysis(DATA_PATH,modelledFilenames) # viewer kv = plotViewers.NormalizedKinematicsPlotViewer(analysisInstance) kv.setConcretePlotFunction(plot.gaitConsistencyPlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot()
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 cgm_staticPlot(modelVersion, modelledStaticFilename, DATA_PATH, outputPath=None, pdfFilename="staticProcessing", pointLabelSuffix=""): # check model is the CGM1 logging.info("loaded model : %s" % (modelVersion)) if outputPath is None: outputPath = DATA_PATH trial = trialTools.smartTrialReader(DATA_PATH, modelledStaticFilename) #viewer if modelVersion in [ "CGM1.0", "CGM1.1", "CGM2.1", "CGM2.2", "CGM2.2e", "CGM2.3", "CGM2.3e" ]: kv = plotViewers.TemporalGaitKinematicsPlotViewer( trial, pointLabelSuffix=pointLabelSuffix) else: raise Exception("[pyCGM2] Model version not known") pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setPath(outputPath) pf.setPdfName(pdfFilename) pf.plot()
def gaitDescriptiveKinematicPlotPanel(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysisInstance = analysis.makeAnalysis("Gait", "CGM1.0", DATA_PATH,modelledFilenames,None, None, None) # viewer kv = plotViewers.LowerLimbKinematicsPlotViewer(analysisInstance) kv.setConcretePlotFunction(plot.gaitDescriptivePlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot() plt.show()
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 singleAnalysis(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure( DATA_PATH, modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo = None subjectInfo = None experimentalInfo = None analysisInstance = analysis.makeAnalysis(DATA_PATH, modelledFilenames, None, None, None) # viewer kv = plotViewers.SpatioTemporalPlotViewer(analysisInstance) kv.setNormativeDataset(normativeDatasets.NormalSTP()) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setExport(DATA_PATH, "stp", "pdf") pf.plot() plt.show()
def plot_MAP(DATA_PATH, analysis, normativeDataset, exportPdf=False, outputName=None, pointLabelSuffix=None, show=True, title=None, exportPng=False): """ plot_MAP : display the Movement Analysis Profile :param DATA_PATH [str]: path to your data :param analysis [pyCGM2.Processing.analysis.Analysis]: pyCGM2 analysis instance :param normativeDataset [pyCGM2.Report.normativeDatasets]: pyCGM2 normative dataset instance **optional** :param pointLabelSuffix [string]: (None) suffix added to outputs :param exportPdf [bool]: save as pdf (False[default]) :param outputName [string]: name of your pdf file (None[default] export your pdf with name : Global Analysis) :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel """ if outputName is None: outputName = "PyCGM2-Analysis" if exportPdf or exportPng: filenameOut = outputName + "-Map" #compute gps = scores.CGM1_GPS(pointSuffix=pointLabelSuffix) scf = scores.ScoreFilter(gps, analysis, normativeDataset) scf.compute() #plot kv = plotViewers.GpsMapPlotViewer(analysis, pointLabelSuffix=pointLabelSuffix) pf = plotFilters.PlottingFilter() pf.setViewer(kv) if exportPdf: pf.setExport(DATA_PATH, filenameOut, "pdf") if title is not None: pf.setTitle(title + "-Map") fig = pf.plot() if show: plt.show() if exportPng: fig.savefig(DATA_PATH + filenameOut + ".png") return fig, filenameOut + ".png" else: return fig
def test_temporalKineticPlotPanel(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d", "gait Trial 02.c3d"] trial = trialTools.smartTrialReader(DATA_PATH, modelledFilenames[0]) # viewer kv = plotViewers.TemporalKineticsPlotViewer(trial) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot()
def temporalKineticPlotPanel(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] trial = trialTools.smartTrialReader(DATA_PATH, modelledFilenames[0]) # viewer kv = plotViewers.TemporalGaitKineticsPlotViewer(trial) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot() plt.show()
def test_lowLevel_NormalizedKinematicsPlotViewer(self): DATA_PATH, analysisInstance = dataTest1() normativeDataset = normativeDatasets.NormativeData( "Schwartz2008", "Free") # viewer kv = plotViewers.NormalizedKinematicsPlotViewer(analysisInstance) kv.setConcretePlotFunction(reportPlot.gaitDescriptivePlot) kv.setNormativeDataset(normativeDataset) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) fig = pf.plot() if SHOW: plt.show() return fig
def plot_spatioTemporal(DATA_PATH, analysis, exportPdf=False, outputName=None, show=True, title=None, exportPng=False): """ plot_spatioTemporal : display spatio-temporal parameters as horizontal histogram :param DATA_PATH [str]: path to your data :param analysis [pyCGM2.Processing.analysis.Analysis]: pyCGM2 analysis instance **optional** :param exportPdf [bool]: save as pdf (False[default]) :param outputName [string]: name of your pdf file (None[default] export your pdf with name : Global Analysis) :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel """ if outputName is None: outputName = "pyCGM2-analysis" if exportPdf or exportPng: filenameOut = outputName + "-SpatioTemporal parameters" stpv = plotViewers.SpatioTemporalPlotViewer(analysis) stpv.setNormativeDataset(normativeDatasets.NormalSTP()) # filter stppf = plotFilters.PlottingFilter() stppf.setViewer(stpv) if title is not None: stppf.setTitle(title + "-SpatioTemporal parameters") if exportPdf: stppf.setExport(DATA_PATH, filenameOut, "pdf") fig = stppf.plot() if show: plt.show() if exportPng: fig.savefig(DATA_PATH + filenameOut + ".png") return fig, filenameOut + ".png" else: return fig
def gaitMeanOnlyKineticPlotPanel(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysis1 = gaitSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo,subjectInfo,experimentalInfo) analysis2 = gaitSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo,subjectInfo,experimentalInfo) kv = plotViewers.multipleAnalyses_LowerLimbKineticsPlotViewer([analysis1,analysis2],"Right", ["ana1","ana2"]) kv.setConcretePlotFunction(plot.gaitMeanPlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot() plt.show()
def singleAnalysis(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysis = gaitSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo,subjectInfo,experimentalInfo) ndp = normativeDatasets.Schwartz2008("Free") gps =scores.CGM1_GPS() scf = scores.ScoreFilter(gps,analysis, ndp) scf.compute() # viewer kv = plotViewers.GpsMapPlotViewer(analysis) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setPath(DATA_PATH) pf.setPdfName(str("map")) pf.plot() plt.show()
def gaitDescriptiveKinematicPlotPanel(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysis = gaitSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo,subjectInfo,experimentalInfo) # viewer kv = plotViewers.LowerLimbKinematicsPlotViewer(analysis) kv.setConcretePlotFunction(plot.gaitDescriptivePlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot() ka = annotator.Annotator(pf.fig) ka.IncreasedRange(0,40,10,40, "Context", timing="Throughout Cycle") print(ka.getAnnotations()) plt.show()
def singleAnalysis(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure( DATA_PATH, modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo = None subjectInfo = None experimentalInfo = None analysisInstance = analysis.makeAnalysis("Gait", "CGM1.0", DATA_PATH, modelledFilenames, None, None, None) ndp = normativeDatasets.Schwartz2008("Free") gps = scores.CGM1_GPS() scf = scores.ScoreFilter(gps, analysisInstance, ndp) scf.compute() # viewer kv = plotViewers.GpsMapPlotViewer(analysisInstance) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setPath(DATA_PATH) pf.setPdfName(str("map")) pf.plot() plt.show()
def gaitDescriptiveKinematicPlotPanel_recorded(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo=None subjectInfo=None experimentalInfo=None analysis = gaitSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo,subjectInfo,experimentalInfo) # viewer kv = plotViewers.LowerLimbKinematicsPlotViewer(analysis) kv.setConcretePlotFunction(plot.gaitDescriptivePlot) kv.setNormativeDataset(normativeDatasets.Schwartz2008("Free")) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setExport("C:\\Users\\HLS501\\Desktop\\","test","png") pf.plot() plt.show()
def test_singleAnalysis(self): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d", "gait Trial 02.c3d"] #---- Analysis #-------------------------------------------------------------------------- modelInfo = None subjectInfo = None experimentalInfo = None analysisInstance = analysis.makeAnalysis(DATA_PATH, modelledFilenames) # viewer kv = plotViewers.SpatioTemporalPlotViewer(analysisInstance) kv.setNormativeDataset(normativeDatasets.NormalSTP()) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot()
def singleAnalysis(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure( DATA_PATH, modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- modelInfo = None subjectInfo = None experimentalInfo = None analysis = gaitSmartFunctions.make_analysis( trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo, subjectInfo, experimentalInfo) # viewer kv = plotViewers.SpatioTemporalPlotViewer(analysis) kv.setNormativeDataset(normativeDatasets.NormalSTP()) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.setExport(DATA_PATH, "stp", "pdf") pf.plot() plt.show()
def compareKinetic(analyses, legends, context, bodyPart, normativeDataset, plotType="Descriptive", type="Gait", pointSuffixes=None, show=True, title=None): """ compareKinetic : compare kinetics of two pyCGM2 analysis instances :param analysis [pyCGM2.Processing.analysis.Analysis list]: list of pyCGM2 analysis instances :param legends [string list]: legend of each analysis instance :param context [string]: gait context (choice: Left, Right) :param bodyPart [str]: body part (choice : LowerLimb, Trunk, UpperLimb) :param normativeDataset [pyCGM2.Report.normativeDatasets]: pyCGM2 normative dataset instance **optional** :param plotType [string]: trace type ( Descriptive [default] or Consistency) :param type [string]: display events (Gait [defaut] or None) :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel :example: >>> normativeData = normativeDatasets.Schwartz2008("Free") >>> plot.compareKinetic([analysisPre,analysisPost],["pre","post"],"Left","LowerLimb",normativeData) """ i = 1 for analysis in analyses: if analysis.kineticStats.data == {}: raise Exception( "[pyCGM2]: Kinetic comparison aborted. Analysis [%i] has no kinetic data" % (i)) i += 1 if bodyPart == "LowerLimb": bodyPart = enums.BodyPartPlot.LowerLimb elif bodyPart == "Trunk": bodyPart = enums.BodyPartPlot.Trunk elif bodyPart == "UpperLimb": bodyPart = enums.BodyPartPlot.UpperLimb else: raise Exception( "[pyCGM2] - bodyPart argument not recognized ( must be LowerLimb, Trunk or UpperLimb) " ) kv = ComparisonPlotViewers.KineticsPlotComparisonViewer( analyses, context, legends, bodyPart=bodyPart, pointLabelSuffix_lst=pointSuffixes) if plotType == "Descriptive": kv.setConcretePlotFunction( plot.gaitDescriptivePlot ) if type == "Gait" else kv.setConcretePlotFunction( plot.descriptivePlot) elif plotType == "Consistency": kv.setConcretePlotFunction( plot.gaitConsistencyPlot ) if type == "Gait" else kv.setConcretePlotFunction( plot.consistencyPlot) if normativeDataset is not None: kv.setNormativeDataset(normativeDataset) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) #pf.setExport(outputPath,str(pdfFilename+"-consisntency Kinematics"),"pdf") if title is not None: pf.setTitle(str(title + "-Kinetic comparison")) pf.plot() if show: plt.show()
def test_envelopGaitPlotPanel(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'] acq = btkTools.smartReader(DATA_PATH +gaitTrial) bf = emgFilters.BasicEmgProcessingFilter(acq,EMG_LABELS) bf.setHighPassFrequencies(20.0,200.0) bf.run() envf = emgFilters.EmgEnvelopProcessingFilter(acq,EMG_LABELS) envf.setCutoffFrequency(180.0) envf.run() btkTools.smartWriter(acq,DATA_PATH_OUT+"test_envelopGaitPlotPanel.c3d") modelledFilenames = ["test_envelopGaitPlotPanel.c3d"] c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH_OUT,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableSpatioTemporal(False) cmf.enableKinematic(False) cmf.enableKinetic(False) cmf.enableEmg(True) trialManager = cmf.generate() #---- GAIT CYCLES FILTER #-------------------------------------------------------------------------- cycleBuilder = cycle.GaitCyclesBuilder(spatioTemporalTrials=trialManager.spatioTemporal["Trials"], kinematicTrials = trialManager.kinematic["Trials"], kineticTrials = trialManager.kinetic["Trials"], emgTrials=trialManager.emg["Trials"]) cyclefilter = cycle.CyclesFilter() cyclefilter.setBuilder(cycleBuilder) cycles = cyclefilter.build() modelInfo=None subjectInfo=None experimentalInfo=None analysisBuilder = analysis.GaitAnalysisBuilder(cycles, kinematicLabelsDict = None, kineticLabelsDict = None, emgLabelList = ['EMG1_Rectify_Env','EMG2_Rectify_Env'], subjectInfos=subjectInfo, modelInfos=modelInfo, experimentalInfos=experimentalInfo) analysisFilter = analysis.AnalysisFilter() analysisFilter.setBuilder(analysisBuilder) analysisFilter.setInfo(model = modelInfo) analysisFilter.build() analysisInstance = analysisFilter.analysis envnf = emgFilters.EmgNormalisationProcessingFilter(analysisInstance,"EMG1","Right") envnf.setMaxMethod(enums.EmgAmplitudeNormalization.MeanMax) envnf.run() envnf = emgFilters.EmgNormalisationProcessingFilter(analysisInstance,"EMG2","Right") envnf.setMaxMethod(enums.EmgAmplitudeNormalization.MeanMax) envnf.run() data = analysisInstance.emgStats.data # viewer kv = emgPlotViewers.EnvEmgGaitPlotPanelViewer (analysisInstance) kv.setEmgs([["EMG1","Right","rf"],["EMG2","Right","rf"]]) kv.setNormalActivationLabels(["RECFEM","RECFEM"]) kv.setConcretePlotFunction(plot.gaitDescriptivePlot) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot()
def plotTemporalEMG(DATA_PATH, processedEmgfile, emgChannels, muscles, contexts, normalActivityEmgs, rectify=True, exportPdf=False, outputName=None, show=True, title=None, openmaTrial=None): """ plotTemporalEMG : display temporal trace of EMG signals :param DATA_PATH [str]: path to your data :param processedEmgfile [string]: c3d file :param emgChannels [string list]: labels of your emg channels :param muscles [string list]: muscle labels associated with your emg channels :param contexts [string list]: contexts associated with your emg channel :param normalActivityEmgs [string list]: normal activities associated with your emg channels :param openmaTrial [openma::Trial]: force use of an openma trial instance **optional** :param rectify [bool]: plot rectify signals (True[default]) :param exportPdf [bool]: save as pdf (False[default]) :param outputName [string]: name of the output filed :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel """ if openmaTrial is not None: trial = openmaTrial else: trial = trialTools.smartTrialReader(DATA_PATH, processedEmgfile) emgChannels_list = [ emgChannels[i:i + 10] for i in range(0, len(emgChannels), 10) ] contexts_list = [contexts[i:i + 10] for i in range(0, len(contexts), 10)] muscles_list = [muscles[i:i + 10] for i in range(0, len(muscles), 10)] normalActivityEmgs_list = [ normalActivityEmgs[i:i + 10] for i in range(0, len(normalActivityEmgs), 10) ] pageNumber = len(emgChannels_list) count = 0 for i in range(0, pageNumber): if exportPdf and pageNumber > 1: if outputName is None: filenameOut = str( processedEmgfile + "-TemporalEmgPlot" + "[rectify]-") + str(count) if rectify else str( processedEmgfile + "-TemporalEmgPlot" + "[raw]-") + str(count) else: filenameOut = str( outputName + "-TemporalEmgPlot" + "[rectify]-") + str( count) if rectify else str(title + "-TemporalEmgPlot" + "[raw]-") + str(count) else: if outputName is None: filenameOut = str(processedEmgfile + "-TemporalEmgPlot" + "[rectify]") if rectify else str( processedEmgfile + "-TemporalEmgPlot" + "[raw]") else: filenameOut = str(outputName + "-TemporalEmgPlot" + "[rectify]") if rectify else str( title + "-TemporalEmgPlot" + "[raw]") combinedEMGcontext = [] for j in range(0, len(emgChannels_list[i])): combinedEMGcontext.append([ emgChannels_list[i][j], contexts_list[i][j], muscles_list[i][j] ]) # # viewer kv = emgPlotViewers.TemporalEmgPlotViewer(trial) kv.setEmgs(combinedEMGcontext) kv.setNormalActivationLabels(normalActivityEmgs_list[i]) kv.setEmgRectify(rectify) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) if title is not None: if pageNumber > 1: pf.setTitle( str(title + "-TemporalEmgPlot" + "[rectify]-") + str(count) if rectify else str(title + "-TemporalEmgPlot" + "[raw]-") + str(count)) else: pf.setTitle( str(title + "-TemporalEmgPlot" + "[rectify]") if rectify else str(title + "-TemporalEmgPlot" + "[raw]")) if exportPdf: pf.setExport(DATA_PATH, filenameOut, "pdf") pf.plot() count += 1 if show: plt.show()
def plotConsistencyEnvelopEMGpanel(DATA_PATH, analysis, emgChannels, muscles, contexts, normalActivityEmgs, normalized=False, type="Gait", exportPdf=False, outputName=None, show=True, title=None): """ plotConsistencyEnvelopEMGpanel : display all cycle of time-normalized traces of EMG envelops :param DATA_PATH [str]: path to your data :param analysis [pyCGM2.Processing.analysis.Analysis]: pyCGM2 analysis instance :param emgChannels [string list]: labels of your emg channels :param muscles [string list]: muscle labels associated with your emg channels :param contexts [string list]: contexts associated with your emg channels :param normalActivityEmgs [string list]: normal activities associated with your emg channels **optional** :param normalized [bool]: (**default**: False) plot normalized amplitude envelops :param type [string]: display gait events ( other choice than gait [default], display foot strikes only) :param exportPdf [bool]: save as pdf (False[default]) :param outputName [string]: name of your pdf file (None[default] export your pdf with name : Global Analysis) :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel """ if outputName is None: outputName = "Global Analysis" if exportPdf: filenameOut = str(outputName + "-ConsistencyEmgEnv" + "[No Normalized]-") if not normalized else str( outputName + "-DescriptiveEmgEnv" + "[Normalized]") # viewer combinedEMGcontext = [] for i in range(0, len(emgChannels)): combinedEMGcontext.append([emgChannels[i], contexts[i], muscles[i]]) kv = emgPlotViewers.EnvEmgGaitPlotPanelViewer(analysis) kv.setEmgs(combinedEMGcontext) kv.setNormalActivationLabels(normalActivityEmgs) kv.setNormalizedEmgFlag(normalized) if type == "Gait": kv.setConcretePlotFunction(plot.gaitConsistencyPlot) else: kv.setConcretePlotFunction(plot.consistencyPlot) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) if title is not None: pf.setTitle( str(title + "-ConsistencyEmgEnv" + "[No Normalized]-" ) if not normalized else str(title + "-DescriptiveEmgEnv" + "[Normalized]")) if exportPdf: pf.setExport(DATA_PATH, filenameOut, "pdf") pf.plot() if show: plt.show()
def plot_ConsistencyKinetic(DATA_PATH, analysis, bodyPart, normativeDataset, pointLabelSuffix=None, type="Gait", exportPdf=False, outputName=None, show=True, title=None): """ plot_ConsistencyKinetic : display all gait cycle of time-normalized kinetic outputs :param DATA_PATH [str]: path to your data :param analysis [pyCGM2.Processing.analysis.Analysis]: pyCGM2 analysis instance :param bodyPart [str]: body part (choice : LowerLimb, Trunk, UpperLimb) :param normativeDataset [pyCGM2.Report.normativeDatasets]: pyCGM2 normative dataset instance **optional** :param pointLabelSuffix [string]: suffix previously added to your model outputs :param type [string]: display gait events ( other choice than gait [default], display foot strikes only) :param exportPdf [bool]: save as pdf (False[default]) :param outputName [string]: name of your pdf file (None[default] export your pdf with name : Global Analysis) :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel """ if bodyPart == "LowerLimb": bodyPart = enums.BodyPartPlot.LowerLimb elif bodyPart == "Trunk": bodyPart = enums.BodyPartPlot.Trunk elif bodyPart == "UpperLimb": bodyPart = enums.BodyPartPlot.UpperLimb else: raise Exception( "[pyCGM2] - bodyPart argument not recognized ( must be LowerLimb, Trunk or UpperLimb) " ) if outputName is None: outputName = "Global Analysis [" + bodyPart.name + "]" if exportPdf: filenameOut = str(outputName + "-consistency Kinetics [" + bodyPart.name + "]") kv = plotViewers.NormalizedKineticsPlotViewer( analysis, pointLabelSuffix=pointLabelSuffix, bodyPart=bodyPart) if type == "Gait": kv.setConcretePlotFunction(plot.gaitConsistencyPlot) else: kv.setConcretePlotFunction(plot.consistencyPlot) if normativeDataset is not None: kv.setNormativeDataset(normativeDataset) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) if exportPdf: pf.setExport(DATA_PATH, filenameOut, "pdf") if title is not None: pf.setTitle( str(title + "-consistency Kinetics [" + bodyPart.name + "]")) pf.plot() if show: plt.show()
def plotTemporalKinetic(DATA_PATH, modelledFilenames, bodyPart, pointLabelSuffix=None, exportPdf=False, outputName=None, show=True, title=None, openmaTrial=None): """ plotTemporalKinetic : display temporal trace of the Kinetics :param DATA_PATH [str]: path to your data :param modelledFilenames [string list]: c3d files :param bodyPart [str]: body part (choice : LowerLimb, Trunk, UpperLimb) **optional** :param pointLabelSuffix [string]: suffix previously added to your model outputs :param exportPdf [bool]: save as pdf (False[default]) :param outputName [string]: name of the output filed :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel :param openmaTrial [openma::Trial]: force use of an openma trial instance Examples: """ if bodyPart == "LowerLimb": bodyPart = enums.BodyPartPlot.LowerLimb elif bodyPart == "Trunk": bodyPart = enums.BodyPartPlot.Trunk elif bodyPart == "UpperLimb": bodyPart = enums.BodyPartPlot.UpperLimb else: raise Exception( "[pyCGM2] - bodyPart argument not recognized ( must be LowerLimb, Trunk or UpperLimb) " ) if exportPdf: if outputName is None: filenameOut = str(modelledFilenames + "-Temporal Kinetics[" + bodyPart.name + "]") else: filenameOut = str(outputName + "-Temporal Kinetics [" + bodyPart.name + "]") if openmaTrial is not None: trial = openmaTrial trialTools.sortedEvents(trial) else: trial = trialTools.smartTrialReader(DATA_PATH, modelledFilenames) kv = plotViewers.TemporalKineticsPlotViewer( trial, pointLabelSuffix=pointLabelSuffix, bodyPart=bodyPart) # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) if title is not None: pf.setTitle(str(title + "-Temporal Kinetics [" + bodyPart.name + "]")) if exportPdf: pf.setExport(DATA_PATH, filenameOut, "pdf") pf.plot() if show: plt.show()
def compareEmgEnvelops(analyses, legends, emgChannels, muscles, contexts, normalActivityEmgs, normalized=False, plotType="Descriptive", show=True, title=None, type="Gait"): """ compareEmgEvelops : compare emg envelops from two pyCGM2 analysis instances :param analysis [pyCGM2.Processing.analysis.Analysis list]: list of pyCGM2 analysis instances :param legends [string list]: legend of each analysis instance :param emgChannels [string list]: label of your emg channels :param muscles [string list]: muscle label associated with your emg channels :param contexts [string list]: context associated with your emg channels :param normalActivityEmgs [string list]: normal activity associated with your emg channels **optional** :param normalized [bool]: plot normalized-amplitude envelops :param plotType [string]: trace type ( Descriptive [default] or Consistency) :param show [bool]: enable matplotlib show function :param title [string]: change default title of the plot panel :example: >> plot.compareEmgEvelops([emgAnalysisPre,emgAnalysisPost], >>> ["Pre","Post"], >>> ["EMG1","EMG2"] >>> ["Left","Right"] >>> ["RECFEM","VASLAT"]) """ i = 1 for analysis in analyses: if analysis.emgStats.data == {}: raise Exception( "[pyCGM2]: EMG comparison aborted. Analysis [%i] has no emg data" % (i)) i += 1 combinedEMGcontext = [] for i in range(0, len(emgChannels)): combinedEMGcontext.append([emgChannels[i], contexts[i], muscles[i]]) kv = emgPlotViewers.MultipleAnalysis_EnvEmgPlotPanelViewer( analyses, legends) kv.setEmgs(combinedEMGcontext) kv.setNormalActivationLabels(normalActivityEmgs) if normalized: kv.setNormalizedEmgFlag(True) if type == "Gait": if plotType == "Descriptive": kv.setConcretePlotFunction(plot.gaitDescriptivePlot) elif plotType == "Consistency": kv.setConcretePlotFunction(plot.gaitConsistencyPlot) else: if plotType == "Descriptive": kv.setConcretePlotFunction(plot.descriptivePlot) elif plotType == "Consistency": kv.setConcretePlotFunction(plot.consistencyPlot) # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) #pf.setExport(outputPath,str(pdfFilename+"-consisntency Kinematics"),"pdf") if title is not None: pf.setTitle(str(title + "-EMG envelop comparison")) pf.plot() if show: plt.show()
def EnvelopCoactivationPlot(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "EMG\\SampleNantes\\" gaitTrial = "gait.c3d" restTrial = "repos.c3d" EMG_LABELS = ['EMG1', 'EMG2'] acq = btkTools.smartReader(DATA_PATH + gaitTrial) bf = emgFilters.BasicEmgProcessingFilter(acq, EMG_LABELS) bf.setHighPassFrequencies(20.0, 200.0) bf.run() envf = emgFilters.EmgEnvelopProcessingFilter(acq, EMG_LABELS) envf.setCutoffFrequency(180.0) envf.run() btkTools.smartWriter(acq, DATA_PATH + "test.c3d") modelledFilenames = ["test.c3d"] c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure( DATA_PATH, modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableSpatioTemporal(False) cmf.enableKinematic(False) cmf.enableKinetic(False) cmf.enableEmg(True) trialManager = cmf.generate() #---- GAIT CYCLES FILTER #-------------------------------------------------------------------------- cycleBuilder = cycle.GaitCyclesBuilder( spatioTemporalTrials=trialManager.spatioTemporal["Trials"], kinematicTrials=trialManager.kinematic["Trials"], kineticTrials=trialManager.kinetic["Trials"], emgTrials=trialManager.emg["Trials"]) cyclefilter = cycle.CyclesFilter() cyclefilter.setBuilder(cycleBuilder) cycles = cyclefilter.build() modelInfo = None subjectInfo = None experimentalInfo = None analysisBuilder = analysis.GaitAnalysisBuilder( cycles, kinematicLabelsDict=None, kineticLabelsDict=None, emgLabelList=['EMG1_Rectify_Env', 'EMG2_Rectify_Env'], subjectInfos=subjectInfo, modelInfos=modelInfo, experimentalInfos=experimentalInfo) analysisFilter = analysis.AnalysisFilter() analysisFilter.setBuilder(analysisBuilder) analysisFilter.setInfo(model=modelInfo) analysisFilter.build() analysisInstance = analysisFilter.analysis envnf = emgFilters.EmgNormalisationProcessingFilter( analysisInstance, "EMG1", "Left") envnf.setMaxMethod(enums.EmgAmplitudeNormalization.MeanMax) envnf.run() envnf = emgFilters.EmgNormalisationProcessingFilter( analysisInstance, "EMG2", "Left") envnf.setMaxMethod(enums.EmgAmplitudeNormalization.MeanMax) envnf.run() # viewer kv = emgPlotViewers.CoactivationEmgPlotViewer(analysisInstance) kv.setEmgs("EMG1", "EMG2") kv.setMuscles("RF1", "RF2") kv.setConcretePlotFunction(plot.gaitDescriptivePlot) kv.setContext("Left") # # filter pf = plotFilters.PlottingFilter() pf.setViewer(kv) pf.plot() plt.show()