Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import os
00019 from pylab import *
00020
00021 EPS = 0.001
00022
00023 DO_REVERSE = True
00024
00025 global SAVE_DIR
00026 SAVE_DIR = '/home/fxm-mb/Scripts/Tests/ResultsFmt'
00027
00028 colors = ('b', 'r', 'y', 'g', 'm', 'c', 'k', )
00029
00030 def getMeasData(filename):
00031 newData = []
00032 with open(filename) as fp:
00033 for line in fp.readlines():
00034 line = line.strip()
00035 if line.startswith('[') and line.endswith(']'):
00036 newData.append(eval(line))
00037 if DO_REVERSE: newData.reverse()
00038 return newData
00039
00040 def evalData(oldData, newData):
00041 allErrors = []
00042 if len(newData) < len(oldData):
00043 minLen = len(newData)
00044 else:
00045 minLen = len(oldData)
00046
00047 for lv in range(minLen):
00048 tmpNew = newData[lv]
00049 tmpOld = oldData[lv]
00050 jointErrors = []
00051 for idx, newVal in enumerate(tmpNew):
00052 errorVal = abs(newVal - tmpOld[idx])
00053
00054
00055 jointErrors.append(errorVal)
00056 allErrors.append(jointErrors)
00057 if DO_REVERSE: allErrors.reverse()
00058 return allErrors
00059
00060 def plotErrors(errorData, strTitle):
00061 errorCnt = len(errorData)
00062 fig = figure(figsize=(16.0, 10.0))
00063
00064 positions = []
00065 if len(errorData[0]) > 7:
00066 position = 210
00067 else:
00068 position = 110
00069 colorIdx = 0
00070 for idx in range(len(errorData[0])):
00071 if 0 == idx % 7:
00072 position += 1
00073 positions.append(position)
00074 colorIdx = idx % 7
00075 fig.add_subplot(position).stem([elem[idx] for elem in errorData], linefmt=colors[colorIdx] + '-', markerfmt= colors[colorIdx] + 'o', label='joint %d' % idx)
00076
00077 for position in positions:
00078 fig.add_subplot(position).set_xlabel('data set number')
00079 fig.add_subplot(position).set_ylabel('abs. error in rad/s')
00080 fig.add_subplot(position).set_title(strTitle)
00081 fig.add_subplot(position).grid(True)
00082 fig.add_subplot(position).legend()
00083
00084 fig.subplots_adjust(wspace = 0.2, hspace = 0.5)
00085 fig.tight_layout()
00086 if SAVE_DIR is not None:
00087 fig.savefig(os.path.join(SAVE_DIR, strTitle.replace('.txt', '') + '.eps'))
00088
00089
00090 def doEvaluation(filenameNew, filenameOld, titleText):
00091 newData = getMeasData(filenameNew)
00092 oldData = getMeasData(filenameOld)
00093 errorData = evalData(oldData, newData)
00094 plotErrors(errorData, titleText)
00095
00096 def evaluateFiles(basedir, testdir):
00097 baseTestDir = os.path.join(baseDir, testDir)
00098 if not os.path.exists(baseTestDir):
00099 raise IOError('Could not find directory "%s"' % baseTestDir)
00100
00101 testResults = []
00102 for root, dirs, files in os.walk(baseTestDir):
00103 for file in files:
00104 if '_new_' in file.lower():
00105 testResults.append((file, file.replace('_new_', '_old_'), ))
00106
00107 if len(files) != len(testResults) * 2:
00108 print('<<<< WARN >>>>: Could not process all files in dir %s. Expected %d files but found %d' % (dirs, len(testResults) * 2, len(files)))
00109
00110 for testResultNewOld in testResults:
00111 filepathNew = os.path.join(baseTestDir, testResultNewOld[0])
00112 filepathOld = os.path.join(baseTestDir, testResultNewOld[1])
00113 if not os.path.exists(filepathNew):
00114 print('Could not find path "%s" -> Trying next files for comparison' % filepathNew)
00115 continue
00116 if not os.path.exists(filepathOld):
00117 print('Could not find path "%s" -> Trying next files for comparison' % filepathOld)
00118 continue
00119
00120 doEvaluation(filepathNew, filepathOld, testDir + '_' + testResultNewOld[0].replace('_new_', ''))
00121
00122
00123 if __name__ == '__main__':
00124 baseDir = "/home/fxm-mb/Scripts/Tests/"
00125 for root, dirs, files in os.walk(baseDir):
00126 for testDir in dirs:
00127 if True:
00128 print('Evaluating files in dir %s' % testDir)
00129 evaluateFiles(baseDir, testDir)