- Timestamp:
- Jul 6, 2018 2:23:21 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
- Children:
- eb6abab
- Parents:
- 058f6c3
- Location:
- src/sas/sascalc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/data_util/nxsunit.py
r574adc7 r8f882fe 136 136 sld = { '10^-6 Angstrom^-2': 1e-6, 'Angstrom^-2': 1 } 137 137 Q = { 'invA': 1, 'invAng': 1, 'invAngstroms': 1, '1/A': 1, 138 '1/Angstrom': 1, '1/angstrom': 1, 'A^{-1}': 1, 'cm^{-1}': 1, 138 139 '10^-3 Angstrom^-1': 1e-3, '1/cm': 1e-8, '1/m': 1e-10, 139 'nm^ -1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 }140 'nm^{-1}': 1, 'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 } 140 141 141 142 _caret_optional(sld) … … 157 158 # units for that particular dimension. 158 159 # Note: don't have support for dimensionless units. 159 unknown = {None:1, '???':1, '': 1, 'a.u.': 1 }160 unknown = {None:1, '???':1, '': 1, 'a.u.': 1, 'Counts': 1, 'counts': 1} 160 161 161 162 def __init__(self, name): -
src/sas/sascalc/dataloader/file_reader_base_class.py
r058f6c3 r8f882fe 175 175 # Normalize the units for 176 176 data.x_unit = self.format_unit(data.x_unit) 177 data._xunit = data.x_unit 177 178 data.y_unit = self.format_unit(data.y_unit) 179 data._yunit = data.y_unit 178 180 # Sort data by increasing x and remove 1st point 179 181 ind = np.lexsort((data.y, data.x)) … … 206 208 elif isinstance(data, Data2D): 207 209 # Normalize the units for 208 data.x_unit = self.format_unit(data.Q_unit) 209 data.y_unit = self.format_unit(data.I_unit) 210 data.Q_unit = self.format_unit(data.Q_unit) 211 data.I_unit = self.format_unit(data.I_unit) 212 data._xunit = data.Q_unit 213 data._yunit = data.Q_unit 214 data._zunit = data.I_unit 210 215 data.data = data.data.astype(np.float64) 211 216 data.qx_data = data.qx_data.astype(np.float64) … … 318 323 try: 319 324 data.x = data_conv_x(data.x, units=default_q_unit) 325 data._xunit = default_q_unit 326 data.x_unit = default_q_unit 320 327 if data.dx is not None: 321 328 data.dx = data_conv_x(data.dx, units=default_q_unit) … … 330 337 try: 331 338 data.y = data_conv_y(data.y, units=default_i_unit) 339 data._yunit = default_i_unit 340 data.y_unit = default_i_unit 332 341 if data.dy is not None: 333 342 data.dy = data_conv_y(data.dy, units=default_i_unit) -
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
r3bab401 r8f882fe 137 137 if isinstance(value, h5py.Group): 138 138 # Set parent class before recursion 139 last_parent_class = self.parent_class 139 140 self.parent_class = class_name 140 141 parent_list.append(key) … … 144 145 self.add_data_set(key) 145 146 elif class_prog.match(u'SASdata'): 147 self._initialize_new_data_set(value) 146 148 self._find_data_attributes(value) 147 self._initialize_new_data_set(parent_list)148 149 # Recursion step to access data within the group 149 150 self.read_children(value, parent_list) 151 self.add_intermediate() 150 152 # Reset parent class when returning from recursive method 151 self.parent_class = class_name 152 self.add_intermediate() 153 self.parent_class = last_parent_class 153 154 parent_list.remove(key) 154 155 … … 533 534 self.current_datainfo = DataInfo() 534 535 535 def _initialize_new_data_set(self, parent_list=None):536 def _initialize_new_data_set(self, value=None): 536 537 """ 537 538 A private class method to generate a new 1D or 2D data object based on … … 541 542 :param parent_list: List of names of parent elements 542 543 """ 543 544 if parent_list is None: 545 parent_list = [] 546 if self._find_intermediate(parent_list, "Qx"): 544 if self._is2d(value): 547 545 self.current_dataset = plottable_2D() 548 546 else: … … 565 563 :param value: SASdata/NXdata HDF5 Group 566 564 """ 565 signal = "I" 566 i_axes = ["Q"] 567 q_indices = [0] 567 568 attrs = value.attrs 568 signal = attrs.get("signal") 569 i_axes = np.array(str(attrs.get("I_axes")).split(",")) 570 q_indices = np.int_(attrs.get("Q_indices").split(",")) 569 if hasattr(attrs, "signal"): 570 signal = attrs.get("signal") 571 if hasattr(attrs, "I_axes"): 572 i_axes = np.array(str(attrs.get("I_axes")).split(",")) 573 if hasattr(attrs, "Q_indices"): 574 q_indices = np.int_(attrs.get("Q_indices").split(",")) 571 575 keys = value.keys() 572 576 self.mask_name = attrs.get("mask") … … 578 582 if item in keys: 579 583 q_vals = value.get(item) 580 self.q_uncertainties = q_vals.attrs.get("uncertainty") 581 self.q_resolutions = q_vals.attrs.get("resolution") 584 self.q_uncertainties = q_vals.attrs.get("uncertainties") 585 if self.q_uncertainties is None: 586 self.q_uncertainties = q_vals.attrs.get("uncertainty") 587 self.q_resolutions = q_vals.attrs.get("resolutions") 582 588 if self.i_name in keys: 583 589 i_vals = value.get(self.i_name) 584 self.i_uncertainties = i_vals.attrs.get("uncertainty") 585 586 def _find_intermediate(self, parent_list, basename=""): 587 """ 588 A private class used to find an entry by either using a direct key or 589 knowing the approximate basename. 590 self.i_uncertainties = i_vals.attrs.get("uncertainties") 591 if self.i_uncertainties is None: 592 self.i_uncertainties = i_vals.attrs.get("uncertainty") 593 594 def _is2d(self, value, basename="I"): 595 """ 596 A private class to determine if the data set is 1d or 2d. 590 597 591 598 :param parent_list: List of parents nodes in the HDF5 file 592 599 :param basename: Approximate name of an entry to search for 593 :return: 594 """ 595 596 entry = False 597 key_prog = re.compile(basename) 598 top = self.raw_data 599 for parent in parent_list: 600 top = top.get(parent) 601 for key in top.keys(): 602 if key_prog.match(key): 603 entry = True 604 break 605 return entry 600 :return: True if 2D, otherwise false 601 """ 602 603 vals = value.get(basename) 604 return (vals is not None and vals.shape is not None 605 and len(vals.shape) != 1) 606 606 607 607 def _create_unique_key(self, dictionary, name, numb=0):
Note: See TracChangeset
for help on using the changeset viewer.