def processEMG_fromBtkAcq(acq, emgChannels, highPassFrequencies=[20, 200], envelopFrequency=6.0): """ processEMG_fromBtkAcq : filt emg from a btk acq :param acq [btk::Acquisition]: btk acquisition :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 """ bf = emgFilters.BasicEmgProcessingFilter(acq, emgChannels) bf.setHighPassFrequencies(highPassFrequencies[0], highPassFrequencies[1]) bf.run() envf = emgFilters.EmgEnvelopProcessingFilter(acq, emgChannels) envf.setCutoffFrequency(envelopFrequency) envf.run() return 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 EnveloppeProcessing(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,"test.c3d") values = acq.GetAnalog("EMG1_Rectify").GetValues()
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) 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 psd(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,"test.c3d") values = acq.GetAnalog("EMG1_Rectify").GetValues() fpcntile, mpf, fmax, Ptotal, f, P = signal_processing.psd(values[:,0],1000,show=True)
def test_envelopPlotSingleEmg(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_envelopPlotSingleEmg.c3d") modelledFilenames = ["test_envelopPlotSingleEmg.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","Left") envnf.setMaxMethod(enums.EmgAmplitudeNormalization.MeanMax) envnf.run() fig = plt.figure() ax = plt.gca() plot.gaitDescriptivePlot(ax,analysisInstance.emgStats, "EMG1_Rectify_Env","Left",0, color=None, title="title", xlabel=None, ylabel=None,ylim=None,legendLabel=None, customLimits=None) footOff = analysisInstance.emgStats.pst['stancePhase', "Left"]["mean"] plot.addNormalActivationLayer(ax,"RECFEM", footOff)
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 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()
def cycleAnalysis(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