Changeset b39c817 in sasview for DataLoader/readers


Ignore:
Timestamp:
Aug 4, 2008 10:39:43 AM (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:
ccb560a
Parents:
cfe97ea
Message:

Added unit converter for CanSAS format reader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/readers/cansas_reader.py

    r8780e9a rb39c817  
    2222from DataLoader.data_info import Data1D, Collimation, Detector, Process 
    2323from xml import xpath 
     24 
     25has_converter = True 
     26try: 
     27    from data_util.nxsunit import Converter 
     28except: 
     29    has_converter = False 
    2430 
    2531def get_node_text(node): 
     
    8793    if content is not None: 
    8894        try: 
    89             value = float(content)         
     95            value = float(content)    
    9096        except: 
    9197            # Could not pass, skip and return None 
     
    113119    value, attr = get_float(location, node) 
    114120    if value is not None: 
    115         exec "storage.%s = value" % variable 
    116          
    117121        # If the entry has units, check to see that they are 
    118122        # compatible with what we currently have in the data object 
     
    121125            exec "local_unit = storage.%s_unit.lower()" % toks[0] 
    122126            if attr['unit'].lower()!=local_unit: 
    123                 raise ValueError, "CanSAS reader: unrecognized %s unit [%s]; expecting [%s]" \ 
    124                     % (variable, attr['unit'], local_unit) 
     127                if has_converter==True: 
     128                    try: 
     129                        conv = Converter(attr['unit']) 
     130                        exec "storage.%s = %g" % (variable, conv(value, units=local_unit)) 
     131                    except: 
     132                        raise ValueError, "CanSAS reader: could not convert %s unit [%s]; expecting [%s]\n  %s" \ 
     133                        % (variable, attr['unit'], local_unit, sys.exc_value) 
     134                else: 
     135                    raise ValueError, "CanSAS reader: unrecognized %s unit [%s]; expecting [%s]" \ 
     136                        % (variable, attr['unit'], local_unit) 
     137            else: 
     138                exec "storage.%s = value" % variable 
     139        else: 
     140            exec "storage.%s = value" % variable 
     141             
    125142 
    126143def _store_content(location, node, variable, storage): 
Note: See TracChangeset for help on using the changeset viewer.