- Timestamp:
- Jul 27, 2017 7:11:42 AM (7 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:
- 9d786e5
- Parents:
- 7477fb9
- Location:
- src/sas/sascalc/dataloader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
r7477fb9 r0b79323 54 54 self.f_open = open(filepath, 'rb') 55 55 self.get_file_contents() 56 self.sort_one_d_data() 56 57 if isinstance(self.output[0], Data1D): 58 self.sort_one_d_data() 59 elif isinstance(self.output[0], Data2D): 60 self.sort_two_d_data() 61 57 62 except DataReaderException as e: 58 63 self.handle_error_message(e.message) … … 124 129 self.output = final_list 125 130 131 def sort_two_d_data(self): 132 final_list = [] 133 for dataset in self.output: 134 dataset.data = dataset.data.astype(np.float64) 135 dataset.qx_data = dataset.qx_data.astype(np.float64) 136 dataset.xmin = np.min(dataset.qx_data) 137 dataset.xmax = np.max(dataset.qx_data) 138 dataset.qy_data = dataset.qy_data.astype(np.float64) 139 dataset.ymin = np.min(dataset.qy_data) 140 dataset.ymax = np.max(dataset.qy_data) 141 dataset.q_data = np.sqrt(dataset.qx_data * dataset.qx_data 142 + dataset.qy_data * dataset.qy_data) 143 if dataset.err_data is not None: 144 dataset.err_data = dataset.err_data.astype(np.float64) 145 if dataset.dqx_data is not None: 146 dataset.dqx_data = dataset.dqx_data.astype(np.float64) 147 if dataset.dqy_data is not None: 148 dataset.dqy_data = dataset.dqy_data.astype(np.float64) 149 if dataset.mask is not None: 150 dataset.mask = dataset.mask.astype(dtype=bool) 151 152 if len(dataset.shape) == 2: 153 n_rows, n_cols = dataset.shape 154 dataset.y_bins = dataset.qy_data[0::int(n_cols)] 155 dataset.x_bins = dataset.qx_data[:int(n_cols)] 156 dataset.data = dataset.data.flatten() 157 else: 158 dataset.y_bins = [] 159 dataset.x_bins = [] 160 dataset.data = dataset.data.flatten() 161 final_list.append(dataset) 162 self.output = final_list 163 126 164 def set_all_to_none(self): 127 165 """ -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r7477fb9 r0b79323 236 236 self.parent_class = tagname_original 237 237 if tagname == 'SASdata': 238 self.current_dataset = plottable_1D(np.array(0), np.array(0)) 238 self._initialize_new_data_set(node) 239 if isinstance(self.current_dataset, plottable_2D): 240 x_bins = attr.get("x_bins", "") 241 y_bins = attr.get("y_bins", "") 242 if x_bins is not "" and y_bins is not "": 243 self.current_dataset.shape = (x_bins, y_bins) 244 else: 245 self.current_dataset.shape = () 239 246 # Recurse to access data within the group 240 247 self._parse_entry(node, recurse=True) … … 250 257 self._add_intermediate() 251 258 else: 252 data_point, unit = self._get_node_value(node, tagname) 259 if isinstance(self.current_dataset, plottable_2D): 260 data_point = node.text 261 unit = attr.get('unit', '') 262 else: 263 data_point, unit = self._get_node_value(node, tagname) 253 264 254 265 # If this is a dataset, store the data appropriately … … 260 271 elif tagname == 'SASnote': 261 272 self.current_datainfo.notes.append(data_point) 262 elif tagname == 'I': # I and Q points 273 274 # I and Q points 275 elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 263 276 unit_list = unit.split("|") 264 277 if len(unit_list) > 1: … … 268 281 self.current_dataset.yaxis("Intensity", unit) 269 282 self.current_dataset.y = np.append(self.current_dataset.y, data_point) 270 elif tagname == 'Idev' :283 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 271 284 self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 272 285 elif tagname == 'Q': … … 294 307 elif tagname == 'zacceptance': 295 308 self.current_datainfo.sample.zacceptance = (data_point, unit) 309 310 # I and Qx, Qy - 2D data 311 elif tagname == 'I' and isinstance(self.current_dataset, plottable_2D): 312 self.current_dataset.yaxis("Intensity", unit) 313 self.current_dataset.data = np.fromstring(data_point, dtype=float, sep=",") 314 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_2D): 315 self.current_dataset.err_data = np.fromstring(data_point, dtype=float, sep=",") 316 elif tagname == 'Qx': 317 self.current_dataset.xaxis("Qx", unit) 318 self.current_dataset.qx_data = np.fromstring(data_point, dtype=float, sep=",") 319 elif tagname == 'Qy': 320 self.current_dataset.yaxis("Qy", unit) 321 self.current_dataset.qy_data = np.fromstring(data_point, dtype=float, sep=",") 322 elif tagname == 'Qxdev': 323 self.current_dataset.xaxis("Qxdev", unit) 324 self.current_dataset.dqx_data = np.fromstring(data_point, dtype=float, sep=",") 325 elif tagname == 'Qydev': 326 self.current_dataset.yaxis("Qydev", unit) 327 self.current_dataset.dqy_data = np.fromstring(data_point, dtype=float, sep=",") 328 elif tagname == 'Mask': 329 inter = [item == "1" for item in data_point.split(",")] 330 self.current_dataset.mask = np.asarray(inter, dtype=bool) 296 331 297 332 # Sample Information … … 647 682 np.zeros([array_size])) 648 683 684 def _initialize_new_data_set(self, node=None): 685 if node is not None: 686 for child in node: 687 if child.tag.replace(self.base_ns, "") == "Idata": 688 for i_child in child: 689 if i_child.tag.replace(self.base_ns, "") == "Qx": 690 self.current_dataset = plottable_2D() 691 return 692 self.current_dataset = plottable_1D(np.array(0), np.array(0)) 693 694 ## Writing Methods 649 695 def write(self, filename, datainfo): 650 696 """
Note: See TracChangeset
for help on using the changeset viewer.