Changeset cb9feea8 in sasview
- Timestamp:
- Apr 4, 2017 6:15:55 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 8390cf6
- Parents:
- 56e2e3e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/sesans_reader.py
r56e2e3e rcb9feea8 49 49 basename = os.path.basename(path) 50 50 _, extension = os.path.splitext(basename) 51 if self.allow_all or extension.lower() in self.ext: 52 with open(path, 'r') as input_f: 53 # Read in binary mode since GRASP frequently has no-ascii 54 # characters that brakes the open operation 55 line = input_f.readline() 56 params = {} 57 while line.strip() != "": 58 terms = line.strip().split("\t") 59 params[terms[0].strip()] = " ".join(terms[1:]).strip() 60 line = input_f.readline() 61 headers_temp = input_f.readline().strip().split("\t") 62 headers = {} 63 for h in headers_temp: 64 temp = h.strip().split() 65 headers[h[:-1].strip()] = temp[-1][1:-1] 66 data = np.loadtxt(input_f) 67 if data.size < 1: 68 raise RuntimeError("{} is empty".format(path)) 69 x = data[:, 0] 70 dx = data[:, 3] 71 lam = data[:, 4] 72 dlam = data[:, 5] 73 y = data[:, 1] 74 dy = data[:, 2] 51 if not (self.allow_all or extension.lower() in self.ext): 52 raise RuntimeError("{} has an unrecognized file extension".format(path)) 53 else: 54 raise RunetimeError("{} is not a file".format(path)) 55 with open(path, 'r') as input_f: 56 # Read in binary mode since GRASP frequently has no-ascii 57 # characters that brakes the open operation 58 line = input_f.readline() 59 params = {} 60 while line.strip() != "": 61 terms = line.strip().split("\t") 62 params[terms[0].strip()] = " ".join(terms[1:]).strip() 63 line = input_f.readline() 64 headers_temp = input_f.readline().strip().split("\t") 65 headers = {} 66 for h in headers_temp: 67 temp = h.strip().split() 68 headers[h[:-1].strip()] = temp[-1][1:-1] 69 data = np.loadtxt(input_f) 70 if data.size < 1: 71 raise RuntimeError("{} is empty".format(path)) 72 x = data[:, 0] 73 dx = data[:, 3] 74 lam = data[:, 4] 75 dlam = data[:, 5] 76 y = data[:, 1] 77 dy = data[:, 2] 75 78 76 77 78 79 lam_unit = self._header_fetch(headers, "wavelength") 80 if lam_unit == "AA": 81 lam_unit = "A" 79 82 80 81 82 83 84 85 86 87 88 89 83 x, x_unit = self._unit_conversion( 84 x, lam_unit, 85 self._fetch_unit(headers, "spin echo length")) 86 dx, dx_unit = self._unit_conversion( 87 dx, lam_unit, 88 self._fetch_unit(headers, "error SEL")) 89 dlam, dlam_unit = self._unit_conversion( 90 dlam, lam_unit, 91 self._fetch_unit(headers, "error wavelength")) 92 y_unit = r'\AA^{-2} cm^{-1}' 90 93 91 92 93 94 95 96 97 98 99 100 94 output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, 95 isSesans=True) 96 self.filename = output.filename = basename 97 output.xaxis(r"\rm{z}", x_unit) 98 # Adjust label to ln P/(lam^2 t), remove lam column refs 99 output.yaxis(r"\rm{ln(P)/(t \lambda^2)}", y_unit) 100 # Store loading process information 101 output.meta_data['loader'] = self.type_name 102 output.sample.name = params["Sample"] 103 output.sample.ID = params["DataFileTitle"] 101 104 102 103 104 105 output.sample.zacceptance = ( 106 float(self._header_fetch(params, "Q_zmax")), 107 self._fetch_unit(params, "Q_zmax")) 105 108 106 output.sample.yacceptance = ( 107 float(self._header_fetch(params, "Q_ymax")), 108 self._fetch_unit(params, "Q_ymax")) 109 return output 110 111 else: 112 raise RuntimeError("%s is not a file" % path) 113 return None 109 output.sample.yacceptance = ( 110 float(self._header_fetch(params, "Q_ymax")), 111 self._fetch_unit(params, "Q_ymax")) 112 return output 114 113 115 114 @staticmethod
Note: See TracChangeset
for help on using the changeset viewer.