; attempt to interpolate from one grid to another, using "conserve" interpolation ; from unstructured grid ; ; based on ESMF_all_conserve_12.ncl ; ; Revisions: ; 2013 Jun 02 - rfrench - original version ; 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/esmf/ESMF_regridding.ncl" begin ;---Input file srcFileName = "rgf_regrid_test_v3small.nc" ;---Interpolation method to use interpMethod = "conserve" ;---Output (and, eventually, input) files srcGridName = "rgf_regrid_test_v3_srcGrid_" + interpMethod + ".nc" dstGridName = "rgf_regrid_test_v3_dstGrid_" + interpMethod + ".nc" wgtFileName = "rgf_regrid_test_v3_wgt_" + interpMethod + ".nc" ; retrieve the data sfile = addfile(srcFileName,"r") flux = sfile->flux flux = flux * 100. ; scale values to range 0 to 100 lat_corners = sfile->lat_corners lon_corners = sfile->lon_corners ; set options: Opt = True ; regridding options Opt@SrcMask2D = where(ismissing(flux),0,1) Opt@InputFileName = srcFileName Opt@SrcFileName = srcGridName Opt@DstFileName = dstGridName Opt@WgtFileName = wgtFileName Opt@ForceOverwrite = True ; source grid information Opt@SrcGridLat = sfile->lat_centers ; source grid Opt@SrcGridLon = sfile->lon_centers Opt@GridCornerLat = lat_corners Opt@GridCornerLon = lon_corners Opt@InterpMethod = interpMethod Opt@Pole = "none" Opt@SrcRegional = True ; destination grid information Opt@DstGridType = "0.25deg" ; destination grid Opt@DstTitle = "World Grid 0.25 degree resolution" Opt@DstLLCorner = (/-89.75d, 0.00d /) Opt@DstURCorner = (/ 89.75d, 359.75d /) ; regrid... Opt@Debug = True flux_regrid = ESMF_regrid(flux,Opt) ; print summary of input and output data arrays printVarSummary(flux) ; THIS IS WHERE THE PROBLEM COMES IN printVarSummary(flux_regrid) ;---------------------------------------------------------------------- ; Plotting section ;---------------------------------------------------------------------- wks = gsn_open_wks("ps","rgf_regrid_test_v3_wgt_" + interpMethod) gsn_define_colormap(wks,"rainbow") ; Change color map ;---Resources to share between both plots res = True ; Plot modes desired. res@gsnDraw = False res@gsnFrame = False res@gsnMaximize = True ; Maximize plot res@cnFillOn = True ; color plot desired res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour labels res@cnFillMode = "RasterFill" ; turn raster on res@cnLevelSelectionMode = "ManualLevels" res@cnMinLevelValF = 0 res@cnMaxLevelValF = 100 res@cnLevelSpacingF = 5. res@lbLabelBarOn = False ; Will turn on in panel later. res@mpFillOn = False res@trGridType = "TriangularMesh" ; allow missing coordinates ;---Zoom in on area of interest res@mpMinLatF = 0. res@mpMaxLatF = 90 res@mpMinLonF = -80 res@mpMaxLonF = 20 res@tiMainFontHeightF = 0.015 ;---Resources for plotting regridded data dims = str_join(tostring(dimsizes(flux_regrid))," x ") res@gsnAddCyclic = True res@tiMainString = "Regridded to 0.25 degree grid ("+dims+")" plot_regrid = gsn_csm_contour_map(wks,flux_regrid,res) ;---Resources for plotting original data res@sfXArray = sfile->lon_centers res@sfYArray = sfile->lat_centers res@gsnAddCyclic = False res@tiMainString = "Original grid " plot_orig = gsn_csm_contour_map(wks,flux,res) ;--Attach the lat_corners/lon_corners grid to the regridded plot nlat = dimsizes(lat_corners(:,0,0)) nlon = dimsizes(lat_corners(0,:,0)) line_id = new((/nlat,nlon/),graphic) lnres = True do i=0,nlat-1 do j=0,nlon-1 line_id(i,j) = gsn_add_polyline(wks,plot_regrid,\ lon_corners(i,j,:),\ lat_corners(i,j,:),lnres) end do end do ;---Compare the plots in a panel pres = True pres@gsnMaximize = True pres@gsnPanelLabelBar = True gsn_panel(wks,(/plot_orig,plot_regrid/),(/1,2/),pres) end