def setData(self, data): """Load the data in various formats. param data: string or An open file-like object, or list of array or 2D array if string or open file-like object, (name of a file that contains data or a string containing the data.) this uses the PDFParser to load the data and then passes it to the build-in profile with loadParsedData. if list of array or (2D array), then the first row profile[0] will be x, the second row profile[1] will be y and third row profile[2] (if exists) will be dy """ if isinstance(data, (np.ndarray, list)): if len(data) == 2: x, y = data dy = None elif len(data) == 3: x, y, dy = data self.profile.setObservedProfile(xobs=x, yobs=y, dyobs=dy) else: self.loadData(data) # Get the data into a string from diffpy.srfit.util.inpututils import inputToString datstr = inputToString(data) # Load data with a PDFParser from diffpy.srfit.pdf.pdfparser import PDFParser parser = PDFParser() parser.parseString(datstr) # Pass it to the profile self.profile.loadParsedData(parser) return
def resultsDictionary(results): """Get dictionary of results from file. This reads the results from file and stores them in a dictionary to be returned to the caller. The dictionary may contain non-result entries. results -- An open file-like object, name of a file that contains results from FitResults or a string containing fit results. """ resstr = inputToString(results) rx = {'f' : r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", 'n' : r'[a-zA-Z_]\w*'} pat = r"(%(n)s)\s+(%(f)s)" % rx matches = re.findall(pat, resstr) # Prefer the first match matches.reverse() mpairs = dict(matches) return mpairs
def loadData(self, data): """Load the data in various formats. This uses the PDFParser to load the data and then passes it to the build-in profile with loadParsedData. data -- An open file-like object, name of a file that contains data or a string containing the data. """ # Get the data into a string from diffpy.srfit.util.inpututils import inputToString datstr = inputToString(data) # Load data with a PDFParser from diffpy.srfit.pdf.pdfparser import PDFParser parser = PDFParser() parser.parseString(datstr) # Pass it to the profile self.profile.loadParsedData(parser) return
def resultsDictionary(results): """Get dictionary of results from file. This reads the results from file and stores them in a dictionary to be returned to the caller. The dictionary may contain non-result entries. results -- An open file-like object, name of a file that contains results from FitResults or a string containing fit results. """ resstr = inputToString(results) rx = { 'f': r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", 'n': r'[a-zA-Z_]\w*' } pat = r"(%(n)s)\s+(%(f)s)" % rx matches = re.findall(pat, resstr) # Prefer the first match matches.reverse() mpairs = dict(matches) return mpairs