how to do averaging over land

Douglas Clark dbcl at CEH.AC.UK
Thu May 10 05:42:29 EDT 2007


There is a 'direct' way to do this within GrADS:

1. Create a land/sea mask variable (1 at land,0 sea)
If you don't already have this, you could create a new GrADS file, using the same grid as in your existing file.

2. Use aave and maskout to calculate area average at land points.
e.g.
set x 1
set y 1
set t 1 12
define a1=aave(maskout(val1,land-0.5),lon=0,lon=90,lat=0,lat=30)
will calculate the area average of the variable val1 at land points and store it in variable a1.
maskout is used here to remove sea points (where land-0.5 is <0)
This can be done with the time dimension varying, so you get a time series as the result.

Doug

>>> stegert at IFM.UNI-HAMBURG.DE 10/05/2007 10:03 >>>
Dear,

I don't know whether there is a 'direct' way within GrADS.
Anyway, I calculated average values at certain ocean areas.

I assume you have a certain grid of say 180x120 cells (i.e.
1'x1' per cell for your area).

1) You create a land-sea-mask within an ASCII-file
(landsea.dat) containing a 180x120 matrix of zeros and ones
representing land and sea, respectively.

2) open your grads-file and do a loop through the map (assumably
a 2d dataset!?)
var = 0
inc = 0
j   = 120
while (j>0)
  'set y 'j
  lsmask = read(landsea.dat)  * opens the dat-file
  lsline = sublin(lsmask,2)   * read line
  i = 1
  while (i<181)
    'set x 'i
    lsval = subwrd(lsline,i)  * read value
    if (lsval = 1)            * only when on land
      'd parameter'           * read value from grads
      var = var + subwrd(result,4)
      inc = inc + 1
    endif
    i = i+1
  endwhile
  j = j-1
endwhile
st = close(landsea.dat)

With 'var' you have the total amount over land.
With 'var/inc' you'll get the average over land.
Mind: In the .dat the 10°N/100°E is in the last
line (that's why to count j from 120 to 0).

You can also put this within a temporal loop to
read different time steps as well as you can define
different areas (defined by 0,1,2,...) and with
elseif (lsval = 2) var2 = var2+subwrd(result,4); inc2 = inc2+1; endif
elseif (lsval = 3) var3 = var3+subwrd(result,4); inc3 = inc3+1; endif
etc.

Hope, this helps.
Christoph

praise praise wrote:
>
> Dear frineds,
>
> My problem is to construct a time series representing an area average of
> a parameter, say temperature, over the area say (100-130E, 10-30N).  But
> I am only interested in the average over land.
>
> Thus, do anyone know how to define the variable representing an areal
> average over land only?
>
> Thanks
>
> MC


--
Christoph Stegert
Institute for Oceanography - Ecological Modelling group
University of Hamburg, GER - (ZMK/ZMAW alliance member)
Bundesstr.53 20146 Hamburg - +49-40/42838-7486 Room 348


--
This message (and any attachments) is for the recipient only. NERC
is subject to the Freedom of Information Act 2000 and the contents
of this email and any reply you make may be disclosed by NERC unless
it is exempt from release under the Act. Any material supplied to
NERC may be stored in an electronic records management system.



More information about the gradsusr mailing list