Changeset 574adc7 in sasview for src/sas/sascalc/data_util/nxsunit.py
- Timestamp:
- Sep 22, 2017 2:01:32 PM (7 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, 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/data_util/nxsunit.py
r8e9536f r574adc7 13 13 in the NeXus definition files. 14 14 15 Unlike other units packages, this package does not carry the units along with 15 Unlike other units packages, this package does not carry the units along with 16 16 the value but merely provides a conversion function for transforming values. 17 17 … … 68 68 Ack! Allows, e.g., Coulomb and coulomb even though Coulomb is not 69 69 a unit because some NeXus files store it that way! 70 70 71 71 Returns a dictionary of names and scales. 72 72 """ … … 78 78 n=1e-9,p=1e-12,f=1e-15) 79 79 map = {abbr:1} 80 map.update([(P+abbr,scale) for (P,scale) in short_prefix.ite ritems()])80 map.update([(P+abbr,scale) for (P,scale) in short_prefix.items()]) 81 81 for name in [unit,unit.capitalize()]: 82 82 map.update({name:1,name+'s':1}) 83 map.update([(P+name,scale) for (P,scale) in prefix.ite ritems()])84 map.update([(P+'*'+name,scale) for (P,scale) in prefix.ite ritems()])85 map.update([(P+name+'s',scale) for (P,scale) in prefix.ite ritems()])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()]) 86 86 return map 87 87 … … 91 91 """ 92 92 map = {} 93 map.update([(name,scale) for name,scale in kw.ite ritems()])94 map.update([(name+'s',scale) for name,scale in kw.ite ritems()])93 map.update([(name,scale) for name,scale in kw.items()]) 94 map.update([(name+'s',scale) for name,scale in kw.items()]) 95 95 return map 96 96 … … 101 101 * WARNING * this will incorrect transform 10^3 to 103. 102 102 """ 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()) 105 105 if '^' in k) 106 106 … … 130 130 temperature.update(_build_metric_units('Celcius', 'C')) 131 131 temperature.update(_build_metric_units('celcius', 'C')) 132 132 133 133 charge = _build_metric_units('coulomb','C') 134 134 charge.update({'microAmp*hour':0.0036}) 135 135 136 136 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, 138 138 '10^-3 Angstrom^-1': 1e-3, '1/cm': 1e-8, '1/m': 1e-10, 139 139 'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 } … … 189 189 190 190 def _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)) 192 193 #print expect,"==",get 193 194 … … 202 203 _check(123,Converter('a.u.')(123,units='s')) # arbitrary units always returns the same value 203 204 _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") 207 211 208 212 # TODO: more tests
Note: See TracChangeset
for help on using the changeset viewer.