Changes in / [845144e:67ed543] in sasview
- Files:
-
- 12 added
- 14 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/data_util/nxsunit.py
rb011ecb r574adc7 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}': 1e-8,139 138 '10^-3 Angstrom^-1': 1e-3, '1/cm': 1e-8, '1/m': 1e-10, 140 'nm^ {-1}': 1, 'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 }139 'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 } 141 140 142 141 _caret_optional(sld) … … 158 157 # units for that particular dimension. 159 158 # Note: don't have support for dimensionless units. 160 unknown = {None:1, '???':1, '': 1, 'a.u.': 1 , 'Counts': 1, 'counts': 1}159 unknown = {None:1, '???':1, '': 1, 'a.u.': 1} 161 160 162 161 def __init__(self, name): -
src/sas/sascalc/dataloader/data_info.py
r4fdcc65 rdeaa0c6 954 954 _str += "Data:\n" 955 955 _str += " Type: %s\n" % self.__class__.__name__ 956 _str += " X-axis: %s\t[%s]\n" % (self._xaxis, self._xunit) 957 _str += " Y-axis: %s\t[%s]\n" % (self._yaxis, self._yunit) 956 _str += " X- & Y-axis: %s\t[%s]\n" % (self._yaxis, self._yunit) 958 957 _str += " Z-axis: %s\t[%s]\n" % (self._zaxis, self._zunit) 959 958 _str += " Length: %g \n" % (len(self.data)) … … 984 983 qx_data=qx_data, qy_data=qy_data, 985 984 q_data=q_data, mask=mask) 986 987 clone._xaxis = self._xaxis988 clone._yaxis = self._yaxis989 clone._zaxis = self._zaxis990 clone._xunit = self._xunit991 clone._yunit = self._yunit992 clone._zunit = self._zunit993 clone.x_bins = self.x_bins994 clone.y_bins = self.y_bins995 985 996 986 clone.title = self.title … … 1163 1153 def combine_data_info_with_plottable(data, datainfo): 1164 1154 """ 1165 A function that combines the DataInfo data in self.current_datainto with a 1166 plottable_1D or 2D data object. 1155 A function that combines the DataInfo data in self.current_datainto with a plottable_1D or 2D data object. 1167 1156 1168 1157 :param data: A plottable_1D or plottable_2D data object … … 1182 1171 final_dataset.yaxis(data._yaxis, data._yunit) 1183 1172 elif isinstance(data, plottable_2D): 1184 final_dataset = Data2D(data.data, data.err_data, data.qx_data, 1185 data.qy_data, data.q_data, data.mask, 1186 data.dqx_data, data.dqy_data) 1173 final_dataset = Data2D(data.data, data.err_data, data.qx_data, data.qy_data, data.q_data, 1174 data.mask, data.dqx_data, data.dqy_data) 1187 1175 final_dataset.xaxis(data._xaxis, data._xunit) 1188 1176 final_dataset.yaxis(data._yaxis, data._yunit) 1189 1177 final_dataset.zaxis(data._zaxis, data._zunit) 1190 final_dataset.y_bins = data.y_bins 1191 final_dataset.x_bins = data.x_bins 1178 if len(data.data.shape) == 2: 1179 n_rows, n_cols = data.data.shape 1180 final_dataset.y_bins = data.qy_data[0::int(n_cols)] 1181 final_dataset.x_bins = data.qx_data[:int(n_cols)] 1192 1182 else: 1193 return_string = ("Should Never Happen: _combine_data_info_with_plottabl" 1194 "e input is not a plottable1d or plottable2d data " 1195 "object") 1183 return_string = "Should Never Happen: _combine_data_info_with_plottable input is not a plottable1d or " + \ 1184 "plottable2d data object" 1196 1185 return return_string 1197 1186 -
src/sas/sascalc/dataloader/file_reader_base_class.py
rb1ec23d r4a8d55c 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 Converter19 18 20 19 logger = logging.getLogger(__name__) … … 37 36 "load the file was made, but, should it be successful, " 38 37 "SasView cannot guarantee the accuracy of the data.") 39 40 38 41 39 class FileReader(object): … … 100 98 if len(self.output) > 0: 101 99 # Sort the data that's been loaded 102 self. convert_data_units()103 self.sort_ data()100 self.sort_one_d_data() 101 self.sort_two_d_data() 104 102 else: 105 103 msg = "Unable to find file at: {}\n".format(filepath) … … 142 140 Returns the entire file as a string. 143 141 """ 142 #return self.f_open.read() 144 143 return decode(self.f_open.read()) 145 144 … … 167 166 self.output.append(data_obj) 168 167 169 def sort_ data(self):168 def sort_one_d_data(self): 170 169 """ 171 170 Sort 1D data along the X axis for consistency … … 175 174 # Normalize the units for 176 175 data.x_unit = self.format_unit(data.x_unit) 177 data._xunit = data.x_unit178 176 data.y_unit = self.format_unit(data.y_unit) 179 data._yunit = data.y_unit180 177 # Sort data by increasing x and remove 1st point 181 178 ind = np.lexsort((data.y, data.x)) … … 206 203 data.ymin = np.min(data.y) 207 204 data.ymax = np.max(data.y) 208 elif isinstance(data, Data2D):209 # Normalize the units for210 data.Q_unit = self.format_unit(data.Q_unit)211 data.I_unit = self.format_unit(data.I_unit)212 data._xunit = data.Q_unit213 data._yunit = data.Q_unit214 data._zunit = data.I_unit215 data.data = data.data.astype(np.float64)216 data.qx_data = data.qx_data.astype(np.float64)217 data.xmin = np.min(data.qx_data)218 data.xmax = np.max(data.qx_data)219 data.qy_data = data.qy_data.astype(np.float64)220 data.ymin = np.min(data.qy_data)221 data.ymax = np.max(data.qy_data)222 data.q_data = np.sqrt(data.qx_data * data.qx_data223 + data.qy_data * data.qy_data)224 if data.err_data is not None:225 data.err_data = data.err_data.astype(np.float64)226 if data.dqx_data is not None:227 data.dqx_data = data.dqx_data.astype(np.float64)228 if data.dqy_data is not None:229 data.dqy_data = data.dqy_data.astype(np.float64)230 if data.mask is not None:231 data.mask = data.mask.astype(dtype=bool)232 233 n_rows, n_cols = data.data.shape234 data.y_bins = data.qy_data[0::int(n_cols)]235 data.x_bins = data.qx_data[:int(n_cols)]236 data.data = data.data.flatten()237 data = self._remove_nans_in_data(data)238 if len(data.data) > 0:239 data.xmin = np.min(data.qx_data)240 data.xmax = np.max(data.qx_data)241 data.ymin = np.min(data.qy_data)242 data.ymax = np.max(data.qx_data)243 205 244 206 @staticmethod … … 280 242 return data 281 243 282 @staticmethod 283 def set_default_1d_units(data): 284 """ 285 Set the x and y axes to the default 1D units 286 :param data: 1D data set 287 :return: 288 """ 289 data.xaxis(r"\rm{Q}", '1/A') 290 data.yaxis(r"\rm{Intensity}", "1/cm") 291 return data 292 293 @staticmethod 294 def set_default_2d_units(data): 295 """ 296 Set the x and y axes to the default 2D units 297 :param data: 2D data set 298 :return: 299 """ 300 data.xaxis("\\rm{Q_{x}}", '1/A') 301 data.yaxis("\\rm{Q_{y}}", '1/A') 302 data.zaxis("\\rm{Intensity}", "1/cm") 303 return data 304 305 def convert_data_units(self, default_q_unit="1/A", default_i_unit="1/cm"): 306 """ 307 Converts al; data to the sasview default of units of A^{-1} for Q and 308 cm^{-1} for I. 309 :param default_q_unit: The default Q unit used by Sasview 310 :param default_i_unit: The default I unit used by Sasview 311 """ 312 new_output = [] 313 for data in self.output: 314 if data.isSesans: 315 new_output.append(data) 316 continue 317 file_x_unit = data._xunit 318 data_conv_x = Converter(file_x_unit) 319 file_y_unit = data._yunit 320 data_conv_y = Converter(file_y_unit) 321 if isinstance(data, Data1D): 322 try: 323 data.x = data_conv_x(data.x, units=default_q_unit) 324 data._xunit = default_q_unit 325 data.x_unit = default_q_unit 326 if data.dx is not None: 327 data.dx = data_conv_x(data.dx, units=default_q_unit) 328 if data.dxl is not None: 329 data.dxl = data_conv_x(data.dxl, units=default_q_unit) 330 if data.dxw is not None: 331 data.dxw = data_conv_x(data.dxw, units=default_q_unit) 332 except KeyError: 333 message = "Unable to convert Q units from {0} to 1/A." 334 message.format(default_q_unit) 335 data.errors.append(message) 336 try: 337 data.y = data_conv_y(data.y, units=default_i_unit) 338 data._yunit = default_i_unit 339 data.y_unit = default_i_unit 340 if data.dy is not None: 341 data.dy = data_conv_y(data.dy, units=default_i_unit) 342 except KeyError: 343 message = "Unable to convert I units from {0} to 1/cm." 344 message.format(default_q_unit) 345 data.errors.append(message) 346 elif isinstance(data, Data2D): 347 try: 348 data.qx_data = data_conv_x(data.qx_data, 349 units=default_q_unit) 350 if data.dqx_data is not None: 351 data.dqx_data = data_conv_x(data.dqx_data, 352 units=default_q_unit) 353 data.qy_data = data_conv_y(data.qy_data, 354 units=default_q_unit) 355 if data.dqy_data is not None: 356 data.dqy_data = data_conv_y(data.dqy_data, 357 units=default_q_unit) 358 except KeyError: 359 message = "Unable to convert Q units from {0} to 1/A." 360 message.format(default_q_unit) 361 data.errors.append(message) 362 try: 363 file_z_unit = data._zunit 364 data_conv_z = Converter(file_z_unit) 365 data.data = data_conv_z(data.data, units=default_i_unit) 366 if data.err_data is not None: 367 data.err_data = data_conv_z(data.err_data, 368 units=default_i_unit) 369 except KeyError: 370 message = "Unable to convert I units from {0} to 1/cm." 371 message.format(default_q_unit) 372 data.errors.append(message) 373 else: 374 # TODO: Throw error of some sort... 375 pass 376 new_output.append(data) 377 self.output = new_output 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) 378 279 379 280 def format_unit(self, unit=None): … … 466 367 self.current_dataset.qy_data)) 467 368 if has_error_dy: 468 self.current_dataset.err_data = self.current_dataset.err_data[ 469 x != 0] 369 self.current_dataset.err_data = self.current_dataset.err_data[x != 0] 470 370 if has_error_dqx: 471 self.current_dataset.dqx_data = self.current_dataset.dqx_data[ 472 x != 0] 371 self.current_dataset.dqx_data = self.current_dataset.dqx_data[x != 0] 473 372 if has_error_dqy: 474 self.current_dataset.dqy_data = self.current_dataset.dqy_data[ 475 x != 0] 373 self.current_dataset.dqy_data = self.current_dataset.dqy_data[x != 0] 476 374 if has_mask: 477 375 self.current_dataset.mask = self.current_dataset.mask[x != 0] -
src/sas/sascalc/dataloader/loader.py
rb1ec23d r4a8d55c 367 367 try: 368 368 return fn(path, data) 369 except Exception as exc: 370 msg = "Saving file {} using the {} writer failed.\n".format( 371 path, type(fn).__name__) 372 msg += str(exc) 373 logger.exception(msg) # give other loaders a chance to succeed 369 except Exception: 370 pass # give other loaders a chance to succeed 371 # If we get here it is because all loaders failed 372 raise # reraises last exception 374 373 375 374 -
src/sas/sascalc/dataloader/readers/abs_reader.py
rbd5c3b1 rbd5c3b1 225 225 raise ValueError("ascii_reader: could not load file") 226 226 227 self.current_dataset = self.set_default_1d_units(self.current_dataset)228 227 if data_conv_q is not None: 229 228 self.current_dataset.xaxis("\\rm{Q}", base_q_unit) 229 else: 230 self.current_dataset.xaxis("\\rm{Q}", 'A^{-1}') 230 231 if data_conv_i is not None: 231 232 self.current_dataset.yaxis("\\rm{Intensity}", base_i_unit) 233 else: 234 self.current_dataset.yaxis("\\rm{Intensity}", "cm^{-1}") 232 235 233 236 # Store loading process information -
src/sas/sascalc/dataloader/readers/ascii_reader.py
r3bab401 r7b07fbe 157 157 158 158 self.remove_empty_q_values() 159 self.current_dataset = self.set_default_1d_units(self.current_dataset) 159 self.current_dataset.xaxis("\\rm{Q}", 'A^{-1}') 160 self.current_dataset.yaxis("\\rm{Intensity}", "cm^{-1}") 160 161 161 162 # Store loading process information -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r058f6c3 r2469df7 812 812 node.append(point) 813 813 self.write_node(point, "Q", datainfo.x[i], 814 {'unit': datainfo. _xunit})814 {'unit': datainfo.x_unit}) 815 815 if len(datainfo.y) >= i: 816 816 self.write_node(point, "I", datainfo.y[i], 817 {'unit': datainfo. _yunit})817 {'unit': datainfo.y_unit}) 818 818 if datainfo.dy is not None and len(datainfo.dy) > i: 819 819 self.write_node(point, "Idev", datainfo.dy[i], 820 {'unit': datainfo. _yunit})820 {'unit': datainfo.y_unit}) 821 821 if datainfo.dx is not None and len(datainfo.dx) > i: 822 822 self.write_node(point, "Qdev", datainfo.dx[i], 823 {'unit': datainfo. _xunit})823 {'unit': datainfo.x_unit}) 824 824 if datainfo.dxw is not None and len(datainfo.dxw) > i: 825 825 self.write_node(point, "dQw", datainfo.dxw[i], 826 {'unit': datainfo. _xunit})826 {'unit': datainfo.x_unit}) 827 827 if datainfo.dxl is not None and len(datainfo.dxl) > i: 828 828 self.write_node(point, "dQl", datainfo.dxl[i], 829 {'unit': datainfo. _xunit})829 {'unit': datainfo.x_unit}) 830 830 if datainfo.isSesans: 831 831 sesans_attrib = {'x_axis': datainfo._xaxis, -
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rb204004 r61f329f0 12 12 Data1D, Data2D, DataInfo, Process, Aperture, Collimation, \ 13 13 TransmissionSpectrum, Detector 14 from ..data_info import combine_data_info_with_plottable 14 15 from ..loader_exceptions import FileContentsException, DefaultReaderException 15 16 from ..file_reader_base_class import FileReader, decode 16 17 17 18 18 def h5attr(node, key, default=None): 19 19 return decode(node.attrs.get(key, default)) 20 21 20 22 21 class Reader(FileReader): … … 39 38 # CanSAS version 40 39 cansas_version = 2.0 40 # Logged warnings or messages 41 logging = None 42 # List of errors for the current data set 43 errors = None 44 # Raw file contents to be processed 45 raw_data = None 46 # List of plottable1D objects that should be linked to the current_datainfo 47 data1d = None 48 # List of plottable2D objects that should be linked to the current_datainfo 49 data2d = None 41 50 # Data type name 42 type_name = " NXcanSAS"51 type_name = "CanSAS 2.0" 43 52 # Wildcards 44 type = [" NXcanSAS HDF5 Files (*.h5)|*.h5|"]53 type = ["CanSAS 2.0 HDF5 Files (*.h5)|*.h5"] 45 54 # List of allowed extensions 46 55 ext = ['.h5', '.H5'] … … 72 81 except Exception as e: 73 82 if extension not in self.ext: 74 msg = "NXcanSAS Reader could not load file {}".format( 75 basename + extension) 83 msg = "CanSAS2.0 HDF5 Reader could not load file {}".format(basename + extension) 76 84 raise DefaultReaderException(msg) 77 85 raise FileContentsException(e.message) … … 87 95 self.raw_data.close() 88 96 89 for data_set in self.output: 90 if isinstance(data_set, Data1D): 91 if data_set.x.size < 5: 92 exception = FileContentsException( 93 "Fewer than 5 data points found.") 94 data_set.errors.append(exception) 97 for dataset in self.output: 98 if isinstance(dataset, Data1D): 99 if dataset.x.size < 5: 100 self.output = [] 101 raise FileContentsException("Fewer than 5 data points found.") 95 102 96 103 def reset_state(self): … … 104 111 self.errors = set() 105 112 self.logging = [] 106 self.q_names = []107 self.mask_name = u''108 self.i_name = u''109 self.i_node = u''110 self.i_uncertainties_name = u''111 self.q_uncertainty_names = []112 self.q_resolution_names = []113 113 self.parent_class = u'' 114 114 self.detector = Detector() … … 131 131 value = data.get(key) 132 132 class_name = h5attr(value, u'canSAS_class') 133 if isinstance(class_name, (list, tuple, np.ndarray)):134 class_name = class_name[0]135 133 if class_name is None: 136 134 class_name = h5attr(value, u'NX_class') … … 142 140 if isinstance(value, h5py.Group): 143 141 # Set parent class before recursion 144 last_parent_class = self.parent_class145 142 self.parent_class = class_name 146 143 parent_list.append(key) … … 150 147 self.add_data_set(key) 151 148 elif class_prog.match(u'SASdata'): 152 self._initialize_new_data_set(value) 153 self._find_data_attributes(value) 149 self._initialize_new_data_set(parent_list) 154 150 # Recursion step to access data within the group 155 151 self.read_children(value, parent_list) 152 # Reset parent class when returning from recursive method 153 self.parent_class = class_name 156 154 self.add_intermediate() 157 # Reset parent class when returning from recursive method158 self.parent_class = last_parent_class159 155 parent_list.remove(key) 160 156 161 157 elif isinstance(value, h5py.Dataset): 162 158 # If this is a dataset, store the data appropriately 163 data_set = value.value159 data_set = data[key][:] 164 160 unit = self._get_unit(value) 161 162 # I and Q Data 163 if key == u'I': 164 if isinstance(self.current_dataset, plottable_2D): 165 self.current_dataset.data = data_set 166 self.current_dataset.zaxis("Intensity", unit) 167 else: 168 self.current_dataset.y = data_set.flatten() 169 self.current_dataset.yaxis("Intensity", unit) 170 continue 171 elif key == u'Idev': 172 if isinstance(self.current_dataset, plottable_2D): 173 self.current_dataset.err_data = data_set.flatten() 174 else: 175 self.current_dataset.dy = data_set.flatten() 176 continue 177 elif key == u'Q': 178 self.current_dataset.xaxis("Q", unit) 179 if isinstance(self.current_dataset, plottable_2D): 180 self.current_dataset.q = data_set.flatten() 181 else: 182 self.current_dataset.x = data_set.flatten() 183 continue 184 elif key == u'Qdev': 185 self.current_dataset.dx = data_set.flatten() 186 continue 187 elif key == u'dQw': 188 self.current_dataset.dxw = data_set.flatten() 189 continue 190 elif key == u'dQl': 191 self.current_dataset.dxl = data_set.flatten() 192 continue 193 elif key == u'Qy': 194 self.current_dataset.yaxis("Q_y", unit) 195 self.current_dataset.qy_data = data_set.flatten() 196 continue 197 elif key == u'Qydev': 198 self.current_dataset.dqy_data = data_set.flatten() 199 continue 200 elif key == u'Qx': 201 self.current_dataset.xaxis("Q_x", unit) 202 self.current_dataset.qx_data = data_set.flatten() 203 continue 204 elif key == u'Qxdev': 205 self.current_dataset.dqx_data = data_set.flatten() 206 continue 207 elif key == u'Mask': 208 self.current_dataset.mask = data_set.flatten() 209 continue 210 # Transmission Spectrum 211 elif (key == u'T' 212 and self.parent_class == u'SAStransmission_spectrum'): 213 self.trans_spectrum.transmission = data_set.flatten() 214 continue 215 elif (key == u'Tdev' 216 and self.parent_class == u'SAStransmission_spectrum'): 217 self.trans_spectrum.transmission_deviation = \ 218 data_set.flatten() 219 continue 220 elif (key == u'lambda' 221 and self.parent_class == u'SAStransmission_spectrum'): 222 self.trans_spectrum.wavelength = data_set.flatten() 223 continue 165 224 166 225 for data_point in data_set: … … 173 232 if key == u'definition': 174 233 self.current_datainfo.meta_data['reader'] = data_point 175 # Run176 234 elif key == u'run': 177 235 self.current_datainfo.run.append(data_point) … … 182 240 except Exception: 183 241 pass 184 # Title185 242 elif key == u'title': 186 243 self.current_datainfo.title = data_point 187 # Note188 244 elif key == u'SASnote': 189 245 self.current_datainfo.notes.append(data_point) 246 190 247 # Sample Information 191 elif self.parent_class == u'SASsample': 192 self.process_sample(data_point, key) 248 # CanSAS 2.0 format 249 elif key == u'Title' and self.parent_class == u'SASsample': 250 self.current_datainfo.sample.name = data_point 251 # NXcanSAS format 252 elif key == u'name' and self.parent_class == u'SASsample': 253 self.current_datainfo.sample.name = data_point 254 # NXcanSAS format 255 elif key == u'ID' and self.parent_class == u'SASsample': 256 self.current_datainfo.sample.name = data_point 257 elif (key == u'thickness' 258 and self.parent_class == u'SASsample'): 259 self.current_datainfo.sample.thickness = data_point 260 elif (key == u'temperature' 261 and self.parent_class == u'SASsample'): 262 self.current_datainfo.sample.temperature = data_point 263 elif (key == u'transmission' 264 and self.parent_class == u'SASsample'): 265 self.current_datainfo.sample.transmission = data_point 266 elif (key == u'x_position' 267 and self.parent_class == u'SASsample'): 268 self.current_datainfo.sample.position.x = data_point 269 elif (key == u'y_position' 270 and self.parent_class == u'SASsample'): 271 self.current_datainfo.sample.position.y = data_point 272 elif key == u'pitch' and self.parent_class == u'SASsample': 273 self.current_datainfo.sample.orientation.x = data_point 274 elif key == u'yaw' and self.parent_class == u'SASsample': 275 self.current_datainfo.sample.orientation.y = data_point 276 elif key == u'roll' and self.parent_class == u'SASsample': 277 self.current_datainfo.sample.orientation.z = data_point 278 elif (key == u'details' 279 and self.parent_class == u'SASsample'): 280 self.current_datainfo.sample.details.append(data_point) 281 193 282 # Instrumental Information 194 283 elif (key == u'name' 195 284 and self.parent_class == u'SASinstrument'): 196 285 self.current_datainfo.instrument = data_point 197 # Detector 198 elif self.parent_class == u'SASdetector': 199 self.process_detector(data_point, key, unit) 200 # Collimation 201 elif self.parent_class == u'SAScollimation': 202 self.process_collimation(data_point, key, unit) 203 # Aperture 204 elif self.parent_class == u'SASaperture': 205 self.process_aperture(data_point, key) 286 elif key == u'name' and self.parent_class == u'SASdetector': 287 self.detector.name = data_point 288 elif key == u'SDD' and self.parent_class == u'SASdetector': 289 self.detector.distance = float(data_point) 290 self.detector.distance_unit = unit 291 elif (key == u'slit_length' 292 and self.parent_class == u'SASdetector'): 293 self.detector.slit_length = float(data_point) 294 self.detector.slit_length_unit = unit 295 elif (key == u'x_position' 296 and self.parent_class == u'SASdetector'): 297 self.detector.offset.x = float(data_point) 298 self.detector.offset_unit = unit 299 elif (key == u'y_position' 300 and self.parent_class == u'SASdetector'): 301 self.detector.offset.y = float(data_point) 302 self.detector.offset_unit = unit 303 elif (key == u'pitch' 304 and self.parent_class == u'SASdetector'): 305 self.detector.orientation.x = float(data_point) 306 self.detector.orientation_unit = unit 307 elif key == u'roll' and self.parent_class == u'SASdetector': 308 self.detector.orientation.z = float(data_point) 309 self.detector.orientation_unit = unit 310 elif key == u'yaw' and self.parent_class == u'SASdetector': 311 self.detector.orientation.y = float(data_point) 312 self.detector.orientation_unit = unit 313 elif (key == u'beam_center_x' 314 and self.parent_class == u'SASdetector'): 315 self.detector.beam_center.x = float(data_point) 316 self.detector.beam_center_unit = unit 317 elif (key == u'beam_center_y' 318 and self.parent_class == u'SASdetector'): 319 self.detector.beam_center.y = float(data_point) 320 self.detector.beam_center_unit = unit 321 elif (key == u'x_pixel_size' 322 and self.parent_class == u'SASdetector'): 323 self.detector.pixel_size.x = float(data_point) 324 self.detector.pixel_size_unit = unit 325 elif (key == u'y_pixel_size' 326 and self.parent_class == u'SASdetector'): 327 self.detector.pixel_size.y = float(data_point) 328 self.detector.pixel_size_unit = unit 329 elif (key == u'distance' 330 and self.parent_class == u'SAScollimation'): 331 self.collimation.length = data_point 332 self.collimation.length_unit = unit 333 elif (key == u'name' 334 and self.parent_class == u'SAScollimation'): 335 self.collimation.name = data_point 336 elif (key == u'shape' 337 and self.parent_class == u'SASaperture'): 338 self.aperture.shape = data_point 339 elif (key == u'x_gap' 340 and self.parent_class == u'SASaperture'): 341 self.aperture.size.x = data_point 342 elif (key == u'y_gap' 343 and self.parent_class == u'SASaperture'): 344 self.aperture.size.y = data_point 345 206 346 # Process Information 207 elif self.parent_class == u'SASprocess': # CanSAS 2.0 208 self.process_process(data_point, key) 347 elif (key == u'Title' 348 and self.parent_class == u'SASprocess'): # CanSAS 2.0 349 self.process.name = data_point 350 elif (key == u'name' 351 and self.parent_class == u'SASprocess'): # NXcanSAS 352 self.process.name = data_point 353 elif (key == u'description' 354 and self.parent_class == u'SASprocess'): 355 self.process.description = data_point 356 elif key == u'date' and self.parent_class == u'SASprocess': 357 self.process.date = data_point 358 elif key == u'term' and self.parent_class == u'SASprocess': 359 self.process.term = data_point 360 elif self.parent_class == u'SASprocess': 361 self.process.notes.append(data_point) 362 209 363 # Source 210 elif self.parent_class == u'SASsource': 211 self.process_source(data_point, key, unit) 364 elif (key == u'wavelength' 365 and self.parent_class == u'SASdata'): 366 self.current_datainfo.source.wavelength = data_point 367 self.current_datainfo.source.wavelength_unit = unit 368 elif (key == u'incident_wavelength' 369 and self.parent_class == 'SASsource'): 370 self.current_datainfo.source.wavelength = data_point 371 self.current_datainfo.source.wavelength_unit = unit 372 elif (key == u'wavelength_max' 373 and self.parent_class == u'SASsource'): 374 self.current_datainfo.source.wavelength_max = data_point 375 self.current_datainfo.source.wavelength_max_unit = unit 376 elif (key == u'wavelength_min' 377 and self.parent_class == u'SASsource'): 378 self.current_datainfo.source.wavelength_min = data_point 379 self.current_datainfo.source.wavelength_min_unit = unit 380 elif (key == u'incident_wavelength_spread' 381 and self.parent_class == u'SASsource'): 382 self.current_datainfo.source.wavelength_spread = \ 383 data_point 384 self.current_datainfo.source.wavelength_spread_unit = \ 385 unit 386 elif (key == u'beam_size_x' 387 and self.parent_class == u'SASsource'): 388 self.current_datainfo.source.beam_size.x = data_point 389 self.current_datainfo.source.beam_size_unit = unit 390 elif (key == u'beam_size_y' 391 and self.parent_class == u'SASsource'): 392 self.current_datainfo.source.beam_size.y = data_point 393 self.current_datainfo.source.beam_size_unit = unit 394 elif (key == u'beam_shape' 395 and self.parent_class == u'SASsource'): 396 self.current_datainfo.source.beam_shape = data_point 397 elif (key == u'radiation' 398 and self.parent_class == u'SASsource'): 399 self.current_datainfo.source.radiation = data_point 400 elif (key == u'transmission' 401 and self.parent_class == u'SASdata'): 402 self.current_datainfo.sample.transmission = data_point 403 212 404 # Everything else goes in meta_data 213 elif self.parent_class == u'SASdata':214 if isinstance(self.current_dataset, plottable_2D):215 self.process_2d_data_object(data_set, key, unit)216 else:217 self.process_1d_data_object(data_set, key, unit)218 219 break220 elif self.parent_class == u'SAStransmission_spectrum':221 self.process_trans_spectrum(data_set, key)222 break223 405 else: 224 406 new_key = self._create_unique_key( … … 229 411 # I don't know if this reachable code 230 412 self.errors.add("ShouldNeverHappenException") 231 232 def process_1d_data_object(self, data_set, key, unit):233 """234 SASdata processor method for 1d data items235 :param data_set: data from HDF5 file236 :param key: canSAS_class attribute237 :param unit: unit attribute238 """239 if key == self.i_name:240 self.current_dataset.y = data_set.flatten()241 self.current_dataset.yaxis("Intensity", unit)242 elif key == self.i_uncertainties_name:243 self.current_dataset.dy = data_set.flatten()244 elif key in self.q_names:245 self.current_dataset.xaxis("Q", unit)246 self.current_dataset.x = data_set.flatten()247 elif key in self.q_resolution_names:248 if (len(self.q_resolution_names) > 1249 and np.where(self.q_resolution_names == key)[0] == 0):250 self.current_dataset.dxw = data_set.flatten()251 elif (len(self.q_resolution_names) > 1252 and np.where(self.q_resolution_names == key)[0] == 1):253 self.current_dataset.dxl = data_set.flatten()254 else:255 self.current_dataset.dx = data_set.flatten()256 elif key in self.q_uncertainty_names:257 if (len(self.q_uncertainty_names) > 1258 and np.where(self.q_uncertainty_names == key)[0] == 0):259 self.current_dataset.dxw = data_set.flatten()260 elif (len(self.q_uncertainty_names) > 1261 and np.where(self.q_uncertainty_names == key)[0] == 1):262 self.current_dataset.dxl = data_set.flatten()263 else:264 self.current_dataset.dx = data_set.flatten()265 elif key == self.mask_name:266 self.current_dataset.mask = data_set.flatten()267 elif key == u'wavelength':268 self.current_datainfo.source.wavelength = data_set[0]269 self.current_datainfo.source.wavelength_unit = unit270 271 def process_2d_data_object(self, data_set, key, unit):272 if key == self.i_name:273 self.current_dataset.data = data_set274 self.current_dataset.zaxis("Intensity", unit)275 elif key == self.i_uncertainties_name:276 self.current_dataset.err_data = data_set.flatten()277 elif key in self.q_names:278 self.current_dataset.xaxis("Q_x", unit)279 self.current_dataset.yaxis("Q_y", unit)280 if self.q_names[0] == self.q_names[1]:281 # All q data in a single array282 self.current_dataset.qx_data = data_set[0]283 self.current_dataset.qy_data = data_set[1]284 elif self.q_names.index(key) == 0:285 self.current_dataset.qx_data = data_set286 elif self.q_names.index(key) == 1:287 self.current_dataset.qy_data = data_set288 elif key in self.q_uncertainty_names or key in self.q_resolution_names:289 if ((self.q_uncertainty_names[0] == self.q_uncertainty_names[1]) or290 (self.q_resolution_names[0] == self.q_resolution_names[1])):291 # All q data in a single array292 self.current_dataset.dqx_data = data_set[0].flatten()293 self.current_dataset.dqy_data = data_set[1].flatten()294 elif (self.q_uncertainty_names.index(key) == 0 or295 self.q_resolution_names.index(key) == 0):296 self.current_dataset.dqx_data = data_set.flatten()297 elif (self.q_uncertainty_names.index(key) == 1 or298 self.q_resolution_names.index(key) == 1):299 self.current_dataset.dqy_data = data_set.flatten()300 self.current_dataset.yaxis("Q_y", unit)301 elif key == self.mask_name:302 self.current_dataset.mask = data_set.flatten()303 elif key == u'Qy':304 self.current_dataset.yaxis("Q_y", unit)305 self.current_dataset.qy_data = data_set.flatten()306 elif key == u'Qydev':307 self.current_dataset.dqy_data = data_set.flatten()308 elif key == u'Qx':309 self.current_dataset.xaxis("Q_x", unit)310 self.current_dataset.qx_data = data_set.flatten()311 elif key == u'Qxdev':312 self.current_dataset.dqx_data = data_set.flatten()313 314 def process_trans_spectrum(self, data_set, key):315 """316 SAStransmission_spectrum processor317 :param data_set: data from HDF5 file318 :param key: canSAS_class attribute319 """320 if key == u'T':321 self.trans_spectrum.transmission = data_set.flatten()322 elif key == u'Tdev':323 self.trans_spectrum.transmission_deviation = data_set.flatten()324 elif key == u'lambda':325 self.trans_spectrum.wavelength = data_set.flatten()326 327 def process_sample(self, data_point, key):328 """329 SASsample processor330 :param data_point: Single point from an HDF5 data file331 :param key: class name data_point was taken from332 """333 if key == u'Title':334 self.current_datainfo.sample.name = data_point335 elif key == u'name':336 self.current_datainfo.sample.name = data_point337 elif key == u'ID':338 self.current_datainfo.sample.name = data_point339 elif key == u'thickness':340 self.current_datainfo.sample.thickness = data_point341 elif key == u'temperature':342 self.current_datainfo.sample.temperature = data_point343 elif key == u'transmission':344 self.current_datainfo.sample.transmission = data_point345 elif key == u'x_position':346 self.current_datainfo.sample.position.x = data_point347 elif key == u'y_position':348 self.current_datainfo.sample.position.y = data_point349 elif key == u'pitch':350 self.current_datainfo.sample.orientation.x = data_point351 elif key == u'yaw':352 self.current_datainfo.sample.orientation.y = data_point353 elif key == u'roll':354 self.current_datainfo.sample.orientation.z = data_point355 elif key == u'details':356 self.current_datainfo.sample.details.append(data_point)357 358 def process_detector(self, data_point, key, unit):359 """360 SASdetector processor361 :param data_point: Single point from an HDF5 data file362 :param key: class name data_point was taken from363 :param unit: unit attribute from data set364 """365 if key == u'name':366 self.detector.name = data_point367 elif key == u'SDD':368 self.detector.distance = float(data_point)369 self.detector.distance_unit = unit370 elif key == u'slit_length':371 self.detector.slit_length = float(data_point)372 self.detector.slit_length_unit = unit373 elif key == u'x_position':374 self.detector.offset.x = float(data_point)375 self.detector.offset_unit = unit376 elif key == u'y_position':377 self.detector.offset.y = float(data_point)378 self.detector.offset_unit = unit379 elif key == u'pitch':380 self.detector.orientation.x = float(data_point)381 self.detector.orientation_unit = unit382 elif key == u'roll':383 self.detector.orientation.z = float(data_point)384 self.detector.orientation_unit = unit385 elif key == u'yaw':386 self.detector.orientation.y = float(data_point)387 self.detector.orientation_unit = unit388 elif key == u'beam_center_x':389 self.detector.beam_center.x = float(data_point)390 self.detector.beam_center_unit = unit391 elif key == u'beam_center_y':392 self.detector.beam_center.y = float(data_point)393 self.detector.beam_center_unit = unit394 elif key == u'x_pixel_size':395 self.detector.pixel_size.x = float(data_point)396 self.detector.pixel_size_unit = unit397 elif key == u'y_pixel_size':398 self.detector.pixel_size.y = float(data_point)399 self.detector.pixel_size_unit = unit400 401 def process_collimation(self, data_point, key, unit):402 """403 SAScollimation processor404 :param data_point: Single point from an HDF5 data file405 :param key: class name data_point was taken from406 :param unit: unit attribute from data set407 """408 if key == u'distance':409 self.collimation.length = data_point410 self.collimation.length_unit = unit411 elif key == u'name':412 self.collimation.name = data_point413 414 def process_aperture(self, data_point, key):415 """416 SASaperture processor417 :param data_point: Single point from an HDF5 data file418 :param key: class name data_point was taken from419 """420 if key == u'shape':421 self.aperture.shape = data_point422 elif key == u'x_gap':423 self.aperture.size.x = data_point424 elif key == u'y_gap':425 self.aperture.size.y = data_point426 427 def process_source(self, data_point, key, unit):428 """429 SASsource processor430 :param data_point: Single point from an HDF5 data file431 :param key: class name data_point was taken from432 :param unit: unit attribute from data set433 """434 if key == u'incident_wavelength':435 self.current_datainfo.source.wavelength = data_point436 self.current_datainfo.source.wavelength_unit = unit437 elif key == u'wavelength_max':438 self.current_datainfo.source.wavelength_max = data_point439 self.current_datainfo.source.wavelength_max_unit = unit440 elif key == u'wavelength_min':441 self.current_datainfo.source.wavelength_min = data_point442 self.current_datainfo.source.wavelength_min_unit = unit443 elif key == u'incident_wavelength_spread':444 self.current_datainfo.source.wavelength_spread = data_point445 self.current_datainfo.source.wavelength_spread_unit = unit446 elif key == u'beam_size_x':447 self.current_datainfo.source.beam_size.x = data_point448 self.current_datainfo.source.beam_size_unit = unit449 elif key == u'beam_size_y':450 self.current_datainfo.source.beam_size.y = data_point451 self.current_datainfo.source.beam_size_unit = unit452 elif key == u'beam_shape':453 self.current_datainfo.source.beam_shape = data_point454 elif key == u'radiation':455 self.current_datainfo.source.radiation = data_point456 457 def process_process(self, data_point, key):458 """459 SASprocess processor460 :param data_point: Single point from an HDF5 data file461 :param key: class name data_point was taken from462 """463 term_match = re.compile(u'^term[0-9]+$')464 if key == u'Title': # CanSAS 2.0465 self.process.name = data_point466 elif key == u'name': # NXcanSAS467 self.process.name = data_point468 elif key == u'description':469 self.process.description = data_point470 elif key == u'date':471 self.process.date = data_point472 elif term_match.match(key):473 self.process.term.append(data_point)474 else:475 self.process.notes.append(data_point)476 413 477 414 def add_intermediate(self): … … 515 452 spectrum_list = [] 516 453 for spectrum in self.current_datainfo.trans_spectrum: 454 spectrum.transmission = np.delete(spectrum.transmission, [0]) 517 455 spectrum.transmission = spectrum.transmission.astype(np.float64) 456 spectrum.transmission_deviation = np.delete( 457 spectrum.transmission_deviation, [0]) 518 458 spectrum.transmission_deviation = \ 519 459 spectrum.transmission_deviation.astype(np.float64) 460 spectrum.wavelength = np.delete(spectrum.wavelength, [0]) 520 461 spectrum.wavelength = spectrum.wavelength.astype(np.float64) 521 462 if len(spectrum.transmission) > 0: … … 549 490 if dataset.data.ndim == 2: 550 491 (n_rows, n_cols) = dataset.data.shape 551 flat_qy = dataset.qy_data[0::n_cols].flatten() 552 # For 2D arrays of Qx and Qy, the Q value should be constant 553 # along each row -OR- each column. The direction is not 554 # specified in the NXcanSAS standard. 555 if flat_qy[0] == flat_qy[1]: 556 flat_qy = np.transpose(dataset.qy_data)[0::n_cols].flatten() 557 dataset.y_bins = np.unique(flat_qy) 558 flat_qx = dataset.qx_data[0::n_rows].flatten() 559 # For 2D arrays of Qx and Qy, the Q value should be constant 560 # along each row -OR- each column. The direction is not 561 # specified in the NXcanSAS standard. 562 if flat_qx[0] == flat_qx[1]: 563 flat_qx = np.transpose(dataset.qx_data)[0::n_rows].flatten() 564 dataset.x_bins = np.unique(flat_qx) 492 dataset.y_bins = dataset.qy_data[0::n_cols] 493 dataset.x_bins = dataset.qx_data[:n_cols] 565 494 dataset.data = dataset.data.flatten() 566 dataset.qx_data = dataset.qx_data.flatten()567 dataset.qy_data = dataset.qy_data.flatten()568 495 self.current_dataset = dataset 569 496 self.send_to_output() … … 588 515 self.current_datainfo = DataInfo() 589 516 590 def _initialize_new_data_set(self, value=None): 517 518 def _initialize_new_data_set(self, parent_list=None): 591 519 """ 592 520 A private class method to generate a new 1D or 2D data object based on … … 596 524 :param parent_list: List of names of parent elements 597 525 """ 598 if self._is2d(value): 526 527 if parent_list is None: 528 parent_list = [] 529 if self._find_intermediate(parent_list, "Qx"): 599 530 self.current_dataset = plottable_2D() 600 531 else: … … 603 534 self.current_dataset = plottable_1D(x, y) 604 535 self.current_datainfo.filename = self.raw_data.filename 605 self.mask_name = u'' 606 self.i_name = u'' 607 self.i_node = u'' 608 self.i_uncertainties_name = u'' 609 self.q_names = [] 610 self.q_uncertainty_names = [] 611 self.q_resolution_names = [] 612 613 @staticmethod 614 def check_is_list_or_array(iterable): 615 try: 616 iter(iterable) 617 if (not isinstance(iterable, np.ndarray) and not isinstance( 618 iterable, list)) or (isinstance(iterable, basestring)): 619 raise TypeError 620 except TypeError: 621 iterable = iterable.split(",") 622 return iterable 623 624 def _find_data_attributes(self, value): 625 """ 626 A class to find the indices for Q, the name of the Qdev and Idev, and 627 the name of the mask. 628 :param value: SASdata/NXdata HDF5 Group 629 """ 630 attrs = value.attrs 631 signal = attrs.get("signal", "I") 632 i_axes = attrs.get("I_axes", ["Q"]) 633 q_indices = attrs.get("Q_indices", [0]) 634 q_indices = map(int, self.check_is_list_or_array(q_indices)) 635 i_axes = self.check_is_list_or_array(i_axes) 636 keys = value.keys() 637 self.mask_name = attrs.get("mask") 638 for val in q_indices: 639 self.q_names.append(i_axes[val]) 640 self.i_name = signal 641 self.i_node = value.get(self.i_name) 642 for item in self.q_names: 643 if item in keys: 644 q_vals = value.get(item) 645 if q_vals.attrs.get("uncertainties") is not None: 646 self.q_uncertainty_names = q_vals.attrs.get("uncertainties") 647 elif q_vals.attrs.get("uncertainty") is not None: 648 self.q_uncertainty_names = q_vals.attrs.get("uncertainty") 649 if isinstance(self.q_uncertainty_names, basestring): 650 self.q_uncertainty_names = self.q_uncertainty_names.split(",") 651 if q_vals.attrs.get("resolutions") is not None: 652 self.q_resolution_names = q_vals.attrs.get("resolutions") 653 if isinstance(self.q_resolution_names, basestring): 654 self.q_resolution_names = self.q_resolution_names.split(",") 655 if self.i_name in keys: 656 i_vals = value.get(self.i_name) 657 self.i_uncertainties_name = i_vals.attrs.get("uncertainties") 658 if self.i_uncertainties_name is None: 659 self.i_uncertainties_name = i_vals.attrs.get("uncertainty") 660 661 def _is2d(self, value, basename="I"): 662 """ 663 A private class to determine if the data set is 1d or 2d. 536 537 def _find_intermediate(self, parent_list, basename=""): 538 """ 539 A private class used to find an entry by either using a direct key or 540 knowing the approximate basename. 664 541 665 542 :param parent_list: List of parents nodes in the HDF5 file 666 543 :param basename: Approximate name of an entry to search for 667 :return: True if 2D, otherwise false 668 """ 669 670 vals = value.get(basename) 671 return (vals is not None and vals.shape is not None 672 and len(vals.shape) != 1) 544 :return: 545 """ 546 547 entry = False 548 key_prog = re.compile(basename) 549 top = self.raw_data 550 for parent in parent_list: 551 top = top.get(parent) 552 for key in top.keys(): 553 if key_prog.match(key): 554 entry = True 555 break 556 return entry 673 557 674 558 def _create_unique_key(self, dictionary, name, numb=0): … … 699 583 if unit is None: 700 584 unit = h5attr(value, u'unit') 585 # Convert the unit formats 586 if unit == "1/A": 587 unit = "A^{-1}" 588 elif unit == "1/cm": 589 unit = "cm^{-1}" 701 590 return unit -
src/sas/sascalc/dataloader/readers/danse_reader.py
rfc51d06 r2469df7 180 180 detector.beam_center.y = center_y * pixel 181 181 182 self.current_dataset = self.set_default_2d_units(self.current_dataset) 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}") 186 183 187 self.current_dataset.x_bins = x_vals 184 188 self.current_dataset.y_bins = y_vals -
src/sas/sascalc/dataloader/readers/red2d_reader.py
r058f6c3 rc8321cfc 317 317 318 318 # Units of axes 319 self.current_dataset = self.set_default_2d_units(self.current_dataset) 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}") 320 322 321 323 # Store loading process information -
src/sas/sascalc/file_converter/nxcansas_writer.py
r2ca5d57b r574adc7 8 8 import os 9 9 10 from sas.sascalc.dataloader.readers.cansas_reader_HDF5 import Reader 10 from sas.sascalc.dataloader.readers.cansas_reader_HDF5 import Reader as Cansas2Reader 11 11 from sas.sascalc.dataloader.data_info import Data1D, Data2D 12 12 13 class NXcanSASWriter( Reader):13 class NXcanSASWriter(Cansas2Reader): 14 14 """ 15 15 A class for writing in NXcanSAS data files. Any number of data sets may be … … 87 87 entry[names[2]].attrs['units'] = units 88 88 89 valid_data = all([issubclass(d.__class__, (Data1D, Data2D)) for d in 90 dataset]) 89 valid_data = all([issubclass(d.__class__, (Data1D, Data2D)) for d in dataset]) 91 90 if not valid_data: 92 raise ValueError("All entries of dataset must be Data1D or Data2D" 93 "objects") 91 raise ValueError("All entries of dataset must be Data1D or Data2D objects") 94 92 95 93 # Get run name and number from first Data object … … 111 109 sasentry.attrs['version'] = '1.0' 112 110 113 for i, data_obj in enumerate(dataset): 114 data_entry = sasentry.create_group("sasdata{0:0=2d}".format(i+1)) 111 i = 1 112 113 for data_obj in dataset: 114 data_entry = sasentry.create_group("sasdata{0:0=2d}".format(i)) 115 115 data_entry.attrs['canSAS_class'] = 'SASdata' 116 116 if isinstance(data_obj, Data1D): … … 118 118 elif isinstance(data_obj, Data2D): 119 119 self._write_2d_data(data_obj, data_entry) 120 i += 1 120 121 121 122 data_info = dataset[0] … … 147 148 sample_entry.create_dataset('details', data=details) 148 149 149 # Instrum ent metadata150 # Instrumment metadata 150 151 instrument_entry = sasentry.create_group('sasinstrument') 151 152 instrument_entry.attrs['canSAS_class'] = 'SASinstrument' … … 175 176 units=data_info.source.beam_size_unit, write_fn=_write_h5_float) 176 177 178 177 179 # Collimation metadata 178 180 if len(data_info.collimation) > 0: 179 for i, coll_info in enumerate(data_info.collimation): 181 i = 1 182 for coll_info in data_info.collimation: 180 183 collimation_entry = instrument_entry.create_group( 181 'sascollimation{0:0=2d}'.format(i + 1))184 'sascollimation{0:0=2d}'.format(i)) 182 185 collimation_entry.attrs['canSAS_class'] = 'SAScollimation' 183 186 if coll_info.length is not None: 184 187 _write_h5_float(collimation_entry, coll_info.length, 'SDD') 185 collimation_entry['SDD'].attrs['units'] =\ 186 coll_info.length_unit 188 collimation_entry['SDD'].attrs['units'] = coll_info.length_unit 187 189 if coll_info.name is not None: 188 190 collimation_entry['name'] = _h5_string(coll_info.name) 189 191 else: 190 # Create a blank one - at least 1 collimation required by format 191 instrument_entry.create_group('sascollimation01') 192 # Create a blank one - at least 1 set of collimation metadata 193 # required by format 194 collimation_entry = instrument_entry.create_group('sascollimation01') 192 195 193 196 # Detector metadata 194 197 if len(data_info.detector) > 0: 195 198 i = 1 196 for i, det_info in enumerate(data_info.detector):199 for det_info in data_info.detector: 197 200 detector_entry = instrument_entry.create_group( 198 'sasdetector{0:0=2d}'.format(i + 1))201 'sasdetector{0:0=2d}'.format(i)) 199 202 detector_entry.attrs['canSAS_class'] = 'SASdetector' 200 203 if det_info.distance is not None: 201 204 _write_h5_float(detector_entry, det_info.distance, 'SDD') 202 detector_entry['SDD'].attrs['units'] =\ 203 det_info.distance_unit 205 detector_entry['SDD'].attrs['units'] = det_info.distance_unit 204 206 if det_info.name is not None: 205 207 detector_entry['name'] = _h5_string(det_info.name) … … 207 209 detector_entry['name'] = _h5_string('') 208 210 if det_info.slit_length is not None: 209 _write_h5_float(detector_entry, det_info.slit_length, 210 'slit_length') 211 detector_entry['slit_length'].attrs['units'] =\ 212 det_info.slit_length_unit 211 _write_h5_float(detector_entry, det_info.slit_length, 'slit_length') 212 detector_entry['slit_length'].attrs['units'] = det_info.slit_length_unit 213 213 _write_h5_vector(detector_entry, det_info.offset) 214 214 # NXcanSAS doesn't save information about pitch, only roll … … 224 224 names=['x_pixel_size', 'y_pixel_size'], 225 225 write_fn=_write_h5_float, units=det_info.pixel_size_unit) 226 227 i += 1 226 228 else: 227 229 # Create a blank one - at least 1 detector required by format … … 229 231 detector_entry.attrs['canSAS_class'] = 'SASdetector' 230 232 detector_entry.attrs['name'] = '' 231 232 # Process meta data233 for i, process in enumerate(data_info.process):234 process_entry = sasentry.create_group('sasprocess{0:0=2d}'.format(235 i + 1))236 process_entry.attrs['canSAS_class'] = 'SASprocess'237 if process.name:238 name = _h5_string(process.name)239 process_entry.create_dataset('name', data=name)240 if process.date:241 date = _h5_string(process.date)242 process_entry.create_dataset('date', data=date)243 if process.description:244 desc = _h5_string(process.description)245 process_entry.create_dataset('description', data=desc)246 for j, term in enumerate(process.term):247 # Don't save empty terms248 if term:249 h5_term = _h5_string(term)250 process_entry.create_dataset('term{0:0=2d}'.format(251 j + 1), data=h5_term)252 for j, note in enumerate(process.notes):253 # Don't save empty notes254 if note:255 h5_note = _h5_string(note)256 process_entry.create_dataset('note{0:0=2d}'.format(257 j + 1), data=h5_note)258 259 # Transmission Spectrum260 for i, trans in enumerate(data_info.trans_spectrum):261 trans_entry = sasentry.create_group(262 'sastransmission_spectrum{0:0=2d}'.format(i + 1))263 trans_entry.attrs['canSAS_class'] = 'SAStransmission_spectrum'264 trans_entry.attrs['signal'] = 'T'265 trans_entry.attrs['T_axes'] = 'T'266 trans_entry.attrs['name'] = trans.name267 if trans.timestamp is not '':268 trans_entry.attrs['timestamp'] = trans.timestamp269 transmission = trans_entry.create_dataset('T',270 data=trans.transmission)271 transmission.attrs['unertainties'] = 'Tdev'272 trans_entry.create_dataset('Tdev',273 data=trans.transmission_deviation)274 trans_entry.create_dataset('lambda', data=trans.wavelength)275 233 276 234 note_entry = sasentry.create_group('sasnote'.format(i)) … … 296 254 data_entry.attrs['signal'] = 'I' 297 255 data_entry.attrs['I_axes'] = 'Q' 298 data_entry.attrs['Q_indices'] = [0] 299 q_entry = data_entry.create_dataset('Q', data=data_obj.x) 300 q_entry.attrs['units'] = data_obj.x_unit 301 i_entry = data_entry.create_dataset('I', data=data_obj.y) 302 i_entry.attrs['units'] = data_obj.y_unit 303 if data_obj.dy is not None: 304 i_entry.attrs['uncertainties'] = 'Idev' 305 i_dev_entry = data_entry.create_dataset('Idev', data=data_obj.dy) 306 i_dev_entry.attrs['units'] = data_obj.y_unit 307 if data_obj.dx is not None: 308 q_entry.attrs['resolutions'] = 'dQ' 309 dq_entry = data_entry.create_dataset('dQ', data=data_obj.dx) 310 dq_entry.attrs['units'] = data_obj.x_unit 311 elif data_obj.dxl is not None: 312 q_entry.attrs['resolutions'] = ['dQl','dQw'] 313 dql_entry = data_entry.create_dataset('dQl', data=data_obj.dxl) 314 dql_entry.attrs['units'] = data_obj.x_unit 315 dqw_entry = data_entry.create_dataset('dQw', data=data_obj.dxw) 316 dqw_entry.attrs['units'] = data_obj.x_unit 256 data_entry.attrs['I_uncertainties'] = 'Idev' 257 data_entry.attrs['Q_indicies'] = 0 258 259 dI = data_obj.dy 260 if dI is None: 261 dI = np.zeros((data_obj.y.shape)) 262 263 data_entry.create_dataset('Q', data=data_obj.x) 264 data_entry.create_dataset('I', data=data_obj.y) 265 data_entry.create_dataset('Idev', data=dI) 317 266 318 267 def _write_2d_data(self, data, data_entry): … … 324 273 """ 325 274 data_entry.attrs['signal'] = 'I' 326 data_entry.attrs['I_axes'] = 'Qx,Qy' 327 data_entry.attrs['Q_indices'] = [0,1] 275 data_entry.attrs['I_axes'] = 'Q,Q' 276 data_entry.attrs['I_uncertainties'] = 'Idev' 277 data_entry.attrs['Q_indicies'] = [0,1] 328 278 329 279 (n_rows, n_cols) = (len(data.y_bins), len(data.x_bins)) … … 338 288 raise ValueError("Unable to calculate dimensions of 2D data") 339 289 340 intensity = np.reshape(data.data, (n_rows, n_cols)) 341 qx = np.reshape(data.qx_data, (n_rows, n_cols)) 290 I = np.reshape(data.data, (n_rows, n_cols)) 291 dI = np.zeros((n_rows, n_cols)) 292 if not all(data.err_data == [None]): 293 dI = np.reshape(data.err_data, (n_rows, n_cols)) 294 qx = np.reshape(data.qx_data, (n_rows, n_cols)) 342 295 qy = np.reshape(data.qy_data, (n_rows, n_cols)) 343 296 344 i_entry = data_entry.create_dataset('I', data=intensity) 345 i_entry.attrs['units'] = data.I_unit 346 qx_entry = data_entry.create_dataset('Qx', data=qx) 347 qx_entry.attrs['units'] = data.Q_unit 348 qy_entry = data_entry.create_dataset('Qy', data=qy) 349 qy_entry.attrs['units'] = data.Q_unit 350 if data.err_data is not None and not all(data.err_data == [None]): 351 d_i = np.reshape(data.err_data, (n_rows, n_cols)) 352 i_entry.attrs['uncertainties'] = 'Idev' 353 i_dev_entry = data_entry.create_dataset('Idev', data=d_i) 354 i_dev_entry.attrs['units'] = data.I_unit 355 if data.dqx_data is not None and not all(data.dqx_data == [None]): 356 qx_entry.attrs['resolutions'] = 'dQx' 357 dqx_entry = data_entry.create_dataset('dQx', data=data.dqx_data) 358 dqx_entry.attrs['units'] = data.Q_unit 359 if data.dqy_data is not None and not all(data.dqy_data == [None]): 360 qy_entry.attrs['resolutions'] = 'dQy' 361 dqy_entry = data_entry.create_dataset('dQy', data=data.dqy_data) 362 dqy_entry.attrs['units'] = data.Q_unit 297 I_entry = data_entry.create_dataset('I', data=I) 298 I_entry.attrs['units'] = data.I_unit 299 Qx_entry = data_entry.create_dataset('Qx', data=qx) 300 Qx_entry.attrs['units'] = data.Q_unit 301 Qy_entry = data_entry.create_dataset('Qy', data=qy) 302 Qy_entry.attrs['units'] = data.Q_unit 303 Idev_entry = data_entry.create_dataset('Idev', data=dI) 304 Idev_entry.attrs['units'] = data.I_unit -
src/sas/sasgui/guiframe/gui_manager.py
rb1ec23d r8ac05a5 46 46 from sas.sasgui.guiframe.CategoryManager import CategoryManager 47 47 from sas.sascalc.dataloader.loader import Loader 48 from sas.sascalc.file_converter.nxcansas_writer import NXcanSASWriter49 48 from sas.sasgui.guiframe.proxy import Connection 50 49 … … 2420 2419 default_name = fname 2421 2420 wildcard = "Text files (*.txt)|*.txt|"\ 2422 "CanSAS 1D files (*.xml)|*.xml|"\ 2423 "NXcanSAS files (*.h5)|*.h5|" 2424 options = [".txt", ".xml",".h5"] 2421 "CanSAS 1D files(*.xml)|*.xml" 2422 path = None 2425 2423 dlg = wx.FileDialog(self, "Choose a file", 2426 2424 self._default_save_location, … … 2432 2430 # This is MAC Fix 2433 2431 ext_num = dlg.GetFilterIndex() 2434 2435 ext_format = options[ext_num] 2432 if ext_num == 0: 2433 ext_format = '.txt' 2434 else: 2435 ext_format = '.xml' 2436 2436 path = os.path.splitext(path)[0] + ext_format 2437 2437 mypath = os.path.basename(path) 2438 fName = os.path.splitext(path)[0] + ext_format 2439 2440 if os.path.splitext(mypath)[1].lower() == options[0]: 2438 2439 # Instantiate a loader 2440 loader = Loader() 2441 ext_format = ".txt" 2442 if os.path.splitext(mypath)[1].lower() == ext_format: 2441 2443 # Make sure the ext included in the file name 2442 2444 # especially on MAC 2445 fName = os.path.splitext(path)[0] + ext_format 2443 2446 self._onsaveTXT(data, fName) 2444 elif os.path.splitext(mypath)[1].lower() == options[1]: 2447 ext_format = ".xml" 2448 if os.path.splitext(mypath)[1].lower() == ext_format: 2445 2449 # Make sure the ext included in the file name 2446 2450 # especially on MAC 2447 # Instantiate a loader 2448 loader = Loader() 2451 fName = os.path.splitext(path)[0] + ext_format 2449 2452 loader.save(fName, data, ext_format) 2450 elif os.path.splitext(mypath)[1].lower() == options[2]:2451 nxcansaswriter = NXcanSASWriter()2452 nxcansaswriter.write([data], fName)2453 2453 try: 2454 2454 self._default_save_location = os.path.dirname(path) … … 2477 2477 if has_errors: 2478 2478 if data.dx is not None and data.dx != []: 2479 out.write("<X> \t<Y>\t<dY>\t<dX>\n")2479 out.write("<X> <Y> <dY> <dX>\n") 2480 2480 else: 2481 out.write("<X> \t<Y>\t<dY>\n")2481 out.write("<X> <Y> <dY>\n") 2482 2482 else: 2483 out.write("<X> \t<Y>\n")2483 out.write("<X> <Y>\n") 2484 2484 2485 2485 for i in range(len(data.x)): … … 2525 2525 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2526 2526 text += '\nData Points:\n' 2527 text += "<index> \t<X> \t<Y> \t<dY> " 2528 text += "\t<dX>\n" if(data.dxl is not None and 2529 data.dxw is not None) else "\t<dXl> \t<dXw>\n" 2527 x_st = "X" 2530 2528 for index in range(len(data.x)): 2531 2529 if data.dy is not None and len(data.dy) > index: … … 2538 2536 dx_val = 0.0 2539 2537 if data.dxl is not None and len(data.dxl) > index: 2538 if index == 0: 2539 x_st = "Xl" 2540 2540 dx_val = data.dxl[index] 2541 if data.dxw is not None and len(data.dxw) > index: 2542 dx_val = "%s \t%s" % (data.dxl[index], data.dxw[index]) 2543 2541 elif data.dxw is not None and len(data.dxw) > index: 2542 if index == 0: 2543 x_st = "Xw" 2544 dx_val = data.dxw[index] 2545 2546 if index == 0: 2547 text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st 2544 2548 text += "%s \t%s \t%s \t%s \t%s\n" % (index, 2545 2549 data.x[index], … … 2558 2562 """ 2559 2563 default_name = fname 2560 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT|"\ 2561 "NXcanSAS files (*.h5)|*.h5|" 2564 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" 2562 2565 dlg = wx.FileDialog(self, "Choose a file", 2563 2566 self._default_save_location, … … 2571 2574 if ext_num == 0: 2572 2575 ext_format = '.dat' 2573 elif ext_num == 1:2574 ext_format = '.h5'2575 2576 else: 2576 2577 ext_format = '' … … 2580 2581 # Instantiate a loader 2581 2582 loader = Loader() 2582 if os.path.splitext(mypath)[1].lower() == '.dat': 2583 2584 ext_format = ".dat" 2585 if os.path.splitext(mypath)[1].lower() == ext_format: 2583 2586 # Make sure the ext included in the file name 2584 2587 # especially on MAC 2585 2588 fileName = os.path.splitext(path)[0] + ext_format 2586 2589 loader.save(fileName, data, ext_format) 2587 elif os.path.splitext(mypath)[1].lower() == '.h5':2588 # Make sure the ext included in the file name2589 # especially on MAC2590 fileName = os.path.splitext(path)[0] + ext_format2591 nxcansaswriter = NXcanSASWriter()2592 nxcansaswriter.write([data], fileName)2593 2590 try: 2594 2591 self._default_save_location = os.path.dirname(path) -
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
r9c7e2b8 r9c7e2b8 205 205 except NoKnownLoaderException as e: 206 206 exception_occurred = True 207 error_message = "Loading data failed! \n" + e.message207 error_message = "Loading data failed!" + e.message 208 208 file_errors[basename] = [error_message] 209 209 except Exception as e: … … 224 224 for message in error_array: 225 225 error_message += message + "\n" 226 error_message = error_message[:-1]227 226 self.load_complete(output=output, 228 227 message=error_message, … … 232 231 self.load_complete(output=output, message="Loading data complete!", 233 232 info="info") 233 else: 234 self.load_complete(output=None, message=error_message, info="error") 234 235 235 236 def load_update(self, message="", info="warning"): -
test/sasdataloader/test/utest_abs_reader.py
rf4e2f22 rbd5c3b1 80 80 data_cor = Loader().load(find("sam14_cor.cor")) 81 81 for i in range(0, len(data_abs) - 1): 82 self.assertEqual (data_abs.x[i], data_cor.x[i])83 self.assertEqual (data_abs.y[i], data_cor.y[i])84 self.assertEqual (data_abs.dxl[i], data_cor.dxl[i])85 self.assertEqual (data_abs.dxw[i], data_cor.dxw[i])82 self.assertEquals(data_abs.x[i], data_cor.x[i]) 83 self.assertEquals(data_abs.y[i], data_cor.y[i]) 84 self.assertEquals(data_abs.dxl[i], data_cor.dxl[i]) 85 self.assertEquals(data_abs.dxw[i], data_cor.dxw[i]) 86 86 self.assertTrue(data_abs.dxl > 0) 87 87 … … 118 118 self.assertEqual(self.data.detector[0].beam_center.y, center_y) 119 119 120 self.assertEqual(self.data.I_unit, ' cm^{-1}')120 self.assertEqual(self.data.I_unit, '1/cm') 121 121 self.assertEqual(self.data.data[0], 1.57831) 122 122 self.assertEqual(self.data.data[1], 2.70983) -
test/sasdataloader/test/utest_averaging.py
rf4e2f22 rf53d684 106 106 107 107 def setUp(self): 108 filepath = find(' test_data' + os.sep + 'MAR07232_rest.h5')108 filepath = find('MAR07232_rest.h5') 109 109 self.data_list = Loader().load(filepath) 110 110 self.data = self.data_list[0] … … 121 121 122 122 o = r(self.data) 123 filepath = find(' test_data' + os.sep + 'ring_testdata.txt')123 filepath = find('ring_testdata.txt') 124 124 answer_list = Loader().load(filepath) 125 125 answer = answer_list[0] … … 142 142 o = r(self.data) 143 143 144 filepath = find(' test_data' + os.sep + 'avg_testdata.txt')144 filepath = find('avg_testdata.txt') 145 145 answer = Loader().load(filepath)[0] 146 146 for i in range(r.nbins_phi): … … 158 158 s, ds, npoints = r(self.data) 159 159 self.assertAlmostEqual(s, 34.278990899999997, 4) 160 self.assertAlmostEqual(ds, 8.237259999538685, 4)160 self.assertAlmostEqual(ds, 7.8007981835194293, 4) 161 161 self.assertAlmostEqual(npoints, 324.0000, 4) 162 162 … … 164 164 s, ds = r(self.data) 165 165 self.assertAlmostEqual(s, 0.10579935462962962, 4) 166 self.assertAlmostEqual(ds, 0.02 542364197388483, 4)166 self.assertAlmostEqual(ds, 0.024076537603455028, 4) 167 167 168 168 def test_slabX(self): … … 177 177 o = r(self.data) 178 178 179 filepath = find(' test_data' + os.sep + 'slabx_testdata.txt')179 filepath = find('slabx_testdata.txt') 180 180 answer = Loader().load(filepath)[0] 181 181 for i in range(len(o.x)): … … 195 195 o = r(self.data) 196 196 197 filepath = find(' test_data' + os.sep + 'slaby_testdata.txt')197 filepath = find('slaby_testdata.txt') 198 198 answer = Loader().load(filepath)[0] 199 199 for i in range(len(o.x)): … … 221 221 o = r(self.data) 222 222 223 filepath = find(' test_data' + os.sep + 'ring_testdata.txt')223 filepath = find('ring_testdata.txt') 224 224 answer = Loader().load(filepath)[0] 225 225 for i in range(len(o.x)): … … 238 238 o = r(self.data) 239 239 240 filepath = find(' test_data' + os.sep + 'sectorphi_testdata.txt')240 filepath = find('sectorphi_testdata.txt') 241 241 answer = Loader().load(filepath)[0] 242 242 for i in range(len(o.x)): … … 255 255 o = r(self.data) 256 256 257 filepath = find(' test_data' + os.sep + 'sectorq_testdata.txt')257 filepath = find('sectorq_testdata.txt') 258 258 answer = Loader().load(filepath)[0] 259 259 for i in range(len(o.x)): -
test/sasdataloader/test/utest_cansas.py
rf4e2f22 rf53d684 91 91 reader = XMLreader(self.xml_valid, self.schema_1_0) 92 92 valid = reader.validate_xml() 93 self.assertTrue(valid) 93 if valid: 94 self.assertTrue(valid) 95 else: 96 self.assertFalse(valid) 94 97 95 98 def _check_data(self, data): … … 190 193 def test_save_cansas_v1_0(self): 191 194 xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) 192 self.assertTrue(xmlreader.validate_xml()) 195 valid = xmlreader.validate_xml() 196 self.assertTrue(valid) 193 197 reader_generic = Loader() 194 198 dataloader = reader_generic.load(self.isis_1_0) … … 203 207 return_data = reader2.read(self.write_1_0_filename) 204 208 written_data = return_data[0] 205 xmlreader = XMLreader(self.write_1_0_filename, self.schema_1_0) 206 self.assertTrue(xmlreader.validate_xml()) 209 XMLreader(self.write_1_0_filename, self.schema_1_0) 210 valid = xmlreader.validate_xml() 211 self.assertTrue(valid) 207 212 self._check_data(written_data) 208 213 if os.path.isfile(self.write_1_0_filename): … … 255 260 self.loader = Loader() 256 261 self.datafile_basic = find("simpleexamplefile.h5") 257 self.datafile_multiplesasentry = find( 258 "test_data" + os.sep + "nxcansas_1Dand2D_multisasentry.h5") 259 self.datafile_multiplesasdata = find( 260 "test_data" + os.sep + "nxcansas_1Dand2D_multisasdata.h5") 261 self.datafile_multiplesasdata_multiplesasentry = find( 262 "test_data" + os.sep + "nxcansas_1Dand2D_multisasentry_multisasdata.h5") 262 self.datafile_multiplesasentry = find("cansas_1Dand2D_samedatafile.h5") 263 self.datafile_multiplesasdata = find("cansas_1Dand2D_samesasentry.h5") 264 self.datafile_multiplesasdata_multiplesasentry = find("cansas_1Dand2D_multiplesasentry_multiplesasdata.h5") 263 265 264 266 def test_real_data(self): … … 271 273 self._check_multiple_data(self.data[0]) 272 274 self._check_multiple_data(self.data[1]) 273 if isinstance(self.data[0], Data1D): 274 self._check_1d_data(self.data[0]) 275 self._check_2d_data(self.data[1]) 276 else: 277 self._check_1d_data(self.data[1]) 278 self._check_2d_data(self.data[0]) 279 280 def test_multiple_sasdatas(self): 281 self.data = self.loader.load(self.datafile_multiplesasdata) 282 self.assertTrue(len(self.data) == 2) 283 self._check_multiple_data(self.data[0]) 284 self._check_multiple_data(self.data[1]) 285 if isinstance(self.data[0], Data1D): 286 self._check_1d_data(self.data[0]) 287 self._check_2d_data(self.data[1]) 288 else: 289 self._check_1d_data(self.data[1]) 290 self._check_2d_data(self.data[0]) 291 292 def test_multiple_sasentries_multiplesasdatas(self): 293 self.data = self.loader.load( 294 self.datafile_multiplesasdata_multiplesasentry) 295 self.assertTrue(len(self.data) == 4) 296 self._check_multiple_data(self.data[0]) 297 self._check_multiple_data(self.data[1]) 298 self._check_multiple_data(self.data[2]) 299 self._check_multiple_data(self.data[3]) 300 for data in self.data: 301 if isinstance(data, Data1D): 302 self._check_1d_data(data) 303 else: 304 self._check_2d_data(data) 275 self._check_1d_data(self.data[0]) 305 276 306 277 def _check_multiple_data(self, data): 307 self.assertEqual(data.title, "MH4_5deg_16T_SLOW") 308 self.assertEqual(data.run[0], '33837') 309 self.assertEqual(len(data.run), 1) 310 self.assertEqual(data.instrument, "SANS2D") 311 self.assertEqual(data.source.radiation, "Spallation Neutron Source") 312 self.assertEqual(len(data.detector), 2) 313 self.assertTrue(data.detector[0].name == "rear-detector" 314 or data.detector[1].name == "rear-detector") 315 self.assertTrue(data.detector[0].name == "front-detector" 316 or data.detector[1].name == "front-detector") 317 self.assertAlmostEqual(data.detector[0].distance + 318 data.detector[1].distance, 7230.54, 2) 319 self.assertEqual(data.detector[0].distance_unit, 'mm') 320 self.assertEqual(len(data.trans_spectrum), 1) 278 self.assertTrue(data.title == "MH4_5deg_16T_SLOW") 279 self.assertTrue(data.run[0] == '33837') 280 self.assertTrue(len(data.run) == 1) 281 self.assertTrue(data.instrument == "SANS2D") 282 self.assertTrue(data.source.radiation == "Spallation Neutron Source") 283 self.assertTrue(len(data.detector) == 1) 284 self.assertTrue(data.detector[0].name == "rear-detector") 285 self.assertTrue(data.detector[0].distance == 4.385281) 286 self.assertTrue(data.detector[0].distance_unit == 'm') 287 self.assertTrue(len(data.trans_spectrum) == 1) 321 288 322 289 def _check_1d_data(self, data): 323 self.assertEqual(len(data.x), 66) 324 self.assertEqual(len(data.x), len(data.y)) 325 self.assertAlmostEqual(data.dy[10], 0.207214) 326 self.assertAlmostEqual(data.y[10], 24.1939) 327 self.assertAlmostEqual(data.x[10], 0.00898113) 290 self.assertTrue(isinstance(data, Data1D)) 291 self.assertTrue(len(data.x) == 66) 292 self.assertTrue(len(data.x) == len(data.y)) 293 self.assertTrue(data.dy[10] == 0.20721350111248701) 294 self.assertTrue(data.y[10] == 24.193889608153476) 295 self.assertTrue(data.x[10] == 0.008981127988654792) 328 296 329 297 def _check_2d_data(self, data): 330 298 self.assertTrue(isinstance(data, Data2D)) 331 self.assertEqual(len(data.q_data), 150*150) 332 self.assertEqual(len(data.q_data), len(data.data)) 333 self.assertAlmostEqual(data.err_data[10], 0.186723989418) 334 self.assertAlmostEqual(data.data[10], 0.465181) 335 self.assertAlmostEqual(data.qx_data[10], -0.129) 336 self.assertAlmostEqual(data.qy_data[10], -0.149) 299 self.assertTrue(len(data.x) == 66) 300 self.assertTrue(len(data.x) == len(data.y)) 301 self.assertTrue(data.dy[10] == 0.20721350111248701) 302 self.assertTrue(data.y[10] == 24.193889608153476) 303 self.assertTrue(data.x[10] == 0.008981127988654792) 337 304 338 305 def _check_example_data(self, data): 339 self.assert Equal(data.title,"")340 self.assert Equal(data.x.size,100)341 self.assert Equal(data._xunit,"A^{-1}")342 self.assert Equal(data._yunit,"cm^{-1}")343 self.assert Equal(data.y.size,100)306 self.assertTrue(data.title == "") 307 self.assertTrue(data.x.size == 100) 308 self.assertTrue(data._xunit == "A^{-1}") 309 self.assertTrue(data._yunit == "cm^{-1}") 310 self.assertTrue(data.y.size == 100) 344 311 self.assertAlmostEqual(data.y[40], 0.952749011516985) 345 312 self.assertAlmostEqual(data.x[40], 0.3834415188257777) -
test/sasdataloader/test/utest_generic_file_reader_class.py
rf4e2f22 r4a8d55c 45 45 last_f = f[0] 46 46 if hasattr(last_f, "errors"): 47 self.assertEqual (len(last_f.errors), 1)47 self.assertEquals(len(last_f.errors), 1) 48 48 else: 49 49 self.fail("Errors did not propogate to the file properly.") … … 51 51 def test_same_file_unknown_extensions(self): 52 52 # Five files, all with the same content, but different file extensions 53 no_ext = find("test_data " + os.sep + "TestExtensions")54 not_xml = find("test_data " + os.sep + "TestExtensions.notxml")53 no_ext = find("test_data//TestExtensions") 54 not_xml = find("test_data//TestExtensions.notxml") 55 55 # Deprecated extensions 56 asc_dep = find("test_data " + os.sep + "TestExtensions.asc")57 nxs_dep = find("test_data " + os.sep + "TestExtensions.nxs")56 asc_dep = find("test_data//TestExtensions.asc") 57 nxs_dep = find("test_data//TestExtensions.nxs") 58 58 # Native extension as a baseline 59 xml_native = find("test_data " + os.sep + "TestExtensions.xml")59 xml_native = find("test_data//TestExtensions.xml") 60 60 # Load the files and check contents 61 61 no_ext_load = self.generic_reader.load(no_ext) … … 70 70 self.check_unknown_extension(xml_load[0]) 71 71 # Be sure the deprecation warning is passed with the file 72 self.assertEqual (len(asc_load[0].errors), 1)73 self.assertEqual (len(nxs_load[0].errors), 1)72 self.assertEquals(len(asc_load[0].errors), 1) 73 self.assertEquals(len(nxs_load[0].errors), 1) 74 74 75 75 def check_unknown_extension(self, data): 76 76 self.assertTrue(isinstance(data, Data1D)) 77 self.assertEqual (len(data.x), 138)78 self.assertEqual (data.sample.ID, "TK49 c10_SANS")79 self.assertEqual (data.meta_data["loader"], "CanSAS XML 1D")77 self.assertEquals(len(data.x), 138) 78 self.assertEquals(data.sample.ID, "TK49 c10_SANS") 79 self.assertEquals(data.meta_data["loader"], "CanSAS XML 1D") 80 80 81 81 def tearDown(self): -
test/sasdataloader/test/utest_red2d_reader.py
rfc51d06 rf53d684 31 31 self.assertEqual(f.qx_data[0],-0.03573497) 32 32 self.assertEqual(f.qx_data[36863],0.2908819) 33 self.assertEqual(f.Q_unit, ' A^{-1}')34 self.assertEqual(f.I_unit, ' cm^{-1}')33 self.assertEqual(f.Q_unit, '1/A') 34 self.assertEqual(f.I_unit, '1/cm') 35 35 36 36 self.assertEqual(f.meta_data['loader'],"IGOR/DAT 2D Q_map") -
test/sasdataloader/test/utest_sesans.py
rf4e2f22 rf53d684 25 25 Test .SES in the full loader to make sure that the file type is correctly accepted 26 26 """ 27 file = Loader().load(find("sesans_examples" + os.sep + 28 "sphere2micron.ses")) 27 file = Loader().load(find("sesans_examples/sphere2micron.ses")) 29 28 f = file[0] 30 29 # self.assertEqual(f, 5) … … 45 44 Test .SES loading on a TOF dataset 46 45 """ 47 file = self.loader(find("sesans_examples " + os.sep + "sphere_isis.ses"))46 file = self.loader(find("sesans_examples/sphere_isis.ses")) 48 47 f = file[0] 49 48 self.assertEqual(len(file), 1) … … 63 62 FileContentsException, 64 63 self.loader, 65 find("sesans_examples " + os.sep + "sesans_no_data.ses"))64 find("sesans_examples/sesans_no_data.ses")) 66 65 67 66 def test_sesans_no_spin_echo_unit(self): … … 72 71 FileContentsException, 73 72 self.loader, 74 find("sesans_examples " + os.sep + "no_spin_echo_unit.ses"))73 find("sesans_examples/no_spin_echo_unit.ses")) 75 74 76 75 def test_sesans_future_version(self): … … 81 80 FileContentsException, 82 81 self.loader, 83 find("sesans_examples " + os.sep + "next_gen.ses"))82 find("sesans_examples/next_gen.ses")) 84 83 85 84 def test_sesans_mandatory_headers(self): … … 90 89 FileContentsException, 91 90 self.loader, 92 find("sesans_examples " + os.sep + "no_wavelength.ses"))91 find("sesans_examples/no_wavelength.ses")) 93 92 94 93 def test_sesans_columns_match_headers(self): … … 99 98 FileContentsException, 100 99 self.loader, 101 find("sesans_examples " + os.sep + "too_many_headers.ses"))100 find("sesans_examples/too_many_headers.ses")) 102 101 103 102 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.