Changeset 1462 in lmdz_wrf for trunk/tools
- Timestamp:
- Mar 4, 2017, 7:01:07 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1454 r1462 47 47 # auto_val: Function to provide a value following an 'auto' configuration 48 48 # Capturing: Class to capture the standard output from a function 49 # CF_gribequiv: Function to provide the GRIB variable code number from a CF name 49 50 # CFmonthU_daysU: Function to transform from a CF date series with units as 'months since [DATE]' to 'days since [DATE]' 50 51 # CFvar_DIAGvar: Function to provide which model diagnostic values can provide a CF-variable from ASCII file … … 74 75 # get_configuration: Function to get the configuration from an ASCII external file 75 76 # get_specdictionary_HMT: Function to get specific values from a dictionary by selcting that keys with H*M*T 77 # grib_CFequiv: Function to provide the CF name of a GRIB variable code number 76 78 # ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box 77 79 # incomming_flow: Function to determine if a fgrid-flow inflows to the central grid point … … 11363 11365 return timelab 11364 11366 11367 def grib_CFequiv(gribcode, table): 11368 """ Function to provide the CF name of a GRIB variable code number 11369 gridcode= grib number to search for the reference 11370 table= gribd table reference 11371 returns list with [CFname], [GRistdbname], [Griblong_name], [Gribunits]] 11372 >>> grib_CFequiv(129, '128ECMWF') 11373 ['z', 'Z', 'Geopotential', 'm2s-2'] 11374 """ 11375 fname = 'grib_CFequiv' 11376 11377 availtables = ['128ECMWF'] 11378 11379 if table == '128ECMWF': 11380 # Source: https://rda.ucar.edu/cgi-bin/transform?xml=/metadata/ParameterTables/WMO_GRIB1.98-0.128.xml&view=gribdoc 11381 11382 gribCF = {129: ['z', 'z', 'Geopotential', 'm2 s-2'], \ 11383 130: ['ta', 't', 'Temperature', 'K'], \ 11384 131: ['ua', 'u', 'U velocity', 'm s-1'], \ 11385 132: ['va', 'v', 'U velocity', 'm s-1'], \ 11386 157: ['hur', 'r', 'Relative humidity', '%']} 11387 11388 else: 11389 print errormsg 11390 print ' ' + fname + ": grib table '" + table + "' not ready !!" 11391 print ' available ones:', availtables 11392 quit(-1) 11393 11394 if not gribCF.has_key(gribcode): 11395 print errormsg 11396 print ' ' + fname + ": table '" + table + "' does not have grib code :", \ 11397 gribcode, '!!' 11398 print ' available ones:', gribCF.keys() 11399 quit(-1) 11400 11401 CFname = gribCF[gribcode] 11402 11403 return CFname 11404 11405 def CF_gribequiv(CFname, table): 11406 """ Function to provide the GRIB variable code number from a CF name 11407 CFname= CF-variable name 11408 table= gribd table reference 11409 >>> CF_gribequiv('ua', '128ECMWF') 11410 [131, 'U', 'U velocity', 'm s-1'] 11411 """ 11412 fname = 'CF_gribequiv' 11413 11414 availtables = ['128ECMWF'] 11415 11416 if table == '128ECMWF': 11417 # Source: https://rda.ucar.edu/cgi-bin/transform?xml=/metadata/ParameterTables/WMO_GRIB1.98-0.128.xml&view=gribdoc 11418 gribCF = {129: ['z', 'z', 'Geopotential', 'm2 s-2'], \ 11419 130: ['ta', 't', 'Temperature', 'K'], \ 11420 131: ['ua', 'u', 'U velocity', 'm s-1'], \ 11421 132: ['va', 'v', 'U velocity', 'm s-1'], \ 11422 157: ['hur', 'r', 'Relative humidity', '%']} 11423 11424 else: 11425 print errormsg 11426 print ' ' + fname + ": grib table '" + table + "' not ready !!" 11427 print ' available ones:', availtables 11428 quit(-1) 11429 11430 # Inverting dictionaries (no need to hand write two dictionaries!) 11431 # For single values 11432 # FROM: http://stackoverflow.com/questions/483666/python-reverse-invert-a-mapping 11433 # CFgrib = dict((gribCF[k], k) for k in gribCF) 11434 CFgrib = {} 11435 for kv in gribCF.keys(): 11436 vals = gribCF[kv] 11437 newkv = vals[0] 11438 vals[0] = kv 11439 CFgrib[newkv] = vals 11440 11441 if not CFgrib.has_key(CFname): 11442 print errormsg 11443 print ' ' + fname + ": table '" + table + "' does not have CF name :" + \ 11444 CFname + "' !!" 11445 print ' available ones:', CFgrib.keys() 11446 quit(-1) 11447 11448 gribcode = CFgrib[CFname] 11449 11450 return gribcode 11451 11365 11452 #quit()
Note: See TracChangeset
for help on using the changeset viewer.