- Timestamp:
- Dec 27, 2018, 10:05:14 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r2271 r2272 68 68 ## e.g. # nc_var.py -o dimrename -f /media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out_irene/simcdx_vars_cape_120lev_cdxwrf2.nc -S Time -v time0 69 69 ## e.g. # nc_var.py -o area_weighted -f 'reference_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1,get_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1' -S 'yes:min,max,mean,stddev,count' -v ct_values,xband_values,box_values,mosaic_values 70 ## e.g. # nc_var.py -o area_weighted -f '/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA150k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1,/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA50k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1' -S 'no:mean' -v HGT_M 70 71 71 72 from optparse import OptionParser -
trunk/tools/nc_var_tools.py
r2271 r2272 27179 27179 return 27180 27180 27181 def compute_WRFbnds(lonu, latu, lonv, latv): 27182 """ Function to compute vertices of the cells using WRF 'XLONG_[U/V]', 'XLAT_[U/V]' 27183 lonu: longitudes on the u-staggered matrix 27184 latu: latitudes on the u-staggered matrix 27185 lonv: longitudes on the v-staggered matrix 27186 latv: latitudes on the v-staggered matrix 27187 """ 27188 fname = 'compute_WRFbnds' 27189 27190 dx = lonv.shape[1] 27191 dy = lonu.shape[0] 27192 sdx = lonu.shape[1] 27193 sdy = lonv.shape[0] 27194 27195 lonbnds = np.zeros((4, dy, dx), dtype=np.float) 27196 latbnds = np.zeros((4, dy, dx), dtype=np.float) 27197 27198 for j in range(dy-1): 27199 lonbnds[0,j,:] = 0.5*(lonu[j,0:sdx-1]+lonu[j+1,0:sdx-1]) 27200 lonbnds[1,j,:] = 0.5*(lonu[j,1:sdx]+lonu[j+1,1:sdx]) 27201 lonbnds[2,j,:] = 0.5*(lonu[j-1,1:sdx]+lonu[j,1:sdx]) 27202 lonbnds[3,j,:] = 0.5*(lonu[j-1,0:sdx-1]+lonu[j,0:sdx-1]) 27203 27204 for i in range(dx-1): 27205 latbnds[0,:,i] = 0.5*(latv[1:sdy,i-1]+latv[1:sdy,i]) 27206 latbnds[1,:,i] = 0.5*(latv[1:sdy,i]+latv[1:sdy,i+1]) 27207 latbnds[2,:,i] = 0.5*(latv[0:sdy-1,i]+latv[0:sdy-1,i+1]) 27208 latbnds[3,:,i] = 0.5*(latv[0:sdy-1,i-1]+latv[0:sdy-1,i]) 27209 27210 return lonbnds, latbnds 27211 27181 27212 def area_weighted(values, ncfiles, variable): 27182 27213 """ Function to provide an area weighted statistics within two different values … … 27204 27235 [dimxn]: name of the dimension along the x-axis 27205 27236 [varxn]: name of the variable with the values of dimxn 27206 [varxbndsn]: name of the variable with the bounds of the values of varxn 27237 [varxbndsn]: name of the variable with the bounds of the values of varxn 27238 ('WRFxbnds' to be computed from WRF output using XLONG_[U/V], XLAT_[U/V]) 27207 27239 [dimyn]: name of the dimension along the y-axis 27208 27240 [varyn]: name of the variable with the values of dimyn 27209 27241 [varybndsn]: name of the variable with the bounds of the values of varyn 27242 ('WRFybnds' to be computed from WRF output using XLONG_[U/V], XLAT_[U/V]) 27210 27243 [slicedim]: series of values to define the slicing of the variable 27211 27244 * [integer]: which value of the dimension … … 27309 27342 quit(-1) 27310 27343 27311 if not oncref.variables.has_key(refvarxbndsn): 27344 if refvarxbndsn != 'WRFxbnds' and \ 27345 not oncref.variables.has_key(refvarxbndsn): 27312 27346 print errormsg 27313 27347 print ' ' + fname + ": reference file '" + netcdfrefn + "' does " + \ … … 27336 27370 quit(-1) 27337 27371 27338 if not oncref.variables.has_key(refvarybndsn): 27372 if refvarybndsn != 'WRFybnds' and \ 27373 not oncref.variables.has_key(refvarybndsn): 27339 27374 print errormsg 27340 27375 print ' ' + fname + ": reference file '" + netcdfrefn + "' does " + \ … … 27347 27382 slicedict = {refdimxn: slicedimx, refdimyn: slicedimy} 27348 27383 ovarx = oncref.variables[refvarxn] 27349 ovarxbnds = oncref.variables[refvarxbndsn]27350 27384 ovary = oncref.variables[refvaryn] 27351 ovarybnds = oncref.variables[refvarybndsn]27352 27353 27385 srefvarx, dims = SliceVarDict(ovarx,slicedict) 27354 srefvarbndsx, dims = SliceVarDict(ovarxbnds,slicedict)27355 27386 srefvary, dims = SliceVarDict(ovary,slicedict) 27356 srefvarbndsy, dims = SliceVarDict(ovarybnds,slicedict)27357 27358 27387 reflon, reflat = gen.lonlat2D(ovarx[tuple(srefvarx)], ovary[tuple(srefvary)]) 27359 refvarbndsx = ovarxbnds[tuple(srefvarbndsx)] 27360 refvarbndsy = ovarybnds[tuple(srefvarbndsy)] 27388 27389 if refvarxbndsn != 'WRFxbnds': 27390 ovarxbnds = oncref.variables[refvarxbndsn] 27391 ovarybnds = oncref.variables[refvarybndsn] 27392 srefvarbndsx, dims = SliceVarDict(ovarxbnds,slicedict) 27393 srefvarbndsy, dims = SliceVarDict(ovarybnds,slicedict) 27394 refvarbndsx = ovarxbnds[tuple(srefvarbndsx)] 27395 refvarbndsy = ovarybnds[tuple(srefvarbndsy)] 27396 else: 27397 oulon = oncref.variables['XLONG_U'] 27398 oulat = oncref.variables['XLAT_U'] 27399 ovlon = oncref.variables['XLONG_V'] 27400 ovlat = oncref.variables['XLAT_V'] 27401 refvarbndsx, refvarbndsy= compute_WRFbnds(oulon[0,:,:], oulat[0,:,:],\ 27402 ovlon[0,:,:], ovlat[0,:,:]) 27361 27403 27362 27404 refdx = reflon.shape[1] … … 27412 27454 quit(-1) 27413 27455 27414 if not oncget.variables.has_key(getvarxbndsn): 27456 if getvarxbndsn != 'WRFxbnds' and \ 27457 not oncget.variables.has_key(getvarxbndsn): 27415 27458 print errormsg 27416 27459 print ' ' + fname + ": get file '" + netcdfgetn + "' does " + \ … … 27439 27482 quit(-1) 27440 27483 27441 if not oncget.variables.has_key(getvarybndsn): 27484 if getvarybndsn != 'WRFybnds' and \ 27485 not oncget.variables.has_key(getvarybndsn): 27442 27486 print errormsg 27443 27487 print ' ' + fname + ": get file '" + netcdfgetn + "' does " + \ … … 27450 27494 getslicedict = {getdimxn: slicedimx, getdimyn: slicedimy} 27451 27495 ovarx = oncget.variables[getvarxn] 27452 ovarxbnds = oncget.variables[getvarxbndsn]27453 27496 ovary = oncget.variables[getvaryn] 27454 ovarybnds = oncget.variables[getvarybndsn]27455 27456 27497 sgetvarx, dims = SliceVarDict(ovarx,getslicedict) 27457 sgetvarbndsx, dims = SliceVarDict(ovarxbnds,getslicedict)27458 27498 sgetvary, dims = SliceVarDict(ovary,getslicedict) 27459 sgetvarbndsy, dims = SliceVarDict(ovarybnds,getslicedict)27460 27461 27499 getlon, getlat = gen.lonlat2D(ovarx[tuple(sgetvarx)], ovary[tuple(sgetvary)]) 27462 getvarbndsx = ovarxbnds[tuple(sgetvarbndsx)] 27463 getvarbndsy = ovarybnds[tuple(sgetvarbndsy)] 27500 27501 if getvarxbndsn != 'WRFxbnds': 27502 ovarxbnds = oncget.variables[getvarxbndsn] 27503 ovarybnds = oncget.variables[getvarybndsn] 27504 sgetvarbndsx, dims = SliceVarDict(ovarxbnds,getslicedict) 27505 sgetvarbndsy, dims = SliceVarDict(ovarybnds,getslicedict) 27506 getvarbndsx = ovarxbnds[tuple(sgetvarbndsx)] 27507 getvarbndsy = ovarybnds[tuple(sgetvarbndsy)] 27508 else: 27509 oulon = oncget.variables['XLONG_U'] 27510 oulat = oncget.variables['XLAT_U'] 27511 ovlon = oncget.variables['XLONG_V'] 27512 ovlat = oncget.variables['XLAT_V'] 27513 getvarbndsx, getvarbndsy= compute_WRFbnds(oulon[0,:,:], oulat[0,:,:],\ 27514 ovlon[0,:,:], ovlat[0,:,:]) 27515 27464 27516 getdx = getlon.shape[1] 27465 27517 getdy = getlon.shape[0]
Note: See TracChangeset
for help on using the changeset viewer.