Changeset 3bab401 in sasview
- Timestamp:
- Jun 22, 2018 12:52:36 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:
- 058f6c3
- Parents:
- c7634fd
- Location:
- src/sas/sascalc/dataloader
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
r4a8d55c r3bab401 16 16 from .data_info import Data1D, Data2D, DataInfo, plottable_1D, plottable_2D,\ 17 17 combine_data_info_with_plottable 18 from sas.sascalc.data_util.nxsunit import Converter 18 19 19 20 logger = logging.getLogger(__name__) … … 98 99 if len(self.output) > 0: 99 100 # Sort the data that's been loaded 100 self. sort_one_d_data()101 self.sort_ two_d_data()101 self.convert_data_units() 102 self.sort_data() 102 103 else: 103 104 msg = "Unable to find file at: {}\n".format(filepath) … … 166 167 self.output.append(data_obj) 167 168 168 def sort_ one_d_data(self):169 def sort_data(self): 169 170 """ 170 171 Sort 1D data along the X axis for consistency … … 203 204 data.ymin = np.min(data.y) 204 205 data.ymax = np.max(data.y) 206 elif isinstance(data, Data2D): 207 # 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.data = data.data.astype(np.float64) 211 data.qx_data = data.qx_data.astype(np.float64) 212 data.xmin = np.min(data.qx_data) 213 data.xmax = np.max(data.qx_data) 214 data.qy_data = data.qy_data.astype(np.float64) 215 data.ymin = np.min(data.qy_data) 216 data.ymax = np.max(data.qy_data) 217 data.q_data = np.sqrt(data.qx_data * data.qx_data 218 + data.qy_data * data.qy_data) 219 if data.err_data is not None: 220 data.err_data = data.err_data.astype(np.float64) 221 if data.dqx_data is not None: 222 data.dqx_data = data.dqx_data.astype(np.float64) 223 if data.dqy_data is not None: 224 data.dqy_data = data.dqy_data.astype(np.float64) 225 if data.mask is not None: 226 data.mask = data.mask.astype(dtype=bool) 227 228 if len(data.data.shape) == 2: 229 n_rows, n_cols = data.data.shape 230 data.y_bins = data.qy_data[0::int(n_cols)] 231 data.x_bins = data.qx_data[:int(n_cols)] 232 data.data = data.data.flatten() 233 data = self._remove_nans_in_data(data) 234 if len(data.data) > 0: 235 data.xmin = np.min(data.qx_data) 236 data.xmax = np.max(data.qx_data) 237 data.ymin = np.min(data.qy_data) 238 data.ymax = np.max(data.qx_data) 205 239 206 240 @staticmethod … … 242 276 return data 243 277 244 def sort_two_d_data(self): 245 for dataset in self.output: 246 if isinstance(dataset, Data2D): 247 # Normalize the units for 248 dataset.x_unit = self.format_unit(dataset.Q_unit) 249 dataset.y_unit = self.format_unit(dataset.I_unit) 250 dataset.data = dataset.data.astype(np.float64) 251 dataset.qx_data = dataset.qx_data.astype(np.float64) 252 dataset.xmin = np.min(dataset.qx_data) 253 dataset.xmax = np.max(dataset.qx_data) 254 dataset.qy_data = dataset.qy_data.astype(np.float64) 255 dataset.ymin = np.min(dataset.qy_data) 256 dataset.ymax = np.max(dataset.qy_data) 257 dataset.q_data = np.sqrt(dataset.qx_data * dataset.qx_data 258 + dataset.qy_data * dataset.qy_data) 259 if dataset.err_data is not None: 260 dataset.err_data = dataset.err_data.astype(np.float64) 261 if dataset.dqx_data is not None: 262 dataset.dqx_data = dataset.dqx_data.astype(np.float64) 263 if dataset.dqy_data is not None: 264 dataset.dqy_data = dataset.dqy_data.astype(np.float64) 265 if dataset.mask is not None: 266 dataset.mask = dataset.mask.astype(dtype=bool) 267 268 if len(dataset.data.shape) == 2: 269 n_rows, n_cols = dataset.data.shape 270 dataset.y_bins = dataset.qy_data[0::int(n_cols)] 271 dataset.x_bins = dataset.qx_data[:int(n_cols)] 272 dataset.data = dataset.data.flatten() 273 dataset = self._remove_nans_in_data(dataset) 274 if len(dataset.data) > 0: 275 dataset.xmin = np.min(dataset.qx_data) 276 dataset.xmax = np.max(dataset.qx_data) 277 dataset.ymin = np.min(dataset.qy_data) 278 dataset.ymax = np.max(dataset.qx_data) 278 @staticmethod 279 def set_default_1d_units(data): 280 """ 281 Set the x and y axes to the default 1D units 282 :param data: 1D data set 283 :return: 284 """ 285 data.xaxis("\\rm{Q}", '1/A') 286 data.yaxis("\\rm{Intensity}", "1/cm") 287 return data 288 289 @staticmethod 290 def set_default_2d_units(data): 291 """ 292 Set the x and y axes to the default 2D units 293 :param data: 2D data set 294 :return: 295 """ 296 data.xaxis("\\rm{Q_{x}}", '1/A') 297 data.yaxis("\\rm{Q_{y}}", '1/A') 298 data.zaxis("\\rm{Intensity}", "1/cm") 299 return data 300 301 def convert_data_units(self, default_q_unit="1/A", default_i_unit="1/cm"): 302 """ 303 Converts al; data to the sasview default of units of A^{-1} for Q and 304 cm^{-1} for I. 305 :param default_x_unit: The default x unit used by Sasview 306 :param default_y_unit: The default y unit used by Sasview 307 """ 308 new_output = [] 309 for data in self.output: 310 file_x_unit = data._xunit 311 data_conv_x = Converter(file_x_unit) 312 file_y_unit = data._yunit 313 data_conv_y = Converter(file_y_unit) 314 if isinstance(data, Data1D): 315 try: 316 data.x = data_conv_x(data.x, units=default_q_unit) 317 if data.dx is not None: 318 data.dx = data_conv_x(data.dx, units=default_q_unit) 319 if data.dxl is not None: 320 data.dxl = data_conv_x(data.dxl, units=default_q_unit) 321 if data.dxw is not None: 322 data.dxw = data_conv_x(data.dxw, units=default_q_unit) 323 except KeyError: 324 message = "Unable to convert Q units from {0} to 1/A." 325 message.format(default_q_unit) 326 data.errors.append(message) 327 try: 328 data.y = data_conv_y(data.y, units=default_i_unit) 329 if data.dy is not None: 330 data.dy = data_conv_y(data.dy, units=default_i_unit) 331 except KeyError: 332 message = "Unable to convert I units from {0} to 1/cm." 333 message.format(default_q_unit) 334 data.errors.append(message) 335 new_output.append(data) 336 elif isinstance(data, Data2D): 337 try: 338 data.qx_data = data_conv_x(data.qx_data, units=default_q_unit) 339 if data.dqx_data is not None: 340 data.dqx_data = data_conv_x(data.dqx_data, units=default_q_unit) 341 data.qy_data = data_conv_y(data.qy_data, units=default_q_unit) 342 if data.dqy_data is not None: 343 data.dqy_data = data_conv_y(data.dqy_data, units=default_q_unit) 344 except KeyError: 345 message = "Unable to convert Q units from {0} to 1/A." 346 message.format(default_q_unit) 347 data.errors.append(message) 348 try: 349 file_z_unit = data._zunit 350 data_conv_z = Converter(file_z_unit) 351 data.data = data_conv_z(data.data, units=default_i_unit) 352 if data.err_data is not None: 353 data.err_data = data_conv_z(data.err_data, units=default_i_unit) 354 except KeyError: 355 message = "Unable to convert I units from {0} to 1/cm." 356 message.format(default_q_unit) 357 data.errors.append(message) 358 new_output.append(data) 359 else: 360 # TODO: Throw error of some sort... 361 pass 362 self.output = new_output 279 363 280 364 def format_unit(self, unit=None): -
src/sas/sascalc/dataloader/readers/abs_reader.py
re3775c6 r3bab401 225 225 raise ValueError("ascii_reader: could not load file") 226 226 227 self.current_dataset = self.set_default_1d_units(self.current_dataset) 227 228 if data_conv_q is not None: 228 229 self.current_dataset.xaxis("\\rm{Q}", base_q_unit) 229 else:230 self.current_dataset.xaxis("\\rm{Q}", 'A^{-1}')231 230 if data_conv_i is not None: 232 231 self.current_dataset.yaxis("\\rm{Intensity}", base_i_unit) 233 else:234 self.current_dataset.yaxis("\\rm{Intensity}", "cm^{-1}")235 232 236 233 # Store loading process information -
src/sas/sascalc/dataloader/readers/ascii_reader.py
r9e6aeaf r3bab401 157 157 158 158 self.remove_empty_q_values() 159 self.current_dataset.xaxis("\\rm{Q}", 'A^{-1}') 160 self.current_dataset.yaxis("\\rm{Intensity}", "cm^{-1}") 159 self.current_dataset = self.set_default_1d_units(self.current_dataset) 161 160 162 161 # Store loading process information -
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
r18af6d2 r3bab401 632 632 if unit is None: 633 633 unit = h5attr(value, u'unit') 634 # Convert the unit formats635 if unit == "1/A":636 unit = "A^{-1}"637 elif unit == "1/cm":638 unit = "cm^{-1}"639 634 return unit -
src/sas/sascalc/dataloader/readers/danse_reader.py
r2469df7 r3bab401 181 181 182 182 183 self.current_dataset.xaxis("\\rm{Q_{x}}", ' A^{-1}')184 self.current_dataset.yaxis("\\rm{Q_{y}}", ' A^{-1}')185 self.current_dataset.zaxis("\\rm{Intensity}", " cm^{-1}")183 self.current_dataset.xaxis("\\rm{Q_{x}}", '1/A') 184 self.current_dataset.yaxis("\\rm{Q_{y}}", '1/A') 185 self.current_dataset.zaxis("\\rm{Intensity}", "1/cm") 186 186 187 187 self.current_dataset.x_bins = x_vals -
src/sas/sascalc/dataloader/readers/red2d_reader.py
rc8321cfc r3bab401 317 317 318 318 # Units of axes 319 self.current_dataset.xaxis(r"\rm{Q_{x}}", 'A^{-1}') 320 self.current_dataset.yaxis(r"\rm{Q_{y}}", 'A^{-1}') 321 self.current_dataset.zaxis(r"\rm{Intensity}", "cm^{-1}") 319 self.set_default_2d_units() 322 320 323 321 # Store loading process information
Note: See TracChangeset
for help on using the changeset viewer.