Changeset 65e61c1 in sasview for src/sas/sascalc/dataloader/readers
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
ra2573fc r65e61c1 195 195 """ 196 196 197 if not self._is_call_local() and not recurse: 198 self.reset_state() 199 self.add_data_set() 200 self.names.append("SASentry") 201 self.parent_class = "SASentry" 197 self.reset_state() 202 198 self._check_for_empty_data() 199 self._initialize_new_data_set(dom) 200 self.add_data_set() 201 202 self.names.append("SASentry") 203 self.parent_class = "SASentry" 204 203 205 self.base_ns = "{0}{1}{2}".format("{", \ 204 206 CANSAS_NS.get(self.cansas_version).get("ns"), "}") 205 207 208 self.ns_list = CONSTANTS.iterate_namespace(self.names) 209 206 210 # Go through each child in the parent element 207 for node in dom: 208 attr = node.attrib 209 name = attr.get("name", "") 210 type = attr.get("type", "") 211 unit = attr.get("unit", "") 212 # Get the element name and set the current names level 213 tagname = node.tag.replace(self.base_ns, "") 214 tagname_original = tagname 215 # Skip this iteration when loading in save state information 216 if tagname == "fitting_plug_in" or tagname == "pr_inversion" or tagname == "invariant": 211 for sasNode in dom: 212 # Add a new data home 213 # self.add_data_set() 214 # Get the element name and set the current name's level 215 currentTagName = sasNode.tag.replace(self.base_ns, "") 216 # As this is the most likely tag to examine, lets put it first! 217 if currentTagName == "SASdata": 218 # Are there multiple entries here? 219 if len(sasNode) <= 1: 220 multipleEntries = False 221 else: 222 multipleEntries = True 223 224 for setupNode in sasNode[0]: 225 # Iterating through the tags in the unit node, getting their tag name and respective unit 226 setupTagName = setupNode.tag.replace(self.base_ns, "") 227 units = setupNode.attrib.get("unit", "") 228 229 # Creating our data array first, if there's only one dataNode we will handle this... 230 startArray = np.fromstring(setupNode.text, dtype=float, sep=",") 231 232 if multipleEntries == True: 233 setupArray = np.zeros((len(sasNode), len(startArray))) 234 setupArray[0] = startArray 235 else: 236 setupArray = startArray 237 238 # Now put this into the relevant location 239 if setupTagName == "I": 240 self.current_dataset.yaxis("Intensity", units) 241 self.current_dataset.y = setupArray 242 elif setupTagName == "Q": 243 self.current_dataset.xaxis("Q", units) 244 self.current_dataset.x = setupArray 245 246 elif setupTagName == "Idev": 247 self.current_dataset.dy = setupArray 248 elif setupTagName == "Qdev": 249 self.current_dataset.err_data = setupArray 250 251 elif setupTagName == "Qx": 252 self.current_dataset.xaxis("Qx", units) 253 self.current_dataset.qx_data = setupArray 254 elif setupTagName == "Qy": 255 self.current_dataset.yaxis("Qy", units) 256 self.current_dataset.qy_data = setupArray 257 elif setupTagName == "Qxdev": 258 self.current_dataset.xaxis("Qxdev", units) 259 self.current_dataset.dqx_data = setupArray 260 elif setupTagName == "Qydev": 261 self.current_dataset.yaxis("Qydev", units) 262 self.current_dataset.dqy_data = setupArray 263 elif setupTagName == "dQw": 264 self.current_dataset.dxw = setupArray 265 elif setupTagName == "dQl": 266 self.current_dataset.dxl = setupArray 267 268 elif setupTagName == "Mask": 269 self.current_dataset.mask = np.ndarray.astype(setupArray, dtype=bool) 270 elif setupTagName == "Sesans": 271 self.current_datainfo.isSesans = bool(setupNode.text) 272 273 elif setupTagName == "zacceptance": 274 self.current_datainfo.sample.zacceptance = (setupNode.text, units) 275 elif setupTagName == "Qmean": 276 pass 277 elif setupTagName == "Shadowfactor": 278 pass 279 280 # If there's more data present, let's deal with that too 281 for loopIter in range(1, len(sasNode)): 282 for dataNode in sasNode[loopIter]: 283 # Iterating through the tags in the unit node, getting their tag name and respective unit 284 dataTagName = dataNode.tag.replace(self.base_ns, "") 285 # Creating our data array first 286 dataArray = np.fromstring(dataNode.text, dtype=float, sep=",") 287 288 if dataTagName == "I": 289 self.current_dataset.y[loopIter] = dataArray 290 elif dataTagName == "Q": 291 self.current_dataset.x[loopIter] = dataArray 292 elif dataTagName == "Idev": 293 self.current_dataset.dy[loopIter] = dataArray 294 elif dataTagName == "Qdev": 295 self.current_dataset.err_data[loopIter] = dataArray 296 elif dataTagName == "Qx": 297 self.current_dataset.qx_data[loopIter] = dataArray 298 elif dataTagName == "Qy": 299 self.current_dataset.qy_data[loopIter] = dataArray 300 elif dataTagName == "Qxdev": 301 self.current_dataset.dqx_data[loopIter] = dataArray 302 elif dataTagName == "Qydev": 303 self.current_dataset.dqy_data[loopIter] = dataArray 304 elif dataTagName == "dQw": 305 self.current_dataset.dxw[loopIter] = dataArray 306 elif dataTagName == "dQl": 307 self.current_dataset.dxl[loopIter] = dataArray 308 309 if len(dataArray) == 1: 310 self.current_dataset.x = self.current_dataset.x.reshape(len(sasNode)) 311 self.current_dataset.y = self.current_dataset.y.reshape(len(sasNode)) 312 self.current_dataset.err_data = self.current_dataset.err_data.reshape(len(sasNode)) 313 self.current_dataset.dy = self.current_dataset.dy.reshape(len(sasNode)) 314 315 316 self.add_intermediate() 317 318 # If it's not data, let's check for other tags starting with skippable ones... 319 elif currentTagName == "fitting_plug_in" or currentTagName == "pr_inversion" or currentTagName == "invariant": 217 320 continue 218 321 219 # Get where to store content 220 self.names.append(tagname_original) 221 self.ns_list = CONSTANTS.iterate_namespace(self.names) 222 # If the element is a child element, recurse 223 if len(node.getchildren()) > 0: 224 self.parent_class = tagname_original 225 if tagname == 'SASdata': 226 self._initialize_new_data_set(node) 227 if isinstance(self.current_dataset, plottable_2D): 228 x_bins = attr.get("x_bins", "") 229 y_bins = attr.get("y_bins", "") 230 if x_bins is not "" and y_bins is not "": 231 self.current_dataset.shape = (x_bins, y_bins) 232 else: 233 self.current_dataset.shape = () 234 # Recursion step to access data within the group 235 self._parse_entry(node, True) 236 if tagname == "SASsample": 237 self.current_datainfo.sample.name = name 238 elif tagname == "beam_size": 239 self.current_datainfo.source.beam_size_name = name 240 elif tagname == "SAScollimation": 241 self.collimation.name = name 242 elif tagname == "aperture": 243 self.aperture.name = name 244 self.aperture.type = type 245 self.add_intermediate() 322 # If we'e dealing with a title node then extract the text of the node and put it in the right place 323 elif currentTagName == "Title": 324 self.current_datainfo.title = sasNode.text 325 326 327 # If we'e dealing with a run node then extract the name and text of the node and put it in the right place 328 elif currentTagName == "Run": 329 self.current_datainfo.run_name[sasNode.text] = sasNode.attrib.get("name", "") 330 self.current_datainfo.run.append(sasNode.text) 331 332 # If we'e dealing with a sample node 333 elif currentTagName == "SASsample": 334 for sampleNode in sasNode: 335 # Get the variables 336 sampleTagName = sampleNode.tag.replace(self.base_ns, "") 337 sampleUnits = sampleNode.attrib.get("unit", "") 338 sampleData = sampleNode.text 339 340 # Populate it via if switching 341 if sampleTagName == "ID": 342 self.current_datainfo.sample.ID = sampleData 343 elif sampleTagName == "Title": 344 self.current_datainfo.sample.name = sampleData 345 elif sampleTagName == "thickness": 346 self.current_datainfo.sample.thickness = sampleData 347 self.current_datainfo.sample.thickness_unit = sampleUnits 348 elif sampleTagName == "transmission": 349 self.current_datainfo.sample.transmission = sampleData 350 elif sampleTagName == "temperature": 351 self.current_datainfo.sample.temperature = sampleData 352 self.current_datainfo.sample.temperature_unit = sampleUnits 353 elif sampleTagName == "details": 354 self.current_datainfo.sample.details.append(sampleData) 355 356 # Extract the positional data 357 elif sampleTagName == "position": 358 for positionNode in sampleNode: 359 positionTagName = positionNode.tag.replace(self.base_ns, "") 360 positionUnits = positionNode.attrib.get("unit", "") 361 positionData = positionNode.text 362 363 # Extract specific tags 364 if positionTagName == "x": 365 self.current_datainfo.sample.position.x = positionData 366 self.current_datainfo.sample.position_unit = positionUnits 367 elif positionTagName == "y": 368 self.current_datainfo.sample.position.y = positionData 369 self.current_datainfo.sample.position_unit = positionUnits 370 elif positionTagName == "z": 371 self.current_datainfo.sample.position.z = positionData 372 self.current_datainfo.sample.position_unit = positionUnits 373 374 # Extract the orientation data 375 elif sampleTagName == "orientation": 376 for orientationNode in sampleNode: 377 orientationTagName = orientationNode.tag.replace(self.base_ns, "") 378 orientationUnits = orientationNode.attrib.get("unit", "") 379 orientationData = orientationNode.text 380 381 # Extract specific tags 382 if orientationTagName == "roll": 383 self.current_datainfo.sample.orientation.x = orientationData 384 self.current_datainfo.sample.orientation_unit = orientationUnits 385 elif orientationTagName == "pitch": 386 self.current_datainfo.sample.orientation.y = orientationData 387 self.current_datainfo.sample.orientation_unit = orientationUnits 388 elif orientationTagName == "yaw": 389 self.current_datainfo.sample.orientation.z = orientationData 390 self.current_datainfo.sample.orientation_unit = orientationUnits 391 392 # If we're dealing with an instrument node 393 elif currentTagName == "SASinstrument": 394 for instrumentNode in sasNode: 395 instrumentTagName = instrumentNode.tag.replace(self.base_ns, "") 396 instrumentUnits = instrumentNode.attrib.get("unit", "") 397 instrumentData = instrumentNode.text 398 399 # Extract the source name 400 if instrumentTagName == "SASsource": 401 self.name = instrumentNode.attrib.get("name", "") 402 403 for sourceNode in instrumentNode: 404 sourceTagName = sourceNode.tag.replace(self.base_ns, "") 405 sourceUnits = sourceNode.attrib.get("unit", "") 406 sourceData = sourceNode.text 407 408 ## Source Information 409 if sourceTagName == "wavelength": 410 self.current_datainfo.source.wavelength = sourceData 411 self.current_datainfo.source.wavelength_unit = sourceUnits 412 elif sourceTagName == "wavelength_min": 413 self.current_datainfo.source.wavelength_min = sourceData 414 self.current_datainfo.source.wavelength_min_unit = sourceUnits 415 elif sourceTagName == "wavelength_max": 416 self.current_datainfo.source.wavelength_max = sourceData 417 self.current_datainfo.source.wavelength_max_unit = sourceUnits 418 elif sourceTagName == "wavelength_spread": 419 self.current_datainfo.source.wavelength_spread = sourceData 420 self.current_datainfo.source.wavelength_spread_unit = sourceUnits 421 elif sourceTagName == "radiation": 422 self.current_datainfo.source.radiation = sourceData 423 elif sourceTagName == "beam_shape": 424 self.current_datainfo.source.beam_shape = sourceData 425 426 elif sourceTagName == "beam_size": 427 for beamNode in sourceNode: 428 beamTagName = beamNode.tag.replace(self.base_ns, "") 429 beamUnits = beamNode.attrib.get("unit", "") 430 beamData = beamNode.text 431 432 if beamTagName == "x" and self.parent_class == "beam_size": 433 self.current_datainfo.source.beam_size.x = beamData 434 self.current_datainfo.source.beam_size_unit = beamUnits 435 elif beamTagName == "y" and self.parent_class == "beam_size": 436 self.current_datainfo.source.beam_size.y = beamData 437 self.current_datainfo.source.beam_size_unit = beamUnits 438 439 elif sourceTagName == "pixel_size": 440 for pixelNode in sourceNode: 441 pixelTagName = pixelNode.tag.replace(self.base_ns, "") 442 pixelUnits = pixelNode.attrib.get("unit", "") 443 pixelData = pixelNode.text 444 445 if pixelTagName == "z": 446 self.current_datainfo.source.data_point.z = pixelData 447 self.current_datainfo.source.beam_size_unit = pixelUnits 448 449 # Extract the collimation 450 elif instrumentTagName == "SAScollimation": 451 self.collimation.name = instrumentNode.attrib.get("name", "") 452 453 for collimationNode in instrumentNode: 454 collimationTagName = pixelNode.tag.replace(self.base_ns, "") 455 collimationUnits = pixelNode.attrib.get("unit", "") 456 collimationData = pixelNode.text 457 458 if collimationTagName == "length": 459 self.collimation.length = collimationData 460 self.collimation.length_unit = collimationUnits 461 elif collimationTagName == "name": 462 self.collimation.name = collimationData 463 464 if collimationTagName == "aperture": 465 for apertureNode in collimationNode: 466 apertureTagName = apertureNode.tag.replace(self.base_ns, "") 467 apertureUnits = apertureNode.attrib.get("unit", "") 468 apertureData = apertureNode.text 469 470 if tagname == "distance": 471 self.aperture.distance = apertureData 472 self.aperture.distance_unit = apertureUnits 473 474 if collimationTagName == "size": 475 for sizeNode in collimationNode: 476 sizeTagName = sizeNode.tag.replace(self.base_ns, "") 477 sizeUnits = sizeNode.attrib.get("unit", "") 478 sizeData = sizeNode.text 479 480 if tagname == "x": 481 self.aperture.size.x = sizeData 482 self.collimation.size_unit = sizeUnits 483 elif tagname == "y": 484 self.aperture.size.y = sizeData 485 self.collimation.size_unit = sizeUnits 486 elif tagname == "z": 487 self.aperture.size.z = sizeData 488 self.collimation.size_unit = sizeUnits 489 490 # Extract the detector 491 elif instrumentTagName == "SASdetector": 492 self.name = instrumentNode.attrib.get("name", "") 493 494 for detectorNode in instrumentNode: 495 detectorTagName = detectorNode.tag.replace(self.base_ns, "") 496 detectorUnits = detectorNode.attrib.get("unit", "") 497 detectorData = detectorNode.text 498 499 if detectorTagName == "name": 500 self.detector.name = detectorData 501 elif detectorTagName == "SDD": 502 self.detector.distance = detectorData 503 self.detector.distance_unit = detectorUnits 504 elif detectorTagName == "slit_length": 505 self.detector.slit_length = detectorData 506 self.detector.slit_length_unit = detectorUnits 507 508 elif detectorTagName == "offset": 509 for offsetNode in detectorNode: 510 offsetTagName = offsetNode.tag.replace(self.base_ns, "") 511 offsetUnits = offsetNode.attrib.get("unit", "") 512 offsetData = offsetNode.text 513 514 if offsetTagName == "x": 515 self.detector.offset.x = offsetData 516 self.detector.offset_unit = offsetUnits 517 elif offsetTagName == "y": 518 self.detector.offset.y = offsetData 519 self.detector.offset_unit = offsetUnits 520 elif offsetTagName == "z": 521 self.detector.offset.z = offsetData 522 self.detector.offset_unit = offsetUnits 523 524 elif detectorTagName == "beam_center": 525 for beamCenterNode in detectorNode: 526 beamCenterTagName = beamCenterNode.tag.replace(self.base_ns, "") 527 beamCenterUnits = beamCenterNode.attrib.get("unit", "") 528 beamCenterData = beamCenterNode.text 529 530 if beamCenterTagName == "x": 531 self.detector.beam_center.x = beamCenterData 532 self.detector.beam_center_unit = beamCenterUnits 533 elif beamCenterTagName == "y": 534 self.detector.beam_center.y = beamCenterData 535 self.detector.beam_center_unit = beamCenterUnits 536 elif beamCenterTagName == "z": 537 self.detector.beam_center.z = beamCenterData 538 self.detector.beam_center_unit = beamCenterUnits 539 540 elif detectorTagName == "pixel_size": 541 for pixelSizeNode in detectorNode: 542 pixelSizeTagName = pixelSizeNode.tag.replace(self.base_ns, "") 543 pixelSizeUnits = pixelSizeNode.attrib.get("unit", "") 544 pixelSizeData = pixelSizeNode.text 545 546 if pixelSizeTagName == "x": 547 self.detector.pixel_size.x = pixelSizeData 548 self.detector.pixel_size_unit = pixelSizeUnits 549 elif pixelSizeTagName == "y": 550 self.detector.pixel_size.y = pixelSizeData 551 self.detector.pixel_size_unit = pixelSizeUnits 552 elif pixelSizeTagName == "z": 553 self.detector.pixel_size.z = pixelSizeData 554 self.detector.pixel_size_unit = pixelSizeUnits 555 556 elif detectorTagName == "orientation": 557 for orientationNode in detectorNode: 558 orientationTagName = orientationNode.tag.replace(self.base_ns, "") 559 orientationUnits = orientationNode.attrib.get("unit", "") 560 orientationData = orientationNode.text 561 562 if orientationTagName == "roll": 563 self.detector.orientation.x = orientationData 564 self.detector.orientation_unit = orientationUnits 565 elif orientationTagName == "pitch": 566 self.detector.orientation.y = orientationData 567 self.detector.orientation_unit = orientationUnits 568 elif orientationTagName == "yaw": 569 self.detector.orientation.z = orientationData 570 self.detector.orientation_unit = orientationUnits 571 572 ## If we'e dealing with a process node 573 elif currentTagName == "SASprocess": 574 for processNode in sasNode: 575 setupTagName = setupNode.tag.replace(self.base_ns, "") 576 units = setupNode.attrib.get("unit", "") 577 578 if processTagName == "name": 579 self.process.name = processNode.text 580 elif processTagName == "description": 581 self.process.description = processNode.text 582 elif processTagName == "date": 583 try: 584 self.process.date = datetime.datetime.fromtimestamp(processNode.text) 585 except: 586 self.process.date = processNode.text 587 elif processTagName == "term": 588 unit = attr.get("unit", "") 589 dic = {} 590 dic["name"] = processNode.attrib.get("name", "") 591 dic["value"] = processNode.text 592 dic["unit"] = processNode.attrib.get("unit", "") 593 self.process.term.append(dic) 594 595 # If we're dealing with a process note node 596 elif currentTagName == "SASprocessnote": 597 for processNoteNode in sasNode: 598 self.process.notes.append(processNoteNode.text) 599 600 # If we're dealing with a sas note node 601 elif currentTagName == "SASnote": 602 for noteNode in sasNode: 603 print '1' 604 self.current_datainfo.notes.append(noteNode.text) 605 606 # If we're dealing with a transmission data node 607 elif currentTagName == "Tdata": 608 for transmissionDataNode in sasNode: 609 transmissionDataTagName = transmissionDataNode.tag.replace(self.base_ns, "") 610 transmissionDataUnits = transmissionDataNode.attrib.get("unit", "") 611 transmissionDataData = transmissionDataNode.text 612 613 # Are there multiple entries here? 614 if len(sasNode) <= 1: 615 multipleEntries == False 616 else: 617 multipleEntries == True 618 619 for setupNode in sasNode[0]: 620 # Iterating through the tags in the unit node, getting their tag name and respective unit 621 setupTagName = setupNode.tag.replace(self.base_ns, "") 622 transmissionDataUnits = setupNode.attrib.get("unit", "") 623 624 # Creating our data array first, if there's only one dataNode we will handle this... 625 startArray = np.fromstring(setupNode.text, dtype=float, sep=",") 626 627 if multipleEntries == True: 628 setupArray = np.zeros((len(sasNode), len(startArray))) 629 setupArray[0] = startArray 630 else: 631 setupArray = startArray 632 633 ## Transmission Spectrum 634 if setupTagName == "T": 635 self.transspectrum.transmission = setupArray 636 self.transspectrum.transmission_unit = transmissionDataUnits 637 elif setupTagName == "Tdev": 638 self.transspectrum.transmission_deviation = setupArray 639 self.transspectrum.transmission_deviation_unit = transmissionDataUnits 640 elif setupTagName == "Lambda": 641 self.transspectrum.wavelength = setupArray 642 self.transspectrum.wavelength_unit = transmissionDataUnits 643 644 # If there's more data present, let's deal with that too 645 for loopIter in range(1, len(sasNode)): 646 for dataNode in sasNode[loopIter]: 647 dataTagName = dataNode.tag.replace(self.base_ns, "") 648 dataArray = np.fromstring(dataNode.text, dtype=float, sep=",") 649 650 if dataTagName == "T": 651 self.transspectrum.transmission[loopIter] = setupArray 652 elif dataTagName == "Tdev": 653 self.transspectrum.transmission_deviation[loopIter] = setupArray 654 elif dataTagName == "Lambda": 655 self.transspectrum.wavelength[loopIter] = setupArray 656 657 ## Everything else goes in meta_data 246 658 else: 247 if isinstance(self.current_dataset, plottable_2D): 248 data_point = node.text 249 unit = attr.get('unit', '') 250 else: 251 data_point, unit = self._get_node_value(node) 252 253 # If this is a dataset, store the data appropriately 254 if tagname == 'Run': 255 self.current_datainfo.run_name[data_point] = name 256 self.current_datainfo.run.append(data_point) 257 elif tagname == 'Title': 258 self.current_datainfo.title = data_point 259 elif tagname == 'SASnote': 260 self.current_datainfo.notes.append(data_point) 261 262 # I and Q - 1D data 263 elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 264 unit_list = unit.split("|") 265 266 if len(unit_list) > 1: 267 self.current_dataset.yaxis(unit_list[0].strip(), 268 unit_list[1].strip()) 269 else: 270 self.current_dataset.yaxis("Intensity", unit) 271 272 self.current_dataset.y = np.append(self.current_dataset.y, data_point) 273 print data_point 274 275 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 276 self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 277 278 elif tagname == 'Q': 279 unit_list = unit.split("|") 280 if len(unit_list) > 1: 281 self.current_dataset.xaxis(unit_list[0].strip(), 282 unit_list[1].strip()) 283 else: 284 self.current_dataset.xaxis("Q", unit) 285 self.current_dataset.x = np.append(self.current_dataset.x, data_point) 286 elif tagname == 'Qdev': 287 self.current_dataset.dx = np.append(self.current_dataset.dx, data_point) 288 elif tagname == 'dQw': 289 self.current_dataset.dxw = np.append(self.current_dataset.dxw, data_point) 290 elif tagname == 'dQl': 291 self.current_dataset.dxl = np.append(self.current_dataset.dxl, data_point) 292 elif tagname == 'Qmean': 293 pass 294 elif tagname == 'Shadowfactor': 295 pass 296 elif tagname == 'Sesans': 297 self.current_datainfo.isSesans = bool(data_point) 298 elif tagname == 'zacceptance': 299 self.current_datainfo.sample.zacceptance = (data_point, unit) 300 301 # I and Qx, Qy - 2D data 302 elif tagname == 'I' and isinstance(self.current_dataset, plottable_2D): 303 self.current_dataset.yaxis("Intensity", unit) 304 self.current_dataset.data = np.fromstring(data_point, dtype=float, sep=",") 305 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_2D): 306 self.current_dataset.err_data = np.fromstring(data_point, dtype=float, sep=",") 307 elif tagname == 'Qx': 308 self.current_dataset.xaxis("Qx", unit) 309 self.current_dataset.qx_data = np.fromstring(data_point, dtype=float, sep=",") 310 elif tagname == 'Qy': 311 self.current_dataset.yaxis("Qy", unit) 312 self.current_dataset.qy_data = np.fromstring(data_point, dtype=float, sep=",") 313 elif tagname == 'Qxdev': 314 self.current_dataset.xaxis("Qxdev", unit) 315 self.current_dataset.dqx_data = np.fromstring(data_point, dtype=float, sep=",") 316 elif tagname == 'Qydev': 317 self.current_dataset.yaxis("Qydev", unit) 318 self.current_dataset.dqy_data = np.fromstring(data_point, dtype=float, sep=",") 319 elif tagname == 'Mask': 320 inter = [item == "1" for item in data_point.split(",")] 321 self.current_dataset.mask = np.asarray(inter, dtype=bool) 322 323 # Sample Information 324 elif tagname == 'ID' and self.parent_class == 'SASsample': 325 self.current_datainfo.sample.ID = data_point 326 elif tagname == 'Title' and self.parent_class == 'SASsample': 327 self.current_datainfo.sample.name = data_point 328 elif tagname == 'thickness' and self.parent_class == 'SASsample': 329 self.current_datainfo.sample.thickness = data_point 330 self.current_datainfo.sample.thickness_unit = unit 331 elif tagname == 'transmission' and self.parent_class == 'SASsample': 332 self.current_datainfo.sample.transmission = data_point 333 elif tagname == 'temperature' and self.parent_class == 'SASsample': 334 self.current_datainfo.sample.temperature = data_point 335 self.current_datainfo.sample.temperature_unit = unit 336 elif tagname == 'details' and self.parent_class == 'SASsample': 337 self.current_datainfo.sample.details.append(data_point) 338 elif tagname == 'x' and self.parent_class == 'position': 339 self.current_datainfo.sample.position.x = data_point 340 self.current_datainfo.sample.position_unit = unit 341 elif tagname == 'y' and self.parent_class == 'position': 342 self.current_datainfo.sample.position.y = data_point 343 self.current_datainfo.sample.position_unit = unit 344 elif tagname == 'z' and self.parent_class == 'position': 345 self.current_datainfo.sample.position.z = data_point 346 self.current_datainfo.sample.position_unit = unit 347 elif tagname == 'roll' and self.parent_class == 'orientation' and 'SASsample' in self.names: 348 self.current_datainfo.sample.orientation.x = data_point 349 self.current_datainfo.sample.orientation_unit = unit 350 elif tagname == 'pitch' and self.parent_class == 'orientation' and 'SASsample' in self.names: 351 self.current_datainfo.sample.orientation.y = data_point 352 self.current_datainfo.sample.orientation_unit = unit 353 elif tagname == 'yaw' and self.parent_class == 'orientation' and 'SASsample' in self.names: 354 self.current_datainfo.sample.orientation.z = data_point 355 self.current_datainfo.sample.orientation_unit = unit 356 357 # Instrumental Information 358 elif tagname == 'name' and self.parent_class == 'SASinstrument': 359 self.current_datainfo.instrument = data_point 360 # Detector Information 361 elif tagname == 'name' and self.parent_class == 'SASdetector': 362 self.detector.name = data_point 363 elif tagname == 'SDD' and self.parent_class == 'SASdetector': 364 self.detector.distance = data_point 365 self.detector.distance_unit = unit 366 elif tagname == 'slit_length' and self.parent_class == 'SASdetector': 367 self.detector.slit_length = data_point 368 self.detector.slit_length_unit = unit 369 elif tagname == 'x' and self.parent_class == 'offset': 370 self.detector.offset.x = data_point 371 self.detector.offset_unit = unit 372 elif tagname == 'y' and self.parent_class == 'offset': 373 self.detector.offset.y = data_point 374 self.detector.offset_unit = unit 375 elif tagname == 'z' and self.parent_class == 'offset': 376 self.detector.offset.z = data_point 377 self.detector.offset_unit = unit 378 elif tagname == 'x' and self.parent_class == 'beam_center': 379 self.detector.beam_center.x = data_point 380 self.detector.beam_center_unit = unit 381 elif tagname == 'y' and self.parent_class == 'beam_center': 382 self.detector.beam_center.y = data_point 383 self.detector.beam_center_unit = unit 384 elif tagname == 'z' and self.parent_class == 'beam_center': 385 self.detector.beam_center.z = data_point 386 self.detector.beam_center_unit = unit 387 elif tagname == 'x' and self.parent_class == 'pixel_size': 388 self.detector.pixel_size.x = data_point 389 self.detector.pixel_size_unit = unit 390 elif tagname == 'y' and self.parent_class == 'pixel_size': 391 self.detector.pixel_size.y = data_point 392 self.detector.pixel_size_unit = unit 393 elif tagname == 'z' and self.parent_class == 'pixel_size': 394 self.detector.pixel_size.z = data_point 395 self.detector.pixel_size_unit = unit 396 elif tagname == 'roll' and self.parent_class == 'orientation' and 'SASdetector' in self.names: 397 self.detector.orientation.x = data_point 398 self.detector.orientation_unit = unit 399 elif tagname == 'pitch' and self.parent_class == 'orientation' and 'SASdetector' in self.names: 400 self.detector.orientation.y = data_point 401 self.detector.orientation_unit = unit 402 elif tagname == 'yaw' and self.parent_class == 'orientation' and 'SASdetector' in self.names: 403 self.detector.orientation.z = data_point 404 self.detector.orientation_unit = unit 405 # Collimation and Aperture 406 elif tagname == 'length' and self.parent_class == 'SAScollimation': 407 self.collimation.length = data_point 408 self.collimation.length_unit = unit 409 elif tagname == 'name' and self.parent_class == 'SAScollimation': 410 self.collimation.name = data_point 411 elif tagname == 'distance' and self.parent_class == 'aperture': 412 self.aperture.distance = data_point 413 self.aperture.distance_unit = unit 414 elif tagname == 'x' and self.parent_class == 'size': 415 self.aperture.size.x = data_point 416 self.collimation.size_unit = unit 417 elif tagname == 'y' and self.parent_class == 'size': 418 self.aperture.size.y = data_point 419 self.collimation.size_unit = unit 420 elif tagname == 'z' and self.parent_class == 'size': 421 self.aperture.size.z = data_point 422 self.collimation.size_unit = unit 423 424 # Process Information 425 elif tagname == 'name' and self.parent_class == 'SASprocess': 426 self.process.name = data_point 427 elif tagname == 'description' and self.parent_class == 'SASprocess': 428 self.process.description = data_point 429 elif tagname == 'date' and self.parent_class == 'SASprocess': 430 try: 431 self.process.date = datetime.datetime.fromtimestamp(data_point) 432 except: 433 self.process.date = data_point 434 elif tagname == 'SASprocessnote': 435 self.process.notes.append(data_point) 436 elif tagname == 'term' and self.parent_class == 'SASprocess': 437 unit = attr.get("unit", "") 438 dic = {} 439 dic["name"] = name 440 dic["value"] = data_point 441 dic["unit"] = unit 442 self.process.term.append(dic) 443 444 # Transmission Spectrum 445 elif tagname == 'T' and self.parent_class == 'Tdata': 446 self.transspectrum.transmission = np.append(self.transspectrum.transmission, data_point) 447 self.transspectrum.transmission_unit = unit 448 elif tagname == 'Tdev' and self.parent_class == 'Tdata': 449 self.transspectrum.transmission_deviation = np.append(self.transspectrum.transmission_deviation, data_point) 450 self.transspectrum.transmission_deviation_unit = unit 451 elif tagname == 'Lambda' and self.parent_class == 'Tdata': 452 self.transspectrum.wavelength = np.append(self.transspectrum.wavelength, data_point) 453 self.transspectrum.wavelength_unit = unit 454 455 # Source Information 456 elif tagname == 'wavelength' and (self.parent_class == 'SASsource' or self.parent_class == 'SASData'): 457 self.current_datainfo.source.wavelength = data_point 458 self.current_datainfo.source.wavelength_unit = unit 459 elif tagname == 'wavelength_min' and self.parent_class == 'SASsource': 460 self.current_datainfo.source.wavelength_min = data_point 461 self.current_datainfo.source.wavelength_min_unit = unit 462 elif tagname == 'wavelength_max' and self.parent_class == 'SASsource': 463 self.current_datainfo.source.wavelength_max = data_point 464 self.current_datainfo.source.wavelength_max_unit = unit 465 elif tagname == 'wavelength_spread' and self.parent_class == 'SASsource': 466 self.current_datainfo.source.wavelength_spread = data_point 467 self.current_datainfo.source.wavelength_spread_unit = unit 468 elif tagname == 'x' and self.parent_class == 'beam_size': 469 self.current_datainfo.source.beam_size.x = data_point 470 self.current_datainfo.source.beam_size_unit = unit 471 elif tagname == 'y' and self.parent_class == 'beam_size': 472 self.current_datainfo.source.beam_size.y = data_point 473 self.current_datainfo.source.beam_size_unit = unit 474 elif tagname == 'z' and self.parent_class == 'pixel_size': 475 self.current_datainfo.source.data_point.z = data_point 476 self.current_datainfo.source.beam_size_unit = unit 477 elif tagname == 'radiation' and self.parent_class == 'SASsource': 478 self.current_datainfo.source.radiation = data_point 479 elif tagname == 'beam_shape' and self.parent_class == 'SASsource': 480 self.current_datainfo.source.beam_shape = data_point 481 482 # Everything else goes in meta_data 483 else: 484 new_key = self._create_unique_key(self.current_datainfo.meta_data, tagname) 485 self.current_datainfo.meta_data[new_key] = data_point 486 487 self.names.remove(tagname_original) 488 length = 0 489 if len(self.names) > 1: 490 length = len(self.names) - 1 491 self.parent_class = self.names[length] 492 if not self._is_call_local() and not recurse: 493 self.frm = "" 494 self.add_data_set() 495 empty = None 496 return self.output[0], empty 659 new_key = self._create_unique_key(self.current_datainfo.meta_data, currentTagName) 660 self.current_datainfo.meta_data[new_key] = sasNode.text 661 662 self._final_cleanup() 663 print self.current_dataset.y 664 print len(self.current_dataset.y) 665 666 # As before in the code, I guess in case we have to return a tuple for some reason... 667 return self.output, None 497 668 498 669
Note: See TracChangeset
for help on using the changeset viewer.