Changeset d744767 in sasview for src/sas/qtgui/Plotting/ConvertUnits.py
- Timestamp:
- Mar 16, 2018 12:05:42 PM (6 years ago)
- Branches:
- 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
- Children:
- 47bf906
- Parents:
- 477c473 (diff), e4c475b7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotting/ConvertUnits.py
re7a0b2f rd744767 4 4 """ 5 5 import re 6 import string7 6 8 7 def convertUnit(power, unit): … … 11 10 """ 12 11 if power != 0: 13 if string.find(unit,"^") != -1: # if the unit contains a powerer ^12 if unit.find("^") != -1: # if the unit contains a powerer ^ 14 13 toks = re.split("\^", unit) 15 if string.find(toks[0],"/") != -1 or \16 string.find(toks[0],"-") != -1:14 if toks[0].find("/") != -1 or \ 15 toks[0].find("-") != -1: 17 16 if power == 1: 18 17 unit = unit … … 20 19 unit = "(" + unit + ")" + "^{" + str(power) + "}" 21 20 else: 22 if string.find(toks[1],"{") != -1: # if found a {21 if toks[1].find("{") != -1: # if found a { 23 22 find_power_toks = re.split("{", toks[1]) 24 if string.find(find_power_toks[1],"}") != -1: # found }23 if find_power_toks[1].find("}") != -1: # found } 25 24 unit_toks = re.split("}", find_power_toks[1]) 26 if string.find(unit_toks[0],".") != -1:25 if unit_toks[0].find(".") != -1: 27 26 powerer = float(unit_toks[0]) * power 28 elif string.find(unit_toks[0],"/") != -1:27 elif unit_toks[0].find("/") != -1: 29 28 power_toks = re.split("/", unit_toks[0]) 30 29 powerer = power * int(power_toks[0])\ … … 42 41 unit = toks[0] + "^{" + str(powerer) + "}" 43 42 else: 44 raise ValueError , "missing } in unit expression"43 raise ValueError("missing } in unit expression") 45 44 else: # no powerer 46 45 if power != 1: 47 46 unit = "(" + unit + ")" + "^{" + str(power) + "}" 48 47 else: 49 raise ValueError , "empty unit ,enter a powerer different from zero"48 raise ValueError("empty unit ,enter a powerer different from zero") 50 49 return unit 51 50 … … 68 67 unit8 = "m/s^{4}" # x^2 (m/s^{4})^{2} 69 68 70 print "this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))71 print "this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))72 print "this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))73 print "this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))74 print "this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))75 print "this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))76 print "this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))77 print "this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))78 print "this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))69 print("this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))) 70 print("this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))) 71 print("this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))) 72 print("this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))) 73 print("this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))) 74 print("this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))) 75 print("this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))) 76 print("this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))) 77 print("this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))) 79 78 80 79
Note: See TracChangeset
for help on using the changeset viewer.