Changeset 1055 in lmdz_wrf for trunk/tools/nc_var_tools.py
- Timestamp:
- Aug 27, 2016, 10:43:17 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1054 r1055 16194 16194 # Gessing orgin of the file 16195 16195 dimsinfile = onc.dimensions.keys() 16196 varsinfile = onc.variables.keys() 16197 16196 16198 if gen.searchInlist(dimsinfile,'bottom_top'): 16197 16199 modname = 'WRF' … … 16220 16222 'lat', 'time_counter'] 16221 16223 MODvardims = ['lon', 'lat', 'time_counter'] 16224 elif gen.searchInlist(dimsinfile,'pres') and gen.searchInlist(varsinfile, \ 16225 'psol'): 16226 modname = 'cfLMDZ' 16227 print warnmsg 16228 print ' ' + fname + ": gessing that file '" + ncfile + "' comes from '" + \ 16229 modname + "' ('pres, time_counter' variables renamed as 'p, time') !!" 16230 16231 # Variables to interpolate 16232 MODdims = ['time', 'pres', 'lat', 'lon'] 16233 newMODdims = ['time', 'pres', 'lat', 'lon'] 16234 notCHK = [] 16235 MODvarrequired = ['p', 'psol', 'geop', 'phis', 'temp', 'ovap', 'lon', \ 16236 'lat', 'time'] 16237 MODvardims = ['lon', 'lat', 'time'] 16222 16238 else: 16223 16239 modname = 'CF' … … 16286 16302 CFdimvs = {'time': dimt, 'presnivs': dimz, 'lat': dimy, 'lon': dimx} 16287 16303 unstaggerDIM = 'lon' 16304 elif modname == 'cfLMDZ': 16305 ovar1 = onc.variables['p'] 16306 pres = ovar1[:].astype('float64') 16307 dimx = pres.shape[3] 16308 dimy = pres.shape[2] 16309 dimz = pres.shape[1] 16310 dimt = pres.shape[0] 16311 MODdimvs = {'time':dimt, 'pres':dimz, 'lat':dimy, 'lon': dimx} 16312 CFdimvs = {'time': dimt, 'pres': dimz, 'lat': dimy, 'lon': dimx} 16313 unstaggerDIM = 'lon' 16288 16314 else: 16289 16315 ovar1 = onc.variables['p'] … … 16301 16327 ovar1 = onc.variables['PSFC'] 16302 16328 psfc = ovar1[:].astype('float64') 16303 elif modname == 'LMDZ' :16329 elif modname == 'LMDZ' or modname == 'cfLMDZ': 16304 16330 ovar1 = onc.variables['psol'] 16305 16331 psfc = ovar1[:].astype('float64') … … 16317 16343 geop = np.zeros(tuple(unstg), dtype=np.float) 16318 16344 geop = 0.5*(geop0[:,1:dimz,:,:] + geop0[:,0:dimz-1,:,:]).astype('float64') 16319 elif modname == 'LMDZ' :16345 elif modname == 'LMDZ' or modname == 'cfLMDZ': 16320 16346 ovar1 = onc.variables['geop'] 16321 16347 geop = ovar1[:].astype('float64') … … 16328 16354 ovar1 = onc.variables['HGT'] 16329 16355 hgt = ovar1[0,:,:].astype('float64') 16330 elif modname == 'LMDZ' :16356 elif modname == 'LMDZ' or modname == 'cfLMDZ': 16331 16357 grav = 9.81 16332 16358 ovar1 = onc.variables['phis'] … … 16340 16366 ovar1 = onc.variables['QVAPOR'] 16341 16367 qv = ovar1[:].astype('float64') 16342 elif modname == 'LMDZ' :16368 elif modname == 'LMDZ' or modname == 'cfLMDZ': 16343 16369 ovar1 = onc.variables['ovap'] 16344 16370 qv = ovar1[:].astype('float64') … … 16355 16381 ovar1 = onc.variables['T'] 16356 16382 temp = ((ovar1[:]+300.)*(pres[:]/p0)**RCP).astype('float64') 16357 elif modname == 'LMDZ' :16383 elif modname == 'LMDZ' or modname == 'cfLMDZ': 16358 16384 ovar1 = onc.variables['temp'] 16359 16385 temp = ovar1[:].astype('float64') … … 16699 16725 ncvars = ncf.variables.keys() 16700 16726 16701 # # CFing dimension-variables 16702 # CFvardims = {'time_counter': 'time', 'presnivs': 'pres'} 16703 # for varn in CFvardims.keys(): 16704 # if gen.searchInlist(ncvars,varn): 16705 # # Making sure CF vardimension is not in the file 16706 # if not gen.searchInlist(ncvars,CFvardims[varn]): 16707 # newname = ncf.renameVariable(varn,CFvardims[varn]) 16708 16709 # ncf.sync() 16727 # CFing variable 'pres' 16728 if gen.searchInlist(ncvars,'pres'): 16729 print warnmsg 16730 print fname + ": renaming variable 'pres' as 'p' !!" 16731 newname = ncf.renameVariable('pres','p') 16732 ncf.sync() 16710 16733 16711 16734 # CFing dimensions … … 16716 16739 if not gen.searchInlist(ncdims,CFdims[dimn]): 16717 16740 newname = ncf.renameDimension(dimn,CFdims[dimn]) 16718 16719 16741 ncf.sync() 16720 16742 … … 16732 16754 16733 16755 ncf.sync() 16734 16735 16756 ncf.close() 16736 16757
Note: See TracChangeset
for help on using the changeset viewer.