Beispiel #1
0
    def test_temporalEmgPlot(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)

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

        EMG_LABELS,EMG_MUSCLES,EMG_CONTEXT,NORMAL_ACTIVITIES  =  manager.getEmgConfiguration()

        rectifyBool=True

        acq = btkTools.smartReader(DATA_PATH+gaitTrial)


        analysis.processEMG_fromBtkAcq(acq, EMG_LABELS,
            highPassFrequencies=[20,200],
            envelopFrequency=6.0)

        openmaTrial = trialTools.convertBtkAcquisition(acq)

        plot.plotTemporalEMG(DATA_PATH,gaitTrial, EMG_LABELS,EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES,exportPdf=False,rectify=rectifyBool,openmaTrial=openmaTrial)
Beispiel #2
0
    def test_temporalEmgPlot(self):
        DATA_PATH, modelledFilenames,acq = dataTest2()

        emg.processEMG(DATA_PATH, modelledFilenames, emgChannels,
            highPassFrequencies=[20,200],envelopFrequency=6.0,
            fileSuffix=None,outDataPath=None)


        figs = plot.plotTemporalEMG(DATA_PATH, modelledFilenames[0],
                emgChannels, muscles, contexts, normalActivityEmgs,
                rectify = True,
                exportPdf=False,outputName=None,show=False,title=None,
                btkAcq=None)

        if SHOW: plt.show()
        return figs[0]
Beispiel #3
0
def main():

    parser = argparse.ArgumentParser(description='EMG-plot_temporalEMG')
    parser.add_argument('-bpf', '--BandpassFrequencies', nargs='+',help='bandpass filter')
    parser.add_argument('-ecf','--EnvelopLowpassFrequency', type=int, help='cutoff frequency for emg envelops')
    parser.add_argument('-r','--raw', action='store_true', help='rectified data')
    args = parser.parse_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)

        rectifyBool = False if args.raw else True




        # --------------------------SUBJECT ------------------------------------
        subjects = NEXUS.GetSubjectNames()
        subject = nexusTools.checkActivatedSubject(NEXUS,subjects)


        # btk Acquisition
        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)



        plot.plotTemporalEMG(DATA_PATH,inputFile, EMG_LABELS,EMG_MUSCLES, EMG_CONTEXT, NORMAL_ACTIVITIES,exportPdf=True,rectify=rectifyBool,
                            openmaTrial=openmaTrial)

    else:
        raise Exception("NO Nexus connection. Turn on Nexus")
Beispiel #4
0
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..")