Changeset 5a0dac1f in sasview


Ignore:
Timestamp:
Apr 12, 2012 2:47:19 PM (12 years ago)
Author:
Mathieu Doucet <doucetm@…>
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
Message:

Fixing code style problems and bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansdataloader/src/sans/dataloader/readers/cansas_reader.py

    r0a5c8f5 r5a0dac1f  
    3939import xml.dom.minidom 
    4040_ZERO = 1e-16 
    41 has_converter = True 
     41HAS_CONVERTER = True 
    4242try: 
    4343    from data_util.nxsunit import Converter 
    4444except: 
    45     has_converter = False 
     45    HAS_CONVERTER = False 
    4646 
    4747CANSAS_NS = "cansas1d/1.0" 
    48 allow_all = True 
     48ALLOW_ALL = True 
    4949 
    5050def write_node(doc, parent, name, value, attr={}): 
     
    124124 
    125125    ## List of allowed extensions 
    126     ext = ['.xml', '.XML','.avex', '.AVEx', '.absx', 'ABSx']   
     126    ext = ['.xml', '.XML', '.avex', '.AVEx', '.absx', 'ABSx']   
    127127     
    128128    def __init__(self): 
     
    147147            basename  = os.path.basename(path) 
    148148            root, extension = os.path.splitext(basename) 
    149             if allow_all or extension.lower() in self.ext: 
     149            if ALLOW_ALL or extension.lower() in self.ext: 
    150150                try: 
    151151                    tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 
     
    436436            if attr.has_key('unit') and \ 
    437437                attr['unit'].lower() != data_info.x_unit.lower(): 
    438                 if has_converter==True: 
     438                if HAS_CONVERTER == True: 
    439439                    try: 
    440440                        data_conv_q = Converter(attr['unit']) 
     
    442442                    except: 
    443443                        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) 
    447447                        raise ValueError, msg 
    448448                         
    449449                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 
    452453                    raise ValueError, msg 
    453454                         
     
    455456            if attr_d.has_key('unit') and \ 
    456457                attr_d['unit'].lower() != data_info.x_unit.lower(): 
    457                 if has_converter==True: 
     458                if HAS_CONVERTER == True: 
    458459                    try: 
    459460                        data_conv_q = Converter(attr_d['unit']) 
    460461                        _dx = data_conv_q(_dx, units=data_info.x_unit) 
    461462                    except: 
    462                         msg = "CanSAS reader: could not convert dQ unit [%s];" 
     463                        msg = "CanSAS reader: could not convert dQ unit [%s]; "\ 
     464                        % attr['unit'] 
    463465                        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) 
    466467                        raise ValueError, msg 
    467468                         
    468469                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 
    471473                    raise ValueError,  msg 
    472474                         
     
    474476            if attr_l.has_key('unit') and \ 
    475477                attr_l['unit'].lower() != data_info.x_unit.lower(): 
    476                 if has_converter == True: 
     478                if HAS_CONVERTER == True: 
    477479                    try: 
    478480                        data_conv_q = Converter(attr_l['unit']) 
    479481                        _dxl = data_conv_q(_dxl, units=data_info.x_unit) 
    480482                    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) 
    484487                        raise ValueError, msg 
    485488                         
    486489                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 
    489493                    raise ValueError, msg 
    490494                         
     
    492496            if attr_w.has_key('unit') and \ 
    493497            attr_w['unit'].lower() != data_info.x_unit.lower(): 
    494                 if has_converter == True: 
     498                if HAS_CONVERTER == True: 
    495499                    try: 
    496500                        data_conv_q = Converter(attr_w['unit']) 
    497501                        _dxw = data_conv_q(_dxw, units=data_info.x_unit) 
    498502                    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) 
    502507                        raise ValueError, msg 
    503508                         
    504509                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 
    507513                    raise ValueError, msg    
    508514            _y, attr = get_float('ns:I', item) 
     
    512518            if attr.has_key('unit') and \ 
    513519            attr['unit'].lower() != data_info.y_unit.lower(): 
    514                 if has_converter==True: 
     520                if HAS_CONVERTER == True: 
    515521                    try: 
    516522                        data_conv_i = Converter(attr['unit']) 
     
    526532                            raise ValueError, msg 
    527533                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 
    530537                    raise ValueError, msg  
    531538                         
    532539            if attr_d.has_key('unit') and \ 
    533540            attr_d['unit'].lower() != data_info.y_unit.lower(): 
    534                 if has_converter==True: 
     541                if HAS_CONVERTER == True: 
    535542                    try: 
    536543                        data_conv_i = Converter(attr_d['unit']) 
     
    545552                            raise ValueError, msg 
    546553                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 
    549557                    raise ValueError, msg 
    550558                 
     
    573581        data_conv_i = None 
    574582         
    575         if has_converter == True and data_info.x_unit != '1/A': 
     583        if HAS_CONVERTER == True and data_info.x_unit != '1/A': 
    576584            data_conv_q = Converter('1/A') 
    577585            # Test it 
    578586            data_conv_q(1.0, output.Q_unit) 
    579587             
    580         if has_converter == True and data_info.y_unit != '1/cm': 
     588        if HAS_CONVERTER == True and data_info.y_unit != '1/cm': 
    581589            data_conv_i = Converter('1/cm') 
    582590            # Test it 
     
    888896                exec "local_unit = storage.%s_unit" % toks[0] 
    889897                if units.lower()!=local_unit.lower(): 
    890                     if has_converter==True: 
     898                    if HAS_CONVERTER == True: 
    891899                        try: 
    892900                            conv = Converter(units) 
     
    903911                                raise ValueError, err_mess  
    904912                    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 
    908916                        self.errors.append(err_mess) 
    909917                        if optional: 
Note: See TracChangeset for help on using the changeset viewer.