Ignore:
Timestamp:
Sep 22, 2017 2:01:32 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
34d7b35
Parents:
9706d88
Message:

convert sascalc to python 2/3 syntax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/nxsunit.py

    r8e9536f r574adc7  
    1313in the NeXus definition files. 
    1414 
    15 Unlike other units packages, this package does not carry the units along with  
     15Unlike other units packages, this package does not carry the units along with 
    1616the value but merely provides a conversion function for transforming values. 
    1717 
     
    6868    Ack! Allows, e.g., Coulomb and coulomb even though Coulomb is not 
    6969    a unit because some NeXus files store it that way! 
    70      
     70 
    7171    Returns a dictionary of names and scales. 
    7272    """ 
     
    7878                        n=1e-9,p=1e-12,f=1e-15) 
    7979    map = {abbr:1} 
    80     map.update([(P+abbr,scale) for (P,scale) in short_prefix.iteritems()]) 
     80    map.update([(P+abbr,scale) for (P,scale) in short_prefix.items()]) 
    8181    for name in [unit,unit.capitalize()]: 
    8282        map.update({name:1,name+'s':1}) 
    83         map.update([(P+name,scale) for (P,scale) in prefix.iteritems()]) 
    84         map.update([(P+'*'+name,scale) for (P,scale) in prefix.iteritems()]) 
    85         map.update([(P+name+'s',scale) for (P,scale) in prefix.iteritems()]) 
     83        map.update([(P+name,scale) for (P,scale) in prefix.items()]) 
     84        map.update([(P+'*'+name,scale) for (P,scale) in prefix.items()]) 
     85        map.update([(P+name+'s',scale) for (P,scale) in prefix.items()]) 
    8686    return map 
    8787 
     
    9191    """ 
    9292    map = {} 
    93     map.update([(name,scale) for name,scale in kw.iteritems()]) 
    94     map.update([(name+'s',scale) for name,scale in kw.iteritems()]) 
     93    map.update([(name,scale) for name,scale in kw.items()]) 
     94    map.update([(name+'s',scale) for name,scale in kw.items()]) 
    9595    return map 
    9696 
     
    101101    * WARNING * this will incorrect transform 10^3 to 103. 
    102102    """ 
    103     s.update((k.replace('^',''),v)  
    104              for k,v in s.items() 
     103    s.update((k.replace('^',''),v) 
     104             for k, v in list(s.items()) 
    105105             if '^' in k) 
    106106 
     
    130130    temperature.update(_build_metric_units('Celcius', 'C')) 
    131131    temperature.update(_build_metric_units('celcius', 'C')) 
    132      
     132 
    133133    charge = _build_metric_units('coulomb','C') 
    134134    charge.update({'microAmp*hour':0.0036}) 
    135135 
    136136    sld = { '10^-6 Angstrom^-2': 1e-6, 'Angstrom^-2': 1 } 
    137     Q = { 'invA': 1, 'invAng': 1, 'invAngstroms': 1, '1/A': 1,  
     137    Q = { 'invA': 1, 'invAng': 1, 'invAngstroms': 1, '1/A': 1, 
    138138          '10^-3 Angstrom^-1': 1e-3, '1/cm': 1e-8, '1/m': 1e-10, 
    139139          'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 } 
     
    189189 
    190190def _check(expect,get): 
    191     if expect != get: raise ValueError, "Expected %s but got %s"%(expect,get) 
     191    if expect != get: 
     192        raise ValueError("Expected %s but got %s"%(expect, get)) 
    192193     #print expect,"==",get 
    193194 
     
    202203    _check(123,Converter('a.u.')(123,units='s')) # arbitrary units always returns the same value 
    203204    _check(123,Converter('a.u.')(123,units='')) # arbitrary units always returns the same value 
    204     try: Converter('help') 
    205     except KeyError: pass 
    206     else: raise Exception("unknown unit did not raise an error") 
     205    try: 
     206        Converter('help') 
     207    except KeyError: 
     208        pass 
     209    else: 
     210        raise Exception("unknown unit did not raise an error") 
    207211 
    208212    # TODO: more tests 
Note: See TracChangeset for help on using the changeset viewer.