;====================================================================== ; ESMF_wgts_6.ncl ; ; Concepts illustrated: ; - Interpolating from one grid to another using ESMF_regrid_with_weights ; - Interpolating from one grid to another using an existing weights file ; - Interpolating data from a CMIP5 grid to a 1X1 degree rectilinear grid ;====================================================================== ; This example is identical to ESMF_regrid_6.ncl, except it assumes ; the weights file already exists, and does regridding using ; "ESMF_regrid_with_weights". This is the best method to use if you ; already have the weights. ;====================================================================== ; This example uses the ESMF application "ESMF_RegridWeightGen" to ; generate the weights. ; ; For more information about ESMF: ; ; http://www.earthsystemmodeling.org/ ;====================================================================== ; This script regrids a CMIP5 grid to a 1.0 degree world grid and ; plots sea water potential temperature on the new grid. ; ; It uses SCRIP for both the CMIP5 and 1.0 degree world grid. ;====================================================================== ; ; 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" ; ; This file still has to be loaded manually load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" begin ;---Interpolation methods methods = (/"bilinear","patch","conserve"/) ;---Input file srcFileName = "thetao_Omon_MPI-ESM-LR_piControl_r1i1p1_280001-284912.nc" wgtFile = "CMIP5_2_World_" + methods + ".nc" ;---Get data and lat/lon grid from CMIP5 Grid sfile = addfile(srcFileName,"r") thetao = sfile->thetao(0,0,:,:) thetao@lat2d = sfile->lat ; For plotting thetao@lon2d = sfile->lon ;---------------------------------------------------------------------- ; Setup for graphics ;---------------------------------------------------------------------- wks = gsn_open_wks("png","ESMF_wgts") ; send graphics to PNG file ;---Resources to share between both plots res = True ; Plot modes desired. res@gsnDraw = False ; Will panel later res@gsnFrame = False ; Will panel later res@gsnMaximize = True ; Maximize plot res@cnFillOn = True ; color plot desired res@cnFillPalette = "rainbow" ; set color map res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour labels res@cnFillMode = "RasterFill" ; turn raster on res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = ispan(270,300,2) res@mpFillOn = False res@trGridType = "TriangularMesh" ; allow missing coordinates res@gsnAddCyclic = False res@pmLabelBarWidthF = 0.7 res@lbLabelBarOn = False ; Will do this in panel res@gsnAddCyclic = False ;---Resources for paneling pres = True pres@gsnMaximize = True pres@gsnPanelLabelBar = True pres@lbLabelFontHeightF = 0.01 ;---------------------------------------------------------------------- ; Loop across each method and generate interpolation weights for ; CMIP5 Grid to World Grid ;---------------------------------------------------------------------- plot_regrid = new(dimsizes(methods),graphic) do i=0,dimsizes(methods)-1 ;---------------------------------------------------------------------- ; Interpolate data from CMIP5 to World 1-degree grid. ;---------------------------------------------------------------------- thetao_regrid = ESMF_regrid_with_weights(thetao,wgtFile(i),False) printVarSummary(thetao_regrid) ;---------------------------------------------------------------------- ; Plotting section ;---------------------------------------------------------------------- ;---Resources for plotting original data res@tiMainString = "Data on original CMIP5 grid (" + \ str_join(tostring(dimsizes(thetao))," x ") + ")" plot_orig = gsn_csm_contour_map(wks,thetao,res) ;---Resources for plotting regridded data res@tiMainString = "CMIP5 to 1x1-degree grid (" + \ methods(i) + ") (" + \ str_join(tostring(dimsizes(thetao_regrid))," x ") + ")" plot_regrid(i) = gsn_csm_contour_map(wks,thetao_regrid,res) ;---Panel two plots gsn_panel(wks,(/plot_orig,plot_regrid(i)/),(/2,1/),pres) ;---Clean up before next time in loop. delete(thetao_regrid) end do end