Changeset 1815 in lmdz_wrf for trunk/tools/nc_var_tools.py
- Timestamp:
- Mar 19, 2018, 6:36:13 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1811 r1815 180 180 else: 181 181 isFR64 = False 182 print 'Lluis oneRK:', type(fdef.module_definitions.onerk), 'isFR64:', isFR64183 182 184 183 ## Constants … … 18085 18084 gen.check_arguments(fname, values, arguments, ',') 18086 18085 18087 interplevs = np.array(values.split(',')[0].split(':'), dtype=np.float64) 18086 if isFR64: 18087 interplevs = np.array(values.split(',')[0].split(':'), dtype=np.float64) 18088 else: 18089 interplevs = np.array(values.split(',')[0].split(':'), dtype=np.float) 18088 18090 linloginterp = np.int32(values.split(',')[1]) 18089 18091 extrap = np.int32(values.split(',')[2]) … … 18191 18193 pres = pres0.astype('float64') 18192 18194 else: 18193 pres = pres0. astype('float')18195 pres = pres0.copy() 18194 18196 18195 18197 dimx = pres.shape[3] … … 18206 18208 pres = ovar1[:].astype('float64') 18207 18209 else: 18208 pres = ovar1[:] .astype('float')18210 pres = ovar1[:] 18209 18211 dimx = pres.shape[3] 18210 18212 dimy = pres.shape[2] … … 18219 18221 pres = ovar1[:].astype('float64') 18220 18222 else: 18221 pres = ovar1[:] .astype('float')18223 pres = ovar1[:] 18222 18224 dimx = pres.shape[3] 18223 18225 dimy = pres.shape[2] … … 18232 18234 pres = ovar1[:].astype('float64') 18233 18235 else: 18234 pres = ovar1[:] .astype('float')18236 pres = ovar1[:] 18235 18237 dimx = pres.shape[3] 18236 18238 dimy = pres.shape[2] … … 18249 18251 psfc = ovar1[:].astype('float64') 18250 18252 else: 18251 psfc = ovar1[:] .astype('float')18253 psfc = ovar1[:] 18252 18254 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18253 18255 ovar1 = onc.variables['psol'] … … 18255 18257 psfc = ovar1[:].astype('float64') 18256 18258 else: 18257 psfc = ovar1[:] .astype('float')18259 psfc = ovar1[:] 18258 18260 else: 18259 18261 ovar1 = onc.variables['ps'] … … 18261 18263 psfc = ovar1[:].astype('float64') 18262 18264 else: 18263 psfc = ovar1[:] .astype('float')18265 psfc = ovar1[:] 18264 18266 18265 18267 # geopotential height … … 18270 18272 unstg = list(geop0.shape) 18271 18273 unstg[1] = unstg[1] - 1 18272 geop = np.zeros(tuple(unstg), dtype=np.float)18273 18274 if isFR64: 18275 geop = np.zeros(tuple(unstg), dtype=np.float64) 18274 18276 geop = 0.5*(geop0[:,1:dimz+1,:,:] + geop0[:,0:dimz,:,:]).astype('float64') 18275 18277 else: 18276 geop = 0.5*(geop0[:,1:dimz+1,:,:] + geop0[:,0:dimz,:,:]).astype('float') 18278 geop = np.zeros(tuple(unstg), dtype=np.float) 18279 geop = 0.5*(geop0[:,1:dimz+1,:,:] + geop0[:,0:dimz,:,:]) 18277 18280 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18278 18281 ovar1 = onc.variables['geop'] … … 18280 18283 geop = ovar1[:].astype('float64') 18281 18284 else: 18282 geop = ovar1[:] .astype('float')18285 geop = ovar1[:] 18283 18286 else: 18284 18287 ovar1 = onc.variables['z'] … … 18286 18289 geop = ovar1[:].astype('float64') 18287 18290 else: 18288 geop = ovar1[:] .astype('float')18291 geop = ovar1[:] 18289 18292 18290 18293 # terrain height … … 18294 18297 hgt = ovar1[0,:,:].astype('float64') 18295 18298 else: 18296 hgt = ovar1[0,:,:] .astype('float')18299 hgt = ovar1[0,:,:] 18297 18300 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18298 18301 grav = 9.81 … … 18301 18304 hgt = (ovar1[0,:,:]/grav).astype('float64') 18302 18305 else: 18303 hgt = (ovar1[0,:,:]/grav) .astype('float')18306 hgt = (ovar1[0,:,:]/grav) 18304 18307 else: 18305 18308 ovar1 = onc.variables['orog'] … … 18307 18310 hgt = ovar1[:].astype('float64') 18308 18311 else: 18309 hgt = ovar1[:] .astype('float')18312 hgt = ovar1[:] 18310 18313 18311 18314 # water vapour mixing ratio … … 18315 18318 qv = ovar1[:].astype('float64') 18316 18319 else: 18317 qv = ovar1[:] .astype('float')18320 qv = ovar1[:] 18318 18321 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18319 18322 ovar1 = onc.variables['ovap'] … … 18321 18324 qv = ovar1[:].astype('float64') 18322 18325 else: 18323 qv = ovar1[:] .astype('float')18326 qv = ovar1[:] 18324 18327 else: 18325 18328 ovar1 = onc.variables['hus'] … … 18327 18330 qv = ovar1[:].astype('float64') 18328 18331 else: 18329 qv = ovar1[:] .astype('float')18332 qv = ovar1[:] 18330 18333 18331 18334 # temperature 18332 18335 if modname == 'WRF': 18333 Rd = np.float64(287.04) 18334 Cp = np.float64(7.*Rd/2.) 18335 RCP = np.float64(Rd/Cp) 18336 p0 = np.float64(100000.) 18336 if isFR64: 18337 Rd = np.float64(287.04) 18338 Cp = np.float64(7.*Rd/2.) 18339 RCP = np.float64(Rd/Cp) 18340 p0 = np.float64(100000.) 18341 else: 18342 Rd = 287.04 18343 Cp = 7.*Rd/2. 18344 RCP = Rd/Cp 18345 p0 = 100000. 18337 18346 ovar10 = onc.variables['T'] 18338 18347 var10 = ovar10[:] … … 18340 18349 ovar1 = (var10).astype('float64') 18341 18350 else: 18342 ovar1 = (var10).astype('float')18351 ovar1 = var10[:] 18343 18352 temp0 = (ovar1[:]+300.)*(pres[:]/p0)**RCP 18344 18353 if isFR64: 18345 18354 temp = temp0.astype('float64') 18346 18355 else: 18347 temp = temp0. astype('float')18356 temp = temp0.copy() 18348 18357 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18349 18358 ovar1 = onc.variables['temp'] … … 18351 18360 temp = ovar1[:].astype('float64') 18352 18361 else: 18353 temp = ovar1[:] .astype('float')18362 temp = ovar1[:] 18354 18363 else: 18355 18364 ovar1 = onc.variables['ta'] … … 18357 18366 temp = ovar1[:].astype('float64') 18358 18367 else: 18359 temp = ovar1[:].astype('float') 18360 18368 temp = ovar1[:] 18369 18370 print ' ' + fname + ": Opening output file 'pinterp.nc'" 18361 18371 onewnc = NetCDFFile(ofile, 'w') 18362 18372 # Creation of dimensions … … 18446 18456 print ' ' + fname + ': De-staggering x-wind variable !!' 18447 18457 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx) 18448 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float64) 18449 varin[:] = 0.5*(ovarin[:,:,:,0:dimx] + ovarin[:,:,:,1:dimx+1]) 18458 if isFR64: 18459 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float64) 18460 else: 18461 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float) 18462 # Not pro, but less memory problems! 18463 for it in range(dimt): 18464 varin[it,:,::] = 0.5*(ovarin[it,:,:,0:dimx] + ovarin[it,:,:,1:dimx+1]) 18450 18465 isgeop = False 18451 18466 varattrs = gen.variables_values('ua') … … 18459 18474 print ' ' + fname + ': De-staggering y-wind variable !!' 18460 18475 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx) 18461 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float64) 18476 if isFR64: 18477 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float64) 18478 else: 18479 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float) 18462 18480 varin[:] = 0.5*(ovarin[:,:,0:dimy,:] + ovarin[:,:,1:dimy+1,:]) 18463 18481 isgeop = False … … 18513 18531 tini = itt 18514 18532 tend = itt + dimtfrac 18515 varint = varin[tini:tend,:,:,:].transpose() 18516 prest = pres[tini:tend,:,:,:].transpose() 18517 psfct = psfc[tini:tend,:,:].transpose() 18518 hgtt = hgt.transpose() 18519 tempt = temp[tini:tend,:,:,:].transpose() 18520 qvt = qv[tini:tend,:,:,:].transpose() 18521 18522 varinterp = fin.module_forinterpolate.interp( data_in=varint, \ 18523 pres_field=prest, interp_levels=interplevs, psfc=psfct, \ 18524 ter=hgtt, tk=tempt, qv=qvt, linlog=linloginterp, \ 18525 extrapolate=extrap, geopt=isgeop, missing=gen.fillValueF) 18526 newvar[tini:tend,:,:,:] = varinterp.transpose() 18533 if np.prod([tend-tini+1, dimz, dimx, dimy]) > 150*150*39: 18534 dimyfrac = 50 18535 print warnmsg 18536 print ' ' + fname + ': variable to interpolate:', varin.shape, \ 18537 'too big!!' 18538 print ' p-interpolation will be done by yaxis-slices of 10 grid-points' 18539 print range(0,dimyfrac*int(dimy/dimyfrac),dimyfrac) 18540 for iyy in range(0,dimyfrac*int(dimy/dimyfrac),dimyfrac): 18541 yini = iyy 18542 yend = iyy + dimyfrac 18543 varint = varin[tini:tend,:,yini:yend,:].transpose() 18544 prest = pres[tini:tend,:,yini:yend,:].transpose() 18545 psfct = psfc[tini:tend,yini:yend,:].transpose() 18546 hgtt = hgt[yini:yend,:].transpose() 18547 tempt = temp[tini:tend,:,yini:yend,:].transpose() 18548 qvt = qv[tini:tend,:,yini:yend,:].transpose() 18549 Nplevs = len(interplevs) 18550 Ndt = len(range(tini,tend)) 18551 Ndy = len(range(yini,yend)) 18552 print 'Lluis before!!!!' 18553 varinterp = fin.module_forinterpolate.interp( data_in=varint,\ 18554 pres_field=prest, interp_levels=interplevs, psfc=psfct, \ 18555 ter=hgtt, tk=tempt, qv=qvt, linlog=linloginterp, \ 18556 extrapolate=extrap, geopt=isgeop, missing=gen.fillValueF, \ 18557 ix=dimx, iy=Ndy, iz=dimz, it=Ndt, num_metgrid_levels=Nplevs) 18558 print 'Lluis done!!!!' 18559 newvar[tini:tend,:,yini:yend,:] = varinterp.transpose() 18560 else: 18561 varint = varin[tini:tend,:,:,:].transpose() 18562 prest = pres[tini:tend,:,:,:].transpose() 18563 psfct = psfc[tini:tend,:,:].transpose() 18564 hgtt = hgt.transpose() 18565 tempt = temp[tini:tend,:,:,:].transpose() 18566 qvt = qv[tini:tend,:,:,:].transpose() 18567 Nplevs = len(interplevs) 18568 Ndt = len(range(tini,tend)) 18569 print 'Lluis before!!!!' 18570 varinterp = fin.module_forinterpolate.interp( data_in=varint, \ 18571 pres_field=prest, interp_levels=interplevs, psfc=psfct, \ 18572 ter=hgtt, tk=tempt, qv=qvt, linlog=linloginterp, \ 18573 extrapolate=extrap, geopt=isgeop, missing=gen.fillValueF, \ 18574 ix=dimx, iy=dimy, iz=dimz, it=Ndt, num_metgrid_levels=Nplevs) 18575 print 'Lluis done!!!!' 18576 newvar[tini:tend,:,:,:] = varinterp.transpose() 18527 18577 18528 18578 if dimtfrac != dimt and tend != dimt-1:
Note: See TracChangeset
for help on using the changeset viewer.