Changeset 2810 in lmdz_wrf
- Timestamp:
- Apr 8, 2020, 9:45:23 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2807 r2810 256 256 # of time-steps for a whole period is multiple of a given number 257 257 # timefmt_timelab: Function to transform from C-like time format to general one 258 # truncate: Function to truncate a Float value to a certain decimal 258 259 # unitsdsDate: Function to know how many units of time are from a given pair of dates 259 260 # units_lunits: Function to provide LaTeX equivalences from a given units … … 14095 14096 return values 14096 14097 14098 def truncate(fv, decimals=7): 14099 """ Function to truncate a Float value to a certain decimal 14100 FROM: https://realpython.com/python-rounding/#truncation 14101 fv: float value 14102 decimals: decimals to which truncate (7, default) 14103 >>> truncate(np.pi) 14104 3.1415926 14105 >>> truncate(np.pi, decimals=3) 14106 3.141 14107 >>> truncate(np.pi, decimals=0) 14108 3.0 14109 >>> truncate(1./3., decimals=7) 14110 0.3333333 14111 """ 14112 fname = 'truncate' 14113 14114 multiplier = 10. ** decimals 14115 tfv = int(fv * multiplier) / multiplier 14116 14117 return int(fv * multiplier) / multiplier 14118 14097 14119 def angle_DegMinSec(angle): 14098 14120 """ Function to transform an angle to Degrees Minutes Seconds 14099 14121 angle= decimal angle to transform 14100 14122 >>> angle_DegMinSec(3.98765) 14101 3 5915.5414123 3, 59, 15.54 14102 14124 >>> angle_DegMinSec(-23.0025) 14103 -23 09.014125 -23, 0, 9.0 14104 14126 """ 14105 14127 fname = 'angle_DegMinSec' … … 14108 14130 minv = int((abs(angle) - degv*1.)*60.) 14109 14131 secv = (abs(angle) - degv*1. - minv/60.)*3600. 14132 14133 if secv < 1.e-8: secv = 0. 14110 14134 14111 14135 if angle < 0.: … … 14113 14137 else: 14114 14138 return degv, minv, secv 14139 14140 print angle_DegMinSec(49.1) 14141 print angle_DegMinSec(3.98765) 14142 quit() 14115 14143 14116 14144 def DegMinSec_angle(degv, minv, secv): … … 17568 17596 return newlist 17569 17597 17570 #quit()17571 17572
Note: See TracChangeset
for help on using the changeset viewer.