;====================================================================== ; ESMF_wgts_29.ncl ; ; Concepts illustrated: ; - Regrid data on a WRF grid to a rectilinear grid using a weights file ; - Interpolate wind components on a WRF grid to a rectilinear grid ; - Use uv2dv_cfd to compute divergence on the rectilinear grid ; - Interpolate derived divergence back onto the original WRF grid ;====================================================================== ; This script depends on the weights file generated by ; ESMF_regrid_29.ncl. The point is to show that once you have the ; weights file, you can call ESMF_regrid_with_weights instead of ; ESMF_regrid, which is much faster. ;====================================================================== ; These files are loaded by default in NCL V6.2.0 and newer ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl" ; ; This file still has to be loaded manually load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" ;---Specify method to be used InterpMethod= "patch" ;---Input file srcDirName = "./" srcFileName = "wrfout_d01_2003-07-13_12:00:00" srcFilePath = srcDirName + srcFileName ;===================================================================== ; Regrid WRF wind components to rectilinear grid ;===================================================================== ;---Wgt File: WRF to Rectilinear wgtDirName = "./" wgtFileName = "WRF_to_Rect.WgtFile_"+InterpMethod+".nc" wgtFilePath = wgtDirName + wgtFileName ;---Retrieve either one level, or all levels. Use '-1' for all. sfile = addfile(srcFilePath,"r") ua = wrf_user_getvar(sfile,"ua",-1) ; On mass grid va = wrf_user_getvar(sfile,"va",-1) printVarSummary(ua) ; (Time,bottom_top,south_north,west_east) printVarSummary(va) ; (Time,bottom_top,south_north,west_east) ;---Regrid the wind components to a rectilinear grid ur = ESMF_regrid_with_weights(ua,wgtFilePath,False) vr = ESMF_regrid_with_weights(va,wgtFilePath,False) printVarSummary(ur) printVarSummary(vr) ;---Compute the divergence on the rectilinear grid lat2d = sfile->XLAT(0,:,:) ; (south_north,west_east) lon2d = sfile->XLONG(0,:,:) ;---Generate the same rectilinear grid used to generate the weight file dims = dimsizes(lat2d) nlat = dims(0) nlon = dims(1) lat = fspan(min(lat2d), max(lat2d) ,nlat) lon = fspan(min(lon2d), max(lon2d) ,nlon) ;---Calculate the divergence on a rectilinear grid div_rl = uv2dv_cfd (ur, vr, lat, lon, 2) printVarSummary(div_rl) printMinMax(div_rl,0) ;==================================================================== ; Regrid derived divergence on rectilinear grid onto original WRF grid ;==================================================================== ;---Wgt File: Rectilinear to WRF wgtDirName = "./" wgtFileName = "Rect_to_WRF.WgtFile_"+InterpMethod+".nc" wgtFilePath = wgtDirName + wgtFileName ;---Regrid the divergence on rectilinear grid to WRF grid div_wrf = ESMF_regrid_with_weights(div_rl,wgtFilePath,False) div_wrf@long_name = "divergence" div_wrf@units = "1/s" copy_VarCoords(ua, div_wrf) printVarSummary(div_wrf) printMinMax(div_wrf,0) ;==================================================================== ; Examine the range of the derived variable ;==================================================================== optsd = True optsd@PrintStat = True stat_div = stat_dispersion(div_wrf, optsd ) ;==================================================================== ; Create coordinate metadata for rectilinear grid. Needed for plotting. ;==================================================================== lat!0 = "lat" lat@units = "degrees_north" lon!0 = "lon" lon@units = "degrees_east" div_rl!0 = "Time" div_rl!1 = "bottom_top" div_rl!2 = "lat" div_rl!3 = "lon" div_rl&lat = lat div_rl&lon = lon ;====================================================================== ; Create plots of original data and regridded data ;====================================================================== wks = gsn_open_wks("png","ESMF_wgts") ; send graphics to PNG file plot = new(2,graphic) ; create a plot array res = True res@gsnDraw = False ; don't draw res@gsnFrame = False ; don't advance frame res@gsnAddCyclic = False ; regional data res@cnInfoLabelOn = False ; turn off cn info label res@cnFillOn = True ; turn on color ;res@cnFillMode = "RasterFill" res@cnLinesOn = False res@cnLineLabelsOn = False res@lbLabelBarOn = False ; turn off individual cb's res@cnLevelSelectionMode = "ManualLevels" res@cnMinLevelValF = -4.5e-05 res@cnMaxLevelValF = abs(res@cnMinLevelValF) res@cnLevelSpacingF = 0.25e-05 res@mpMinLatF = min(lat2d) ; range to zoom in on res@mpMaxLatF = max(lat2d) res@mpMinLonF = min(lon2d) res@mpMaxLonF = max(lon2d) res@pmTickMarkDisplayMode = "Always" ; nicer map tickmarks res@gsnLeftString = "" res@gsnRightString= "" nt = 3 ; arbitrary time kl = 20 ; arbitrary level plot(0) = gsn_csm_contour_map(wks,div_rl(nt,kl,:,:) ,res) plot(1) = gsn_csm_contour_map(wks,div_wrf(nt,kl,:,:),res) ;====================================================================== ; Create panel plot ;====================================================================== resP = True ; modify the panel plot resP@gsnPanelMainString = "Divergence: Rectilinear (top); WRF (Bot)" resP@gsnMaximize = True ; make ps, eps, pdf large resP@gsnPanelLabelBar = True ; add common colorbar gsn_panel(wks,plot,(/2,1/),resP) ; now draw as one plot