def _create_plot_pr(self, estimate=False): """ Create and prepare invertor instance from a plottable data set. :param path: path of the file to read in """ # Sanity check if self.current_plottable is None: msg = "Please load a valid data set before proceeding." wx.PostEvent(self.parent, StatusEvent(status=msg)) return None # Get the data from the chosen data set and perform inversion pr = Invertor() pr.d_max = self.max_length pr.alpha = self.alpha pr.q_min = self.q_min pr.q_max = self.q_max pr.x = self.current_plottable.x pr.y = self.current_plottable.y pr.has_bck = self.has_bck pr.slit_height = self.slit_height pr.slit_width = self.slit_width # Keep track of the plot window title to ensure that # we can overlay the plots pr.info["plot_group_id"] = self.current_plottable.group_id # Fill in errors if none were provided err = self.current_plottable.dy all_zeros = True if err == None: err = numpy.zeros(len(pr.y)) else: for i in range(len(err)): if err[i] > 0: all_zeros = False if all_zeros: scale = None min_err = 0.0 for i in range(len(pr.y)): # Scale the error so that we can fit over several decades of Q if scale == None: scale = 0.05 * math.sqrt(pr.y[i]) min_err = 0.01 * pr.y[i] err[i] = scale * math.sqrt(math.fabs(pr.y[i])) + min_err message = "The loaded file had no error bars, " message += "statistical errors are assumed." wx.PostEvent(self.parent, StatusEvent(status=message)) pr.err = err return pr
def _create_file_pr(self, data): """ Create and prepare invertor instance from a file data set. :param path: path of the file to read in """ # Reset the status bar so that we don't get mixed up # with old messages. #TODO: refactor this into a proper status handling wx.PostEvent(self.parent, StatusEvent(status='')) try: class FileData(object): x = None y = None err = None path = None def __init__(self, path): self.path = path self._current_file_data = FileData(data.path) self._current_file_data.x = data.x self._current_file_data.y = data.y self._current_file_data.err = data.dy x, y, err = data.x, data.y, data.dy except: load_error(sys.exc_value) return None # If the file contains no data, just return if x is None or len(x) == 0: load_error("The loaded file contains no data") return None # If we have not errors, add statistical errors if y is not None: if err == None or numpy.all(err) == 0: err = numpy.zeros(len(y)) scale = None min_err = 0.0 for i in range(len(y)): # Scale the error so that we can fit over several decades of Q if scale == None: scale = 0.05 * math.sqrt(y[i]) min_err = 0.01 * y[i] err[i] = scale * math.sqrt(math.fabs(y[i])) + min_err message = "The loaded file had no error bars, " message += "statistical errors are assumed." wx.PostEvent(self.parent, StatusEvent(status=message)) try: # Get the data from the chosen data set and perform inversion pr = Invertor() pr.d_max = self.max_length pr.alpha = self.alpha pr.q_min = self.q_min pr.q_max = self.q_max pr.x = x pr.y = y pr.err = err pr.has_bck = self.has_bck pr.slit_height = self.slit_height pr.slit_width = self.slit_width return pr except: load_error(sys.exc_value) return None