Re: [3610719] Edge issue in Regridding Daymet Joined Tiles with ESMF_Regridding on NCL 6.1.0

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu Apr 25 2013 - 12:38:59 MDT

Ping,

Opt@SrcMask2D (the missing value mask) is an array, not a function.
The problem with your script is that Opt@SrcMask2D is required by
ESMF_regrid to be two dimensional, but you have computed it with three
dimensions here:

   Opt@SrcMask2D = where(.not.ismissing(var),1,0)

Please see the documentation for "SrcMask2D" on the ESMF_regrid function page.

If there is any possibility that missing values may occur in different
grid positions between time steps, then you must recompute the missing
value mask for every time step. This means adding a do loop, and
moving the two grid processing statements inside the loop. This code
is inserted in place of the current line "var_regrid = ...". Please
try this, untested:

   ntimes = dimsizes (var(:,0,0)) ; get number of time steps

   Opt@SrcMask2D = where(.not.ismissing(var(0,:,:)),1,0)
   test_regrid = ESMF_regrid(var(0,:,:),Opt) ; only to get dim sizes
   newdims = dimsizes (test_regrid)
   print ("New lat and lon dims = " + newdims(0) + ", " + newdims(1))

   dims_3d = (/ ntimes, newdims(0), newdims(1) /)
   var_regrid = new (dims_3d, float, test_regrid@_FillValue)

   do t = 0, ntimes-1
      print ("t = " + t)
      Opt@SrcMask2D = where(.not.ismissing(var(t,:,:)),1,0)
      var_regrid(t,:,:) = ESMF_regrid(var(t,:,:),Opt)
   end do

Within the loop, you must have the correct 3-D subscripting on each
reference to a 3-D variable. Also, I had to call ESMF_regrid once
before the loop, to determine the correct dimensions before allocating
the full output array using "new".

--Dave
(Please reply to list only!)

On Tue, Apr 23, 2013 at 3:01 PM, Ping Yang <pyang@ccny.cuny.edu> wrote:
> Dear NCL,
>
> I was trying to use the SrcMask2D function to do the regridding from 1KM to
> 3 armin based on the joined Daymet data,
>
> Is that possible to update the example for using SrcMask2D function?
>
> Actually I tried to create a mask grid from the 1KM resolution Daymet (which
> I think it will be best in resolution), however, I got errors:
>
> (0) write_grid_description: source lat dims = (2082,1551)
> (0) write_grid_description: source lon dims = (2082,1551)
> (0) write_grid_description: source grid type is 'curvilinear'
> fatal:Eq: Dimension size, for dimension number 0, of operands does not
> match, can't continue
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 943 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 2543 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 2654 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 110 in file
> daymet_1KM-3MIN.ncl
> fatal:Variable (var_regrid) is undefined
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 111 in file
> daymet_1KM-3MIN.ncl
> fatal:Variable (var_regrid) is undefined, can not assign attribute
> (grid_mapping)
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 112 in file
> daymet_1KM-3MIN.ncl
> fatal:Variable (var_regrid) is undefined
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 113 in file
> daymet_1KM-3MIN.ncl
>
> However if I remove this code:
> Opt@SrcMask2D = where(.not.ismissing(var),1,0)
> The script runs fine.
>
> I've already uploaded my data onto the ftp(previous message) and my script
> is as follows:
>
> 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/wrf/WRFUserARW.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
>
> ;======================================================================
> ; The main code
> ;======================================================================
>
> vname = "prcp"
> year = 1980
> print("start to process the year of "+ year + " for variable " + vname)
> ;---Input file (Daymet joined tile) ;NE_all_1980_correct_$vname$ .nc
> srcDirName = "/data/ecr/yangping/DAYMET/Grid/1KM/011213/"
> srcFileName = vname + ".NE." + year +".nc"
> srcPathName = srcDirName+srcFileName
> sfile = addfile(srcPathName,"r")
>
> ;---Set the destination file name
> dstDirName = "/data/ecr/yangping/DAYMET/Grid/Intermediate/"
> system("/bin/mkdir -p "+ dstDirName)
> dstFileName = str_upper(vname)+"."+year+"_1KM.esmf.nc"
> dstPathName = dstDirName+dstFileName
>
> setfileoption("nc","Format","LargeFile")
>
> outDirName = "/data/ecr/yangping/DAYMET/Grid/3MIN/"
> outFileName = vname + ".3MIN.lonlat." + year+".nc"
> outPathName = outDirName + outFileName
> system("/bin/rm -f "+outPathName) ; delete any pre-existing file
> out=addfile(outPathName,"c")
>
> ;--- ESMF regrid method: "conserve", "bilinear", "patch"
> method = "conserve"
>
> ;===================================================
>
> ;---Options
> Opt = True
> Opt@SrcTitle = "Daymet Joined Grid "+year+" to rectlinear" ;
> optional
> Opt@WgtFileName = dstDirName + "Daymet_to_Rect.Wgt.nc"
>
> Opt@ForceOverwrite = True
> ;;Opt@PrintTimings = True
>
> ;---Get the source file Daymet lat/lon grid
> lat2d = sfile->lat
> lon2d = sfile->lon
>
> dim2d = dimsizes(lat2d)
> nlat = dim2d(0)
> nlon = dim2d(1)
>
> print(nlat)
> print(nlon)
>
> ;---Get the Daymet source variable
> var = sfile->$vname$ ; (time, y, x)=>(365,232,221)
> printVarSummary(var)
> ;Opt@SrcGridType = "curvilinear"
> Opt@SrcGridLat = lat2d
> Opt@SrcGridLon = lon2d
> Opt@SrcMask2D = where(.not.ismissing(var),1,0)
> ;---Create the destination lat/lon grid
> dll=0.05 ;3MIN
> latrange=abs(max(lat2d)-min(lat2d))
> lonrange=abs(max(lon2d)-min(lon2d))
> kpts_lat= toint(latrange/dll)+1
> kpts_lon= toint(lonrange/dll)+1
> lat = fspan( min(lat2d),max(lat2d), kpts_lat )
> lon = fspan( min(lon2d),max(lon2d), kpts_lon )
>
> newlon = fspan(-84.025,-64.875,384)
> newlat = fspan(34.875,50.125,306)
> Opt@Debug = True
> Opt@DstGridType = "rectilinear"
> ;Opt@DstGridLat = lat
> Opt@DstGridLat = newlat
> ;Opt@DstGridLon = lon
> Opt@DstGridLon = newlon
>
> Opt@CopyVarCoords= True ; default for 6.1.0
>
> Opt@InterpMethod = method
> Opt@SrcRegional = True
> Opt@DstRegional = True
>
> var_regrid = ESMF_regrid(var,Opt) ; Do the regridding for 'var'
> printVarSummary(var_regrid)
> var_regrid@grid_mapping = "lonlat" ;
> out->$vname$=var_regrid ;output the regridding result
>
> I was using the original 1KM Daymet data as a mask by using the SrcMask2D
> function, Is this a correct way to do this? Any suggestions or comments will
> be appreciated.
>
> Thanks,
>
> Ping
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Apr 25 12:39:12 2013

This archive was generated by hypermail 2.1.8 : Fri Apr 26 2013 - 17:10:25 MDT