# [ncl-talk] Area averaged precipitation

Toni Klemm toni-klemm at tamu.edu
Mon Aug 19 08:06:07 MDT 2019

```Hello George,

It sounds like you want to create a subset of your data and then take the average of that. There are several ways you can create subsets with, for all you would need to know the latitude and longitude of the area you’re interested in (Google Earth could tell you): https://www.ncl.ucar.edu/Applications/latlon_subset.shtml <https://www.ncl.ucar.edu/Applications/latlon_subset.shtml>

Here is the method I’ve been using to create a subset:

precip = [input_file]->precipitation_data
lat = [input file]->lat
lon = [input file]->lon

lat_subset = (/range_from,range_to/)	; latitude range
lat_subset at axis = "Y"
lat_subset at units = "degrees_north"
lat_subset at standard_name = "latitude"
lat_subset at long_name = "latitude"

lon_subset = (/range_from,range_to/)	; longitude range
lon_subset at axis = “X"
lon_subset at units = "degrees_east"
lon_subset at standard_name = “longitude"
lon_subset at long_name = “longitude"

lti = ind_nearest_coord(lat_subset,lat,0)	; determines the index numbers of the nearest grid cells
lni = ind_nearest_coord(lon_subset,lon,0)

lat_subdomain = lat(lti(0):lti(1))	; creates subset latitudes and longitudes based on defined range
lon_subdomain = lon(lni(0):lni(1))

precip_subdomain = precip(:,lti(0):lti(1),lni(0):lni(1))	; define the subdomain based on latind and lonind

From this you can now create the average using dim_avg_n (https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_avg_n.shtml <https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_avg_n.shtml>) or avg (https://www.ncl.ucar.edu/Document/Functions/Built-in/avg.shtml <https://www.ncl.ucar.edu/Document/Functions/Built-in/avg.shtml>).

You should also double-check the lat and lon subsets to make sure you got the correct region:
printVarSummary(lat_subdomain)
printVarSummary(lon_subdomain)

Good luck,
Toni

Toni Klemm, Ph.D.
Postdoctoral Research Associate
Department of Ecosystem Science and Management
College of Agriculture and Life Sciences
Texas A&M University, College Station, TX
www.toni-klemm.de <http://www.toni-klemm.de/> | @toniklemm <http://www.twitter.com/toniklemm>
Editorial Board member, Early Career Climate Forum <http://www.eccforum.org/>

> On Aug 19, 2019, at 1:12 AM, Babitha George via ncl-talk <ncl-talk at ucar.edu> wrote:
>
> Hi,
>
> I would like to take the area averaged precipitation over the state Kerala and I was wondering how to select the region.
> I have the shapefile of India, but I want to select only Kerala and do area average
> Does anyone have any advice on this?
>
> Thank you
> --
> Babitha George
> Research Scholar
> IIST, Valiamala
> Thiruvananthapuram,Kerala
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=zmhRVp0i4wZ5_1Ujh0fnRXAExHgKLTQu0rZLW7PxKA4&m=DJHjN80eON8I-D3QAeWzgZMn-iDk_H3IhlRI79wbEjY&s=KlaeyA13Gdhvi1cZK3cYojB3WgGsFpXh7TkT_zcj9lw&e=

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190819/9432b126/attachment.html>
```

More information about the ncl-talk mailing list