# [ncl-talk] how to take area average of a user-defined polygon region

Mon Sep 28 09:44:52 MDT 2015

```Hi Mira,
First off, if you do not have a land/sea mask available for the dataset
that you are analyzing, it would be best to use the built-in NCL function
There are numerous examples available on the bottom of that page.

For your averaging question: If you want to average over a rectangle and
you are analyzing a rectilinear grid you can use wgt_areaave_Wrap:
https://www.ncl.ucar.edu/Document/Functions/Contributed/wgt_areaave_Wrap.shtml

You can use index or coordinate subscripting to specify your rectangle; see
example #3 on that page for examples of both. If you do not know what
coordinate subscripting is I strongly suggest you peruse the following
https://www.ncl.ucar.edu/Document/Language/subscript_coord.shtml
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#Subscripts

Finally, if you'd like to chose a grid cell closest to a lat/lon point you
can again use coordinate subscripting. An example:

; arr is a 3 dimensional array ordered time x latitude x longitude with
coordinate variables time, lat, and lon
plat = 35.
plon = 15.
pt = arr(:, {plat},{plon})
printVarSummary(pt)

Finally: If you have not done so I would highly recommend you read through
the mini-language manual here:
http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf

Hope that helps. If not or if you have further questions please respond to
the ncl-talk email list.

On Sun, Sep 27, 2015 at 12:30 PM, <mberdahl at envsci.rutgers.edu> wrote:

> Hi all,
>
> I have model output for the north atlantic/greenland region and I would
> like to take regional averages of precipitation.  I'm wondering how to
> define the regions with NCL.  For example, I would like to take the
> average of precipitation over the Southeast of Greenland, this region
> would have to be a polygon defined by the user.  I would only like to
> consider grid cells on land as well.  Does anyone have any advice on this?
>
> Independent of this, I would like to be able to choose the grid cell
> closest to a lat/lon point that is user-defined.  Can someone point me in
>
> Thanks very much,
> Mira
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

--