; 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 ; set options: Opt = True ; regridding options Opt@InputFileName = srcFileName Opt@SrcFileName = srcGridName Opt@DstFileName = dstGridName Opt@WgtFileName = wgtFileName Opt@ForceOverwrite = True ; source grid information Opt@SrcGridLat = ndtooned(sfile->lat_centers) ; source grid Opt@SrcGridLon = ndtooned(sfile->lon_centers) Opt@GridCornerLat = ndtooned(sfile->lat_corners) Opt@GridCornerLon = ndtooned(sfile->lon_corners) Opt@SrcGridType = "unstructured" Opt@SrcESMF = True ; unstructured format Opt@InterpMethod = interpMethod Opt@Pole = "none" ; 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 res@gsnAddCyclic = False ;---Resources for plotting regridded data res@gsnAddCyclic = False dims = tostring(dimsizes(flux_regrid)) res@tiMainString = "Data regridded to 0.25 degree grid (" + \ str_join(dims," x ") + ")" plot_regrid = gsn_csm_contour_map(wks,flux_regrid,res) 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) ;---Compare the plots in a panel pres = True pres@gsnMaximize = True pres@gsnPanelLabelBar = True gsn_panel(wks,(/plot_orig,plot_regrid/),(/2,1/),pres) end