Changeset 2711 in lmdz_wrf
- Timestamp:
- Sep 26, 2019, 3:08:03 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2710 r2711 123 123 # 360 days/yr (or 12 30-days months) calendar 124 124 # dtsec360dyr: Class to operate a number of seconds to a date in a 360 days/yr (or 12 30-days months) calendar 125 # equal_units: Function to provide the same units of two datasets 125 126 # files_folder_HMT: Function to retrieve a list of files from a folder [fold] and files with [head]*[middle]*[tail] 126 127 # fill_Narray: Function to fill a n-dimensional array with an arrary of lesser rank … … 17122 17123 return lu 17123 17124 17124 def e uqal_units(units1, units2):17125 def equal_units(units1, units2, vals2): 17125 17126 """ Function to provide the same units of two datasets 17126 17127 units1: units of reference (from units_lunits) 17127 """ 17128 units2: units to change 17129 >>> equal_units('$gkg^{-1}$','$kgkg^{-1}$', 0.023) 17130 ['mulc', 1000.0], 23.0 17131 >>> equal_units('$K$','$^{\circ}C$', 23) 17132 ['addc', 273.15], 296.15 17133 """ 17134 fname = 'equal_units' 17135 availunits = ['$gkg^{-1}$', 'K'] 17136 17137 if units1 == '$gkg^{-1}$': 17138 availunits1 = ['$kgkg^{-1}$'] 17139 if units2 == '$kgkg^{-1}$': factor = ['mulc', 1000.] 17140 else: 17141 print errormsg 17142 print ' ' + fname + ": for ref. units '" + units1 + "' not available '"+\ 17143 units2 + "' !!" 17144 print ' available ones:', availunits1 17145 quit() 17146 elif units1 == '$K$': 17147 availunits1 = ['$^{\circ}C$'] 17148 if units2 == '$^{\circ}C$': factor = ['addc', 273.15] 17149 else: 17150 print errormsg 17151 print ' ' + fname + ": for ref. units '" + units1 + "' not available '"+\ 17152 units2 + "' !!" 17153 print ' available ones:', availunits1 17154 quit() 17155 else: 17156 print errormsg 17157 print ' ' + fname + ": reference units '" + units1 + "' not available !!" 17158 print ' available ones:', availunits 17159 quit() 17160 17161 # Changing values 17162 if factor[0] == 'mulc': vals2 = vals2*factor[1] 17163 if factor[0] == 'addc': vals2 = vals2 + factor[1] 17164 17165 return factor, vals2 17128 17166 17129 17167 #quit()
Note: See TracChangeset
for help on using the changeset viewer.