Changeset 2b310602 in sasview for src/sas/sascalc/dataloader
- Timestamp:
- Apr 5, 2017 10:33:21 AM (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:
- d37ea0e
- Parents:
- 8390cf6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/sesans_reader.py
rcb9feea8 r2b310602 58 58 line = input_f.readline() 59 59 params = {} 60 while line.strip() != "": 61 terms = line.strip().split("\t") 62 params[terms[0].strip()] = " ".join(terms[1:]).strip() 60 while not line.startswith("BEGIN_DATA"): 61 terms = line.split() 62 if len(terms) >= 2: 63 params[terms[0]] = " ".join(terms[1:]) 63 64 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] 65 self.params = params 66 headers = input_f.readline().split() 67 69 68 data = np.loadtxt(input_f) 70 69 if data.size < 1: 71 70 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]71 x = data[:, headers.index("SpinEchoLength")] 72 dx = data[:, headers.index("SpinEchoLength_error")] 73 lam = data[:, headers.index("Wavelength")] 74 dlam = data[:, headers.index("Wavelength_error")] 75 y = data[:, headers.index("Depolarisation")] 76 dy = data[:, headers.index("Depolarisation_error")] 78 77 79 lam_unit = self._header_fetch(headers, "wavelength") 80 if lam_unit == "AA": 81 lam_unit = "A" 82 83 x, x_unit = self._unit_conversion( 84 x, lam_unit, 85 self._fetch_unit(headers, "spin echo length")) 78 lam_unit = self._unit_fetch("Wavelength") 79 x, x_unit = self._unit_conversion(x, "A", self._unit_fetch("SpinEchoLength")) 86 80 dx, dx_unit = self._unit_conversion( 87 81 dx, lam_unit, 88 self._ fetch_unit(headers, "error SEL"))82 self._unit_fetch("SpinEchoLength")) 89 83 dlam, dlam_unit = self._unit_conversion( 90 84 dlam, lam_unit, 91 self._ fetch_unit(headers, "error wavelength"))92 y_unit = r'\AA^{-2} cm^{-1}'85 self._unit_fetch("Wavelength")) 86 y_unit = self._unit_fetch("Depolarisation") 93 87 94 88 output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, 95 89 isSesans=True) 90 91 output.y_unit = y_unit 92 output.x_unit = x_unit 96 93 self.filename = output.filename = basename 97 94 output.xaxis(r"\rm{z}", x_unit) … … 102 99 output.sample.name = params["Sample"] 103 100 output.sample.ID = params["DataFileTitle"] 101 output.sample.thickness = float( 102 self._unit_conversion( 103 params["Thickness"], "cm", self._unit_fetch("Thickness"))[0]) 104 104 105 105 output.sample.zacceptance = ( 106 float( self._header_fetch(params, "Q_zmax")),107 self._ fetch_unit(params, "Q_zmax"))106 float(params["Theta_zmax"]), 107 self._unit_fetch("Theta_zmax")) 108 108 109 109 output.sample.yacceptance = ( 110 float( self._header_fetch(params, "Q_ymax")),111 self._ fetch_unit(params, "Q_ymax"))110 float(params["Theta_ymax"]), 111 self._unit_fetch("Theta_ymax")) 112 112 return output 113 113 … … 131 131 return value, new_unit 132 132 133 @staticmethod 134 def _header_fetch(headers, key): 135 """ 136 Pull the value of a unit defined header from a dict. Example:: 137 138 d = {"Length [m]": 17} 139 self._header_fetch(d, "Length") == 17 140 141 :param header: A dictionary of values 142 :param key: A string which is a prefix for one of the keys in the dict 143 :return: The value of the dictionary for the specified key 144 """ 145 # (dict<string, x>, string) -> x 146 index = [k for k in headers.keys() 147 if k.startswith(key)][0] 148 return headers[index] 149 150 @staticmethod 151 def _fetch_unit(params, key): 152 """ 153 Pull the unit off of a dictionary header. Example:: 154 155 d = {"Length [m]": 17} 156 self._fetch_unit(d, "Length") == "m" 157 158 :param header: A dictionary of values, where the keys are strings 159 with the units for the values appended onto the string within square 160 brackets (See the example above) 161 :param key: A string with the prefix of the dictionary key whose unit 162 is being fetched 163 :return: A string containing the unit specifed in the header 164 """ 165 # (dict<string, _>, string) -> string 166 index = [k for k in params.keys() 167 if k.startswith(key)][0] 168 unit = index.strip().split()[-1][1:-1] 169 if unit.startswith(r"\A"): 170 unit = "1/A" 171 return unit 133 def _unit_fetch(self, unit): 134 return self.params[unit+"_unit"]
Note: See TracChangeset
for help on using the changeset viewer.