Re: ESMF regridding question

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 13 2014 - 08:24:55 MDT

I *think* the issue is with the inconsistent manner in which longitudes
are referenced between the destination (WRF) and source (ERA-I) data.

Destination grid

Variable: lon_dst
Dimensions and sizes: [south_north | 64] x [west_east | 69]
[snip]
(0) lon_dst: min=-179.99 max=180 <===========

========================
Source Grid

Variable: Z_sfc_in
Dimensions and sizes: [g4_lat_0 | 256] x [g4_lon_1 | 512]
Coordinates:
             g4_lat_0: [89.46282..-89.46282]
             g4_lon_1: [ 0..359.297] <============

========================

If you use 'lonFlip'
http://www.ncl.ucar.edu/Document/Functions/Contributed/lonFlip.shtml
*Both* the array and associated coordinate variable are reordered.

   Z_sfc_in = lonFlip(Z_sfc_in)
   printVarSummary(Z_sfc_in) ; Z_sfc_in&g4_lon_2: [-179.9999..179.2969]

=========================

Since the test script is on NCAR internal machines, further info
will be sent offline.

Cheers

On 3/10/14, 4:09 PM, Dennis Shea wrote:
> Typically, when you have a source/destination grid with missing
> values, one would see
>
> optESMF@SrcMask2D = where(.not.ismissing(var_in),1,0)
>
> Also, the output grid would have some specification
> of the missing template. I think ESMF will regrid to all destination
> lat an lon by default. I think WRF has a LAND_MASK variable
>
> XLAND(Time, south_north, west_east)
> msk_dst = f_dst->XLAND(0,:,:) ; MASK (1 FOR LAND, 2 FOR WATER)
>
> optESMF@DstMask2D = where(ismissing(msk_dst),0,1) ; or ,1,0)
> ===========
> In any event, we have no idea where files like
> ~/era_i/domain/alaska/geo_em.d01.nc
>
> are located.
>
> ---
> See ESMG-26 or -28
>
> D
>
>
> 03/10/2014 10:45 AM, Elizabeth Cassano wrote:
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ; 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
>
> _______________________________________________
> 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
Received on Thu Mar 13 08:25:04 2014

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