Changeset e390933 in sasview for DataLoader/readers


Ignore:
Timestamp:
Sep 2, 2008 2:32:02 PM (16 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:
daa56d0
Parents:
1b162dfa
Message:

Added unit conversion tests for data loader.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/readers/cansas_reader.py

    r579ba85 re390933  
    1717#TODO: Notes need to be implemented. They can be any XML structure in version 1.0 
    1818#      Process notes have the same problem. 
     19#TODO: Unit conversion is not complete (temperature units are missing) 
    1920 
    2021 
     
    145146        if attr.has_key('unit'): 
    146147            toks = variable.split('.') 
    147             exec "local_unit = storage.%s_unit.lower()" % toks[0] 
    148             if attr['unit'].lower()!=local_unit: 
     148            exec "local_unit = storage.%s_unit" % toks[0] 
     149            if attr['unit'].lower()!=local_unit.lower(): 
    149150                if has_converter==True: 
    150151                    try: 
     
    462463        for item in nodes: 
    463464            _x, attr = get_float('Q', item) 
    464             _dx, attr = get_float('Qdev', item) 
     465            _dx, attr_d = get_float('Qdev', item) 
    465466            if _dx == None: 
    466467                _dx = 0.0 
     468                 
    467469            if attr.has_key('unit') and attr['unit'].lower() != data_info.x_unit.lower(): 
    468                 raise ValueError, "CanSAS reader: unrecognized %s unit [%s]; expecting [%s]" \ 
    469                     % (variable, attr['unit'], local_unit) 
    470                  
     470                if has_converter==True: 
     471                    try: 
     472                        data_conv_q = Converter(attr['unit']) 
     473                        _x = data_conv_q(_x, units=data_info.x_unit) 
     474                    except: 
     475                        raise ValueError, "CanSAS reader: could not convert Q unit [%s]; expecting [%s]\n  %s" \ 
     476                        % (attr['unit'], data_info.x_unit, sys.exc_value) 
     477                else: 
     478                    raise ValueError, "CanSAS reader: unrecognized Q unit [%s]; expecting [%s]" \ 
     479                        % (attr['unit'], data_info.x_unit) 
     480            if attr_d.has_key('unit') and attr_d['unit'].lower() != data_info.x_unit.lower(): 
     481                if has_converter==True: 
     482                    try: 
     483                        data_conv_q = Converter(attr_d['unit']) 
     484                        _dx = data_conv_q(_dx, units=data_info.x_unit) 
     485                    except: 
     486                        raise ValueError, "CanSAS reader: could not convert dQ unit [%s]; expecting [%s]\n  %s" \ 
     487                        % (attr['unit'], data_info.x_unit, sys.exc_value) 
     488                else: 
     489                    raise ValueError, "CanSAS reader: unrecognized dQ unit [%s]; expecting [%s]" \ 
     490                        % (attr['unit'], data_info.x_unit) 
     491                     
    471492            _y, attr = get_float('I', item) 
    472             _dy, attr = get_float('Idev', item) 
     493            _dy, attr_d = get_float('Idev', item) 
    473494            if _dy == None: 
    474495                _dy = 0.0 
    475496            if attr.has_key('unit') and attr['unit'].lower() != data_info.y_unit.lower(): 
    476                 raise ValueError, "CanSAS reader: unrecognized %s unit [%s]; expecting [%s]" \ 
    477                     % (variable, attr['unit'], local_unit) 
     497                if has_converter==True: 
     498                    try: 
     499                        data_conv_i = Converter(attr['unit']) 
     500                        _y = data_conv_i(_y, units=data_info.y_unit) 
     501                    except: 
     502                        raise ValueError, "CanSAS reader: could not convert I(q) unit [%s]; expecting [%s]\n  %s" \ 
     503                        % (attr['unit'], data_info.y_unit, sys.exc_value) 
     504                else: 
     505                    raise ValueError, "CanSAS reader: unrecognized I(q) unit [%s]; expecting [%s]" \ 
     506                        % (attr['unit'], data_info.y_unit) 
     507            if attr_d.has_key('unit') and attr_d['unit'].lower() != data_info.y_unit.lower(): 
     508                if has_converter==True: 
     509                    try: 
     510                        data_conv_i = Converter(attr_d['unit']) 
     511                        _dy = data_conv_i(_dy, units=data_info.y_unit) 
     512                    except: 
     513                        raise ValueError, "CanSAS reader: could not convert dI(q) unit [%s]; expecting [%s]\n  %s" \ 
     514                        % (attr_d['unit'], data_info.y_unit, sys.exc_value) 
     515                else: 
     516                    raise ValueError, "CanSAS reader: unrecognized dI(q) unit [%s]; expecting [%s]" \ 
     517                        % (attr_d['unit'], data_info.y_unit) 
    478518                 
    479519            if _x is not None and _y is not None: 
     
    499539            data_conv_i = Converter('1/cm') 
    500540            # Test it 
    501             data_conv_i(1.0, output.I_unit)             
    502      
    503          
     541            data_conv_i(1.0, output.I_unit)                     
     542                 
    504543        if data_conv_q is not None: 
    505544            data_info.xaxis("\\rm{Q}", data_info.x_unit) 
Note: See TracChangeset for help on using the changeset viewer.