Changeset e3133dc in sasview
- Timestamp:
- Jan 3, 2018 8:41:36 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:
- f02a0c6
- Parents:
- cc62607
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
r8475d16 re3133dc 159 159 data.y_unit = self.format_unit(data.y_unit) 160 160 # Sort data by increasing x and remove 1st point 161 self.ind = np.lexsort((data.y, data.x))162 data.x = self. sort_1d_array(data.x)163 data.y = self. sort_1d_array(data.y)161 ind = np.lexsort((data.y, data.x)) 162 data.x = self._reorder_1d_array(data.x, ind) 163 data.y = self._reorder_1d_array(data.y, ind) 164 164 if data.dx is not None: 165 165 if len(data.dx) == 0: 166 166 data.dx = None 167 167 continue 168 data.dx = self. sort_1d_array(data.dx)168 data.dx = self._reorder_1d_array(data.dx, ind) 169 169 if data.dxl is not None: 170 data.dxl = self. sort_1d_array(data.dxl)170 data.dxl = self._reorder_1d_array(data.dxl, ind) 171 171 if data.dxw is not None: 172 data.dxw = self. sort_1d_array(data.dxw)172 data.dxw = self._reorder_1d_array(data.dxw, ind) 173 173 if data.dy is not None: 174 174 if len(data.dy) == 0: 175 175 data.dy = None 176 176 continue 177 data.dy = self. sort_1d_array(data.dy)177 data.dy = self._reorder_1d_array(data.dy, ind) 178 178 if data.lam is not None: 179 data.lam = self. sort_1d_array(data.lam)179 data.lam = self._reorder_1d_array(data.lam, ind) 180 180 if data.dlam is not None: 181 data.dlam = self.sort_1d_array(data.dlam) 181 data.dlam = self._reorder_1d_array(data.dlam, ind) 182 data = self._remove_nans_in_1d_data(data) 182 183 if len(data.x) > 0: 183 184 data.xmin = np.min(data.x) … … 186 187 data.ymax = np.max(data.y) 187 188 188 def sort_1d_array(self, array=[]): 189 if array.any(): 190 for i in self.ind: 191 if math.isnan(array[i]): 192 array[i] = 0 193 array = np.asarray([array[i] for i in self.ind]).astype(np.float64) 194 return array 189 @staticmethod 190 def _reorder_1d_array(array, ind): 191 """ 192 Reorders a 1D array based on the indices passed as ind 193 :param array: Array to be reordered 194 :param ind: Indices used to reorder array 195 :return: reordered array 196 """ 197 array = np.asarray(array, dtype=np.float64) 198 return array[ind] 199 200 @staticmethod 201 def _remove_nans_in_1d_data(data): 202 """ 203 Remove data points where nan is loaded 204 :param data: 1D data set 205 :return: data with mask=0 for any value of nan in data .x, .y, .dx, .dy 206 """ 207 mask = np.ones(len(data.x)) 208 data_list = [data.x, data.y, data.dx, data.dy, data.dxl, data.dxw] 209 for array in data_list: 210 if array is not None: 211 # Set mask[i] to 0 when data.<param> is nan 212 mask[np.isnan(array)] = 0 213 # Data indices to mask/remove from the data 214 nans = np.where(mask == 0)[0] 215 if len(nans) > 0: 216 data.x = np.delete(data.x, nans) 217 data.y = np.delete(data.y, nans) 218 if data.dx is not None: 219 data.dx = np.delete(data.dx, nans) 220 if data.dxl is not None: 221 data.dxl = np.delete(data.dxl, nans) 222 if data.dxw is not None: 223 data.dxw = np.delete(data.dxw, nans) 224 if data.dy is not None: 225 data.dy = np.delete(data.dy, nans) 226 return data 195 227 196 228 def sort_two_d_data(self):
Note: See TracChangeset
for help on using the changeset viewer.