NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: [idvusers] Formula to compute anomalies

I wanted to post this example (see below), which was the solution to
Joseph Maina's question as an example.  His problem was exacerbated by
the two grids having different domains -- not only in longitude, but
in latitude....one of them had finer resolution near the equator than
in other latitudes.

On Tue, May 11, 2010 at 4:03 AM, Joseph Maina <jmaina@xxxxxxx> wrote:
> Hi List, I intend to compute temperature anomalies of a long time series by
> taking the difference between each time step  in a monthly mean time series
> and the temperature anomaly (single grid). The output would be a time series
> of this difference (anomalies), which I would then compute a cumulative sum
> of only the positive anomalies, more like the current inbuilt sum over time
> steps formula but in this case only the positive anomalies would be
> summed..any help would be much appreciated. Thanks

He wanted to get 3 sets of data:  a grid of the "tos" values minus the
"mmm" (average) -- the "tos" values were in a time ordered grid, but
the averages were in a single time grid.

Secondly, he wanted to get a set of grids where the anomalies < 0 were
set to zero, and finally, a single grid which summed up the anomalies
> 0 over the time periods.

To accomplish this, I first created a common domain and then computed
the anomalies while resampling into this common domain.

def joseph(mmm, tos):

 # first, resample the mmm grid
 nd=makeDomain("(Longitude,Latitude)",0,360,361,-90,90,181)
 mmr = resample(mmm,nd)

 # now resample the tos data and compute the anomalies
 anon = tos.clone()
 n = len(anon)
 for i in xrange(n):
   anon[i] = resample(tos[i],nd) - mmr
 #return anon

 # find where anon < 0, and replace with 0.0
 for i in xrange(n):
   index = find(anon[i], "<", 0.0)
   anon[i] = replace(anon[i], index, 0.0)
 #return anon

 # create a single-time data and set values = 0
 count = replace(anon[0], 0.0)
 # now, add "1" for each non-zero entry in anon[i]
 for i in xrange(n):
   count = count + mask(anon[i],">",0.0)
 count = newUnit(count,"counts","count")
 return count

-- 
Tom Whittaker
University of Wisconsin-Madison
Space Science & Engineering Center (SSEC)
Cooperative Institute for Meteorological Satellite Studies (CIMSS)
1225 W. Dayton Street
Madison, WI  53706  USA
ph: +1 608 262 2759



  • 2010 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the idvusers archives: