def __init__(self, outputRecorder=None, errorRecorder=None): # Initialize the global AUTO runner runner = runAUTO.runAUTO() if outputRecorder is not None: stdout = sys.stdout class WriteLog(object): def write(self, s): outputRecorder.write(s) stdout.write(s) def flush(self): outputRecorder.flush() stdout.flush() runner.config(log=WriteLog()) if errorRecorder is not None: stderr = sys.stderr class WriteErr(object): def write(self, s): errorRecorder.write(s) stderr.write(s) def flush(self): errorRecorder.flush() stderr.flush() runner.config(err=WriteErr()) self._runner = runner # Read in the aliases. self._aliases = None parser = AUTOutil.getAUTORC() if parser.has_section("AUTO_command_aliases"): self._aliases = {} for option in parser.options("AUTO_command_aliases"): cmd = parser.get("AUTO_command_aliases", option) if cmd not in self._aliases: self._aliases[cmd] = [] self._aliases[cmd].append(option) self._addCommands([AUTOCommands]) # Now I resolve the aliases for key, aliases in self._aliases.items(): for alias in aliases: f = self._copyfunction(getattr(AUTOCommands, key).fun, alias) setattr(self, alias, f) doc = getattr(AUTOCommands, key).__doc__ doc = self._adjustdoc(doc, alias, key) f.__doc__ = doc
def __compactindexed(self, value): """compact THL/THU/UZR lists""" d = [] v0s = [] for v0, v1 in value: if v0 in v0s: if not AUTOutil.isiterable(v1): v1 = [v1] # add to list when parameter was already encountered try: d[v0s.index(v0)][1].extend(v1) except AttributeError: d[v0s.index(v0)][1] = [d[v0s.index(v0)][1]] d[v0s.index(v0)][1].extend(v1) else: v0s.append(v0) d.append([v0,v1]) return d
def __oldstr(self): olist = [self.__newstr([ ["e", "s", "dat", "sv"], ["unames", "parnames"], ["U", "PAR"], ["NPAR", "IBR", "LAB"], ["STOP"], ["SP"], ["NUNSTAB", "NSTAB", "IEQUIB", "ITWIST", "ISTART"], ["IREV", "IFIXED", "IPSI"]])] for j, line_comment in enumerate(self.line_comments): if j==1: s = " ".join([str(len(self["ICP"]))]+map(str,self["ICP"])) elif j==7: s = str(len(self["THL"])) elif j==8: s = str(len(self["THU"])) elif j==9: uzrlist = [] for k, v in self["UZR"] or []: if not AUTOutil.isiterable(v): v = [v] for vv in v: uzrlist.append([k, vv]) s = str(len(uzrlist)) else: s = " ".join([str(self[d]) for d in line_comment.split(",")]) olist.append(s+" "*(max(24-len(s),1))+line_comment+"\n") if j==7: for k, v in self["THL"] or []: olist.append("%s %s\n" % (k, v)) elif j==8: for k, v in self["THU"] or []: olist.append("%s %s\n" % (k, v)) elif j==9: for k, v in uzrlist: olist.append("%s %s\n" % (k, v)) return "".join(olist)
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"): try: optionDefaultsRC[option] = self.parseoption( option,parser.get("AUTO_plotter",option),c) except: optionDefaultsRC[option] = self.parseoption( option,parser.get("AUTO_plotter",option,raw=True),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 readFilename(self, filename): inputfile = AUTOutil.openFilename(filename, "r") self.read(inputfile)
def __init__(self, filename): if isinstance(filename, str): inputfile = AUTOutil.openFilename(filename,"rb") else: inputfile = filename self.inputfile = inputfile self.name = inputfile.name self.solutions = [] # We now go through the file and read the solutions. prev = None # for fort.8 we need to read everything into memory; otherwise load the # data on demand from disk when we really need it # on Windows always load everything because deleting open files is # impossible there inmemory = (os.path.basename(inputfile.name) == 'fort.8' or sys.platform in ['cygwin', 'win32']) while len(inputfile.read(1)) > 0: line = inputfile.readline() if not line: raise PrematureEndofData try: header = list(map(int, line.split())) except ValueError: raise PrematureEndofData if len(header) < 10: raise PrematureEndofData if len(header) == 10: # This is the case for AUTO94 and before header = header + [NPAR] numLinesPerEntry = header[8] start_of_data = inputfile.tell() if prev is not None and all( [header[i] == prevheader[i] for i in [4, 6, 7, 8, 11]]): # guess the end from the previous solution end += inputfile.tell() - prev # See if the guess for the solution end is correct inputfile.seek(end) data = inputfile.readline().split() # This is where we detect the end of the file if len(data) == 0: data = inputfile.read(1) if len(data) != 0: try: # Check length of line... if len(data) != 12 and len(data) != 16: raise IncorrectHeaderLength # and the fact they are all integers map(int,data) # and the fact that NCOL*NTST+1=NTPL if int(data[9])*int(data[10])+1 != int(data[6]): end = None # If it passes all these tests we say it is a header line # and we can read quickly except: # otherwise the guessed end is not valid end = None else: end = None data = None if end is None: # We skip the correct number of lines in the entry to # determine its end. inputfile.seek(start_of_data) if inmemory: data = "".encode("ascii").join([inputfile.readline() for i in range(numLinesPerEntry)]) else: for i in range(numLinesPerEntry): inputfile.readline() end = inputfile.tell() elif inmemory: inputfile.seek(start_of_data) data = inputfile.read(end - start_of_data) else: inputfile.seek(end) if data is None: data = (start_of_data, end) self.solutions.append({'header': header, 'data': data}) prev = start_of_data prevheader = header
def getLabel(self,label): if label is None: return self if isinstance(label, int): for d in self: if d["Label"] == label: return d raise KeyError("Label %s not found"%label) if isinstance(label, str) and len(label) > 2 and label[-1].isdigit(): j = 2 if not label[2].isdigit(): j = 3 number = int(label[j:]) i = 0 for d in self: if d["Type name"] == label[:j]: i = i + 1 if i == number: return d raise KeyError("Label %s not found"%label) if isinstance(label, types.FunctionType): # accept a user-defined boolean function f = label cnt = getattr(f,"func_code",getattr(f,"__code__",None)).co_argcount if cnt == 1: # function takes just one parameter s = [s for s in self if f(s)] elif cnt == 2: # function takes two parameters: compare all solutions # with each other indices = set([]) for i1, s1 in enumerate(self): if i1 in indices: continue for i2 in range(i1+1,len(self)): if i2 not in indices and f(s1, self[i2]): indices.add(i2) s = [self[i] for i in sorted(indices)] else: raise AUTOExceptions.AUTORuntimeError( "Invalid number of arguments for %s."%f.__name__) return self.__class__(s) if not AUTOutil.isiterable(label): label = [label] data = [] counts = [0]*len(label) for d in self: ap = None if d["Label"] in label or d["Type name"] in label: ap = d for i in range(len(label)): lab = label[i] j = 2 if len(lab) > 2 and not lab[2].isdigit(): j = 3 if (isinstance(lab, str) and len(lab) > j and d["Type name"] == lab[:j]): counts[i] = counts[i] + 1 if counts[i] == int(lab[j:]): ap = d if ap is not None: data.append(ap) return self.__class__(data)