[ncl-talk] from staggered grid field to interpolated unique grid field

Dennis Shea shea at ucar.edu
Wed Jul 5 11:05:33 MDT 2017


I would suggest using the ESMF [
http://www.ncl.ucar.edu/Applications/ESMF.shtml ] to separately

(a) interpolate the zonal-winds on the U-grid to the T-Grid and save the
generated weight file: (say)

wgt.Ugrid_to_Tgrid.nc

(b) interpolate the meridional-winds on the V-grid to the T-Grid and save
the generated weight file: (say)

wgt.Vgrid_to_Tgrid.nc

(c) The following is a sparse matrix multiply. It is *very* fast.

U_Tgrid = ESMF_regrid_with_weights(u,"wgt.Ugrid_to_Tgrid.nc",False)
V_Tgrid = ESMF_regrid_with_weights(v,"wgt.Vgrid_to_Tgrid.nc",False)

printVarSummary(U_Tgrid)
printVarSummary(V_tgrid)

The weight files can be reused.

Good luck


On Mon, Jul 3, 2017 at 3:39 PM, Francesco Trotta <francesco.trotta4 at unibo.it
> wrote:

> Hi Dennis,
>
> I'm doing this interpolation because my veocity output (U and V datasets)
> will be use in another code which aspect both U and V on a T-Grid.
>
> Interpolating U and V separatly on a T-grid I think is good.
>
> I tried to do this with the following ncl script but I wonder if there is
> a way to optimized this script (is a bit time consuming)
>
>
> In order to define the field near the coast I extrapolate the field using
> the ncl function "poisson_grid_fill" with arguments:
>
> guess_type=1,nscan=2000,epsx=0.001,relc=0.6. Are these values reasonable)
>
> It is possible to extrapolate with this function not in all the
> Land-points but just near the cost? (this can help to save time)
>
>
> thanks
>
> Francesco
>
>
>    ;;;;====================================================
>
>    ;;;;=== ZONAL VELOCITY U-GRID FILEs
>
>
>    out_T    = addfile(path_exp_outdata_ocean+"/"+file_T,"r")
>    out_Mesh = addfile(path_exp_outdata_oceanMesh+"/"+file_Mesh,"r")
>
>    nlon  = dimsizes(out_T->nav_lon(0,:)-1)
>    nlat  = dimsizes(out_T->nav_lon(:,0)-1)
>    nlev  = dimsizes(out_T->deptht(:)-1)
>    ntime = dimsizes(out_T->time_counter(:)-1)
>
>    lat2dt = out_T->nav_lat(:,:)
>    lon2dt = out_T->nav_lon(:,:)
>    deptht = out_T->deptht(:)
>    time      = out_T->time_counter(0:ntime-1)
>    time_bnds = out_T->time_counter_bnds(0:ntime-1,:)
>
>    var_name = "vozocrtx"
>    out_U  = addfile(path_exp_outdata_ocean+"/"+file_U_Ugrid,"r")
>    lon1du = (/ out_U->nav_lon(0,:) /)
>    u_T    = new((/nlev,nlat,nlon/),typeof(out_U->$var_name$))
>    ;Define dimensions, coord., attributes
>    u_T!0 = "deptht"
>    u_T!1 = "y"
>    u_T!2 = "x"
>    u_T&deptht = (/deptht(0:nlev-1)/)
>    u_T&y      = (/lat2dt(0:nlat-1,0)/)
>    u_T&x      = (/lon2dt(0,0:nlon-1)/)
>    copy_VarAtts(out_U->$var_name$,u_T)
>
>    mask3dt = (/ out_Mesh->tmask(0,:,:,:) /)
>    mask3du = (/ out_Mesh->umask(0,:,:,:) /)
>
>    do itime=0,ntime-1
>       u_U = out_U->$var_name$(itime,:,:,:)
>       ;printVarSummary(u_U)
>
>       ;--- Assign Missing Values at Land Points (grid-U)
>       u_U(0:nlev-1,0:nlat-1,0:nlon-1) = \
>                 where(mask3du(0:nlev-1,0:nlat-1,0:nlon-1).eq.0., \
>                       u_U at _FillValue, \
>                       u_U(0:nlev-1,0:nlat-1,0:nlon-1))
>
>       ;--- Interpolates linearly along the longitude dimension
>       u_T(0:nlev-1,0:nlat-1,0:nlon-1) = \
>                  linint1_n(lon1du(0:nlon-1), \
>                            u_U(0:nlev-1,0:nlat-1,0:nlon-1),False, \
>                            lon2dt(0,0:nlon-1),0,2)
>
>       ;--- Assign an extrapol Value to Missing Values points
>       ;Replaces all Missing(_FillValue) values with values derived from
> solving Poisson's equation via relaxation.
>       poisson_grid_fill(u_T(0:nlev-1,0:nlat-1,0:nlat-1), False, 1, 2000,
> 0.001, 0.6, 0)
>       ;printVarSummary(u_T)
>
>       ;--- Assign Missing Values at Land Points (grid-T)
>       u_T(0:nlev-1,0:nlat-1,0:nlon-1) = \
>                 where(mask3dt(0:nlev-1,0:nlat-1,0:nlon-1).eq.0., \
>                       u_T at _FillValue, \
>                       u_T(0:nlev-1,0:nlat-1,0:nlon-1))
>
>       write_regridVel(path_exp_outdata_ocean,file_U_Tgrid,itime,ntime,nlev,nlat,nlon,
> \
>                       lon2dt(0:nlat-1,0:nlon-1),lat2dt(0:nlat-1,0:nlon-1),deptht(0:nlev-1),
> \
>                       time(0:ntime-1),time_bnds(0:ntime-1,0:1), \
>                       u_T(0:nlev-1,0:nlat-1,0:nlon-1),var_name)
>
>    end do
>
>
> ------------------------------
> *Da:* Dennis Shea <shea at ucar.edu>
> *Inviato:* venerdì 30 giugno 2017 16:11
> *A:* Francesco Trotta
> *Cc:* ncl-talk at ucar.edu
> *Oggetto:* Re: [ncl-talk] from staggered grid field to interpolated
> unique grid field
>
> The Arakawa C-grid has the U, V and scalar (?T?) variables on separate
> grids.
>
> To *my* knowledge, the ESMF regrid package does not interpolate vector
> wind components. Wind components should be interpolated together on the
> sphere. The wind speed is conserved but the magnitudes of the wind
> components will vary. For u and v on the same grid
>
>   uNew = u*cos(rot) - v*sin(rot)    ; rot - rotation angle
>   vNew = u*sin(rot) + v*cos(rot)
>
> Actually, on the Arakawa C-grid, since u and v are on separate grids the
> appropriate rotation angles would be different also.
>
> ---
> What is the objective of the interpolation?
>
> If it is 'just' graphics, then, maybe, interpolating the the V-grid and
> U-grid separately to the T-grid would be acceptable.
>
> ---
>
>
>
> On Thu, Jun 29, 2017 at 3:31 AM, Francesco Trotta <
> francesco.trotta4 at unibo.it> wrote:
>
>> Dear ncl team,
>>   I using ncl and I’m producing 2 netcdf files of meridional e zonal
>> velocity definite on the stagarate grid (C_arakawa U e V grids) and I need
>> to pass this datasets to a collage on a unique T grid.
>>
>>    Is there in ncl some build-in-function which from 2 netcdf file with u
>> e v defined in a staggered U e V grid produce a file with u and v field
>> interpolate on T grid?
>>
>> thanks
>> Francesco​
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170705/e32b82f5/attachment.html 


More information about the ncl-talk mailing list