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 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()