# [ncl-talk] calculating gradients in ocean areas with land

Dennis Shea shea at ucar.edu
Wed Jan 20 08:27:16 MST 2021

```For global data with no missing values, NCL uses spherical harmonic based
functions. These are not applicable for your problem.

There are gradient functions that can 'handle' missing values. These use
centered finite differences (_cfd).

(SST, SST&lat SST&lon, True, False)

variables from returned 'list'

; replace the generic attributes with more specific attributes

if (*isatt* <http://www.ncl.ucar.edu/Document/Functions/Built-in/isatt.shtml>(SST,"units"))
then
SST_grad_lat at units = SST at units+"/m"
else
end if

===============================================
Of course, deriving gradients near 'land' is limited due to missing values.
One approach: if the land areas (missing values) are small, the use of
*poisson_grid_fill* <http://www.ncl.ucar.edu/Applications/grid_fill.shtml>
prior to using the above may be appropriate. None of the original SST
values is changed.
I think this is much better than using (say) bilinear interpolation to fill
in gaps.
For smaller regions, I'd say it is shape preserving interpolation.

SST

guess     = 1                ; use zonal means
is_cyclic = False            ; non-cyclic
nscan     = 1000             ; usually MUCH than this
eps       = 1.e-2            ; variable dependent
relc      = 0.6              ; relaxation coefficient
opt       = 0                ; not used

*poisson_grid_fill*( SST, is_cyclic, guess, nscan, eps, relc, opt)
;;*poisson_grid_fill*( SST, True, 1, 1500, 1e-2, 0.6, 0)
Then use
(SST, SST&lat SST&lon, True, False)

You might save the original grid
SST_SAVE = SST

then use it to restore the original missing value locations

SST = where(ismissing(SST_SAVE), SST at _FillValue,SST)

Some grid filling examples: *Grid Fill*
<http://www.ncl.ucar.edu/Applications/grid_fill.shtml>
*Some Spherical Harmonic Examples*
<http://www.ncl.ucar.edu/Applications/wind.shtml>: These include some
gradient examples: Calculate various divergence and moisture quantities
including Vertically Integrated Moisture Flux Convergence (*VIMFC*).

Good Luck
Happy New Year
Stay Healthy

On Wed, Jan 20, 2021 at 1:36 AM Sam McClatchie via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Colleagues
>
> I have a general question where I suspect the answer is "no".
>
> Problem:
>
> I would like to calculate temperature gradients from satellite measured
> SST in ocean areas around a land mass (see <http://u.pc.cd/K62rtalK>
> <http://u.pc.cd/K62rtalK> for a plot of the SST data). The SST data
> matrix has missing values. Using the landsea_mask and mask functions, I
> have confirmed that the missing data (data at _FillValue) are at grid points
> over land. If I remove the missing values, I destroy the regular grid.
>
> Question: Does NCL have a function for calculating gradients in ocean
> areas with land? Or are the various functions designed to calculate
>
> Best fishes
>
> Sam
> --
> Sam McClatchie (fisheries oceanographer)
> & Elena Turin (accounting & auditing)
> FishOcean Enterprises www.fishocean.info
> 38 Upland Rd, Huia, Auckland 0604, New Zealand
> cell: 027 752 8495
>
>
> “The three great elemental sounds in nature are the sound of rain,
> the sound of wind in a primeval wood, and the sound of outer ocean on a
> beach.
> I have heard them all, and of the three elemental voices,
> that of ocean is the most awesome, beautiful and varied.”
>
> ― Henry Beston, The Outermost House: A Year of Life on the Great Beach of
> Cape Cod
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210120/4b5f40d4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SamMcClatchie2_small.jpg
Type: image/jpeg
Size: 45362 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210120/4b5f40d4/attachment.jpg>
```