[ncl-talk] ESMF_regrid_24.ncl
Sri nandini
bax8609 at uni-hamburg.de
Mon Nov 22 01:31:31 MST 2021
Hello dear NCL users,
I am trying to use the online ncl script: ESMF_regrid_24.ncl:
https://www.ncl.ucar.edu/Applications/Scripts/ESMF_regrid_24.ncl
This example shows how to regrid data from a POP curvilinear gx1v3 grid
(384 x 320) to a 1.0 degree world grid, which is my aim.
My modified script runs successfully with tas=(0,:,:) ====where the
timestep is 0 and x_regrid = ESMF_regrid(x,Opt) does this only
allow for latlon 2D?
At the end i wish to regrid my variable into 1X1 resolution and save it
for future analysis, but i need the entire variable dimensions e.g.
time, lat,lon and not just the lat,lon. When i enter the full 3D
variable into my script, than i get an error at the x_regrid =
ESMF_regrid(x,Opt) "fatal:Eq: Dimension size, for dimension number 0, of
operands does not match, can't continue"
Please have a look at my script below. Would be grateful for any comments.
;----------------------------------------------------------------------
; This script regrids a POP grid to a 1.0 degree regular latlon grid and
; plots sea surface height [zos] on the new grid.
;----------------------------------------------------------------------
; This file still has to be loaded manually
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
begin
ensemble=(/"r1i1p1","r2i1p1","r3i1p1","r4i1p1","r5i1p1","r6i1p1","r7i1p1","r8i1p1","r9i1p1","r10i1p1","r11i1p1","r12i1p1","r13i1p1","r14i1p1","r15i1p1","r16i1p1","r17i1p1","r18i1p1","r19i1p1","r20i1p1","r21i1p1","r22i1p1","r23i1p1","r24i1p1","r25i1p1","r26i1p1","r27i1p1","r28i1p1","r29i1p1","r30i1p1","r31i1p1","r32i1p1","r33i1p1","r34i1p1","r35i1p1","r36i1p1","r37i1p1","r38i1p1","r39i1p1","r40i1p1"/)
do i=0,dimsizes(ensemble)-1
region=ensemble(i)
print(i+": "+region)
print("Starting: "+region+" now")
;---Interpolation methods
methods = (/"bilinear"/) ; ,"conserve","patch"/)
;---Input file
srcDirName = "./"
srcFileName =
"zos_Omon_CESM1-CAM5_historical_rcp85_"+region+"_192001-210012.nc"
print(srcFileName)
varName = "zos"
printVarSummary(varName)
;---Get data and lat/lon grid from source Grid; uses surface level and
initial time
;ne=2172
;do i=0,ne-1
sfile = addfile(srcFileName,"r")
x = sfile->$varName$ ; (time,lat,lon)
printVarSummary(x)
dimx = dimsizes( x )
ntim = dimx( 0 )
x at lat2d = sfile->lat ; Needed for plotting.
x at lon2d = sfile->lon
x at time =sfile->time
;---Specify a name for the destination regridded variable (no spaces)
;;DstGridDir = "./"
DstGridName = "1x1"
;---Create the destination rectilinear lat/lon
lat = fspan(-89.5, 89.5,180)
lon = fspan( 0.5,359.5,360)
;---Specify name of weight file(s) to be generated; name of destination
grid; dst directory
WgtFileDir = "./"
WgtFileName = "POP_gx1v3_to_"+DstGridName+"."+methods+".nc"
Opt = True
Opt at SrcFileName = "POP_gx1v3_SCRIP.nc" ; source grid
description file name
Opt at DstFileName = "Globe1deg_SCRIP.nc" ; destination grid
description file name
Opt at ForceOverwrite = True
Opt at SrcMask2D = where(.not.ismissing(x),1,0) ; land/ocean
mask; Necessary if has
; missing
values.
Opt at DstTitle = "Global Grid 1-degree Resolution"
Opt at DstGridLat = lat
Opt at DstGridLon = lon
;----------------------------------------------------------------------
; Loop across each method and generate interpolation weights for
; POP Grid to regular LatLon Grid
;----------------------------------------------------------------------
plot_regrid = new(dimsizes(methods),graphic)
print("Generating interpolation weights from POP to regular
LatLon Grid")
print("Global LatLon grid using the " +methods+" method.")
Opt at WgtFileName = WgtFileName
Opt at InterpMethod = methods
;-- if we don't need to generate the source and destination grids
again
; Opt at SkipDstGrid = True ;-- if True
skip regridding
; Opt at SkipSrcGrid = True ;-- if True
skip regridding
;----------------------------------------------------------------------
; Interpolate data from POP to destination grid.
;----------------------------------------------------------------------
;----------------------------------------------------------------------
; Regridding over each time independently, pass a 3D variable to
ESMF_regrid, and it will do the
;looping under the hood. What this function does is creates the weights for
;one level, and applies them to the rest of the levels. It assumes that the
;lat/lon grid is the same for each level.
;----------------------------------------------------------------------
x_regrid = ESMF_regrid(x,Opt) ;only allows for latlon 2D
printVarSummary(x_regrid)
;----------------------------------------------------------------------
; Save the regridded data onto new netcdf file
;----------------------------------------------------------------------
print("saving "+region+" regridded")
system("/bin/rm -f
zos_Omon_CESM1-CAM5_historical_rcp85_"+region+"_regridded.nc") ;
remove any pre-existing file
outfile =
addfile("zos_Omon_CESM1-CAM5_historical_rcp85_"+region+"_regridded.nc","c")
outfile->zos = x_regrid
--
Dr. Sri Nandini-Weiss
Center for Earth System Research and Sustainability (CEN)
Cluster of Excellence 'Climate, Climatic Change, and Society' (CLICCS)
Universität Hamburg
Institute of Oceanography
Bundesstraße 53
20146 Hamburg
Germany
More information about the ncl-talk
mailing list