[ncl-talk] Generating weights using ESMF_regrid_gen_weights

Dennis Shea shea at ucar.edu
Tue Nov 26 18:53:59 MST 2019


I have attached an NCL script that generates a weights file.
Also, the png generated 4km [top] and 14km [bottom]
---
NCL: You will have to loop over files and explicitly use *short2flt *to
unpack desired variables.
         Then use *ESMF_regrid_with_weights*
<https://www.ncl.ucar.edu/Document/Functions/ESMF/ESMF_regrid_with_weights.shtml>
---
*ncremap* <http://nco.sourceforge.net/nco.html#ncremap>: As I noted, I have
no idea if the weights file generated by ESMF [via NCL] can be used by the
NCO operator *ncremap* <http://nco.sf.net/nco.html#ncremap>. You will have
to ask the NCO [not NCL] mail list. I am sure Charlie Zender will respond.

Note that ncremap has a -U option

-U (--unpack, --upk, --upk_inp)’

This switch (which takes no argument) causes ncremap to unpack (see Packed
data <http://nco.sourceforge.net/nco.html#Packed-data>) input data before
regridding it.

On Tue, Nov 26, 2019 at 2:36 PM Burakowski, Elizabeth <
Elizabeth.Burakowski at unh.edu> wrote:

> Hi Dennis,
>
> I converted from short to float, but am still getting all zeros in my
> regridded file/variable, regardless of whether I use ncremap or
> ESMF_regrid_with_weights in NCL.
>
> Are there any clues I could look for in my weight file?
>
> Thanks,
>
> Liz
>
> Dr. Elizabeth A Burakowski
> She/Her/Hers
> Research Assistant Professor
> Earth Systems Research Center &
> Institute for the Study of Earth, Oceans, and Space
> University of New Hampshire
> 8 College Road Durham, NH 03824
> 603-862-1796
> elizabeth.burakowski at unh.edu
> ------------------------------
> *From:* Burakowski, Elizabeth <Elizabeth.Burakowski at unh.edu>
> *Sent:* Tuesday, November 26, 2019 8:02 AM
> *To:* Dennis Shea <shea at ucar.edu>
> *Cc:* ncl-talk at ucar.edu <ncl-talk at ucar.edu>
> *Subject:* Re: [ncl-talk] Generating weights using ESMF_regrid_gen_weights
>
> Hi Dennis,
>
> [1] I overlooked the short to float, will try that and see if it resolves
> anything.
>
> [2] I thought the weight files should be compatible? I used ncremap using
> NCL weight files successfully to get unstructured VR-CESM to rectilinear.
>
> Liz
>
> Dr. Elizabeth A Burakowski
> She/Her/Hers
> Research Assistant Professor
> Earth Systems Research Center &
> Institute for the Study of Earth, Oceans, and Space
> University of New Hampshire
> 8 College Road Durham, NH 03824
> 603-862-1796
> elizabeth.burakowski at unh.edu
> ------------------------------
> *From:* Dennis Shea <shea at ucar.edu>
> *Sent:* Monday, November 25, 2019 11:25 PM
> *To:* Burakowski, Elizabeth <Elizabeth.Burakowski at unh.edu>
> *Cc:* ncl-talk at ucar.edu <ncl-talk at ucar.edu>
> *Subject:* Re: [ncl-talk] Generating weights using ESMF_regrid_gen_weights
>
> I have not looked carefully at this.
>
> [1]
> *The SWE variable is type short. *
>
> *short *SWE(time, lat, lon) ;
> SWE:_FillValue = -999s ;
> SWE:long_name = "Snow Water Equivalent" ;
> SWE:grid_mapping = "crs" ;
> SWE:units = "millimeters h20" ;
>
> *You *must* unpack before use.*
>
> swe = *short2flt*
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Contributed_short2flt.shtml&d=DwMFaQ&c=c6MrceVCY5m5A_KAUkrdoA&r=JW2rHHzYnVYi6ZDBI-2JFMNSreDPLZO-wwOrczEnOlg&m=nDkI23Mf2E7xmTZ_cukgsNqkSQ1gDBIs2dFWWVoChwo&s=NwMtAWSn6DUG3SStTejycr4eTCrruoiJvqxf4eFOXHw&e=>
> (sfile->SWE)
> or, for a focused regional subset
> swe = *short2flt*(sfile->SWE({latS:latN},{lonW:lonE}))
>
> ===
> [2]
> *ncremap* is a netCDF Operator. It looks like you want the weights
> generated by NCL's *ESMF *regrid package.
> Are the weight files compatible?
>
> ===
>
> D
>
>
> On Mon, Nov 25, 2019 at 2:35 PM Burakowski, Elizabeth via ncl-talk <
> ncl-talk at ucar.edu> wrote:
>
> I'm attempting to generate weights for regridding a 4 km grid to a 14 km
> grid using ESMF_regrid_gen_weights.
>
> Source grid:
> Univ. Arizon Snow Depth and SWE grids
> 4 km rectilinear, [lat | 621] x [lon |1405]
>
> Destination grid:
> VR-CESM CONUS (already regridded using ESMF)
> 14 km rectilinear, [lat | 361] x [lon |560]
>
> In the below NCL script, I use rectilinear_to_SCRIP on source and
> destination grids, then ESMF_regrid_gen_weights to create the weight file.
> No errors occur, however, when I try to regrid using ncremap, I get a bunch
> of zeros. I'd like to use the weight file on hundreds of files, hence using
> ncremap.
>
> When I test the weight file on one source variable using NCL's
> ESMF_regrid_with_weights, I get an argument type mismatch error, but I
> can't figure out why.  Any ideas how to fix this? Files are on cheyenne.
>
> Script to generate weights:
>
> ;======================================================================
> ; ESMF Regrid:   UA-SNOW-4km (rectilinear) to VRCESM-CONUS (rectilinear)
> ;======================================================================
> 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"
>
> ;======================================================================
> ;                         The main code
> ;======================================================================
>
> begin
> ;---Specify interpolation to be used
>     method = "patch"
>
> ;---Specify weight file name
>     wgtFileName = "UASnow4km2VRCESMCONUS14km_"+method+".nc"
>
> ;---Input file (Source)
>     srcFileDir  = "/glade/work/burakows/plot/validation/UA_Snow_4km/"
>     srcFileName = "4km_SWE_Depth_WY2014_v01.nc"       ; any UA-Snow file
>     srcGridName = "UASnow_4km_SCRIP.nc"
>
> ;---Retrieve a sample variable (used in plot)
>     sfile       = addfile(srcFileDir+srcFileName,"r")
>     srcVarName  = "SWE"                                ; [lat | 621] x [x
> | 1405]
>     var_in      = sfile->$srcVarName$
>     printVarSummary(var_in)
>
>     Opt                 = True
>     Opt at ForceOverwrite  = True
>     Opt at Title           = "UA Snow 4km Grid"
>
> ;--- Convert UA Snow 4 km grid to SCRIP convention file
>     rectilinear_to_SCRIP(srcGridName,var_in&lat,var_in&lon,Opt)
>     delete(Opt)
>
> ;================================================================
>
> ;---File that contains the destination file coordinates
>     dstFileDir  =
> "/glade/scratch/burakows/archive/VR-CESM_FHISTSTUB.1984-2015.CONUS30x4_prod/lnd/remap/"
>     dstFileName = "
> VR-CESM_FHISTSTUB.1984-2015.CONUS30x4_prod.clm2.h0.2014-01-01-00000_regrid.nc
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__VR-2DCESM-5FFHISTSTUB.1984-2D2015.CONUS30x4-5Fprod.clm2.h0.2014-2D01-2D01-2D00000-5Fregrid.nc&d=DwMFaQ&c=c6MrceVCY5m5A_KAUkrdoA&r=JW2rHHzYnVYi6ZDBI-2JFMNSreDPLZO-wwOrczEnOlg&m=nDkI23Mf2E7xmTZ_cukgsNqkSQ1gDBIs2dFWWVoChwo&s=9S8vxSlf_i2YzThseQwePEY4m0J2XrINsK9l6u4Pwzw&e=>"
>  ; any VR-CESM file
>     dstGridName = "VRCESMCONUS_14km_SCRIP.nc"
>
> ;---open VR-CESM file that contains the VR-CESM grid coordinates
>     dfile       = addfile(dstFileDir+dstFileName,"r")
>     dstVarName  = "H2OSNO"
>     dvar_in     = dfile->$dstVarName$           ; [lat | 361 ] x [lon |
> 560]
>     printVarSummary(dvar_in)
>
>     Opt                 = True
>     Opt at ForceOverwrite  = True
>     Opt at Title           = "VR-CESM CONUS (14 km) grid"
>
> ;--- Convert VR-CESM CONUS 14 km to SCRIP convention file
>     rectilinear_to_SCRIP(dstGridName,dvar_in&lat,dvar_in&lon,Opt)
>     delete(Opt)
>
> ;--- Generate the weights to convert UA Snow 4 km grid to VR-CESM CONUS 14
> km grid
>
>     Opt         = True
>     Opt at InterpMethod    = "patch"
>     Opt at ForceOverwrite  = "True"
>
>     ESMF_regrid_gen_weights(srcGridName,dstGridName,wgtFileName,Opt)
>     delete(Opt)
> end
>
> ;===============================================================
>
>
> Dr. Elizabeth A Burakowski
> She/Her/Hers
> Research Assistant Professor
> Earth Systems Research Center &
> Institute for the Study of Earth, Oceans, and Space
> University of New Hampshire
> 8 College Road Durham, NH 03824
> 603-862-1796
> elizabeth.burakowski at unh.edu
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=c6MrceVCY5m5A_KAUkrdoA&r=JW2rHHzYnVYi6ZDBI-2JFMNSreDPLZO-wwOrczEnOlg&m=nDkI23Mf2E7xmTZ_cukgsNqkSQ1gDBIs2dFWWVoChwo&s=iaf2-zcxf3E8sZChmMYMznx0UoFQUQmcmNBbSwkBMkM&e=>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191126/7a508fc4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grid_4to14km.ncl
Type: application/octet-stream
Size: 4660 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191126/7a508fc4/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SWE.ESMF_4to14km.png
Type: image/png
Size: 130295 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191126/7a508fc4/attachment.png>


More information about the ncl-talk mailing list