Changeset 5a0dac1f in sasview for sansdataloader/src/sans
- Timestamp:
- Apr 12, 2012 4:47:19 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 4b73c3e
- Parents:
- a3efdeb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansdataloader/src/sans/dataloader/readers/cansas_reader.py
r0a5c8f5 r5a0dac1f 39 39 import xml.dom.minidom 40 40 _ZERO = 1e-16 41 has_converter= True41 HAS_CONVERTER = True 42 42 try: 43 43 from data_util.nxsunit import Converter 44 44 except: 45 has_converter= False45 HAS_CONVERTER = False 46 46 47 47 CANSAS_NS = "cansas1d/1.0" 48 allow_all= True48 ALLOW_ALL = True 49 49 50 50 def write_node(doc, parent, name, value, attr={}): … … 124 124 125 125 ## List of allowed extensions 126 ext = ['.xml', '.XML', '.avex', '.AVEx', '.absx', 'ABSx']126 ext = ['.xml', '.XML', '.avex', '.AVEx', '.absx', 'ABSx'] 127 127 128 128 def __init__(self): … … 147 147 basename = os.path.basename(path) 148 148 root, extension = os.path.splitext(basename) 149 if allow_allor extension.lower() in self.ext:149 if ALLOW_ALL or extension.lower() in self.ext: 150 150 try: 151 151 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) … … 436 436 if attr.has_key('unit') and \ 437 437 attr['unit'].lower() != data_info.x_unit.lower(): 438 if has_converter==True:438 if HAS_CONVERTER == True: 439 439 try: 440 440 data_conv_q = Converter(attr['unit']) … … 442 442 except: 443 443 msg = "CanSAS reader: could not convert " 444 msg += "Q unit [%s]; " 445 msg += "expecting [%s]\n %s" % ( attr['unit'],446 data_info.x_unit,sys.exc_value)444 msg += "Q unit [%s]; " % attr['unit'], 445 msg += "expecting [%s]\n %s" % (data_info.x_unit, 446 sys.exc_value) 447 447 raise ValueError, msg 448 448 449 449 else: 450 msg = "CanSAS reader: unrecognized Q unit [%s]; " 451 msg += "expecting [%s]" % (attr['unit'], data_info.x_unit) 450 msg = "CanSAS reader: unrecognized Q unit [%s]; "\ 451 % attr['unit'] 452 msg += "expecting [%s]" % data_info.x_unit 452 453 raise ValueError, msg 453 454 … … 455 456 if attr_d.has_key('unit') and \ 456 457 attr_d['unit'].lower() != data_info.x_unit.lower(): 457 if has_converter==True:458 if HAS_CONVERTER == True: 458 459 try: 459 460 data_conv_q = Converter(attr_d['unit']) 460 461 _dx = data_conv_q(_dx, units=data_info.x_unit) 461 462 except: 462 msg = "CanSAS reader: could not convert dQ unit [%s];" 463 msg = "CanSAS reader: could not convert dQ unit [%s]; "\ 464 % attr['unit'] 463 465 msg += " expecting " 464 msg += "[%s]\n %s" % (attr['unit'], 465 data_info.x_unit, sys.exc_value) 466 msg += "[%s]\n %s" % (data_info.x_unit, sys.exc_value) 466 467 raise ValueError, msg 467 468 468 469 else: 469 msg = "CanSAS reader: unrecognized dQ unit [%s]; " 470 msg += "expecting [%s]" % (attr['unit'], data_info.x_unit) 470 msg = "CanSAS reader: unrecognized dQ unit [%s]; "\ 471 % attr['unit'] 472 msg += "expecting [%s]" % data_info.x_unit 471 473 raise ValueError, msg 472 474 … … 474 476 if attr_l.has_key('unit') and \ 475 477 attr_l['unit'].lower() != data_info.x_unit.lower(): 476 if has_converter== True:478 if HAS_CONVERTER == True: 477 479 try: 478 480 data_conv_q = Converter(attr_l['unit']) 479 481 _dxl = data_conv_q(_dxl, units=data_info.x_unit) 480 482 except: 481 msg = "CanSAS reader: could not convert dQl unit [%s];" 482 msg += " expecting [%s]\n %s" % (attr['unit'], 483 data_info.x_unit, sys.exc_value) 483 msg = "CanSAS reader: could not convert dQl unit [%s];"\ 484 % attr['unit'] 485 msg += " expecting [%s]\n %s" % (data_info.x_unit, 486 sys.exc_value) 484 487 raise ValueError, msg 485 488 486 489 else: 487 msg = "CanSAS reader: unrecognized dQl unit [%s];" 488 msg += " expecting [%s]" % (attr['unit'], data_info.x_unit) 490 msg = "CanSAS reader: unrecognized dQl unit [%s];"\ 491 % attr['unit'] 492 msg += " expecting [%s]" % data_info.x_unit 489 493 raise ValueError, msg 490 494 … … 492 496 if attr_w.has_key('unit') and \ 493 497 attr_w['unit'].lower() != data_info.x_unit.lower(): 494 if has_converter== True:498 if HAS_CONVERTER == True: 495 499 try: 496 500 data_conv_q = Converter(attr_w['unit']) 497 501 _dxw = data_conv_q(_dxw, units=data_info.x_unit) 498 502 except: 499 msg = "CanSAS reader: could not convert dQw unit [%s];" 500 msg += " expecting [%s]\n %s" % (attr['unit'], 501 data_info.x_unit, sys.exc_value) 503 msg = "CanSAS reader: could not convert dQw unit [%s];"\ 504 % attr['unit'] 505 msg += " expecting [%s]\n %s" % (data_info.x_unit, 506 sys.exc_value) 502 507 raise ValueError, msg 503 508 504 509 else: 505 msg = "CanSAS reader: unrecognized dQw unit [%s];" 506 msg += " expecting [%s]" % (attr['unit'], data_info.x_unit) 510 msg = "CanSAS reader: unrecognized dQw unit [%s];"\ 511 % attr['unit'] 512 msg += " expecting [%s]" % data_info.x_unit 507 513 raise ValueError, msg 508 514 _y, attr = get_float('ns:I', item) … … 512 518 if attr.has_key('unit') and \ 513 519 attr['unit'].lower() != data_info.y_unit.lower(): 514 if has_converter==True:520 if HAS_CONVERTER == True: 515 521 try: 516 522 data_conv_i = Converter(attr['unit']) … … 526 532 raise ValueError, msg 527 533 else: 528 msg = "CanSAS reader: unrecognized I(q) unit [%s];" 529 msg += " expecting [%s]" % (attr['unit'], data_info.y_unit) 534 msg = "CanSAS reader: unrecognized I(q) unit [%s];"\ 535 % attr['unit'] 536 msg += " expecting [%s]" % data_info.y_unit 530 537 raise ValueError, msg 531 538 532 539 if attr_d.has_key('unit') and \ 533 540 attr_d['unit'].lower() != data_info.y_unit.lower(): 534 if has_converter==True:541 if HAS_CONVERTER == True: 535 542 try: 536 543 data_conv_i = Converter(attr_d['unit']) … … 545 552 raise ValueError, msg 546 553 else: 547 msg = "CanSAS reader: unrecognized dI(q) unit [%s]; " 548 msg += "expecting [%s]" % (attr_d['unit'], data_info.y_unit) 554 msg = "CanSAS reader: unrecognized dI(q) unit [%s]; "\ 555 % attr_d['unit'] 556 msg += "expecting [%s]" % data_info.y_unit 549 557 raise ValueError, msg 550 558 … … 573 581 data_conv_i = None 574 582 575 if has_converter== True and data_info.x_unit != '1/A':583 if HAS_CONVERTER == True and data_info.x_unit != '1/A': 576 584 data_conv_q = Converter('1/A') 577 585 # Test it 578 586 data_conv_q(1.0, output.Q_unit) 579 587 580 if has_converter== True and data_info.y_unit != '1/cm':588 if HAS_CONVERTER == True and data_info.y_unit != '1/cm': 581 589 data_conv_i = Converter('1/cm') 582 590 # Test it … … 888 896 exec "local_unit = storage.%s_unit" % toks[0] 889 897 if units.lower()!=local_unit.lower(): 890 if has_converter==True:898 if HAS_CONVERTER == True: 891 899 try: 892 900 conv = Converter(units) … … 903 911 raise ValueError, err_mess 904 912 else: 905 err_mess = "CanSAS reader: unrecognized %s unit [%s];" 906 err_mess += " expecting [%s]" % (variable,907 units, local_unit)913 err_mess = "CanSAS reader: unrecognized %s unit [%s];"\ 914 % (variable, units) 915 err_mess += " expecting [%s]" % local_unit 908 916 self.errors.append(err_mess) 909 917 if optional:
Note: See TracChangeset
for help on using the changeset viewer.