def analysisAdvanced(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\analysis\\gait\\" modelledFilenames = ["gait Trial 03 - viconName.c3d" ] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- # ----INFOS----- modelInfo={"Type":"cgm2", "hjc":"hara"} subjectInfo={"Id":"1", "Name":"Lecter"} experimentalInfo={"Condition":"Barefoot", "context":"block"} analysisInstance = pyCGM2.Lib.analysis.makeAnalysis("Gait", DATA_PATH,modelledFilenames,subjectInfo, experimentalInfo, modelInfo) exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(analysisInstance) exportFilter.export("testAdvanced", path=DATA_PATH,excelFormat = "xls",mode="Advanced")
def analysisAdvancedEMG(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\analysis\\gaitEMG\\" inputFile = ["pre.c3d","post.c3d"] EMG_LABELS = ["EMG1","EMG2"] # for file in inputFile: acq = btkTools.smartReader(DATA_PATH+file) pyCGM2.Lib.analysis.processEMG_fromBtkAcq(acq, EMG_LABELS, highPassFrequencies=[20,200],envelopFrequency=6.0) btkTools.smartWriter(acq,DATA_PATH+file[:-4]+"-emgProcessed.c3d") inputFileProcessed = [file[:-4]+"-emgProcessed.c3d" for file in inputFile] emgAnalysis = pyCGM2.Lib.analysis.makeEmgAnalysis(DATA_PATH, inputFileProcessed, EMG_LABELS,None, None) exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(emgAnalysis) exportFilter.export("testAdvancedEMG", path=DATA_PATH,excelFormat = "xls",mode="Advanced") # exportFilter = exporter.AnalysisExportFilter() # exportFilter.setAnalysisInstance(emgAnalysis) # exportFilter.export("testAdvancedEMG.json", path=DATA_PATH) exportFilter = exporter.AnalysisC3dExportFilter() exportFilter.setAnalysisInstance(emgAnalysis) exportFilter.export("testAdvanced", path=DATA_PATH)
def analysisBasic(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\analysis\\gait\\" modelledFilenames = ["gait Trial 03 - viconName.c3d"] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure( DATA_PATH, modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- Analysis #-------------------------------------------------------------------------- # ----INFOS----- modelInfo = {"Type": "cgm2", "hjc": "hara"} subjectInfo = {"Id": "1", "Name": "Lecter"} experimentalInfo = {"Condition": "Barefoot", "context": "block"} analysis = gaitSmartFunctions.make_analysis( trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo, subjectInfo, experimentalInfo) exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(analysis) exportFilter.export("test", path=DATA_PATH, excelFormat="xls", mode="Basic")
def standardProcessing(DATA_PATH, modelledFilenames, modelVersion, modelInfo, subjectInfo, experimentalInfo, pointSuffix, outputPath=None, outputFilename="standardProcessing", exportXls=False): if outputPath is None: outputPath= DATA_PATH if isinstance(modelledFilenames,str) or isinstance(modelledFilenames,unicode): modelledFilenames = [modelledFilenames] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- make analysis #----------------------------------------------------------------------- # pycgm2-filter pipeline are gathered in a single function if modelVersion in["CGM1.0","CGM1.1","CGM2.1","CGM2.2","CGM2.2e","CGM2.3","CGM2.3e","CGM2.4","CGM2.4e"]: if modelVersion in ["CGM2.4","CGM2.4e"]: cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT["Left"].append("LForeFoot") cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT["Right"].append("RForeFoot") analysis = standardSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo, subjectInfo, experimentalInfo, pointLabelSuffix=pointSuffix) #---- export #----------------------------------------------------------------------- if exportXls: exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(analysis) exportFilter.export(outputFilename, path=outputPath,excelFormat = "xls",mode="Advanced")
def exportAnalysis(analysisInstance, DATA_PATH, name, mode="Advanced"): """ exportAnalysis : export the pyCGM2.Processing.analysis.Analysis instance in a xls spreadsheet :param analysisInstance [pyCGM2.Processing.analysis.Analysis]: pyCGM2 analysis instance :param DATA_PATH [str]: path to your data :param name [string]: name of the output file **optional** :param mode [string]: structure of the output xls (choice: Advanced[Default] or Basic) .. note:: the advanced xls organizes data by row ( one raw = on cycle) whereas the Basic mode exports each model output in a new sheet """ exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(analysisInstance) exportFilter.export(name, path=DATA_PATH, excelFormat="xls", mode=mode)
def analysisAdvancedAndBasic_nonExistingLabel(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH+"operations\\analysis\\gait\\" modelledFilenames = ["gait Trial 03 - viconName.c3d","gait Trial 01 - viconName.c3d" ] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) 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() #---- GAIT ANALYSIS FILTER #-------------------------------------------------------------------------- # ----INFOS----- modelInfo={"type":"S01"} subjectInfo=None experimentalInfo=None kinematicLabelsDict ={ 'Left': ["LHipAngles","LKneeAngles","LAnkleAngles","LForeFootAngles"], 'Right': ["RHipAngles","RKneeAngles","RAnkleAngles"] } kineticLabelsDict =None#{ 'Left': ["LHipMoment","LKneeMoment"], #'Right': ["RHipMoment","RKneeMoment"]} analysisBuilder = analysis.GaitAnalysisBuilder(cycles, kinematicLabelsDict = kinematicLabelsDict, kineticLabelsDict = kineticLabelsDict, subjectInfos=subjectInfo, modelInfos=modelInfo, experimentalInfos=experimentalInfo) analysisFilter = analysis.AnalysisFilter() analysisFilter.setBuilder(analysisBuilder) analysisFilter.setInfo(model = modelInfo) analysisFilter.build() analysisInstance = analysisFilter.analysis # ----INFOS----- modelInfo={"Type":"cgm2", "hjc":"hara"} subjectInfo={"Id":"1", "Name":"Lecter"} experimentalInfo={"Condition":"Barefoot", "context":"block"} exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(analysisInstance) exportFilter.export("testAdvancedNan", path=DATA_PATH,excelFormat = "xls",mode="Advanced") exportFilter2 = exporter.XlsAnalysisExportFilter() exportFilter2.setAnalysisInstance(analysisInstance) exportFilter2.export("testBasic2", path=DATA_PATH,excelFormat = "xls",mode="Basic")
def GpsCGM1Test(cls): # ----DATA----- DATA_PATH = pyCGM2.TEST_DATA_PATH + "operations\\analysis\\gps\\" reconstructedFilenameLabelledNoExt = "gait Trial 03 - viconName" reconstructedFilenameLabelled = reconstructedFilenameLabelledNoExt + ".c3d" logging.info("data Path: " + DATA_PATH) logging.info("reconstructed file: " + reconstructedFilenameLabelled) modelledFilenames = [reconstructedFilenameLabelled] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure( DATA_PATH, modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) 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() #---- GAIT ANALYSIS FILTER #-------------------------------------------------------------------------- # ----INFOS----- modelInfo = {"type": "S01"} subjectInfo = None experimentalInfo = None pointLabelSuffix = "" pointLabelSuffixPlus = pointLabelSuffix if pointLabelSuffix == "" else "_" + pointLabelSuffix kinematicLabelsDict = { 'Left': [ "LHipAngles" + pointLabelSuffixPlus, "LKneeAngles" + pointLabelSuffixPlus, "LAnkleAngles" + pointLabelSuffixPlus, "LFootProgressAngles" + pointLabelSuffixPlus, "LPelvisAngles" + pointLabelSuffixPlus ], 'Right': [ "RHipAngles" + pointLabelSuffixPlus, "RKneeAngles" + pointLabelSuffixPlus, "RAnkleAngles" + pointLabelSuffixPlus, "RFootProgressAngles" + pointLabelSuffixPlus, "RPelvisAngles" + pointLabelSuffixPlus ] } kineticLabelsDict = { 'Left': [ "LHipMoment" + pointLabelSuffixPlus, "LKneeMoment" + pointLabelSuffixPlus, "LAnkleMoment" + pointLabelSuffixPlus, "LHipPower" + pointLabelSuffixPlus, "LKneePower" + pointLabelSuffixPlus, "LAnklePower" + pointLabelSuffixPlus ], 'Right': [ "RHipMoment" + pointLabelSuffixPlus, "RKneeMoment" + pointLabelSuffixPlus, "RAnkleMoment" + pointLabelSuffixPlus, "RHipPower" + pointLabelSuffixPlus, "RKneePower" + pointLabelSuffixPlus, "RAnklePower" + pointLabelSuffixPlus ] } analysisBuilder = analysis.GaitAnalysisBuilder( cycles, kinematicLabelsDict=kinematicLabelsDict, kineticLabelsDict=kineticLabelsDict, subjectInfos=subjectInfo, modelInfos=modelInfo, experimentalInfos=experimentalInfo) analysisFilter = analysis.AnalysisFilter() analysisFilter.setBuilder(analysisBuilder) analysisFilter.setInfo(model=modelInfo) analysisFilter.build() analysisInstance = analysisFilter.analysis ## --- GPS ---- ndp = normativeDatasets.Schwartz2008("Free") gps = scores.CGM1_GPS() scf = scores.ScoreFilter(gps, analysisInstance, ndp) scf.compute() xlsExport = exporter.XlsAnalysisExportFilter() xlsExport.setAnalysisInstance(analysisInstance) xlsExport.export("gpsTest2", path=DATA_PATH, mode="Advanced")
def gaitProcessing(DATA_PATH, modelledFilenames, modelVersion, modelInfo, subjectInfo, experimentalInfo, normativeData, pointSuffix, outputPath=None, outputFilename="gaitProcessing", exportXls=False, plot=True, plotDisplay=True): if outputPath is None: outputPath= DATA_PATH if isinstance(modelledFilenames,str) or isinstance(modelledFilenames,unicode): modelledFilenames = [modelledFilenames] #---- c3d manager #-------------------------------------------------------------------------- c3dmanagerProcedure = c3dManager.UniqueC3dSetProcedure(DATA_PATH,modelledFilenames) cmf = c3dManager.C3dManagerFilter(c3dmanagerProcedure) cmf.enableEmg(False) trialManager = cmf.generate() #---- make analysis #----------------------------------------------------------------------- # pycgm2-filter pipeline are gathered in a single function if modelVersion in["CGM1.0","CGM1.1","CGM2.1","CGM2.2","CGM2.2e","CGM2.3","CGM2.3e","CGM2.4","CGM2.4e"]: if modelVersion in ["CGM2.4","CGM2.4e"]: cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT["Left"].append("LForeFootAngles") cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT["Right"].append("RForeFootAngles") analysis = gaitSmartFunctions.make_analysis(trialManager, cgm.CGM1LowerLimbs.ANALYSIS_KINEMATIC_LABELS_DICT, cgm.CGM1LowerLimbs.ANALYSIS_KINETIC_LABELS_DICT, modelInfo, subjectInfo, experimentalInfo, pointLabelSuffix=pointSuffix) #---- normative dataset #----------------------------------------------------------------------- if normativeData["Author"] == "Schwartz2008": chosenModality = normativeData["Modality"] nds = normativeDatasets.Schwartz2008(chosenModality) # modalites : "Very Slow" ,"Slow", "Free", "Fast", "Very Fast" elif normativeData["Author"] == "Pinzone2014": chosenModality = normativeData["Modality"] nds = normativeDatasets.Pinzone2014(chosenModality) # modalites : "Center One" ,"Center Two" #---- GPS gps =scores.CGM1_GPS(pointSuffix= pointSuffix) scf = scores.ScoreFilter(gps,analysis, nds) scf.compute() #---- export #----------------------------------------------------------------------- files.saveAnalysis(analysis,outputPath,outputFilename) if exportXls: exportFilter = exporter.XlsAnalysisExportFilter() exportFilter.setAnalysisInstance(analysis) exportFilter.export(outputFilename, path=outputPath,excelFormat = "xls",mode="Advanced") #---- plot panels #----------------------------------------------------------------------- if plot: gaitSmartFunctions.cgm_gaitPlots(modelVersion,analysis,trialManager.kineticFlag, outputPath,outputFilename, pointLabelSuffix=pointSuffix, normativeDataset=nds ) if plotDisplay: plt.show() return analysis