Changeset 2730 in lmdz_wrf
- Timestamp:
- Oct 25, 2019, 5:00:12 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2728 r2730 172 172 # list_coincidences: Function to provide the coincidences between two lists 173 173 # list_differences: Function to provide the differences between two lists 174 # list_listKs: Function to provide a new list transforming the values from a given list by 175 # a list of type of values 174 176 # list_norepeatcombos: Function to all possible (Num-1)-combinations of a Num values without repetitions 175 177 # lstring_values: Function to provide a new list-string from a string which is a list of word separated by a character if some values are repeated they are not included … … 253 255 # units_lunits: Function to provide LaTeX equivalences from a given units 254 256 # vals_around: Function to provide the 3x3 values around a given j,i point 257 # variables_values: Function to provide values to plot the different variables values from ASCII file 258 # 'variables_values.dat' 255 259 # xtrm_nx: Function to provide the extreme (a percentage above min,max) of a series of values 256 260 # WRF_percenlevels: Function to compute eta-levels for WRF following a percentage distribution … … 5850 5854 if typeval == 'int' or typeval == 'I': 5851 5855 return int(value) 5856 if typeval == 'float-int' or typeval == 'F-I': 5857 return int(np.float(value)) 5852 5858 elif typeval == 'long': 5853 5859 return long(value) … … 17215 17221 return gamma 17216 17222 17223 def list_listKs(inlist, Klist): 17224 """ Function to provide a new list transforming the values from a given list by 17225 a list of type of values 17226 inlist: input list 17227 Klist: list of types of values to consecutively transform each value of the list 17228 'S': String 17229 'I': Integer 17230 'F': Float 17231 'D': Double float 17232 'B': Bolean 17233 >>> list_listKs(['2.2333', 'Hola', '231.21', '231.21'], ['F', 'S', 'I', 'D']) 17234 [2.2333, 'Hola', 231, 231.21000000000001] 17235 """ 17236 fname = 'list_listKs' 17237 17238 Nin = len(inlist) 17239 NK = len(Klist) 17240 if Nin != NK: 17241 print errormsg 17242 print ' ' + fname + ': number of values in list ', Nin, 'and ' + \ 17243 'number of types to transform to', NK, 'do not coincide !!' 17244 print ' passed values _______' 17245 if Nin > NK: 17246 for iv in range(NK): 17247 print iv, ':', inlist[iv], Klist[iv] 17248 print 'exceeded inlist', inlist[NK:Nin] 17249 else: 17250 for iv in range(Nin): 17251 print iv, ':', inlist[iv], Klist[iv] 17252 print 'exceeded Klist', Klist[Nin:NK] 17253 quit(-1) 17254 17255 newlist = [] 17256 for iv in range(Nin): newlist.append(typemod(inlist[iv], Klist[iv])) 17257 17258 return newlist 17259 17260 print list_listKs(['2.2333', 'Hola', '231.21', '231.21'], ['F', 'S', 'F-I', 'D']) 17261 17262 quit() 17263 17264 def stations_values(stcrit,stval): 17265 """ Function to provide information from a given station from one of its values 17266 from ASCII file 'OBStations.csv' 17267 variables_values([values]) 17268 [stcrit]: name of the criteria from OBStations.csv 17269 one of: 'WMOid', 'station_name', 'longitude', 'latitude', 'lon_deg', 17270 'lon_min', 'lon_sec', 'lat_deg', 'lat_min', 'lat_sec', 'height', 'country', 17271 'prov', 'nice_name', 'add1', 'add2' 17272 [WMOid]: WMO id value 17273 [station_name]: station raw name 17274 [longitude]: longitude of the station in degrees 17275 [latitude]: latitude of the stations in degrees 17276 [lon_deg]: longitude degree of the station 17277 [lon_min]: longitude minute of the station 17278 [lon_sec]: longitude second of the station 17279 [lat_deg]: latitude degree of the station 17280 [lat_min]: latitude mniute of the station 17281 [lat_sec]: latitude second of the station 17282 [height]: height of the station 17283 [country]: country of the station 17284 [prov]: province/state/... 17285 [nice_name]: Complete nice name of the station 17286 [add1]: additional value 1 17287 [add2]: additional value 2 17288 [stval]: value of [stcrit] to be matched 17289 return: [WMOid], [station_name], [longitude], [latitude], [lon_deg], 17290 [lon_min], [lon_sec], [lat_deg], [lat_min], [lat_sec], [height], [country], 17291 [prov], [nice_name], [add1], [add2] 17292 >>> variables_values('WMOid','87582') 17293 17294 """ 17295 import subprocess as sub 17296 fname='stations_values' 17297 17298 criteriavail = ['WMOid', 'station_name', 'longitude', 'latitude', 'lon_deg', \ 17299 'lon_min', 'lon_sec', 'lat_deg', 'lat_min', 'lat_sec', 'height', 'country',\ 17300 'prov', 'nice_name', 'add1', 'add2'] 17301 17302 if stcrit == 'h': 17303 print fname + '_____________________________________________________________' 17304 print stations_values.__doc__ 17305 quit() 17306 17307 folder = os.path.dirname(os.path.realpath(__file__)) 17308 17309 infile = folder + '/OBSstations.csv' 17310 17311 if not os.path.isfile(infile): 17312 print errormsg 17313 print ' ' + fname + ": File '" + infile + "' does not exist !!" 17314 quit(-1) 17315 17316 ifst = False 17317 17318 ncf = open(infile, 'r') 17319 17320 if not searchInlist(criteriavail,stcrit): 17321 print errormsg 17322 print ' ' + fname + ": criteria '" + stcrit + "' not available !!" 17323 print ' available ones:', criteriavail 17324 quit(-1) 17325 icrit = criteriavail.index(stcrit) 17326 stations = {} 17327 Nst = 0 17328 for line in ncf: 17329 if line[0:1] != '#' and len(line) > 10: 17330 values = line.replace('\n','').split(',') 17331 if len(values) != 16: 17332 print errormsg 17333 print "problem in station: '", values[0], \ 17334 ' it should have 16 values and it has', len(values) 17335 quit(-1) 17336 17337 if values[icrit] == stval: 17338 stations[Nst] = [int(values[0]), values[1]] 17339 17340 print errormsg 17341 print ' ' + fname + ": variable '" + varn + "' not defined !!!" 17342 ncf.close() 17343 quit(-1) 17344 17345 return 17346 17217 17347 #quit() 17218 17348
Note: See TracChangeset
for help on using the changeset viewer.