Changeset a40e913 in sasview for src/sas/sascalc
- Timestamp:
- Jan 11, 2018 8:29:18 AM (7 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 8cc9048, 6eb02a5
- Parents:
- 2bdf61a (diff), a58b5a0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Paul Butler <butlerpd@…> (01/11/18 08:29:18)
- git-committer:
- GitHub <noreply@…> (01/11/18 08:29:18)
- Location:
- src/sas/sascalc/dataloader
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
r3053a4a ra58b5a0 7 7 import os 8 8 import sys 9 import re9 import math 10 10 import logging 11 11 from abc import abstractmethod … … 25 25 def decode(s): 26 26 return s.decode() if isinstance(s, bytes) else s 27 28 # Data 1D fields for iterative purposes 29 FIELDS_1D = ('x', 'y', 'dx', 'dy', 'dxl', 'dxw') 30 # Data 2D fields for iterative purposes 31 FIELDS_2D = ('data', 'qx_data', 'qy_data', 'q_data', 'err_data', 32 'dqx_data', 'dqy_data', 'mask') 33 27 34 28 35 class FileReader(object): … … 102 109 self.current_dataset = None 103 110 self.filepath = None 111 self.ind = None 104 112 self.output = [] 105 113 … … 159 167 # Sort data by increasing x and remove 1st point 160 168 ind = np.lexsort((data.y, data.x)) 161 data.x = np.asarray([data.x[i] for i in ind]).astype(np.float64)162 data.y = np.asarray([data.y[i] for i in ind]).astype(np.float64)169 data.x = self._reorder_1d_array(data.x, ind) 170 data.y = self._reorder_1d_array(data.y, ind) 163 171 if data.dx is not None: 164 172 if len(data.dx) == 0: 165 173 data.dx = None 166 174 continue 167 data.dx = np.asarray([data.dx[i] for i in ind]).astype(np.float64)175 data.dx = self._reorder_1d_array(data.dx, ind) 168 176 if data.dxl is not None: 169 data.dxl = np.asarray([data.dxl[i] for i in ind]).astype(np.float64)177 data.dxl = self._reorder_1d_array(data.dxl, ind) 170 178 if data.dxw is not None: 171 data.dxw = np.asarray([data.dxw[i] for i in ind]).astype(np.float64)179 data.dxw = self._reorder_1d_array(data.dxw, ind) 172 180 if data.dy is not None: 173 181 if len(data.dy) == 0: 174 182 data.dy = None 175 183 continue 176 data.dy = np.asarray([data.dy[i] for i in ind]).astype(np.float64)184 data.dy = self._reorder_1d_array(data.dy, ind) 177 185 if data.lam is not None: 178 data.lam = np.asarray([data.lam[i] for i in ind]).astype(np.float64)186 data.lam = self._reorder_1d_array(data.lam, ind) 179 187 if data.dlam is not None: 180 data.dlam = np.asarray([data.dlam[i] for i in ind]).astype(np.float64) 188 data.dlam = self._reorder_1d_array(data.dlam, ind) 189 data = self._remove_nans_in_data(data) 181 190 if len(data.x) > 0: 182 191 data.xmin = np.min(data.x) … … 184 193 data.ymin = np.min(data.y) 185 194 data.ymax = np.max(data.y) 195 196 @staticmethod 197 def _reorder_1d_array(array, ind): 198 """ 199 Reorders a 1D array based on the indices passed as ind 200 :param array: Array to be reordered 201 :param ind: Indices used to reorder array 202 :return: reordered array 203 """ 204 array = np.asarray(array, dtype=np.float64) 205 return array[ind] 206 207 @staticmethod 208 def _remove_nans_in_data(data): 209 """ 210 Remove data points where nan is loaded 211 :param data: 1D or 2D data object 212 :return: data with nan points removed 213 """ 214 if isinstance(data, Data1D): 215 fields = FIELDS_1D 216 elif isinstance(data, Data2D): 217 fields = FIELDS_2D 218 else: 219 return data 220 # Make array of good points - all others will be removed 221 good = np.isfinite(getattr(data, fields[0])) 222 for name in fields[1:]: 223 array = getattr(data, name) 224 if array is not None: 225 # Update good points only if not already changed 226 good &= np.isfinite(array) 227 if not np.all(good): 228 for name in fields: 229 array = getattr(data, name) 230 if array is not None: 231 setattr(data, name, array[good]) 232 return data 186 233 187 234 def sort_two_d_data(self): … … 214 261 dataset.x_bins = dataset.qx_data[:int(n_cols)] 215 262 dataset.data = dataset.data.flatten() 263 dataset = self._remove_nans_in_data(dataset) 216 264 if len(dataset.data) > 0: 217 265 dataset.xmin = np.min(dataset.qx_data) -
src/sas/sascalc/dataloader/readers/abs_reader.py
r1efbc190 re3775c6 29 29 type_name = "IGOR 1D" 30 30 # Wildcards 31 type = ["IGOR 1D files (*.abs)|*.abs" ]31 type = ["IGOR 1D files (*.abs)|*.abs", "IGOR 1D USANS files (*.cor)|*.cor"] 32 32 # List of allowed extensions 33 ext = ['.abs' ]33 ext = ['.abs', '.cor'] 34 34 35 35 def get_file_contents(self): … … 46 46 self.current_datainfo = DataInfo() 47 47 self.current_datainfo.filename = filepath 48 self.reset_data_list(len(lines))49 48 detector = Detector() 50 49 data_line = 0 … … 188 187 self.current_dataset.y[data_line] = _y 189 188 self.current_dataset.dy[data_line] = _dy 190 self.current_dataset.dx[data_line] = _dx 189 if _dx > 0: 190 self.current_dataset.dx[data_line] = _dx 191 else: 192 if data_line == 0: 193 self.current_dataset.dx = None 194 self.current_dataset.dxl = np.zeros(len(lines)) 195 self.current_dataset.dxw = np.zeros(len(lines)) 196 self.current_dataset.dxl[data_line] = abs(_dx) 197 self.current_dataset.dxw[data_line] = 0 191 198 data_line += 1 192 199 … … 197 204 pass 198 205 206 # SANS Data: 199 207 # The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. 200 208 # I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 201 if line.count("The 6 columns") > 0: 209 # USANS Data: 210 # EMP LEVEL: <value> ; BKG LEVEL: <value> 211 if line.startswith("The 6 columns") or line.startswith("EMP LEVEL"): 202 212 is_data_started = True 203 213 -
src/sas/sascalc/dataloader/readers/associations.py
r574adc7 ra32c19c 26 26 ".dat": "red2d_reader", 27 27 ".abs": "abs_reader", 28 ".cor": "abs_reader", 28 29 ".sans": "danse_reader", 29 30 ".pdh": "anton_paar_saxs_reader"
Note: See TracChangeset
for help on using the changeset viewer.