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 noCroppedC3d(cls): NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() DATA_PATH = "C:\\Users\\HLS501\\Documents\\VICON DATA\\pyCGM2-Data\\NexusAPI\\BtkAcquisitionCreator\\sample0\\" filenameNoExt = "gait_noCropped" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) subject = NEXUS.GetSubjectNames()[0] trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( filenameNoExt, subject) root = trialConstructorFilter.build() trial0 = trialTools.smartTrialReader(DATA_PATH, str(filenameNoExt + ".c3d")) # firstFrame = (root.findChild(ma.T_TimeSequence,"LTHI").startTime()+0.01)*100.0 # firstFrame0 = (trial0.findChild(ma.T_TimeSequence,"LTHI").startTime()+0.01)*100.0 # # lastFrame = root.findChild(ma.T_TimeSequence,"LTHI").duration()*100.0 # lastFrame0 = trial0.findChild(ma.T_TimeSequence,"LTHI").duration()*100.0 # # np.testing.assert_equal(firstFrame,firstFrame0) # np.testing.assert_equal(lastFrame,lastFrame0) np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "LTHI").data(), root.findChild(ma.T_TimeSequence, "LTHI").data(), decimal=2) np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "Voltage.EMG1").data(), root.findChild(ma.T_TimeSequence, "Voltage.EMG1").data(), decimal=2) ma.io.write(root, "gait_noCropped_checked.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 interactiveCropping_fromCropped(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) NEXUS.SetTrialRegionOfInterest(300, 400) subject = NEXUS.GetSubjectNames()[0] trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, filenameNoExt, subject) trial = trialConstructorFilter.build() ma.io.write(trialConstructorFilter.m_root, "TestsNOX2d_interactiveCropping_fromCropped_openMA.c3d") trial0 = trialTools.smartTrialReader( DATA_PATH, "forCheckingInteractiveCropped\\gait_Cropped - 300-400.c3d") np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "LTHI").data(), trial.findChild(ma.T_TimeSequence, "LTHI").data(), decimal=2) np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "Voltage.EMG1").data(), trial.findChild(ma.T_TimeSequence, "Voltage.EMG1").data(), decimal=2)
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 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 temporalPlot_OneModelOutputPlot(cls): """ Plot only one Model output """ # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\plot\\gaitPlot\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] trial = trialTools.smartTrialReader(DATA_PATH, modelledFilenames[0]) fig = plt.figure() ax = plt.gca() plot.temporalPlot(ax, trial, "LPelvisAngles", 0, color="blue", title="test", xlabel="frame", ylabel="angle", ylim=None, legendLabel=None, customLimits=None) 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_withx2d\\" filenameNoExt = "gait_cropped" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) subject = NEXUS.GetSubjectNames()[0] trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( DATA_PATH, filenameNoExt, subject) trial = trialConstructorFilter.build() ma.io.write(trialConstructorFilter.m_root, "TestsX2d_croppedC3d_openma.c3d") trial0 = trialTools.smartTrialReader(DATA_PATH, str(filenameNoExt + ".c3d")) np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "LTHI").data(), trial.findChild(ma.T_TimeSequence, "LTHI").data(), decimal=2) np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "Voltage.EMG1").data(), trial.findChild(ma.T_TimeSequence, "Voltage.EMG1").data(), 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 gaitTrialGarches(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\progression\\" gaitFilename="gait_garches_issue2.c3d" trial = trialTools.smartTrialReader(MAIN_PATH,gaitFilename) longitudinalAxis,forwardProgression,globalFrame = trialTools.findProgression(trial,"RHEE") np.testing.assert_equal( longitudinalAxis,"Y") np.testing.assert_equal( forwardProgression,False) np.testing.assert_equal( globalFrame,"YXZ")
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 gaitTrialProgressionY_forward_lateralX(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\progression\\" gaitFilename = "gait_Y_forward.c3d" trial = trialTools.smartTrialReader(MAIN_PATH, gaitFilename) longitudinalAxis, forwardProgression, globalFrame = trialTools.findProgression( trial, "LPSI") np.testing.assert_equal(longitudinalAxis, "Y") np.testing.assert_equal(forwardProgression, True) np.testing.assert_equal(globalFrame, "YXZ") longitudinalAxisFoot, forwardProgressionFoot, globalFrameFoot = trialTools.findProgression( trial, "RHEE") np.testing.assert_equal(longitudinalAxis, "Y") np.testing.assert_equal(forwardProgression, True) np.testing.assert_equal(globalFrame, "YXZ")
def modelOutputs(cls): NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() DATA_PATH = "C:\\Users\\HLS501\\Documents\\VICON DATA\\pyCGM2-Data\\NexusAPI\\BtkAcquisitionCreator\\sample0\\" filenameNoExt = "gait_cropped_ModelOutputDynamic" NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30) subject = NEXUS.GetSubjectNames()[0] trialConstructorFilter = nexusFilters.NexusConstructTrialFilter( filenameNoExt, subject) root = trialConstructorFilter.build() trial0 = trialTools.smartTrialReader(DATA_PATH, str(filenameNoExt + ".c3d")) np.testing.assert_array_almost_equal( trial0.findChild(ma.T_TimeSequence, "LTHI").data(), root.findChild(ma.T_TimeSequence, "LTHI").data(), decimal=2) ma.io.write(root, str("modelOutputsOpenMA_checked.c3d"))
def test_temporalPlot_OneModelOutputPlot(self): """ Plot only one Model output """ # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitData\CGM1-NormalGaitData-Events\Hånnibøl Lecter\\" modelledFilenames = ["gait Trial 01.c3d"] trial = trialTools.smartTrialReader(DATA_PATH, modelledFilenames[0]) fig = plt.figure() ax = plt.gca() plot.temporalPlot(ax, trial, "LPelvisAngles", 0, color="blue", title="test", xlabel="frame", ylabel="angle", ylim=None, legendLabel=None, customLimits=None)
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 test_reader(self): trial = trialTools.smartTrialReader( pyCGM2.TEST_DATA_PATH + "LowLevel\\IO\\Hånnibøl_c3d\\", "static.c3d")
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()