def _modifyOption(self,key,entry): if key[-2:] == "_z" and entry == " 2D Plot ": self.grapher[key] = None return self.grapher[key] = self.grapher.parseoption(key, entry, parseC.parseC()) if key == "type": self.typeUpdateCallback()
def load(self, **kw): """Load solution with the given AUTO constants. Returns a shallow copy with a copied set of updated constants """ constants = kw.get("constants") if "constants" in kw: del kw["constants"] c = parseC.parseC(self.c) datakw = {} for key in self.data_keys: if key in kw and (key not in c or key in ["LAB", "TY"]): datakw[key] = kw[key] if key not in ["LAB", "TY"]: del kw[key] oldirs = c["IRS"] c.update(constants, **kw) if oldirs is not None and c["IRS"] == 0: return AUTOSolution(constants=c, **datakw) if self["LAB"] != 0: c["IRS"] = self["LAB"] return AUTOSolution(self, constants=c, **datakw)
def __init__(self,**kw): # Set the signal handler if hasattr(signal,'SIGALRM') and demo_max_time > 0: signal.signal(signal.SIGALRM, self.__handler) self.options={} self.options["log"] = None self.options["err"] = None self.options["auto_dir"] = None self.options["demos_dir"] = None self.options["equation"] = "all" self.options["verbose"] = "yes" # note: this is ignored! self.options["clean"] = "no" self.options["dir"] = "." self.options["executable"] = None self.options["command"] = None self.options["makefile"] = None self.options["constants"] = parseC.parseC() self.options["solution"] = parseS.AUTOSolution() self.options["homcont"] = None self.options["selected_solution"] = None kw = self.config(**kw)
def datab(r2, **kwargs): n1b = parseB.parseB(r2) ap = n1b[0] c = parseC.parseC(n1b[0]) xlT = False ylT = False if kwargs.get('x'): x = kwargs.get('x') numx = re.sub('\D', '', x) param = x.strip(numx) if param == 'U': paramx = 'U(' + numx + ')' if param == 'P': paramx = 'PAR(' + numx + ')' if param == 'L': paramx = 'L2-NORM' if param == 'T': paramx = 'PERIOD' else: paramx = 'PAR(1)' if kwargs.get('y'): y = kwargs.get('y') numy = re.sub('\D', '', y) param = y.strip(numy) if param == 'U': paramy = 'U(' + numy + ')' if param == 'P': paramy = 'PAR(' + numy + ')' if param == 'L': paramy = 'L2-NORM' if param == 'T': paramy = 'PERIOD' else: paramy = 'L2-NORM' x = [] y = [] special = [] Branch = 0 BranchLast = 0 if ap['PT'] > 0: current = True last = True else: current = False last = False try: xvalue = c[paramx] except KeyError: xvalue = c['MAX U(' + numx + ')'] try: yvalue = c[paramy] except KeyError: yvalue = c['MAX U(' + numy + ')'] if ap['TY name'] != 'No Label': special.append([ap['TY name'], xvalue, yvalue]) x.append(xvalue) y.append(yvalue) Bchange = False #branch change Bchecklast = ap['BR'] Bcheckcurrent = Bchecklast Schange = False #changed of stability #also can have different calculations for i in range(1, len(n1b)): if Schange == True or Bchange == True or i == len(n1b) - 1: if Bchange == True: Branch = BranchLast + 1 # x=[] # y=[] ap = n1b[i] if ap['PT'] > 0: current = True else: current = False last = current Schange = False Bchange = False last = current Bcheckcurrent = ap['BR'] ap = n1b[i] c = parseC.parseC(n1b[i]) try: xvalue = c[paramx] except KeyError: # print paramx xvalue = c['MAX U(' + numx + ')'] try: yvalue = c[paramy] except KeyError: yvalue = c['MAX U(' + numy + ')'] x.append(xvalue) y.append(yvalue) if ap['TY name'] != 'No Label': special.append([ap['TY name'], xvalue, yvalue]) if ap['PT'] == 1 or ap['PT'] == -1 or Bchecklast != Bcheckcurrent: Bchange = True #this is a fudge because sometimes ap['PT'] returned NoneType # this should detect when new line is plotted as first point is 1 if ap['PT'] > 0: current = True else: current = False if current != last: Schange = True BranchLast = Branch Bchecklast = Bcheckcurrent return x, y
def plotb(r2, **kwargs): colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] fig = plt.figure() fig.clf() ax = fig.add_subplot(111) n1b = parseB.parseB(r2) ap = n1b[0] c = parseC.parseC(n1b[0]) xlT = False ylT = False if kwargs.get('xlim'): ax.set_xlim(kwargs.get('xlim')) xl = kwargs.get('xlim') xlT = True if kwargs.get('ylim'): ax.set_ylim(kwargs.get('ylim')) yl = kwargs.get('ylim') ylT = True if kwargs.get('x'): x = kwargs.get('x') numx = re.sub('\D', '', x) param = x.strip(numx) if param == 'U': paramx = 'U(' + numx + ')' if param == 'P': paramx = 'PAR(' + numx + ')' if param == 'L': paramx = 'L2-NORM' if param == 'T': paramx = 'PERIOD' else: paramx = 'PAR(1)' if kwargs.get('y'): y = kwargs.get('y') numy = re.sub('\D', '', y) param = y.strip(numy) if param == 'U': paramy = 'U(' + numy + ')' if param == 'P': paramy = 'PAR(' + numy + ')' if param == 'L': paramy = 'L2-NORM' if param == 'T': paramy = 'PERIOD' else: paramy = 'L2-NORM' if kwargs.get('stable'): if kwargs.get('stable') == 'True': stab_dashed = True else: stab_dashed = False yl = kwargs.get('ylim') x = [] y = [] special = [] Branch = 0 BranchLast = 0 if ap['PT'] > 0: current = True last = True else: current = False last = False try: xvalue = c[paramx] except KeyError: xvalue = c['MAX U(' + numx + ')'] try: yvalue = c[paramy] except KeyError: yvalue = c['MAX U(' + numy + ')'] if ap['TY name'] != 'No Label': special.append([ap['TY name'], xvalue, yvalue]) x.append(xvalue) y.append(yvalue) Bchange = False #branch change Bchecklast = ap['BR'] Bcheckcurrent = Bchecklast Schange = False #changed of stability #also can have different calculations for i in range(1, len(n1b)): if Schange == True or Bchange == True or i == len(n1b) - 1: color = colors[Branch % 7] if Bchange == True: Branch = BranchLast + 1 if last == True and stab_dashed == True: ax.plot(x[0:len(x) - 2], y[0:len(x) - 2], color=color, ls='dotted') else: ax.plot(x[0:len(x) - 2], y[0:len(x) - 2], color=color, ls='solid') x = [] y = [] ap = n1b[i] if ap['PT'] > 0: current = True else: current = False last = current Schange = False Bchange = False last = current Bcheckcurrent = ap['BR'] ap = n1b[i] c = parseC.parseC(n1b[i]) try: xvalue = c[paramx] except KeyError: # print paramx xvalue = c['MAX U(' + numx + ')'] try: yvalue = c[paramy] except KeyError: yvalue = c['MAX U(' + numy + ')'] x.append(xvalue) y.append(yvalue) if ap['TY name'] != 'No Label': special.append([ap['TY name'], xvalue, yvalue]) if ap['PT'] == 1 or ap['PT'] == -1 or Bchecklast != Bcheckcurrent: Bchange = True #this is a fudge because sometimes ap['PT'] returned NoneType # this should detect when new line is plotted as first point is 1 if ap['PT'] > 0: current = True else: current = False if current != last: Schange = True BranchLast = Branch Bchecklast = Bcheckcurrent for i, sp in enumerate(special): if xlT == True: if sp[1] > xl[0] and sp[1] < xl[1]: sp1 = sp[1] if ylT == True: if sp[2] > yl[0] and sp[2] < yl[1]: sp2 = sp[2] ax.plot(sp[1], sp[2], ls='None', marker='x', color='k', markersize=3) ax.text(sp[1], sp[2], sp[0]) else: ax.plot(sp[1], sp[2], ls='None', marker='x', color='k', markersize=3) ax.text(sp[1], sp[2], sp[0]) elif ylT == True: if sp[2] > yl[0] and sp[2] < yl[1]: sp2 = sp[2] ax.plot(sp[1], sp[2], ls='None', marker='x', color='k', markersize=3) ax.text(sp[1], sp[2], sp[0]) else: ax.plot(sp[1], sp[2], ls='None', marker='x', color='k', markersize=3) ax.text(sp[1], sp[2], sp[0]) ax.set_xlabel(paramx) ax.set_ylabel(paramy)
def __init__(self,parent=None,**kw): optionDefaults = {} # The kind of diagram (single solution vs. bifur diagram) optionDefaults["type"] = ("bifurcation",self.__optionCallback) # The X column optionDefaults["bifurcation_x"] = ([0],self.__optionCallback) optionDefaults["solution_x"] = ([-1],self.__optionCallback) # The Y column optionDefaults["bifurcation_y"] = ([1],self.__optionCallback) optionDefaults["solution_y"] = ([0],self.__optionCallback) # The Z column optionDefaults["bifurcation_z"] = (None,self.__optionCallback) optionDefaults["solution_z"] = (None,self.__optionCallback) # The coordinate names optionDefaults["bifurcation_coordnames"] = (None,self.__optionCallback) optionDefaults["solution_indepvarname"] = (None,self.__optionCallback) optionDefaults["solution_coordnames"] = (None,self.__optionCallback) optionDefaults["labelnames"] = (None,self.__optionCallback) # Sets of labels that the user is likely to want to use optionDefaults["label_defaults"] = (None,self.__optionCallback) # Sets of columns that the user is likely to want to use optionDefaults["bifurcation_column_defaults"] = (None,self.__optionCallback) optionDefaults["solution_column_defaults"] = (None,self.__optionCallback) # The index of the solution we wish to draw optionDefaults["index"] = ([0],self.__optionCallback) # The label of the solution we wish to draw optionDefaults["label"] = ([0],self.__optionCallback) # Already parsed data structures optionDefaults["bifurcation_diagram"] = (parseB.parseB(),self.__optionCallback) optionDefaults["solution"] = (parseS.parseS(),self.__optionCallback) optionDefaults["bifurcation_diagram_filename"] = ("",self.__optionCallback) optionDefaults["solution_filename"] = ("",self.__optionCallback) optionDefaults["runner"] = (None,self.__optionCallback) optionDefaults["mark_t"] = (None,self.__optionCallback) optionDefaults["letter_symbols"] = (True,self.__optionCallback) optionDefaults["bifurcation_symbol"] = ("B",self.__optionCallback) optionDefaults["limit_point_symbol"] = ("L",self.__optionCallback) optionDefaults["hopf_symbol"] = ("H",self.__optionCallback) optionDefaults["zero_hopf_symbol"] = ("ZH",self.__optionCallback) optionDefaults["bogdanov_takens_symbol"] = ("BT",self.__optionCallback) optionDefaults["cusp_symbol"] = ("CP",self.__optionCallback) optionDefaults["generalized_hopf_symbol"]= ("GH",self.__optionCallback) optionDefaults["1_1_resonance_symbol"] = ("R1",self.__optionCallback) optionDefaults["1_2_resonance_symbol"] = ("R2",self.__optionCallback) optionDefaults["1_3_resonance_symbol"] = ("R3",self.__optionCallback) optionDefaults["1_4_resonance_symbol"] = ("R4",self.__optionCallback) optionDefaults["fold_flip_symbol"] = ("LPD",self.__optionCallback) optionDefaults["fold_torus_symbol"] = ("LTR",self.__optionCallback) optionDefaults["flip_torus_symbol"] = ("PTR",self.__optionCallback) optionDefaults["torus_torus_symbol"] = ("TTR",self.__optionCallback) optionDefaults["period_doubling_symbol"] = ("D",self.__optionCallback) optionDefaults["torus_symbol"] = ("T",self.__optionCallback) optionDefaults["user_point_symbol"] = ("U",self.__optionCallback) optionDefaults["error_symbol"] = ("X",self.__optionCallback) optionDefaults["ps_colormode"] = ("color",self.__optionCallback) optionDefaults["stability"] = (False,self.__optionCallback) optionDefaults["coloring_method"] = ("curve",self.__optionCallback) parser = AUTOutil.getAUTORC("AUTO_plotter") optionDefaultsRC = {} c = parseC.parseC() for option in parser.options("AUTO_plotter"): optionDefaultsRC[option] = self.parseoption( option,parser.get("AUTO_plotter",option),c) # Let these override the RC options, if specified. for key in ["hide","xlabel","ylabel","zlabel"]: if key in kw: optionDefaultsRC[key] = kw[key] self.__needsPlot = None grapher.GUIGrapher.__init__(self,parent,**optionDefaultsRC) self.addOptions(**optionDefaults) self.addRCOptions(**optionDefaultsRC) for options in [optionDefaultsRC, kw]: if "letter_symbols" in options: self.__optionCallback("letter_symbols", options["letter_symbols"], options) del options["letter_symbols"] plotter._configNoDraw(self,**optionDefaultsRC) plotter._configNoDraw(self,**kw) self._plotNoDraw() self.__needsPlot = None for coord in 'x', 'y', 'z': if "min"+coord not in kw or "max"+coord not in kw: self.computeRange(coord,kw.get("min"+coord), kw.get("max"+coord)) grapher.GUIGrapher.plot(self)
def parseHeader(self,headerlist): self.headerlist = headerlist if hasattr(str,"split"): split = str.split else: import string split = string.split line = "" if headerlist != []: line = headerlist[-1] ncolumns = len(split(self.__datalist[0])) - 4 self.headernames = [] self.coordnames = [] self.TY = 0 if " PT " in line: linelen = len(self.__datalist[0]) columnlen = (linelen - 19) // ncolumns n = linelen - columnlen * ncolumns for i in range(ncolumns): self.headernames.append(line[n:n+columnlen].rstrip()) self.coordnames.append(line[n:n+columnlen].strip()) n = n + columnlen if self.coordnames == []: self.coordnames = ["COLUMN(%d)"%(i+1) for i in range(ncolumns)] dict = parseC.parseC() i = 0 if len(headerlist) == 0: return words = split(headerlist[0]) if len(words) < 5: return for key in ["RL0","RL1","A0","A1"]: i = i + 1 dict[key] = AUTOatof(words[i]) key = "" userspec = False for line in headerlist[1:]: words = split(line) if len(words) < 2: break if words[-1] in ["constants:", "above:"]: userspec = True continue if words[1] == 'Branch': self.TY = int(words[3]) if words[1] in ["User-specified", "Active"]: line = line.replace("s:",":") for ind in range(2,len(words)): if words[ind] in ["parameter:","parameters:"]: index = ind + 1 break if words[1][0] == "U": key = "ICP" else: key = "Active ICP" d = [] for w in words[index:]: try: w = int(w) except ValueError: if ((w[0] == "'" and w[-1] == "'") or (w[0] == '"' and w[-1] == '"')): w = w[1:-1] d.append(w) dict[key] = d continue dict.parseline(" ".join(words[1:]),userspec) return dict
def __realinit(self, fort7_filename, fort8_filename, fort9_filename, constants): ioerrors = [] try: parseB.parseBR.__init__(self, fort7_filename) for i, d in enumerate(self): self[i] = bifDiagBranch(d) except IOError: ioerrors.append(str(sys.exc_info()[1])) parseB.parseBR.__init__(self) fort7_filename = None if isinstance(fort8_filename, parseS.AUTOSolution): fort8_filename = [fort8_filename] try: solution = parseS.parseS(fort8_filename) except IOError: ioerrors.append(str(sys.exc_info()[1])) solution = None if fort7_filename is None: raise AUTOExceptions.AUTORuntimeError('\n'.join(ioerrors)) if fort7_filename is None and fort8_filename is not None: # simulate a bifurcation diagram labels = {} for s in solution: br = s["Branch number"] if labels == {} or br != branch.BR: if labels != {}: branch.labels = Points.PointInfo(labels) branch = bifDiagBranch() self.append(branch) branch.BR = br branch.coordarray = [] branch.coordnames = [] branch.headernames = [] branch.headerlist = [] branch.c = constants labels = {} base = 0 i = 0 pt = s["PT"] lab = s["LAB"] ty = s["TY number"] if i >= base + pt - 1: # point numbers wrapped around base += 9999 i = base + pt - 1 labels[i] = {s["TY"]: {"LAB": lab, "TY number": ty, "PT": pt}} if labels != {}: branch.labels = Points.PointInfo(labels) if fort9_filename is not None and self.data != []: try: # for now just attach diagnostics information to first branch self[0].diagnostics = parseD.parseD(fort9_filename) except IOError: pass i = 0 if solution is not None: for d in self: if constants is None and d.c is not None: constants = d.c constants = parseC.parseC(constants) for k in constants: if k in self.nonekeys: constants[k] = None for ind in d.labels.getIndices(): if i >= len(solution): break x = d._gettypelabel(ind)[1] s = solution[i] if x.get("LAB", 0) != 0 or s["LAB"] == 0: i = i + 1 s = x["solution"] = parseS.AUTOSolution( s, constants=constants) if d.coordnames != []: s.b = d[ind]
def datab(r2, **kwargs): n1b=parseB.parseB(r2) ap=n1b[0] c=parseC.parseC(n1b[0]) xlT=False ylT=False if kwargs.get('x'): x=kwargs.get('x') numx=re.sub('\D', '',x) param=x.strip(numx) if param=='U': paramx='U('+numx+')' if param=='P': paramx='PAR('+numx+')' if param=='L': paramx='L2-NORM' if param=='T': paramx='PERIOD' else: paramx='PAR(1)' if kwargs.get('y'): y=kwargs.get('y') numy=re.sub('\D', '',y) param=y.strip(numy) if param=='U': paramy='U('+numy+')' if param=='P': paramy='PAR('+numy+')' if param=='L': paramy='L2-NORM' if param=='T': paramy='PERIOD' else: paramy='L2-NORM' x=[] y=[] special=[] Branch=0 BranchLast=0 if ap['PT']>0: current=True last=True else: current=False last=False try: xvalue=c[paramx] except KeyError: xvalue=c['MAX U('+numx+')'] try: yvalue=c[paramy] except KeyError: yvalue=c['MAX U('+numy+')'] if ap['TY name']!='No Label': special.append([ap['TY name'],xvalue,yvalue]) x.append(xvalue) y.append(yvalue) Bchange=False #branch change Bchecklast=ap['BR'] Bcheckcurrent=Bchecklast Schange=False #changed of stability #also can have different calculations for i in range(1,len(n1b)): if Schange==True or Bchange==True or i==len(n1b)-1: if Bchange==True: Branch=BranchLast+1 # x=[] # y=[] ap=n1b[i] if ap['PT']>0: current=True else: current=False last=current Schange=False Bchange=False last=current Bcheckcurrent=ap['BR'] ap=n1b[i] c=parseC.parseC(n1b[i]) try: xvalue=c[paramx] except KeyError: # print paramx xvalue=c['MAX U('+numx+')'] try: yvalue=c[paramy] except KeyError: yvalue=c['MAX U('+numy+')'] x.append(xvalue) y.append(yvalue) if ap['TY name']!='No Label': special.append([ap['TY name'],xvalue,yvalue]) if ap['PT']==1 or ap['PT']==-1 or Bchecklast!=Bcheckcurrent: Bchange=True #this is a fudge because sometimes ap['PT'] returned NoneType # this should detect when new line is plotted as first point is 1 if ap['PT']>0: current=True else: current=False if current!=last: Schange=True BranchLast=Branch Bchecklast=Bcheckcurrent return x,y
def plotb(r2, **kwargs): colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'] fig=plt.figure() fig.clf() ax=fig.add_subplot(111) n1b=parseB.parseB(r2) ap=n1b[0] c=parseC.parseC(n1b[0]) xlT=False ylT=False if kwargs.get('xlim'): ax.set_xlim(kwargs.get('xlim')) xl=kwargs.get('xlim') xlT=True if kwargs.get('ylim'): ax.set_ylim(kwargs.get('ylim')) yl=kwargs.get('ylim') ylT=True if kwargs.get('x'): x=kwargs.get('x') numx=re.sub('\D', '',x) param=x.strip(numx) if param=='U': paramx='U('+numx+')' if param=='P': paramx='PAR('+numx+')' if param=='L': paramx='L2-NORM' if param=='T': paramx='PERIOD' else: paramx='PAR(1)' if kwargs.get('y'): y=kwargs.get('y') numy=re.sub('\D', '',y) param=y.strip(numy) if param=='U': paramy='U('+numy+')' if param=='P': paramy='PAR('+numy+')' if param=='L': paramy='L2-NORM' if param=='T': paramy='PERIOD' else: paramy='L2-NORM' if kwargs.get('stable'): if kwargs.get('stable')=='True': stab_dashed=True else: stab_dashed=False yl=kwargs.get('ylim') x=[] y=[] special=[] Branch=0 BranchLast=0 if ap['PT']>0: current=True last=True else: current=False last=False try: xvalue=c[paramx] except KeyError: xvalue=c['MAX U('+numx+')'] try: yvalue=c[paramy] except KeyError: yvalue=c['MAX U('+numy+')'] if ap['TY name']!='No Label': special.append([ap['TY name'],xvalue,yvalue]) x.append(xvalue) y.append(yvalue) Bchange=False #branch change Bchecklast=ap['BR'] Bcheckcurrent=Bchecklast Schange=False #changed of stability #also can have different calculations for i in range(1,len(n1b)): if Schange==True or Bchange==True or i==len(n1b)-1: color=colors[Branch%7] if Bchange==True: Branch=BranchLast+1 if last==True and stab_dashed==True: ax.plot(x[0:len(x)-2],y[0:len(x)-2],color=color,ls='dotted') else: ax.plot(x[0:len(x)-2],y[0:len(x)-2],color=color,ls='solid') x=[] y=[] ap=n1b[i] if ap['PT']>0: current=True else: current=False last=current Schange=False Bchange=False last=current Bcheckcurrent=ap['BR'] ap=n1b[i] c=parseC.parseC(n1b[i]) try: xvalue=c[paramx] except KeyError: # print paramx xvalue=c['MAX U('+numx+')'] try: yvalue=c[paramy] except KeyError: yvalue=c['MAX U('+numy+')'] x.append(xvalue) y.append(yvalue) if ap['TY name']!='No Label': special.append([ap['TY name'],xvalue,yvalue]) if ap['PT']==1 or ap['PT']==-1 or Bchecklast!=Bcheckcurrent: Bchange=True #this is a fudge because sometimes ap['PT'] returned NoneType # this should detect when new line is plotted as first point is 1 if ap['PT']>0: current=True else: current=False if current!=last: Schange=True BranchLast=Branch Bchecklast=Bcheckcurrent for i,sp in enumerate(special): if xlT==True: if sp[1]>xl[0] and sp[1]<xl[1]: sp1=sp[1] if ylT==True: if sp[2]>yl[0] and sp[2]<yl[1]: sp2=sp[2] ax.plot(sp[1],sp[2],ls='None',marker='x',color='k',markersize=3) ax.text(sp[1],sp[2],sp[0]) else: ax.plot(sp[1],sp[2],ls='None',marker='x',color='k',markersize=3) ax.text(sp[1],sp[2],sp[0]) elif ylT==True: if sp[2]>yl[0] and sp[2]<yl[1]: sp2=sp[2] ax.plot(sp[1],sp[2],ls='None',marker='x',color='k',markersize=3) ax.text(sp[1],sp[2],sp[0]) else: ax.plot(sp[1],sp[2],ls='None',marker='x',color='k',markersize=3) ax.text(sp[1],sp[2],sp[0]) ax.set_xlabel(paramx) ax.set_ylabel(paramy)