Changeset 0d93464 in sasview
- Timestamp:
- Jul 26, 2017 4:24:49 PM (7 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:
- 9e0dd49
- Parents:
- bc04647
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rc94280c r0d93464 118 118 if value.attrs.get(u'canSAS_class') is not None: 119 119 class_name = value.attrs.get(u'canSAS_class') 120 elif value.attrs.get(u'NX_class') is not None: 121 class_name = value.attrs.get(u'NX_class') 120 122 else: 121 class_name = value.attrs.get(u'NX_class')123 class_name = key 122 124 if class_name is not None: 123 125 class_prog = re.compile(class_name) … … 144 146 unit = self._get_unit(value) 145 147 146 # I and Q Data147 if key == u'I':148 if isinstance(self.current_dataset, plottable_2D):149 self.current_dataset.data = data_set150 self.current_dataset.zaxis("Intensity", unit)151 else:152 self.current_dataset.y = data_set.flatten()153 self.current_dataset.yaxis("Intensity", unit)154 continue155 elif key == u'Idev':156 if isinstance(self.current_dataset, plottable_2D):157 self.current_dataset.err_data = data_set.flatten()158 else:159 self.current_dataset.dy = data_set.flatten()160 continue161 elif key == u'Q':162 self.current_dataset.xaxis("Q", unit)163 if isinstance(self.current_dataset, plottable_2D):164 self.current_dataset.q = data_set.flatten()165 else:166 self.current_dataset.x = data_set.flatten()167 continue168 elif key == u'Qdev':169 self.current_dataset.dx = data_set.flatten()170 continue171 elif key == u'dQw':172 self.current_dataset.dxw = data_set.flatten()173 continue174 elif key == u'dQl':175 self.current_dataset.dxl = data_set.flatten()176 continue177 elif key == u'Qy':178 self.current_dataset.yaxis("Q_y", unit)179 self.current_dataset.qy_data = data_set.flatten()180 continue181 elif key == u'Qydev':182 self.current_dataset.dqy_data = data_set.flatten()183 continue184 elif key == u'Qx':185 self.current_dataset.xaxis("Q_x", unit)186 self.current_dataset.qx_data = data_set.flatten()187 continue188 elif key == u'Qxdev':189 self.current_dataset.dqx_data = data_set.flatten()190 continue191 elif key == u'Mask':192 self.current_dataset.mask = data_set.flatten()193 continue194 # Transmission Spectrum195 elif (key == u'T'196 and self.parent_class == u'SAStransmission_spectrum'):197 self.trans_spectrum.transmission = data_set.flatten()198 continue199 elif (key == u'Tdev'200 and self.parent_class == u'SAStransmission_spectrum'):201 self.trans_spectrum.transmission_deviation = \202 data_set.flatten()203 continue204 elif (key == u'lambda'205 and self.parent_class == u'SAStransmission_spectrum'):206 self.trans_spectrum.wavelength = data_set.flatten()207 continue208 209 148 for data_point in data_set: 210 149 # Top Level Meta Data 211 150 if key == u'definition': 212 151 self.current_datainfo.meta_data['reader'] = data_point 152 # Run 213 153 elif key == u'run': 214 154 self.current_datainfo.run.append(data_point) … … 219 159 except: 220 160 pass 161 # Title 221 162 elif key == u'title': 222 163 self.current_datainfo.title = data_point 164 # Note 223 165 elif key == u'SASnote': 224 166 self.current_datainfo.notes.append(data_point) 225 226 167 # Sample Information 227 # CanSAS 2.0 format 228 elif key == u'Title' and self.parent_class == u'SASsample': 229 self.current_datainfo.sample.name = data_point 230 # NXcanSAS format 231 elif key == u'name' and self.parent_class == u'SASsample': 232 self.current_datainfo.sample.name = data_point 233 # NXcanSAS format 234 elif key == u'ID' and self.parent_class == u'SASsample': 235 self.current_datainfo.sample.name = data_point 236 elif (key == u'thickness' 237 and self.parent_class == u'SASsample'): 238 self.current_datainfo.sample.thickness = data_point 239 elif (key == u'temperature' 240 and self.parent_class == u'SASsample'): 241 self.current_datainfo.sample.temperature = data_point 242 elif (key == u'transmission' 243 and self.parent_class == u'SASsample'): 244 self.current_datainfo.sample.transmission = data_point 245 elif (key == u'x_position' 246 and self.parent_class == u'SASsample'): 247 self.current_datainfo.sample.position.x = data_point 248 elif (key == u'y_position' 249 and self.parent_class == u'SASsample'): 250 self.current_datainfo.sample.position.y = data_point 251 elif key == u'pitch' and self.parent_class == u'SASsample': 252 self.current_datainfo.sample.orientation.x = data_point 253 elif key == u'yaw' and self.parent_class == u'SASsample': 254 self.current_datainfo.sample.orientation.y = data_point 255 elif key == u'roll' and self.parent_class == u'SASsample': 256 self.current_datainfo.sample.orientation.z = data_point 257 elif (key == u'details' 258 and self.parent_class == u'SASsample'): 259 self.current_datainfo.sample.details.append(data_point) 260 168 elif self.parent_class == u'SASsample': 169 self.process_sample(data_point, key) 261 170 # Instrumental Information 262 171 elif (key == u'name' 263 172 and self.parent_class == u'SASinstrument'): 264 173 self.current_datainfo.instrument = data_point 265 elif key == u'name' and self.parent_class == u'SASdetector': 266 self.detector.name = data_point 267 elif key == u'SDD' and self.parent_class == u'SASdetector': 268 self.detector.distance = float(data_point) 269 self.detector.distance_unit = unit 270 elif (key == u'slit_length' 271 and self.parent_class == u'SASdetector'): 272 self.detector.slit_length = float(data_point) 273 self.detector.slit_length_unit = unit 274 elif (key == u'x_position' 275 and self.parent_class == u'SASdetector'): 276 self.detector.offset.x = float(data_point) 277 self.detector.offset_unit = unit 278 elif (key == u'y_position' 279 and self.parent_class == u'SASdetector'): 280 self.detector.offset.y = float(data_point) 281 self.detector.offset_unit = unit 282 elif (key == u'pitch' 283 and self.parent_class == u'SASdetector'): 284 self.detector.orientation.x = float(data_point) 285 self.detector.orientation_unit = unit 286 elif key == u'roll' and self.parent_class == u'SASdetector': 287 self.detector.orientation.z = float(data_point) 288 self.detector.orientation_unit = unit 289 elif key == u'yaw' and self.parent_class == u'SASdetector': 290 self.detector.orientation.y = float(data_point) 291 self.detector.orientation_unit = unit 292 elif (key == u'beam_center_x' 293 and self.parent_class == u'SASdetector'): 294 self.detector.beam_center.x = float(data_point) 295 self.detector.beam_center_unit = unit 296 elif (key == u'beam_center_y' 297 and self.parent_class == u'SASdetector'): 298 self.detector.beam_center.y = float(data_point) 299 self.detector.beam_center_unit = unit 300 elif (key == u'x_pixel_size' 301 and self.parent_class == u'SASdetector'): 302 self.detector.pixel_size.x = float(data_point) 303 self.detector.pixel_size_unit = unit 304 elif (key == u'y_pixel_size' 305 and self.parent_class == u'SASdetector'): 306 self.detector.pixel_size.y = float(data_point) 307 self.detector.pixel_size_unit = unit 308 elif (key == u'distance' 309 and self.parent_class == u'SAScollimation'): 310 self.collimation.length = data_point 311 self.collimation.length_unit = unit 312 elif (key == u'name' 313 and self.parent_class == u'SAScollimation'): 314 self.collimation.name = data_point 315 elif (key == u'shape' 316 and self.parent_class == u'SASaperture'): 317 self.aperture.shape = data_point 318 elif (key == u'x_gap' 319 and self.parent_class == u'SASaperture'): 320 self.aperture.size.x = data_point 321 elif (key == u'y_gap' 322 and self.parent_class == u'SASaperture'): 323 self.aperture.size.y = data_point 324 174 # Detector 175 elif self.parent_class == u'SASdetector': 176 self.process_detector(data_point, key, unit) 177 # Collimation 178 elif self.parent_class == u'SAScollimation': 179 self.process_collimation(data_point, key, unit) 180 # Aperture 181 elif self.parent_class == u'SASaperture': 182 self.process_aperture(data_point, key) 325 183 # Process Information 326 elif (key == u'Title' 327 and self.parent_class == u'SASprocess'): # CanSAS 2.0 328 self.process.name = data_point 329 elif (key == u'name' 330 and self.parent_class == u'SASprocess'): # NXcanSAS 331 self.process.name = data_point 332 elif (key == u'description' 333 and self.parent_class == u'SASprocess'): 334 self.process.description = data_point 335 elif key == u'date' and self.parent_class == u'SASprocess': 336 self.process.date = data_point 337 elif key == u'term' and self.parent_class == u'SASprocess': 338 self.process.term = data_point 339 elif self.parent_class == u'SASprocess': 340 self.process.notes.append(data_point) 341 184 elif self.parent_class == u'SASprocess': # CanSAS 2.0 185 self.process_process(data_point, key) 342 186 # Source 343 elif (key == u'wavelength' 344 and self.parent_class == u'SASdata'): 345 self.current_datainfo.source.wavelength = data_point 346 self.current_datainfo.source.wavelength_unit = unit 347 elif (key == u'incident_wavelength' 348 and self.parent_class == 'SASsource'): 349 self.current_datainfo.source.wavelength = data_point 350 self.current_datainfo.source.wavelength_unit = unit 351 elif (key == u'wavelength_max' 352 and self.parent_class == u'SASsource'): 353 self.current_datainfo.source.wavelength_max = data_point 354 self.current_datainfo.source.wavelength_max_unit = unit 355 elif (key == u'wavelength_min' 356 and self.parent_class == u'SASsource'): 357 self.current_datainfo.source.wavelength_min = data_point 358 self.current_datainfo.source.wavelength_min_unit = unit 359 elif (key == u'incident_wavelength_spread' 360 and self.parent_class == u'SASsource'): 361 self.current_datainfo.source.wavelength_spread = \ 362 data_point 363 self.current_datainfo.source.wavelength_spread_unit = \ 364 unit 365 elif (key == u'beam_size_x' 366 and self.parent_class == u'SASsource'): 367 self.current_datainfo.source.beam_size.x = data_point 368 self.current_datainfo.source.beam_size_unit = unit 369 elif (key == u'beam_size_y' 370 and self.parent_class == u'SASsource'): 371 self.current_datainfo.source.beam_size.y = data_point 372 self.current_datainfo.source.beam_size_unit = unit 373 elif (key == u'beam_shape' 374 and self.parent_class == u'SASsource'): 375 self.current_datainfo.source.beam_shape = data_point 376 elif (key == u'radiation' 377 and self.parent_class == u'SASsource'): 378 self.current_datainfo.source.radiation = data_point 379 elif (key == u'transmission' 380 and self.parent_class == u'SASdata'): 381 self.current_datainfo.sample.transmission = data_point 382 187 elif self.parent_class == u'SASsource': 188 self.process_source(data_point, key, unit) 383 189 # Everything else goes in meta_data 190 elif self.parent_class == u'SASdata': 191 self.process_data_object(data_set, key, unit) 192 break 193 elif self.parent_class == u'SAStransmission_spectrum': 194 self.process_trans_spectrum(data_set, key) 195 break 384 196 else: 385 197 new_key = self._create_unique_key( … … 390 202 # I don't know if this reachable code 391 203 self.errors.add("ShouldNeverHappenException") 204 205 def process_data_object(self, data_set, key, unit): 206 """ 207 SASdata processor method 208 :param data_set: data from HDF5 file 209 :param key: canSAS_class attribute 210 :param unit: unit attribute 211 """ 212 # FIXME: check attributes of SASdata for Q, dQ, Mask, etc. 213 if key == u'I': 214 if isinstance(self.current_dataset, plottable_2D): 215 self.current_dataset.data = data_set 216 self.current_dataset.zaxis("Intensity", unit) 217 else: 218 self.current_dataset.y = data_set.flatten() 219 self.current_dataset.yaxis("Intensity", unit) 220 elif key == u'Idev': 221 if isinstance(self.current_dataset, plottable_2D): 222 self.current_dataset.err_data = data_set.flatten() 223 else: 224 self.current_dataset.dy = data_set.flatten() 225 elif key == u'Q': 226 self.current_dataset.xaxis("Q", unit) 227 if isinstance(self.current_dataset, plottable_2D): 228 self.current_dataset.q = data_set.flatten() 229 else: 230 self.current_dataset.x = data_set.flatten() 231 elif key == u'Qdev': 232 self.current_dataset.dx = data_set.flatten() 233 elif key == u'dQw': 234 self.current_dataset.dxw = data_set.flatten() 235 elif key == u'dQl': 236 self.current_dataset.dxl = data_set.flatten() 237 elif key == u'Qy': 238 self.current_dataset.yaxis("Q_y", unit) 239 self.current_dataset.qy_data = data_set.flatten() 240 elif key == u'Qydev': 241 self.current_dataset.dqy_data = data_set.flatten() 242 elif key == u'Qx': 243 self.current_dataset.xaxis("Q_x", unit) 244 self.current_dataset.qx_data = data_set.flatten() 245 elif key == u'Qxdev': 246 self.current_dataset.dqx_data = data_set.flatten() 247 elif key == u'Mask': 248 self.current_dataset.mask = data_set.flatten() 249 elif key == u'wavelength': 250 self.current_datainfo.source.wavelength = data_set[0] 251 self.current_datainfo.source.wavelength_unit = unit 252 253 def process_trans_spectrum(self, data_set, key): 254 """ 255 SAStransmission_spectrum processor 256 :param data_set: data from HDF5 file 257 :param key: canSAS_class attribute 258 """ 259 if key == u'T': 260 self.trans_spectrum.transmission = data_set.flatten() 261 elif key == u'Tdev': 262 self.trans_spectrum.transmission_deviation = data_set.flatten() 263 elif key == u'lambda': 264 self.trans_spectrum.wavelength = data_set.flatten() 265 266 def process_sample(self, data_point, key): 267 """ 268 SASsample processor 269 :param data_point: Single point from an HDF5 data file 270 :param key: class name data_point was taken from 271 """ 272 if key == u'Title': 273 self.current_datainfo.sample.name = data_point 274 elif key == u'name': 275 self.current_datainfo.sample.name = data_point 276 elif key == u'ID': 277 self.current_datainfo.sample.name = data_point 278 elif key == u'thickness': 279 self.current_datainfo.sample.thickness = data_point 280 elif key == u'temperature': 281 self.current_datainfo.sample.temperature = data_point 282 elif key == u'transmission': 283 self.current_datainfo.sample.transmission = data_point 284 elif key == u'x_position': 285 self.current_datainfo.sample.position.x = data_point 286 elif key == u'y_position': 287 self.current_datainfo.sample.position.y = data_point 288 elif key == u'pitch': 289 self.current_datainfo.sample.orientation.x = data_point 290 elif key == u'yaw': 291 self.current_datainfo.sample.orientation.y = data_point 292 elif key == u'roll': 293 self.current_datainfo.sample.orientation.z = data_point 294 elif key == u'details': 295 self.current_datainfo.sample.details.append(data_point) 296 297 def process_detector(self, data_point, key, unit): 298 """ 299 SASdetector processor 300 :param data_point: Single point from an HDF5 data file 301 :param key: class name data_point was taken from 302 :param unit: unit attribute from data set 303 """ 304 if key == u'name': 305 self.detector.name = data_point 306 elif key == u'SDD': 307 self.detector.distance = float(data_point) 308 self.detector.distance_unit = unit 309 elif key == u'slit_length': 310 self.detector.slit_length = float(data_point) 311 self.detector.slit_length_unit = unit 312 elif key == u'x_position': 313 self.detector.offset.x = float(data_point) 314 self.detector.offset_unit = unit 315 elif key == u'y_position': 316 self.detector.offset.y = float(data_point) 317 self.detector.offset_unit = unit 318 elif key == u'pitch': 319 self.detector.orientation.x = float(data_point) 320 self.detector.orientation_unit = unit 321 elif key == u'roll': 322 self.detector.orientation.z = float(data_point) 323 self.detector.orientation_unit = unit 324 elif key == u'yaw': 325 self.detector.orientation.y = float(data_point) 326 self.detector.orientation_unit = unit 327 elif key == u'beam_center_x': 328 self.detector.beam_center.x = float(data_point) 329 self.detector.beam_center_unit = unit 330 elif key == u'beam_center_y': 331 self.detector.beam_center.y = float(data_point) 332 self.detector.beam_center_unit = unit 333 elif key == u'x_pixel_size': 334 self.detector.pixel_size.x = float(data_point) 335 self.detector.pixel_size_unit = unit 336 elif key == u'y_pixel_size': 337 self.detector.pixel_size.y = float(data_point) 338 self.detector.pixel_size_unit = unit 339 340 def process_collimation(self, data_point, key, unit): 341 """ 342 SAScollimation processor 343 :param data_point: Single point from an HDF5 data file 344 :param key: class name data_point was taken from 345 :param unit: unit attribute from data set 346 """ 347 if key == u'distance': 348 self.collimation.length = data_point 349 self.collimation.length_unit = unit 350 elif key == u'name': 351 self.collimation.name = data_point 352 353 def process_aperture(self, data_point, key): 354 """ 355 SASaperture processor 356 :param data_point: Single point from an HDF5 data file 357 :param key: class name data_point was taken from 358 """ 359 if key == u'shape': 360 self.aperture.shape = data_point 361 elif key == u'x_gap': 362 self.aperture.size.x = data_point 363 elif key == u'y_gap': 364 self.aperture.size.y = data_point 365 366 def process_source(self, data_point, key, unit): 367 """ 368 SASsource processor 369 :param data_point: Single point from an HDF5 data file 370 :param key: class name data_point was taken from 371 :param unit: unit attribute from data set 372 """ 373 if key == u'incident_wavelength': 374 self.current_datainfo.source.wavelength = data_point 375 self.current_datainfo.source.wavelength_unit = unit 376 elif key == u'wavelength_max': 377 self.current_datainfo.source.wavelength_max = data_point 378 self.current_datainfo.source.wavelength_max_unit = unit 379 elif key == u'wavelength_min': 380 self.current_datainfo.source.wavelength_min = data_point 381 self.current_datainfo.source.wavelength_min_unit = unit 382 elif key == u'incident_wavelength_spread': 383 self.current_datainfo.source.wavelength_spread = data_point 384 self.current_datainfo.source.wavelength_spread_unit = unit 385 elif key == u'beam_size_x': 386 self.current_datainfo.source.beam_size.x = data_point 387 self.current_datainfo.source.beam_size_unit = unit 388 elif key == u'beam_size_y': 389 self.current_datainfo.source.beam_size.y = data_point 390 self.current_datainfo.source.beam_size_unit = unit 391 elif key == u'beam_shape': 392 self.current_datainfo.source.beam_shape = data_point 393 elif key == u'radiation': 394 self.current_datainfo.source.radiation = data_point 395 396 def process_process(self, data_point, key): 397 """ 398 SASprocess processor 399 :param data_point: Single point from an HDF5 data file 400 :param key: class name data_point was taken from 401 """ 402 if key == u'Title': # CanSAS 2.0 403 self.process.name = data_point 404 elif key == u'name': # NXcanSAS 405 self.process.name = data_point 406 elif key == u'description': 407 self.process.description = data_point 408 elif key == u'date': 409 self.process.date = data_point 410 elif key == u'term': 411 self.process.term = data_point 412 else: 413 self.process.notes.append(data_point) 392 414 393 415 def add_intermediate(self):
Note: See TracChangeset
for help on using the changeset viewer.