Changeset 2306 in lmdz_wrf for trunk/tools
- Timestamp:
- Jan 31, 2019, 2:20:35 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2298 r2306 61 61 # all_consecutive_combs: Function to provide all the consecutive possible 62 62 # combinations from a series of indices 63 # almost_zero: Function to provide if two real values are the same up to certain power 63 64 # angle_DegMinSec: Function to transform an angle to Degrees Minutes Seconds 64 65 # ASCIIfile_stats: Function to provide the statistics of a series of values from an ASCII file … … 15078 15079 return newarray, newdims 15079 15080 15081 def almost_zero(val1, val2, powv): 15082 """ Function to provide if two real values are the same up to certain power 15083 val1, val2: values to compare 15084 powv: power to use to determine zero (as decimal) 15085 >>> almost_zero(1.12345, 1.12346, 3) 15086 True 15087 >>> almost_zero(1.12345, 1.12346, 6) 15088 False 15089 """ 15090 fname = 'almost_zero' 15091 15092 pot = 10.**powv 15093 15094 diff = val1 - val2 15095 adiff = np.abs(diff) 15096 idiff = int(adiff*pot) 15097 15098 fdiff = idiff/pot 15099 15100 iszero = np.abs(fdiff - diff) < 1./pot 15101 print diff, idiff, fdiff, np.abs(fdiff - diff), ':', 1./pot 15102 15103 return iszero 15104 15080 15105 #quit() 15081 15106
Note: See TracChangeset
for help on using the changeset viewer.