def test_onlyAnalogsInAcq_withoutFsBoundaries(self): DATA_PATH = pyCGM2.TEST_DATA_PATH + "LowLevel\\c3OnlyAnalog\\gait\\" EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES = configuration.getEmgConfiguration( None, None) emgTrials_pre = [ "20191120-CN-PRE-Testing-NNNS-dyn 09_withoutFSboundaries.c3d" ] emgTrials_post = [ "20191120-CN-POST-testing-NNNNS-dyn 20_withoutFSBoundaries.c3d" ] analysis.processEMG(DATA_PATH, emgTrials_pre, EMG_LABELS, highPassFrequencies=[20, 200], envelopFrequency=6, fileSuffix=None) preAnalysis = analysis.makeEmgAnalysis(DATA_PATH, emgTrials_pre, EMG_LABELS, type="testing") analysis.normalizedEMG(preAnalysis, EMG_LABELS, EMG_CONTEXT, method="MeanMax") analysis.processEMG(DATA_PATH, emgTrials_post, EMG_LABELS, highPassFrequencies=[20, 200], envelopFrequency=6, fileSuffix=None) postAnalysis = analysis.makeEmgAnalysis(DATA_PATH, emgTrials_post, EMG_LABELS, type="testing") analysis.normalizedEMG(postAnalysis, EMG_LABELS, EMG_CONTEXT, method="MeanMax") plot.compareEmgEnvelops([preAnalysis, postAnalysis], ["pre", "post"], EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES, type="testing") plot.compareSelectedEmgEvelops([preAnalysis, postAnalysis], ["pre", "post"], ["Voltage.EMG1", "Voltage.EMG1"], ["Left", "Left"], type="testing", title="comparison", plotType="Descriptive")
def main(args): NEXUS = ViconNexus.ViconNexus() NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected() if NEXUS_PYTHON_CONNECTED: # run Operation # --- acquisition file and path---- DATA_PATH, inputFileNoExt = NEXUS.GetTrialName() inputFile = inputFileNoExt+".c3d" #--------------------------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() # ----------------------INPUTS------------------------------------------- bandPassFilterFrequencies = manager.BandpassFrequencies#emgSettings["Processing"]["BandpassFrequencies"] if args.BandpassFrequencies is not None: if len(args.BandpassFrequencies) != 2: raise Exception("[pyCGM2] - bad configuration of the bandpass frequencies ... set 2 frequencies only") else: bandPassFilterFrequencies = [float(args.BandpassFrequencies[0]),float(args.BandpassFrequencies[1])] logging.info("Band pass frequency set to %i - %i instead of 20-200Hz",bandPassFilterFrequencies[0],bandPassFilterFrequencies[1]) envelopCutOffFrequency = manager.EnvelopLowpassFrequency#emgSettings["Processing"]["EnvelopLowpassFrequency"] if args.EnvelopLowpassFrequency is not None: envelopCutOffFrequency = args.EnvelopLowpassFrequency logging.info("Cut-off frequency set to %i instead of 6Hz ",envelopCutOffFrequency) consistencyFlag = True if args.consistency else False # --------------------------SUBJECT ------------------------------------ subjects = NEXUS.GetSubjectNames() subject = nexusTools.checkActivatedSubject(NEXUS,subjects) # btkAcq builder nacf = nexusFilters.NexusConstructAcquisitionFilter(DATA_PATH,inputFileNoExt,subject) acq = nacf.build() # --------------emg Processing-------------- EMG_LABELS,EMG_MUSCLES,EMG_CONTEXT,NORMAL_ACTIVITIES = manager.getEmgConfiguration() analysis.processEMG_fromBtkAcq(acq, EMG_LABELS, highPassFrequencies=bandPassFilterFrequencies, envelopFrequency=envelopCutOffFrequency) # high pass then low pass for all c3ds openmaTrial = trialTools.convertBtkAcquisition(acq) emgAnalysis = analysis.makeEmgAnalysis(DATA_PATH, [inputFile], EMG_LABELS,openmaTrials = [openmaTrial]) if not consistencyFlag: plot.plotDescriptiveEnvelopEMGpanel(DATA_PATH,emgAnalysis, EMG_LABELS,EMG_MUSCLES,EMG_CONTEXT, NORMAL_ACTIVITIES, normalized=False,exportPdf=True,outputName=inputFile) else: plot.plotConsistencyEnvelopEMGpanel(DATA_PATH,emgAnalysis, EMG_LABELS,EMG_MUSCLES,EMG_CONTEXT, NORMAL_ACTIVITIES, normalized=False,exportPdf=True,outputName=inputFile) else: raise Exception("NO Nexus connection. Turn on Nexus")
def main(args): DATA_PATH = os.getcwd() + "\\" # User Settings if os.path.isfile(DATA_PATH + args.userFile): userSettings = files.openFile(DATA_PATH, args.userFile) else: raise Exception("user setting file not found") # internal (expert) Settings if args.expertFile: if os.path.isfile(DATA_PATH + args.expertFile): internalSettings = files.openFile(DATA_PATH, args.expertFile) else: raise Exception("expert setting file not found") else: internalSettings = None # --- Manager ---- manager = EmgManager.EmgConfigManager( userSettings, localInternalSettings=internalSettings) manager.contruct() finalSettings = manager.getFinalSettings() files.prettyDictPrint(finalSettings) # reconfiguration of emg settings as lists EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES = manager.getEmgConfiguration( ) #----- rectified view ------- rectTrials = manager.temporal_trials analysis.processEMG( DATA_PATH, rectTrials, EMG_LABELS, highPassFrequencies=manager.BandpassFrequencies, envelopFrequency=manager.EnvelopLowpassFrequency, fileSuffix=None) # high pass then low pass for all c3ds for trial in rectTrials: plot.plotTemporalEMG(DATA_PATH, trial, EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES, exportPdf=True, rectify=manager.rectifyFlag) #----- Gait normalized envelop ------- envTrials = manager.gaitNormalized_trials analysis.processEMG( DATA_PATH, envTrials, EMG_LABELS, highPassFrequencies=manager.BandpassFrequencies, envelopFrequency=manager.EnvelopLowpassFrequency, fileSuffix=None) # high pass then low pass for all c3ds emgAnalysisInstance = analysis.makeEmgAnalysis(DATA_PATH, envTrials, EMG_LABELS, None, None) filename = manager.title if not manager.consistencyFlag: plot.plotDescriptiveEnvelopEMGpanel(DATA_PATH, emgAnalysisInstance, EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES, normalized=False, exportPdf=True, outputName=filename) else: plot.plotConsistencyEnvelopEMGpanel(DATA_PATH, emgAnalysisInstance, EMG_LABELS, EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES, normalized=False, exportPdf=True, outputName=filename) logging.info("=============Writing of final Settings=============") files.saveJson(DATA_PATH, str(filename + "-EMG.completeSettings"), finalSettings) logging.info("---->complete settings (%s) exported" % (str(filename + "-EMG.completeSettings"))) raw_input("Press return to exit..")