5 day precipitation

Dave Allured dave.allured at NOAA.GOV
Tue Feb 7 14:44:39 EST 2006


Ben,

Here are some partial answers for you.

1.  Be careful about nesting functions to deeply in Grads.  To this end
I recommend making your outer time loop with the scripting language's
while/endwhile construct.  Within that loop, I think you can accomplish
the lat/lon gridded operations (5-day summing, threshold test, and
conditional counter) with Grads array expressions, with optimal efficiency.

2.  As a novice, you are poised for that pitfall about the dichotomy
between Grads variables and script variables.  They are two different
things.  It's helpful to think of the scripting language as a text line
driver for the Grads command language.

So for example, generate a time loop index like this in script language;
    tstart = 1
    while (tstart < 2919)

Then "pass" the index to a Grads command via text concatenation, like this:

       'fivedayprec = sum (prec, t = ' tstart ', t = ' tstart+4 ')'

The quoting is critical.  Note that there are five text terms; the
first, third, and fifth are quoted strings.  The numeric expressions
tstart and tstart+4 are evaluated in script mode, then converted to text
before the final command is passed to the Grads command core.

tstart is a scalar script variable, but prec and fivedayprec are
so-called Grads variables (arrays).  t is not a variable at all in this
context, but rather a special syntax that identifies the dimension.  The
spaces are optional, but they improve readability.

3.  For your computation, I think the sum function is the right one.
For the gridded threshold test, use a combination of maskout and const
functions to construct a grid of 1's and 0's for incrementing, then add
this to your counter grid at each time step.  There may be a better way
to do this, but I can't see it right now.  Look all these up on Grads docs.

4.  Remember also that the main Grads functions and the scripting
language functions are two separate libraries that apply only to the
Grads command language and the scripting language, respectively.

HTH.

--Dave

Ben Burford wrote:
> Hello All,
>
> I'm trying to implement a script.  I studied functions (e.g. tloop) and look
> ed in the archives for help, but so far its over my head as a beginner, I'm
> not even sure if Grads can do this.
>
> I have an 8 year (t=1,2922) global gridded daily precipitation data set.  Fo
> r each grid cell I want to go through the time series and check each five da
> y period (2918 possible 5 day periods) to see if the total of the precipitat
> ion for the five days is greater than a certain level, if it is I want to in
> crement a counter.  The result will be a single value (total count) for each
>  grid cell (global grid of a single value per grid cell).
>
> The value that I want to check the five day total against is "10% of the ann
> ual average rainfall" (tenpanave) which I'm calculating as follows (add up a
> ll the daily values for 8 years, divide by 8 to get the annual average, then
>  take 10% of that):
> tenpanave = 0.1*((sum(prec,t=1,t=2922))/8)
>
> A flow chart for the script might look like:
> * Calculate "10% of the annual average rainfall" (tenpanave)
> tenpanave = 0.1*((sum(prec,t=1,t=2922))/8)
>
> * calculate the precipitation over 5 days (5dayprec), if that 5 day total is
>  greater than or equal to ten percent of the annual average precipitation (t
> enpanave) for that grid cell, then increment the counter for that grid cell.
>   Perform this process for all grid cells, over the full time period of 2922
>  days (x from 1 to 2918).
> x=1
> 5dayprec=sum(prec,t=x,t=x+4)
> if 5dayprec is greater than or equal to tenpanave then count=count+1
> x=x+1
> if x=2919 then quit, else go up three steps and calculate the next 5 day win
> dow (5dayp)
>
> * Display results
> d count
>
>
> As I say, I don't know if this can be done with Grads.  Any help would be gr
> eatly appreciated.
>
> Thank you,
>
> Ben
>



More information about the gradsusr mailing list