def get_file_contents(self): """ Reader specific class to access the contents of the file All reader classes that inherit from FileReader must implement """ x = np.zeros(0) y = np.zeros(0) self.current_dataset = plottable_1D(x, y) self.current_datainfo = DataInfo() self.current_datainfo.meta_data["blah"] = self.nextline() self.send_to_output()
def setUp(self): self.reader = FileReader() self.bad_file = "ACB123.txt" self.good_file = "123ABC.txt" self.msg = "Unable to find file at: {}\n".format(self.bad_file) self.msg += "Please check your file path and try again." x = np.zeros(0) y = np.zeros(0) self.reader.current_dataset = plottable_1D(x, y) self.reader.current_datainfo = DataInfo() self.reader.send_to_output()
def get_file_contents(self): """ Reader specific class to access the contents of the file All reader classes that inherit from FileReader must implement """ x = np.zeros(0) y = np.zeros(0) self.current_dataset = plottable_1D(x,y) self.current_datainfo = DataInfo() self.current_datainfo.meta_data["blah"] = self.nextline() self.send_to_output()
def _initialize_new_data_set(self, parent_list = None): """ A private class method to generate a new 1D or 2D data object based on the type of data within the set. Outside methods should call add_data_set() to be sure any existing data is stored properly. :param parent_list: List of names of parent elements """ if parent_list is None: parent_list = [] if self._find_intermediate(parent_list, "Qx"): self.current_dataset = plottable_2D() else: x = np.array(0) y = np.array(0) self.current_dataset = plottable_1D(x, y) self.current_datainfo.filename = self.raw_data.filename
def reset_state(self): self.current_dataset = plottable_1D(np.empty(0), np.empty(0), np.empty(0), np.empty(0)) self.current_datainfo = DataInfo() self.datasets = [] self.raw_data = None self.errors = set() self.logging = [] self.output = [] self.detector = Detector() self.collimation = Collimation() self.aperture = Aperture() self.process = Process() self.source = Source() self.sample = Sample() self.trans_spectrum = TransmissionSpectrum() self.upper = 5 self.lower = 5
def reset_state(self): self.current_dataset = plottable_1D(np.empty(0), np.empty(0), np.empty(0), np.empty(0)) self.current_datainfo = DataInfo() self.datasets = [] self.raw_data = None self.errors = set() self.logging = [] self.output = [] self.detector = Detector() self.collimation = Collimation() self.aperture = Aperture() self.process = Process() self.source = Source() self.sample = Sample() self.trans_spectrum = TransmissionSpectrum() self.upper = 5 self.lower = 5
def _initialize_new_data_set(self, parent_list=None): """ A private class method to generate a new 1D or 2D data object based on the type of data within the set. Outside methods should call add_data_set() to be sure any existing data is stored properly. :param parent_list: List of names of parent elements """ if parent_list is None: parent_list = [] if self._find_intermediate(parent_list, "Qx"): self.current_dataset = plottable_2D() else: x = np.array(0) y = np.array(0) self.current_dataset = plottable_1D(x, y) self.current_datainfo.filename = self.raw_data.filename
def get_file_contents(self): self.current_datainfo = DataInfo() self.current_dataset = plottable_1D(np.array([]), np.array([])) self.current_datainfo.isSesans = True self.output = [] line = self.f_open.readline() params = {} while not line.startswith("BEGIN_DATA"): terms = line.split() if len(terms) >= 2: params[terms[0]] = " ".join(terms[1:]) line = self.f_open.readline() self.params = params if "FileFormatVersion" not in self.params: raise FileContentsException("SES file missing FileFormatVersion") if float(self.params["FileFormatVersion"]) >= 2.0: raise FileContentsException("SASView only supports SES version 1") if "SpinEchoLength_unit" not in self.params: raise FileContentsException("SpinEchoLength has no units") if "Wavelength_unit" not in self.params: raise FileContentsException("Wavelength has no units") if params["SpinEchoLength_unit"] != params["Wavelength_unit"]: raise FileContentsException("The spin echo data has rudely used " "different units for the spin echo length " "and the wavelength. While sasview could " "handle this instance, it is a violation " "of the file format and will not be " "handled by other software.") headers = self.f_open.readline().split() self._insist_header(headers, "SpinEchoLength") self._insist_header(headers, "Depolarisation") self._insist_header(headers, "Depolarisation_error") self._insist_header(headers, "Wavelength") data = np.loadtxt(self.f_open) if data.shape[1] != len(headers): raise FileContentsException( "File has {} headers, but {} columns".format( len(headers), data.shape[1])) if not data.size: raise FileContentsException("{} is empty".format(path)) x = data[:, headers.index("SpinEchoLength")] if "SpinEchoLength_error" in headers: dx = data[:, headers.index("SpinEchoLength_error")] else: dx = x * 0.05 lam = data[:, headers.index("Wavelength")] if "Wavelength_error" in headers: dlam = data[:, headers.index("Wavelength_error")] else: dlam = lam * 0.05 y = data[:, headers.index("Depolarisation")] dy = data[:, headers.index("Depolarisation_error")] lam_unit = self._unit_fetch("Wavelength") x, x_unit = self._unit_conversion(x, "A", self._unit_fetch( "SpinEchoLength")) dx, dx_unit = self._unit_conversion( dx, lam_unit, self._unit_fetch("SpinEchoLength")) dlam, dlam_unit = self._unit_conversion( dlam, lam_unit, self._unit_fetch("Wavelength")) y_unit = self._unit_fetch("Depolarisation") self.current_dataset.x = x self.current_dataset.y = y self.current_dataset.lam = lam self.current_dataset.dy = dy self.current_dataset.dx = dx self.current_dataset.dlam = dlam self.current_datainfo.isSesans = True self.current_datainfo._yunit = y_unit self.current_datainfo._xunit = x_unit self.current_datainfo.source.wavelength_unit = lam_unit self.current_datainfo.source.wavelength = lam self.current_datainfo.filename = os.path.basename(self.f_open.name) self.current_dataset.xaxis(r"\rm{z}", x_unit) # Adjust label to ln P/(lam^2 t), remove lam column refs self.current_dataset.yaxis(r"\rm{ln(P)/(t \lambda^2)}", y_unit) # Store loading process information self.current_datainfo.meta_data['loader'] = self.type_name self.current_datainfo.sample.name = params["Sample"] self.current_datainfo.sample.ID = params["DataFileTitle"] self.current_datainfo.sample.thickness = self._unit_conversion( float(params["Thickness"]), "cm", self._unit_fetch("Thickness"))[0] self.current_datainfo.sample.zacceptance = ( float(params["Theta_zmax"]), self._unit_fetch("Theta_zmax")) self.current_datainfo.sample.yacceptance = ( float(params["Theta_ymax"]), self._unit_fetch("Theta_ymax")) self.send_to_output()