Re: ESMF regridding question

From: Elizabeth Cassano <ecassano_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 10 2014 - 10:45:41 MDT

Hello,

Sorry to take so long to respond. Here is a script that performs the interpolation as well as two figures, one of the original data and one of the interpolated data. You can see that the zero and missing values almost completely overlap. Thank you for your help,

Best,
Liz

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; extract_erai.ncl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; load in the libraries
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; start the main program
begin
        title_dst = "Alaska domain"
; set the time units
  TimeUnits = "hours since 1979-01-01 00:00:00"
; set the value and attributes for the time
        time = cd_inv_calendar(1990, 1, 1, 6, 0, 0, TimeUnits, 0)
                time@long_name = "Time"
                time@standard_name = "time"
                time@units = TimeUnits
                time@calendar = "standard"
                time@_FillValue = 1e20
                time!0 = "time"
                time&time = time
 ; read in the lat/lon from the file with the destination domain
  f_dst = addfile("~/era_i/domain/alaska/geo_em.d01.nc", "r")
  lat_dst = f_dst->XLAT_M(0,:,:)
  lon_dst = f_dst->XLONG_M(0,:,:)
 ; -determine the dimensions of the destination grid
  DimLat = dimsizes(lat_dst)
  nS_N = DimLat(0)
  nW_E = DimLat(1)
 ; -edit some of the attributes
  lat_dst@long_name = "Latitude"
    lat_dst@standard_name = "latitude"
    lat_dst@units = "degrees_north"
    lat_dst!0 = "south_north"
    lat_dst!1 = "west_east"
  lon_dst@long_name = "Longitude"
    lon_dst@standard_name = "longitude"
    lon_dst@units = "degrees_east"
    lon_dst!0 = "south_north"
    lon_dst!1 = "west_east"
 ; set the file name for the weights
  WgtFile = "~/esmf_test/esmf_test-ESMF_weight"
 ; create the list of settings for ESMF_regrid -> non-source related
  optESMF = True
  optESMF@InterpMethod = "bilinear"
  optESMF@WgtFileName = WgtFile
  optESMF@DstGridLat = lat_dst
  optESMF@DstGridLon = lon_dst
  optESMF@DstRegional = True
  optESMF@DstInputFileName = "esmf_test-1990010106.nc"
  optESMF@DstTitle = "Alaska Domain"
  optESMF@CopyVarAtts = True
  optESMF@CopyVarCoords = True
  optESMF@ForceOverwrite = True
  optESMF@RemoveSrcFile = True
  optESMF@RemoveDstFile = True
  optESMF@RemoveWgtFile = False
  optESMF@Debug = False
 ; open the ERA-I GRIB files from NCAR-CISL RDA
        f_sfc1 = addfile("/glade/p/rda/data/ds627.0/ei.oper.an.sfc/199001/"+ \

           "ei.oper.an.sfc.regn128sc.1990010100.grb", "r")
        f_sfc2 = addfile("/glade/p/rda/data/ds627.0/ei.oper.fc.sfc/199001/"+ \

           "ei.oper.fc.sfc.regn128sc.1990010100.grb", "r")
; set the values for the lat/lon of the source domain
        lat_src = f_sfc1->g4_lat_0
        lon_src = f_sfc1->g4_lon_1
; find the values for Z_sfc and LandMask
; create the list of settings for ESMF_regrid -> source related
        optESMF@SrcGridLat = lat_src
        optESMF@SrcGridLon = lon_src
        optESMF@SrcInputFileName = "ei.oper.an.sfc.regn128sc.1990010100"
        optESMF@SrcTitle = "ERA-Interim"
; surface elevation
        Z_sfc_in = f_sfc1->Z_GDS4_SFC ; read in the data
        Z_sfc_1 = Z_sfc_in / 9.81 ; calculate the height
; -call ESMF_regrid with the generation of weights
        Z_sfc = ESMF_regrid(Z_sfc_1, optESMF)
; -copy the attributes (atts were lost with calc)
        copy_VarAtts(Z_sfc_in, Z_sfc)
; -delete some attributes
  delete_VarAtts(Z_sfc,(/"lat2d","lon2d"/))
; -fix/add some of the attributes/coordinates
        Z_sfc@long_name = "Terrain Height"
                Z_sfc@units = "m"
                Z_sfc@coordinates = "lon lat"
                Z_sfc!0 = "south_north"
                Z_sfc!1 = "west_east"
; read the variable from the ERA-I file
        x0 = f_sfc2->TP_GDS4_SFC
        x1 = x0(1,:,:)
; regrid the data to the destination grid, using weights
        x2 = ESMF_regrid_with_weights(x1, WgtFile, optESMF)
; create set equal the new variable with time
        x3 = new((/1,nS_N,nW_E/),"float",0)
        x3(0,:,:) = x2
; delete some attributes
  delete_VarAtts(x3, (/"lat2d","lon2d"/))
; add some attributes / coordinates
        x3@coordinates = "lon lat"
        x3!0 = "time"
        x3!1 = "south_north"
        x3!2 = "west_east"
        x3&time = time
 ; open the file to be written
        path_file_out = "~/esmf_test/esmf_test-1990010106.nc"
 ; -check to see if file is present, if so, delete the previous file
        if isfilepresent(path_file_out) then
                system ("rm "+path_file_out)
        end if
 ; -create the file
        f_out = addfile(path_file_out,"c")
 ; set time to be the unlimited record variable
        filedimdef(f_out,"time",-1,True)
  ; write the data to the file
        f_out->time=time
        f_out->lat=lat_dst
        f_out->lon=lon_dst
        f_out->Z_sfc=Z_sfc
        f_out->precip_t = x3
end

On Feb 13, 2014, at 10:47 AM, Dennis Shea wrote:

> re: "Is this an expected result for this regridding process, ..."
>
> The answer is "no"
>
> You should post a clean simple script that illustrates what
> you have done. It is likely that there is an error 'somewhere.'
>
> On 2/12/14, 10:15 AM, Elizabeth Cassano wrote:
>> Hello,
>>
>> I have some data that were regridded using the ESMF regridding function in NCL.
>> The original data have large areas of zero values, but no missing data.
>> However the regridded data have missing values. These are spatially coherent and
>> overlap with where the data are zero in the original data (though a
> smaller area).
>
>> Is this an expected result for this regridding process, that the ESMF regridding
>> function would produce a missing value in areas where the original data are zero?
>> I am new to this regridding method so any help in this regard would be appreciated.
>
>> Thank you,
>> Liz
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Elizabeth Cassano
~~~~~~~~~~~~~~~~~~~~~~~~~~
CIRES
UCB 216
University of Colorado
Boulder, CO. 80309-0126
phone: 303-492-0281
fax: 303-492-1149

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 10 10:46:00 2014

This archive was generated by hypermail 2.1.8 : Fri Mar 14 2014 - 15:08:52 MDT