Changeset 1053 in lmdz_wrf
- Timestamp:
- Aug 27, 2016, 9:34:32 AM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r1050 r1053 18 18 ## e.g. # nc_var.py -o LMDZ_toCF -f LMDZ/AR40/vas_histins_1-1.nc 19 19 ## e.g. # nc_var.py -o pinterp -f wrfout_d01_2001-11-11_00\:00\:00 -S 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.,1,0 -v WRFt,WRFrh 20 ## e.g. # nc_var.py -o pinterp -f /media/ExtDiskC_ext4/DATA/etudes/WRF_LMDZ/WaquaL_highres/short_copies/LMDZ/AR40/histins_19790101000000-19790304000000_short.nc -S 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.,1,0 -v temp,ovap 20 21 21 22 from optparse import OptionParser -
trunk/tools/nc_var_tools.py
r1050 r1053 16187 16187 16188 16188 CFdims = ['time', 'pres', 'lat', 'lon'] 16189 # Just in case there are weird units, attribute value will be taken from input file 16190 CFattrs = ['standard_name', 'long_name'] 16189 16191 16190 16192 onc = NetCDFFile(ncfile, 'r') … … 16205 16207 'XLONG', 'XLAT', 'Times'] 16206 16208 MODvardims = ['XLONG', 'XLAT', 'Times'] 16209 elif gen.searchInlist(dimsinfile,'presnivs'): 16210 modname = 'LMDZ' 16211 print warnmsg 16212 print ' ' + fname + ": gessing that file '" + ncfile + "' comes from '" + \ 16213 modname + "' !!" 16214 16215 # Variables to interpolate 16216 MODdims = ['time_counter', 'presnivs', 'lat', 'lon'] 16217 newMODdims = ['time_counter', 'pres', 'lat', 'lon'] 16218 notCHK = [] 16219 MODvarrequired = ['pres', 'psol', 'geop', 'phis', 'temp', 'ovap', 'lon', \ 16220 'lat', 'time_counter'] 16221 MODvardims = ['lon', 'lat', 'time_counter'] 16207 16222 16208 16223 varns = gen.str_list(variables, ',') … … 16229 16244 if not gen.searchInlist(onc.variables, var): 16230 16245 print errormsg 16231 print ' ' + fname + ": file '" + ncfile + "' does not have variable '" +\16232 var + "' !!"16246 print ' ' + fname + ": file '" + ncfile + "' does not have required " + \ 16247 "variable '" + var + "' !!" 16233 16248 quit(-1) 16234 16249 … … 16249 16264 CFdimvs = {'time': dimt, 'bottom_top': dimz, 'lat': dimy, 'lon': dimx} 16250 16265 unstaggerDIM = 'west_east' 16266 elif modname == 'LMDZ': 16267 ovar1 = onc.variables['pres'] 16268 pres = ovar1[:].astype('float64') 16269 dimx = pres.shape[3] 16270 dimy = pres.shape[2] 16271 dimz = pres.shape[1] 16272 dimt = pres.shape[0] 16273 MODdimvs = {'time_counter':dimt, 'presnivs':dimz, 'lat':dimy, 'lon': dimx} 16274 CFdimvs = {'time': dimt, 'presnivs': dimz, 'lat': dimy, 'lon': dimx} 16275 unstaggerDIM = 'lon' 16251 16276 16252 16277 # sfc pressure 16253 16278 if modname == 'WRF': 16254 16279 ovar1 = onc.variables['PSFC'] 16280 psfc = ovar1[:].astype('float64') 16281 elif modname == 'LMDZ': 16282 ovar1 = onc.variables['psol'] 16255 16283 psfc = ovar1[:].astype('float64') 16256 16284 … … 16264 16292 geop = np.zeros(tuple(unstg), dtype=np.float) 16265 16293 geop = 0.5*(geop0[:,1:dimz,:,:] + geop0[:,0:dimz-1,:,:]).astype('float64') 16294 elif modname == 'LMDZ': 16295 ovar1 = onc.variables['geop'] 16296 geop = ovar1[:].astype('float64') 16266 16297 16267 16298 # terrain height … … 16269 16300 ovar1 = onc.variables['HGT'] 16270 16301 hgt = ovar1[0,:,:].astype('float64') 16302 elif modname == 'LMDZ': 16303 grav = 9.81 16304 ovar1 = onc.variables['phis'] 16305 hgt = (ovar1[0,:,:]/grav).astype('float64') 16271 16306 16272 16307 # water vapour mixing ratio 16273 16308 if modname == 'WRF': 16274 16309 ovar1 = onc.variables['QVAPOR'] 16310 qv = ovar1[:].astype('float64') 16311 elif modname == 'LMDZ': 16312 ovar1 = onc.variables['ovap'] 16275 16313 qv = ovar1[:].astype('float64') 16276 16314 … … 16283 16321 ovar1 = onc.variables['T'] 16284 16322 temp = ((ovar1[:]+300.)*(pres[:]/p0)**RCP).astype('float64') 16323 elif modname == 'LMDZ': 16324 ovar1 = onc.variables['temp'] 16325 temp = ovar1[:].astype('float64') 16285 16326 16286 16327 onewnc = NetCDFFile(ofile, 'w') … … 16291 16332 newdim = onewnc.createDimension('pres', len(interplevs)) 16292 16333 newdim = onewnc.createDimension('Time', None) 16334 elif modname == 'LMDZ': 16335 newdim = onewnc.createDimension('lon', dimx) 16336 newdim = onewnc.createDimension('lat', dimy) 16337 newdim = onewnc.createDimension('pres', len(interplevs)) 16338 newdim = onewnc.createDimension('time_counter', None) 16293 16339 16294 16340 # Creation of variable dimensions … … 16356 16402 newvarattr['long_name'] = varattrs[4].replace('|',' ') 16357 16403 newvarattr['units'] = varattrs[5] 16358 elif not gen.searchInlist(MODvarrequired, vn) or vn == 'QVAPOR': 16404 elif vn == 'pres': 16405 varin = pres 16406 isgeop = False 16407 varattrs = gen.variables_values('pres') 16408 CFvn = varattrs[0] 16409 newvarattr['standard_name'] = varattrs[1] 16410 newvarattr['long_name'] = varattrs[4].replace('|',' ') 16411 newvarattr['units'] = varattrs[5] 16412 # elif not gen.searchInlist(MODvarrequired, vn) or vn == 'QVAPOR': 16413 else: 16359 16414 ovarin = onc.variables[vn] 16360 16415 varinf = variable_inf(ovarin) … … 16393 16448 16394 16449 for attrn in newvarattr.keys(): 16395 attr = set_attribute(newvar, attrn, newvarattr[attrn]) 16450 if attrn != '_FillValue' and not gen.searchInlist(CFattrs, attrn): 16451 attr = set_attribute(newvar, attrn, newvarattr[attrn]) 16396 16452 onewnc.sync() 16397 16453
Note: See TracChangeset
for help on using the changeset viewer.