# [ncl-talk] Calculating divergence from WRF output

Dennis Shea shea at ucar.edu
Wed Apr 11 22:30:53 MDT 2018

```THX for sending a sample file.

See attached.

The computational part of your original scrip was 'ok':

(a) rcm2rgrid  [better: rcm2rgrid_Wrap]
(b) rgrid2rcm  [better: rgrid2rcm_Wrap]

However, as you found out ... it takes 'forever'. The underlying code is
'brute force' and not efficient.

---
I used ESMF.  I am sure you can follow the code.

It plots both the (a) rectilinear divergence and the (b)  WRF divergence.

The advantage of the ESMF is that weight files are generated:

WRF_to_Rect.WgtFile_bilinear.700_x_850.nc

Rect_to_WRF.WgtFile_bilinear.700_x_850.nc

These can be used on any variable that has the original WRF grid structure.

Then you can use:

https://www.ncl.ucar.edu/Document/Functions/ESMF/ESMF_
regrid_with_weights.shtml

The regridding will be 'instantaneous'

============
d04_div_50_1530.000001.png      regular contour plot
d04_div_50_1530.000002.png      One WRF grid with map

Please be aware that interpolating u and  v independently is 'technically'
not correct. Because, the components have moved  to a new geographic
location, there is rotation

Unew = U*cos(ANGLE) - V*sin(ANGLE)
Vnew = U*sin(ANGLE) + V*cos(ANGLE)

Still, what was done is 'good enough'  !

On Tue, Apr 10, 2018 at 6:24 AM, Ty Buckingham <
ty.buckingham at manchester.ac.uk> wrote:

> Hi there,
>
> Having a little trouble calculating divergence from my WRF output.
>
> I'm transforming from the WRF curvilinear grid to a linear grid in order
> to calculate divergence using finite differences, then transforming back
> for my plots.
>
> The WRF output I'm using covers a small area over the UK - however, the
> produced plot is somehow global. Not entirely sure how that's happened.
>
> I've attached my sample code and an image of the output.
>
> Thanks!
> Ty
>
> _______________________________________________
> 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/20180411/d88d15b2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WRF_Divergence.ESMF.ncl
Type: application/octet-stream
Size: 9931 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180411/d88d15b2/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: d04_div_50_1530.000001.png
Type: image/png
Size: 824309 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180411/d88d15b2/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: d04_div_50_1530.000002.png
Type: image/png
Size: 189295 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180411/d88d15b2/attachment-0003.png>
```