def parsePlotType(plotType, data): if ((not plotType.startswith(PLOT_TYPE_BAR)) and (not plotType.startswith(PLOT_TYPE_POINT))): return (plotType, None, None) list = plotType.split(":") plotTypeId = list[0] assert ((plotTypeId == PLOT_TYPE_BAR) or (plotTypeId == PLOT_TYPE_POINT)) if (len(list) != 3): loggerError("Malformed input plot type (0)", param=plotType, exitNow=True) dimProjectionName = list[1] if (not data.isVariableDim(dimProjectionName)): loggerError("Malformed input plot type (1)", param=dimProjectionName, exitNow=True) if (list[2] == "all"): dimProjectionListValue = data.getAllUnicValueFromDim(dimProjectionName) else: dimProjectionListValue = [ float(valStr) for valStr in list[2].split(LIST_SEPARATOR) ] return (plotTypeId, dimProjectionName, dimProjectionListValue)
def parseInputArg(argList): dataFileName = [] plotType = PLOT_TYPE_SURFACE logX = False logY = False allProjectionIn1Frame = False multipleTry = False resultDimText = RESULT_DIM_TEXT_DEFAULT for i in range(1, len(argList)): arg = argList[i] if (arg == ARGUMENT_INPUT_HELP): printHelp(argList[0]) exit() elif (arg == ARGUMENT_LOG_X): logX = True elif (arg == ARGUMENT_LOG_Y): logY = True elif (arg == ARGUMENT_ALL_PROJECTION_IN_1_FRAME): allProjectionIn1Frame = True elif (arg == ARGUMENT_MULTIPLE_TRY): multipleTry = True elif (arg.startswith(ARGUMENT_PLOT_TYPE)): plotType = arg[len(ARGUMENT_PLOT_TYPE):] elif (arg.startswith(ARGUMENT_RESULT_DIM_TEXT)): resultDimText = arg[len(ARGUMENT_RESULT_DIM_TEXT):] else: dataFileName.append(arg) if (len(dataFileName) == 0): loggerError("Unspecified data file name", exitNow=True) return (dataFileName, plotType, logX, logY, resultDimText, allProjectionIn1Frame, multipleTry)
def plotData_3d(data, plotType): X = data.getVariableDimVect(0) Y = data.getVariableDimVect(1) for resultName in data.getResultDimNameVect(): print "\n\t==========================" print "\tPlot (" + plotType + ") " + str(resultName) Z = data.getResultDimVect(resultName) fig = plt.figure() if (plotType == PLOT_TYPE_SURFACE): plotSurface(X, Y, Z, fig, data.getVariableDimName(0), data.getVariableDimName(1), resultName) elif (plotType == PLOT_TYPE_CLOUD): plotCloud(X, Y, Z, fig, data.getVariableDimName(0), data.getVariableDimName(1), resultName) else: loggerError("Unknown 3d plot type", param=plotType, exitNow=True) fig.canvas.set_window_title(str(data.getBenchmarkPatternInfo())) plt.grid() plt.show(block=False)
def plotData_projection(dataLis, plotType, dimProjectionName, dimProjectionListValue, logX, logY, allProjectionIn1Frame, resultDimText, multipleTry): pointType = 0 if (allProjectionIn1Frame): fig = plt.figure() ax = fig.gca() for dimProjectionValue in dimProjectionListValue: transparency=1. if (allProjectionIn1Frame): resultName = dimProjectionName + "(" + str(dimProjectionValue) + ")" if (not allProjectionIn1Frame): fig = plt.figure() ax = fig.gca() for resultId in xrange(dataLis[0].getNbResultDim()): if (not allProjectionIn1Frame): resultName = dataLis[0].getResultDimName(resultId) if (plotType == PLOT_TYPE_BAR): for data in dataLis: (X_list, Z_list, Z_error_list, X_label_list) = data.getVariableDimVect_projection(dimProjectionName, dimProjectionValue) assert(len(X_list) == len(X_label_list)) Z = Z_list[resultId] Z_error = Z_error_list[resultId] plotBar(X_list[0], Z, Z_error, fig, ax, X_label_list[0], resultDimText, data.getBenchmarkPatternInfo(), BAR_SIZE, logX, logY, legendExtra=resultName, transparency=transparency, generateRandomColor=allProjectionIn1Frame) elif (plotType == PLOT_TYPE_POINT): for data in dataLis: (X_list, Z_list, Z_error_list, X_label_list) = data.getVariableDimVect_projection(dimProjectionName, dimProjectionValue) assert(len(X_list) == len(X_label_list)) Z = Z_list[resultId] Z_error = Z_error_list[resultId] plotPoint(X_list[0], Z, Z_error, fig, ax, X_label_list[0], resultDimText, data.getBenchmarkPatternInfo(), BAR_SIZE, logX, logY, legendExtra=resultName, pointType=pointType)#, generateRandomColor=allProjectionIn1Frame) pointType = (pointType + 1) % len(POINT_TYPE_LIST) else: loggerError("Unknown 2d plot type", param=plotType, exitNow=True) transparency = transparency / 2. if (not allProjectionIn1Frame): projectionPlotHeader(dataLis, dimProjectionName, dimProjectionValue, ax, fig) if (allProjectionIn1Frame): projectionPlotHeader(dataLis, dimProjectionName, dimProjectionValue, ax, fig)
def parseCubeDumpFile(cubeDumpFileName, idList): res = [] try: cubeDumpFile = open(cubeDumpFileName, 'r') except: loggerError(msg="Failed to open the cube_dump result file", param=cubeDumpFileName, exitNow=True) while (not isEndOfFile(cubeDumpFile)): line = nextMeaningfullLine(cubeDumpFile, raiseExceptionIfNon=False) (idD, value) = findKeyValue(line, idList) if (value != None): res.append((idD, value)) if (len(idList) != len(res)): loggerError(msg="Failed while parsing the cube_dump result file" + cubeDumpFileName + ".\nCan't find all the results corresponding to the id", param="Looking for " + str(idList) + " and found " + str(res), exitNow=True) cubeDumpFile.close() resSorted = [] for i in idList: found = False for (idD, value) in res: if (idD == i): resSorted.append(value) found = True break if (not found): loggerError(msg="The id \"" + str(id) + "\" in the cube_dump result file has multiple lines", param=cubeDumpFileName, exitNow=True) return resSorted
def plotData_projection(data, plotType, dimProjectionName, dimProjectionListValue, logX, logY, allProjectionIn1Frame, resultDimText, multipleTry, dataCompare=None): pointType = 0 if (allProjectionIn1Frame): fig = plt.figure() ax = fig.gca() for dimProjectionValue in dimProjectionListValue: (X_list, Z_list, Z_error_list, X_label_list) = data.getVariableDimVect_projection( dimProjectionName, dimProjectionValue) assert (len(X_list) == len(X_label_list)) if (dataCompare != None): if (not data.isSameFixedDim(dataCompare)): loggerError( "The 2 given data files have different fixed dimension", exitNow=False) return (X_list_cmp, Z_list_cmp, Z_error_list_cmp, X_label_list_cmp) = dataCompare.getVariableDimVect_projection( dimProjectionName, dimProjectionValue) assert (len(X_list_cmp) == len(X_label_list_cmp)) assert (X_label_list == X_label_list_cmp) #TODO shift = float(min((X_list_cmp[0][1] - X_list_cmp[0][0]), (X_list[0][1] - X_list[0][0])))/3 transparency = 1. if (allProjectionIn1Frame): resultName = dimProjectionName + "(" + str( dimProjectionValue) + ")" if (not allProjectionIn1Frame): fig = plt.figure() ax = fig.gca() for resultId in xrange(data.getNbResultDim()): if (not allProjectionIn1Frame): resultName = data.getResultDimName(resultId) Z = Z_list[resultId] Z_error = Z_error_list[resultId] if (plotType == PLOT_TYPE_BAR): plotBar(X_list[0], Z, Z_error, fig, ax, X_label_list[0], resultDimText, data.getBenchmarkPatternInfo(), BAR_SIZE, logX, logY, legendExtra=resultName, transparency=transparency, generateRandomColor=allProjectionIn1Frame) if (dataCompare != None): Z_cmp = Z_list_cmp[resultId] Z_cmp_error = Z_error_list_cmp[resultId] plotBar([x + shift for x in X_list_cmp[0]], Z_cmp, Z_cmp_error, fig, ax, X_label_list_cmp[0], resultDimText, dataCompare.getBenchmarkPatternInfo(), BAR_SIZE, logX, logY, legendExtra=resultName, transparency=transparency, generateRandomColor=allProjectionIn1Frame) elif (plotType == PLOT_TYPE_POINT): plotPoint(X_list[0], Z, Z_error, fig, ax, X_label_list[0], resultDimText, data.getBenchmarkPatternInfo(), BAR_SIZE, logX, logY, legendExtra=resultName, pointType=pointType, generateRandomColor=allProjectionIn1Frame) pointType = (pointType + 1) % len(POINT_CORRESPONDENCE) if (dataCompare != None): Z_cmp = Z_list_cmp[resultId] Z_cmp_error = Z_error_list_cmp[resultId] plotPoint(X_list_cmp[0], Z_cmp, Z_cmp_error, fig, ax, X_label_list_cmp[0], resultDimText, dataCompare.getBenchmarkPatternInfo(), BAR_SIZE, logX, logY, legendExtra=resultName, pointType=pointType, generateRandomColor=allProjectionIn1Frame) pointType = (pointType + 1) % len(POINT_CORRESPONDENCE) else: loggerError("Unknown 2d plot type", param=plotType, exitNow=True) transparency = transparency / 2. if (not allProjectionIn1Frame): projectionPlotHeader(data, dataCompare, dimProjectionName, dimProjectionValue, ax, fig) if (allProjectionIn1Frame): projectionPlotHeader(data, dataCompare, dimProjectionName, dimProjectionValue, ax, fig)
def parseAndSet(self, resultFileName, multipleTry=False, variableDimForSort=None): self._resultFileName = resultFileName try: resultFile = open(resultFileName, 'r') except: loggerError(msg="Failed to open the result file", param=resultFileName, exitNow=True) self._benchmarkPatternInfo = nextMeaningfullLine(resultFile) self._variableDimName = nextArrayLine(resultFile) nbVariableDim = len(self._variableDimName) self._variableDimValue = [[] for _ in xrange(nbVariableDim)] self._resultDimName = nextArrayLine(resultFile) nbResultDim = len(self._resultDimName) self._resultDimValue = [[] for _ in xrange(nbResultDim)] if (multipleTry == True): self._resultNbTry = int(nextMeaningfullLine(resultFile)) else: self._resultNbTry = 1 self._resultDimValueMin = [[] for _ in xrange(nbResultDim)] self._resultDimValueMax = [[] for _ in xrange(nbResultDim)] #TODO add asserts on all th read values nbEntry = -1 variableDimForSortInd = None if (not variableDimForSort is None): variableDimForSortInd = findIndexInList(self._variableDimName, variableDimForSort) if (variableDimForSortInd is None): loggerError(msg="Can't find the \"variable\" to sort from ", param=variableDimForSort, exitNow=True) while (not isEndOfFile(resultFile)): nbEntry += 1 # Read/Set the variable dimensions line = nextArrayLine(resultFile) if (len(line) != (self.getNbVariableDim())): text = resultFileName + "\nExpected = " + str( self._variableDimName) + " Found = " + str(line) loggerError(msg="The result contains corrupted data lines", param=text, exitNow=True) pivot = None if (not variableDimForSort is None): pivot = float(line[variableDimForSortInd]) pivot = whereInsertInSortedLIst( self._variableDimValue[variableDimForSortInd], pivot) for i in xrange(nbVariableDim): insertInList(self._variableDimValue[i], float(line[i]), pivot=pivot) # Read/Set the results dimensions for nbTry in xrange(self._resultNbTry): if (isEndOfFile(resultFile)): loggerError( msg= "The result contains data lines with missing result dim", param=resultFileName, exitNow=True) line = nextArrayLine(resultFile) if (len(line) != (self.getNbResultDim())): text = resultFileName + "\nExpected = " + str( self._resultDimName) + " Found = " + str(line) loggerError(msg="The result contains corrupted data lines", param=text, exitNow=True) for i in xrange(nbResultDim): value = float(line[i]) if (nbTry == 0): if (self._resultNbTry == 1): insertInList(self._resultDimValue[i], value, pivot=pivot) else: insertInList(self._resultDimValue[i], value / float(self._resultNbTry), pivot=pivot) insertInList(self._resultDimValueMin[i], value, pivot=pivot) insertInList(self._resultDimValueMax[i], value, pivot=pivot) else: if (variableDimForSort is None): j = nbEntry else: j = pivot self._resultDimValue[i][j] += value / float( self._resultNbTry) if (self._resultDimValueMin[i][j] > value): self._resultDimValueMin[i][j] = value if (self._resultDimValueMax[i][j] < value): self._resultDimValueMax[i][j] = value resultFile.close()