def addCustomExpressions(self,customRegexp, persist=None, start=None, end=None, raiseit=False, writeFiles=False, splitThres=2048, gnuplotTerminal=None, plottingImplementation="dummy"): plots={} masters={} slaves=[] for i,custom in enumerate(customRegexp): if not custom.enabled: continue if persist!=None: custom.persist=persist if start!=None: custom.start=start if end!=None: custom.end=end custom.raiseit=raiseit createPlot=True if custom.type=="phase": self.addAnalyzer(custom.name, PhaseChangerLineAnalyzer(custom.expr, idNr=custom.idNr)) createPlot=False elif custom.type in ["dynamic","dynamicslave"]: self.addAnalyzer(custom.name, RegExpLineAnalyzer(custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, dataTransformations=custom.dataTransformations, progressTemplate=custom.progress, singleFile=True, idNr=custom.idNr, stringValues=custom.stringValues, startTime=custom.start, endTime=custom.end)) elif custom.type in ["regular","slave"]: self.addAnalyzer(custom.name, RegExpLineAnalyzer(custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, dataTransformations=custom.dataTransformations, progressTemplate=custom.progress, stringValues=custom.stringValues, singleFile=True, startTime=custom.start, endTime=custom.end)) else: error("Unknown type",custom.type,"in custom expression",custom.name) if createPlot: if custom.master==None: if custom.type in ["slave","dynamicslave"]: error("Custom expression",custom.name,"is supposed to be a 'slave' but no master is defined") masters[custom.id]=custom plotCustom=createPlotTimelines(self.getAnalyzer(custom.name).lines, custom=custom, gnuplotTerminal=gnuplotTerminal, implementation=plottingImplementation) self.getAnalyzer(custom.name).lines.setSplitting(splitThres=splitThres, advancedSplit=True) plotCustom.setTitle(custom.theTitle) plots["custom%04d" % i]=plotCustom else: if custom.type not in ["slave","dynamicslave"]: error("'master' only makes sense if type is 'slave' or 'dynamicslave' for",custom.name) if getattr(custom,"alternateAxis",None): error("Specify alternate values in 'alternateAxis' of master", custom.master,"for",custom.name) slaves.append(custom) for s in slaves: if s.master not in masters: error("The custom plot",s.id,"wants the master plot", s.master,"but it is not found in the list of masters", list(masters.keys())) else: slave=self.getAnalyzer(s.name) master=self.getAnalyzer(masters[s.master].name) slave.setMaster(master) return plots
def createPlots(self, persist=None, raiseit=False, splitThres=2048, plotLinear=True, plotCont=True, plotBound=True, plotIterations=True, plotCourant=True, plotExecution=True, plotDeltaT=True, start=None, end=None, writeFiles=False, customRegexp=None, plottingImplementation="dummy"): plots = {} if plotLinear and self.hasAnalyzer("Linear"): plots["linear"] = createPlotTimelinesDirect( "linear", self.getAnalyzer("Linear").lines, persist=persist, raiseit=raiseit, forbidden=["final", "iterations"], start=start, end=end, logscale=True, implementation=plottingImplementation) self.getAnalyzer("Linear").lines.setSplitting( splitThres=splitThres, splitFun=max, advancedSplit=True) plots["linear"].setTitle("Residuals") plots["linear"].setYLabel("Initial residual") if plotCont and self.hasAnalyzer("Continuity"): plots["cont"] = createPlotTimelinesDirect( "continuity", self.getAnalyzer("Continuity").lines, persist=persist, alternateAxis=["Global"], raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) plots["cont"].setYLabel("Cumulative") plots["cont"].setYLabel2("Global") self.getAnalyzer("Continuity").lines.setSplitting( splitThres=splitThres, advancedSplit=True) plots["cont"].setTitle("Continuity") if plotBound and self.hasAnalyzer("Bounding"): plots["bound"] = createPlotTimelinesDirect( "bounding", self.getAnalyzer("Bounding").lines, persist=persist, raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Bounding").lines.setSplitting( splitThres=splitThres, splitFun=signedMax, advancedSplit=True) plots["bound"].setTitle("Bounded variables") if plotIterations and self.hasAnalyzer("Iterations"): plots["iter"] = createPlotTimelinesDirect( "iterations", self.getAnalyzer("Iterations").lines, persist=persist, with_="steps", raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Iterations").lines.setSplitting( splitThres=splitThres, advancedSplit=True) plots["iter"].setTitle("Iterations") plots["iter"].setYLabel("Sum of iterations") if plotCourant and self.hasAnalyzer("Courant"): plots["courant"] = createPlotTimelinesDirect( "courant", self.getAnalyzer("Courant").lines, persist=persist, raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Courant").lines.setSplitting( splitThres=splitThres, advancedSplit=True) plots["courant"].setTitle("Courant") plots["courant"].setYLabel("Courant Number [1]") if plotDeltaT and self.hasAnalyzer("DeltaT"): plots["deltaT"] = createPlotTimelinesDirect( "timestep", self.getAnalyzer("DeltaT").lines, persist=persist, raiseit=raiseit, start=start, end=end, logscale=True, implementation=plottingImplementation) self.getAnalyzer("DeltaT").lines.setSplitting( splitThres=splitThres, advancedSplit=True) plots["deltaT"].setTitle("DeltaT") plots["deltaT"].setYLabel("dt [s]") if plotExecution and self.hasAnalyzer("Execution"): plots["execution"] = createPlotTimelinesDirect( "execution", self.getAnalyzer("Execution").lines, persist=persist, with_="steps", raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Execution").lines.setSplitting( splitThres=splitThres, advancedSplit=True) plots["execution"].setTitle("Execution Time") plots["execution"].setYLabel("Time [s]") if customRegexp: self.plotCustom = [] masters = {} slaves = [] for i, custom in enumerate(customRegexp): if not custom.enabled: continue if persist != None: custom.persist = persist if start != None: custom.start = start if end != None: custom.end = end custom.raiseit = raiseit createPlot = True if custom.type == "phase": self.addAnalyzer( custom.name, PhaseChangerLineAnalyzer(custom.expr, idNr=custom.idNr)) createPlot = False elif custom.type == "dynamic": self.addAnalyzer( custom.name, RegExpLineAnalyzer(custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, progressTemplate=custom.progress, singleFile=True, idNr=custom.idNr, startTime=custom.start, endTime=custom.end)) elif custom.type == "regular" or custom.type == "slave": self.addAnalyzer( custom.name, RegExpLineAnalyzer(custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, progressTemplate=custom.progress, singleFile=True, startTime=custom.start, endTime=custom.end)) else: error("Unknown type", custom.type, "in custom expression", custom.name) if createPlot: if custom.master == None: if custom.type == "slave": error( "Custom expression", custom.name, "is supposed to be a 'slave' but no master is defined" ) masters[custom.id] = custom plotCustom = createPlotTimelines( self.getAnalyzer(custom.name).lines, custom=custom, implementation=plottingImplementation) self.getAnalyzer(custom.name).lines.setSplitting( splitThres=splitThres, advancedSplit=True) plotCustom.setTitle(custom.theTitle) plots["custom%04d" % i] = plotCustom else: if custom.type != "slave": error( "'master' only makes sense if type is 'slave' for", custom.name) if getattr(custom, "alternateAxis", None): error( "Specify alternate values in 'alternateAxis' of master", custom.master, "for", custom.name) slaves.append(custom) for s in slaves: if s.master not in masters: error("The custom plot", s.id, "wants the master plot", s.master, "but it is not found in the list of masters", list(masters.keys())) else: slave = self.getAnalyzer(s.name) master = self.getAnalyzer(masters[s.master].name) slave.setMaster(master) self.reset() return plots
l.getData().writeCSV(name) return pRegistry=PlotLinesRegistry() for i,p in plotInfo.iteritems(): theId=p["id"] print "Plotting",i,":",theId, spec=CustomPlotInfo(raw=p["spec"]) if len(registry.get(p["data"]).getTimes())>0 and registry.get(p["data"]).getValueNames()>0: if self.opts.csvFiles: registry.get(p["data"]).getData().writeCSV(self.opts.filePrefix+theId+".csv") else: mp=createPlotTimelines(registry.get(p["data"]), spec, implementation=self.opts.implementation, showWindow=self.opts.showWindow, registry=pRegistry) if self.opts.insertTitles: mp.actualSetTitle(p["spec"]["theTitle"]) if self.opts.writePictures: if mp.hasData(): mp.doHardcopy(self.opts.prefix+theId,"png") else: print "has no data", print else: print "No data - skipping" sleep(self.opts.sleepTime) # there seems to be a timing issue with Gnuplot
def addCustomExpressions(self, customRegexp, persist=None, start=None, end=None, raiseit=False, writeFiles=False, splitThres=2048, gnuplotTerminal=None, plottingImplementation="dummy"): plots = {} masters = {} slaves = [] for i, custom in enumerate(customRegexp): if not custom.enabled: continue if persist != None: custom.persist = persist if start != None: custom.start = start if end != None: custom.end = end custom.raiseit = raiseit createPlot = True if custom.type == "phase": self.addAnalyzer( custom.name, PhaseChangerLineAnalyzer(custom.expr, idNr=custom.idNr)) createPlot = False elif custom.type in ["dynamic", "dynamicslave"]: self.addAnalyzer( custom.name, RegExpLineAnalyzer( custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, dataTransformations=custom.dataTransformations, progressTemplate=custom.progress, singleFile=True, idNr=custom.idNr, stringValues=custom.stringValues, startTime=custom.start, endTime=custom.end)) elif custom.type in ["regular", "slave"]: self.addAnalyzer( custom.name, RegExpLineAnalyzer( custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, dataTransformations=custom.dataTransformations, progressTemplate=custom.progress, stringValues=custom.stringValues, singleFile=True, startTime=custom.start, endTime=custom.end)) else: error("Unknown type", custom.type, "in custom expression", custom.name) if createPlot: if custom.master == None: if custom.type in ["slave", "dynamicslave"]: error( "Custom expression", custom.name, "is supposed to be a 'slave' but no master is defined" ) masters[custom.id] = custom plotCustom = createPlotTimelines( self.getAnalyzer(custom.name).lines, custom=custom, gnuplotTerminal=gnuplotTerminal, implementation=plottingImplementation) self.getAnalyzer(custom.name).lines.setSplitting( splitThres=splitThres, advancedSplit=True) plotCustom.setTitle(custom.theTitle) plots["custom%04d" % i] = plotCustom else: if custom.type not in ["slave", "dynamicslave"]: error( "'master' only makes sense if type is 'slave' or 'dynamicslave' for", custom.name) if getattr(custom, "alternateAxis", None): error( "Specify alternate values in 'alternateAxis' of master", custom.master, "for", custom.name) slaves.append(custom) for s in slaves: if s.master not in masters: error("The custom plot", s.id, "wants the master plot", s.master, "but it is not found in the list of masters", list(masters.keys())) else: slave = self.getAnalyzer(s.name) master = self.getAnalyzer(masters[s.master].name) slave.setMaster(master) return plots
def run(self): if not self.opts.server and not self.opts.pickle: error("No mode selected") if self.opts.server and self.opts.pickle: error("Both modes selected") doPandas = self.opts.pandasData or self.opts.pandasSeries if self.opts.server: if len(self.parser.getArgs()) != 2: error("Need a server and a port to be specified") host = self.parser.getArgs()[0] port = int(self.parser.getArgs()[1]) try: self.server = ServerProxy("http://%s:%d" % (host, port)) methods = self.server.system.listMethods() except socket.error: reason = sys.exc_info()[ 1] # Needed because python 2.5 does not support 'as e' self.error("Socket error while connecting:", reason) except ProtocolError: reason = sys.exc_info()[ 1] # Needed because python 2.5 does not support 'as e' self.error("XMLRPC-problem", reason) plotInfo = self.executeCommand("getPlots()") lineInfo = self.executeCommand("getPlotData()") else: if len(self.parser.getArgs()) != 1: warning("Only the first parameter is used") fName = self.parser.getArgs()[0] unpick = pickle.Unpickler(open(fName)) lineInfo = unpick.load() plotInfo = unpick.load() if not self.quiet: print_("Found", len(plotInfo), "plots and", len(lineInfo), "data sets") registry = TimeLinesRegistry() for nr, line in iteritems(lineInfo): if not self.quiet: print_("Adding line", nr) TimeLineCollection(preloadData=line, registry=registry) registry.resolveSlaves() if (self.opts.csvFiles or self.opts.excelFiles or doPandas or self.opts.numpyData) and self.opts.rawLines: rawData = {} rawSeries = {} rawNumpy = {} for k, l in iteritems(registry.lines): name = str(k) if type(k) == int: name = "Line%d" % k csvName = self.opts.filePrefix + name + ".csv" if self.opts.csvFiles: if not self.quiet: print_("Writing", k, "to", csvName) l.getData().writeCSV(csvName) if self.opts.excelFiles: xlsName = self.opts.filePrefix + name + ".xls" if not self.quiet: print_("Writing", k, "to", xlsName) l.getData().getData().to_excel(xlsName) if self.opts.pandasData: rawData[k] = l.getData().getData() if self.opts.numpyData: rawNumpy[k] = l.getData().data.copy() if self.opts.pandasSeries: rawSeries[k] = l.getData().getSeries() if self.opts.numpyData: self.setData({"rawNumpy": rawNumpy}) if self.opts.pandasData: self.setData({"rawData": rawData}) if self.opts.pandasSeries: self.setData({"rawSeries": rawSeries}) if self.opts.csvFiles or self.opts.excelFiles: return pRegistry = PlotLinesRegistry() plotNumpy = {} plotData = {} plotSeries = {} for i, p in iteritems(plotInfo): theId = p["id"] if not self.quiet: print_("Plotting", i, ":", theId, end=" ") spec = CustomPlotInfo(raw=p["spec"]) if len(registry.get(p["data"]).getTimes()) > 0 and registry.get( p["data"]).getValueNames() > 0: if self.opts.csvFiles or self.opts.excelFiles or doPandas or self.opts.numpyData: dataSet = registry.get(p["data"]).getData() if self.opts.csvFiles: dataSet.writeCSV(self.opts.filePrefix + theId + ".csv") if self.opts.excelFiles: dataSet.getData().to_excel(self.opts.filePrefix + theId + ".xls") if self.opts.numpyData: plotNumpy[theId] = dataSet.data.copy() if self.opts.pandasData: plotData[theId] = dataSet.getData() if self.opts.pandasSeries: plotSeries[theId] = dataSet.getSeries() else: if self.opts.start or self.opts.end: # rewrite CustomPlotInfo one of these days if "start" in spec.getDict(): self.warning("Overriding plot start", spec["start"], "with", self.opts.start) spec.set("start", self.opts.start) if "end" in spec.getDict(): self.warning("Overriding plot end", spec["end"], "with", self.opts.end) spec.set("end", self.opts.end) mp = createPlotTimelines( registry.get(p["data"]), spec, implementation=self.opts.implementation, showWindow=self.opts.showWindow, registry=pRegistry) if self.opts.insertTitles: mp.actualSetTitle(p["spec"]["theTitle"]) if self.opts.writePictures: if mp.hasData(): mp.doHardcopy(self.opts.prefix + theId, "png") else: if not self.quiet: print_("has no data", end=" ") if not self.quiet: print_() else: if not self.quiet: print_("No data - skipping") if not (self.opts.csvFiles or doPandas): sleep(self.opts.sleepTime ) # there seems to be a timing issue with Gnuplot if self.opts.numpyData: self.setData({"plotNumpy": plotNumpy}) if self.opts.pandasData: self.setData({"plotData": plotData}) if self.opts.pandasSeries: self.setData({"plotSeries": plotSeries})
def run(self): if not self.opts.server and not self.opts.pickle: error("No mode selected") if self.opts.server and self.opts.pickle: error("Both modes selected") doPandas=self.opts.pandasData or self.opts.pandasSeries if self.opts.server: if len(self.parser.getArgs())!=2: error("Need a server and a port to be specified") host=self.parser.getArgs()[0] port=int(self.parser.getArgs()[1]) try: self.server=ServerProxy("http://%s:%d" % (host,port)) methods=self.server.system.listMethods() except socket.error: reason = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e' self.error("Socket error while connecting:",reason) except ProtocolError: reason = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e' self.error("XMLRPC-problem",reason) plotInfo=self.executeCommand("getPlots()") lineInfo=self.executeCommand("getPlotData()") else: if len(self.parser.getArgs())!=1: warning("Only the first parameter is used") fName=self.parser.getArgs()[0] unpick=pickle.Unpickler(open(fName,"rb")) lineInfo=unpick.load() plotInfo=unpick.load() if not self.quiet: print_("Found",len(plotInfo),"plots and",len(lineInfo),"data sets") registry=TimeLinesRegistry() for nr,line in iteritems(lineInfo): if not self.quiet: print_("Adding line",nr) TimeLineCollection(preloadData=line,registry=registry) registry.resolveSlaves() if (self.opts.csvFiles or self.opts.excelFiles or doPandas or self.opts.numpyData) and self.opts.rawLines: rawData={} rawSeries={} rawNumpy={} for k,l in iteritems(registry.lines): name=str(k) if type(k)==int: name="Line%d" % k csvName=self.opts.filePrefix+name+".csv" if self.opts.csvFiles: if not self.quiet: print_("Writing",k,"to",csvName) l.getData().writeCSV(csvName) if self.opts.excelFiles: xlsName=self.opts.filePrefix+name+".xls" if not self.quiet: print_("Writing",k,"to",xlsName) l.getData().getData().to_excel(xlsName) if self.opts.pandasData: rawData[k]=l.getData().getData() if self.opts.numpyData: rawNumpy[k]=l.getData().data.copy() if self.opts.pandasSeries: rawSeries[k]=l.getData().getSeries() if self.opts.numpyData: self.setData({"rawNumpy":rawNumpy}) if self.opts.pandasData: self.setData({"rawData":rawData}) if self.opts.pandasSeries: self.setData({"rawSeries":rawSeries}) if self.opts.csvFiles or self.opts.excelFiles: return pRegistry=PlotLinesRegistry() plotNumpy={} plotData={} plotSeries={} for i,p in iteritems(plotInfo): theId=p["id"] if not self.quiet: print_("Plotting",i,":",theId,end=" ") spec=CustomPlotInfo(raw=p["spec"]) if len(registry.get(p["data"]).getTimes())>0 and registry.get(p["data"]).getValueNames()>0: if self.opts.csvFiles or self.opts.excelFiles or doPandas or self.opts.numpyData: dataSet=registry.get(p["data"]).getData() if self.opts.csvFiles: dataSet.writeCSV(self.opts.filePrefix+theId+".csv") if self.opts.excelFiles: dataSet.getData().to_excel(self.opts.filePrefix+theId+".xls") if self.opts.numpyData: plotNumpy[theId]=dataSet.data.copy() if self.opts.pandasData: plotData[theId]=dataSet.getData() if self.opts.pandasSeries: plotSeries[theId]=dataSet.getSeries() else: if self.opts.start or self.opts.end: # rewrite CustomPlotInfo one of these days if "start" in spec.getDict(): self.warning("Overriding plot start",spec["start"], "with",self.opts.start) spec.set("start",self.opts.start) if "end" in spec.getDict(): self.warning("Overriding plot end",spec["end"], "with",self.opts.end) spec.set("end",self.opts.end) mp=createPlotTimelines(registry.get(p["data"]), spec, implementation=self.opts.implementation, showWindow=self.opts.showWindow, registry=pRegistry) if self.opts.insertTitles: mp.actualSetTitle(p["spec"]["theTitle"]) if self.opts.writePictures: if mp.hasData(): mp.doHardcopy(self.opts.prefix+theId,"png") else: if not self.quiet: print_("has no data",end=" ") if not self.quiet: print_() else: if not self.quiet: print_("No data - skipping") if not(self.opts.csvFiles or doPandas): sleep(self.opts.sleepTime) # there seems to be a timing issue with Gnuplot if self.opts.numpyData: self.setData({"plotNumpy":plotNumpy}) if self.opts.pandasData: self.setData({"plotData":plotData}) if self.opts.pandasSeries: self.setData({"plotSeries":plotSeries})
def addCustomExpressions(self, customRegexp, persist=None, quiet=False, start=None, end=None, raiseit=False, writeFiles=False, splitThres=2048, gnuplotTerminal=None, plottingImplementation="dummy"): plots = {} masters = {} slaves = [] canonical = {} marks = [] plotTypes = [ ("regular", "Matches regular expression and plots"), ("slave", "Plot data on a different plot (the 'master')"), ("dynamic", "Dynamically creates lines depending on the match found at 'idNr'" ), ("dynamicslave", "Combination of 'dynamic' and 'slave'"), ("data", "Reads data from a file and plots it"), ("dataslave", "Combination of 'data' and 'slave'"), ("count", "Counts how often an expression occured (no plotting but used for 'alternateTime')" ), ("mark", "If the expression matches then a vertical marker is drawn on the 'targets'" ), ("phase", "Changes the phase prefix (for multi-region cases)") ] for i, custom in enumerate(customRegexp): if not custom.enabled: continue if persist != None: custom.persist = persist if start != None: custom.start = start if end != None: custom.end = end custom.raiseit = raiseit if custom.type not in [p[0] for p in plotTypes]: error( "type '{}' of custom plot '{}' not in known types:\n {}". format( custom.type, custom.id, "\n ".join([ "{:15} : {}".format(n, d) for n, d in plotTypes ]))) createPlot = True if custom.type == "phase": self.addAnalyzer( custom.name, PhaseChangerLineAnalyzer(custom.expr, idNr=custom.idNr)) createPlot = False elif custom.type == "count": self.addAnalyzer(custom.name, CountLineAnalyzer(custom.expr)) createPlot = False elif custom.type == "mark": a = TriggerLineAnalyzer(custom.expr) self.addAnalyzer(custom.name, a) marks.append((custom, a)) createPlot = False elif custom.type in ["dynamic", "dynamicslave"]: self.addAnalyzer( custom.name, RegExpLineAnalyzer( custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles or custom.writeFiles, accumulation=custom.accumulation, dataTransformations=custom.dataTransformations, progressTemplate=custom.progress, singleFile=True, idNr=custom.idNr, stringValues=custom.stringValues, startTime=custom.start, endTime=custom.end)) elif custom.type in ["regular", "slave"]: self.addAnalyzer( custom.name, RegExpLineAnalyzer( custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles or custom.writeFiles, accumulation=custom.accumulation, dataTransformations=custom.dataTransformations, progressTemplate=custom.progress, stringValues=custom.stringValues, singleFile=True, startTime=custom.start, endTime=custom.end)) elif custom.type in ["data", "dataslave"]: self.addAnalyzer( custom.name, ReplayDataFileAnalyzer( timeName=custom.timeName, validData=custom.validData, validMatchRegexp=custom.validMatchRegexp, csvName=custom.csvName, txtName=custom.txtName, namePrefix=custom.namePrefix, excelName=custom.excelName, skip_header=custom.skip_header, stripCharacters=custom.stripCharacters, progressTemplate=custom.progress, replaceFirstLine=custom.replaceFirstLine, startTime=custom.start, endTime=custom.end)) else: error("Unknown type", custom.type, "in custom expression", custom.name) canonical[custom.id] = custom.name if createPlot: if custom.master == None: if custom.type in ["slave", "dynamicslave", "dataslave"]: error( "Custom expression", custom.name, "is supposed to be a 'slave' but no master is defined" ) masters[custom.id] = custom plotCustom = createPlotTimelines( self.getAnalyzer(custom.name).lines, quiet=quiet, custom=custom, gnuplotTerminal=gnuplotTerminal, implementation=plottingImplementation) self.getAnalyzer(custom.name).lines.setSplitting( splitThres=splitThres, advancedSplit=True) plotCustom.setTitle(custom.theTitle) plots["custom%04d" % i] = plotCustom self.plots[custom.id] = plotCustom else: if custom.type not in [ "slave", "dynamicslave", "dataslave" ]: error( "'master' only makes sense if type is 'slave' or 'dynamicslave' for", custom.name) if getattr(custom, "alternateAxis", None): error( "Specify alternate values in 'alternateAxis' of master", custom.master, "for", custom.name) slaves.append(custom) for custom in customRegexp: if custom.alternateTime: self.getAnalyzer(custom.name).setParent( self.getAnalyzer(canonical[custom.alternateTime])) self.getAnalyzer( canonical[custom.alternateTime]).addTimeListener( self.getAnalyzer(custom.name)) for s in slaves: if s.master not in masters: error("The custom plot", s.id, "wants the master plot", s.master, "but it is not found in the list of masters", list(masters.keys())) else: slave = self.getAnalyzer(s.name) master = self.getAnalyzer(masters[s.master].name) slave.setMaster(master) for custom, analyzer in marks: for pName in custom.targets: try: p = self.plots[pName] except KeyError as e: print_("Available plots:", list(self.plots.keys())) raise e def mark(p): def makeMark(): p.addVerticalMarker() return makeMark analyzer.addFunction(mark(p)) return plots
def createPlots(self, persist=None, raiseit=False, splitThres=2048, plotLinear=True, plotCont=True, plotBound=True, plotIterations=True, plotCourant=True, plotExecution=True, plotDeltaT=True, start=None, end=None, writeFiles=False, customRegexp=None, plottingImplementation="dummy"): plots={} if plotLinear and self.hasAnalyzer("Linear"): plots["linear"]=createPlotTimelinesDirect("linear", self.getAnalyzer("Linear").lines, persist=persist, raiseit=raiseit, forbidden=["final","iterations"], start=start, end=end, logscale=True, implementation=plottingImplementation) self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres, splitFun=max, advancedSplit=True) plots["linear"].setTitle("Residuals") plots["linear"].setYLabel("Initial residual") if plotCont and self.hasAnalyzer("Continuity"): plots["cont"]=createPlotTimelinesDirect("continuity", self.getAnalyzer("Continuity").lines, persist=persist, alternateAxis=["Global"], raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) plots["cont"].setYLabel("Cumulative") plots["cont"].setYLabel2("Global") self.getAnalyzer("Continuity").lines.setSplitting(splitThres=splitThres, advancedSplit=True) plots["cont"].setTitle("Continuity") if plotBound and self.hasAnalyzer("Bounding"): plots["bound"]=createPlotTimelinesDirect("bounding", self.getAnalyzer("Bounding").lines, persist=persist, raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Bounding").lines.setSplitting(splitThres=splitThres, splitFun=signedMax, advancedSplit=True) plots["bound"].setTitle("Bounded variables") if plotIterations and self.hasAnalyzer("Iterations"): plots["iter"]=createPlotTimelinesDirect("iterations", self.getAnalyzer("Iterations").lines, persist=persist, with_="steps", raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Iterations").lines.setSplitting(splitThres=splitThres, advancedSplit=True) plots["iter"].setTitle("Iterations") plots["iter"].setYLabel("Sum of iterations") if plotCourant and self.hasAnalyzer("Courant"): plots["courant"]=createPlotTimelinesDirect("courant", self.getAnalyzer("Courant").lines, persist=persist, raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Courant").lines.setSplitting(splitThres=splitThres, advancedSplit=True) plots["courant"].setTitle("Courant") plots["courant"].setYLabel("Courant Number [1]") if plotDeltaT and self.hasAnalyzer("DeltaT"): plots["deltaT"]=createPlotTimelinesDirect("timestep", self.getAnalyzer("DeltaT").lines, persist=persist, raiseit=raiseit, start=start, end=end, logscale=True, implementation=plottingImplementation) self.getAnalyzer("DeltaT").lines.setSplitting(splitThres=splitThres, advancedSplit=True) plots["deltaT"].setTitle("DeltaT") plots["deltaT"].setYLabel("dt [s]") if plotExecution and self.hasAnalyzer("Execution"): plots["execution"]=createPlotTimelinesDirect("execution", self.getAnalyzer("Execution").lines, persist=persist, with_="steps", raiseit=raiseit, start=start, end=end, implementation=plottingImplementation) self.getAnalyzer("Execution").lines.setSplitting(splitThres=splitThres, advancedSplit=True) plots["execution"].setTitle("Execution Time") plots["execution"].setYLabel("Time [s]") if customRegexp: self.plotCustom=[] masters={} slaves=[] for i,custom in enumerate(customRegexp): if not custom.enabled: continue if persist!=None: custom.persist=persist if start!=None: custom.start=start if end!=None: custom.end=end custom.raiseit=raiseit createPlot=True if custom.type=="phase": self.addAnalyzer(custom.name, PhaseChangerLineAnalyzer(custom.expr, idNr=custom.idNr)) createPlot=False elif custom.type=="dynamic": self.addAnalyzer(custom.name, RegExpLineAnalyzer(custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, progressTemplate=custom.progress, singleFile=True, idNr=custom.idNr, startTime=custom.start, endTime=custom.end)) elif custom.type=="regular" or custom.type=="slave": self.addAnalyzer(custom.name, RegExpLineAnalyzer(custom.name.lower(), custom.expr, titles=custom.titles, doTimelines=True, doFiles=writeFiles, accumulation=custom.accumulation, progressTemplate=custom.progress, singleFile=True, startTime=custom.start, endTime=custom.end)) else: error("Unknown type",custom.type,"in custom expression",custom.name) if createPlot: if custom.master==None: if custom.type=="slave": error("Custom expression",custom.name,"is supposed to be a 'slave' but no master is defined") masters[custom.id]=custom plotCustom=createPlotTimelines(self.getAnalyzer(custom.name).lines, custom=custom, implementation=plottingImplementation) self.getAnalyzer(custom.name).lines.setSplitting(splitThres=splitThres, advancedSplit=True) plotCustom.setTitle(custom.theTitle) plots["custom%04d" % i]=plotCustom else: if custom.type!="slave": error("'master' only makes sense if type is 'slave' for",custom.name) if getattr(custom,"alternateAxis",None): error("Specify alternate values in 'alternateAxis' of master", custom.master,"for",custom.name) slaves.append(custom) for s in slaves: if s.master not in masters: error("The custom plot",s.id,"wants the master plot", s.master,"but it is not found in the list of masters", list(masters.keys())) else: slave=self.getAnalyzer(s.name) master=self.getAnalyzer(masters[s.master].name) slave.setMaster(master) self.reset() return plots