[Thread Prev][Thread Next][Index]

Re: [ferret_users] seasonal averages



Hi Steve,
          Please note that @AVE is a "weighted" regridding, hence
simple/direct methods may fail to give expected results. For more 
details please see the following sections in user guide 

    Ch3 Sec2.4.6.  @AVE average
    Ch3 Sec2.4.1.  General information about transformations

and the discussions starting with this mail in the archive,

    http://ferret.pmel.noaa.gov/Ferret/Mail_Archives/fu_2006/msg00679.html

How to find exact values then ? Obviously there are two solutions

 1. Supply exact grid boundaries for the destination axis.
 2. Make the grid box lengths uniform by assigning an Abstract time
        axis.

    Please find examples for these two methods below. Explanations and 
relevant references in the user guide are also given in the example. 
Please let me know if you have any questions.

    Both these methods can be adapted to other such regridding 
calculations, with proper modifications to the example given below.
 
    Please note that you may have to use any recent version of Ferret,
for Method 1.
 
Regards,

Jaison

!------------------------Example Starts Here--------------------------
\ cancel mode verify
!
! Examples for two methods to find accurate seasonal mean from monthly 
!   data.
!
! define variable "pre", on a monthly time axis with 12 points

  let var = TSEQUENCE({2.00,3.10,7.00,11.90,36.90,77.80,75.60,57.20,\
                        64.00,22.70,3.90,1.90})
  define axis/t="15-JAN-1901":"15-DEC-1901":`365.2425/12`/units=days\
                  /T0="30-DEC-1900"  tmon
  let pre = var[GT=tmon@ASN]

! Method 1 : Using Gridbox boundaries and Edges 
!
!      The trick is to supply exact boundaries for weighted averaging.
!          I Guess that this method will be efficient than the next one
!          since there is no "axis" changing business, especially for
!          datasets with many time points. 
!
!             For details about Gridbox/Bounds/Edges etc. please see
!                Ch3 Sec1.3.  Pseudo-variables 
!                GLOSSARY
!                Ref Sec4.3.  DEFINE AXIS (look for EDGES and BOUNDS)
!                Ch10 Sec3.5.3.  Unevenly spaced coordinates  

  let t_lobo = tboxlo[gt=pre,l=1]    ! lowest  grid bound for tmon
  let t_hibo = tboxhi[gt=pre,l=12]   ! highest grid bound for tmon

  define symbol t_zero = `pre,r=T0`       ! get the details of original
  define symbol t_cal  = `pre,r=calendar` !      monthly time axis
  define symbol t_unt  = `pre,r=tunits`

        ! get the "edge" values : seasonal time axis will have 4 points
        !   and hence it will have 5 "edge" values. Therefore, we need to 
        !   get 5 equally spaced points between t_lobo and t_hibo, including
        !   them.

  define axis/t=`t_lobo`:`t_hibo`/npoints=5 tedges 
 
  define axis/t/T0="($t_zero)"/calendar=($t_cal)/units=($t_unt)\
                   /EDGES/from_data tseas=t[gt=tedges] ! destination seasonal
                                                       !    time axis
  let pre_seas = pre[gt=tseas@AVE]

  list pre_seas

! Method 2 : Using Abstract axis
!
!    @AVE on abstract axis will yield expected result. But may not suit for
!         datasets with too big time axis, though we use @ASN to move between
!         abstract and calendar time axis.

  define axis/t=1:12:1  tabs 
  define axis/t=2:11:3  tabs_sonl   ! for exact results

  let pre_abs       = pre[gt=tabs@ASN]          ! assign abstract axis
  let pres_abs_sonl = pre_abs[gt=tabs_sonl@AVE] ! find exact seasonal mean
  
  define axis/edges/t=1-jan-1901:31-dec-1901/npoints=4   tsonl
  
  let pres_sonl     = pres_abs_sonl[gt=tsonl@ASN] ! assign calendar axis

  list pres_sonl

!------------------------Example Ends Here--------------------------



On Fri, 26 Jan 2007, Steve Knox wrote:

> I'm trying to compute averages in groups of 3 months: 
> avg(jan,feb,mar),avg(apr,may,jun), etc
> 
> It seems to work, sortof. For example, the first avg = 4.11, but if you 
> calculate the average by hand of 2+3.1+7 you get 4.03 not 4.11.
> The next group of 3 months is 11.9+36.9+77.8 and the average is 42.2 not 
> 42.55
> What am I missing?
> 
> Thanks,
> 
> Steve
> use pre
> show data
>      currently SET data sets:
>     1> ./pre.nc  (default)
>  name     title                             I         J         K         L
>  PRE      Precipitation                    1:720     1:360     ...       
> 1:1200
>  
> *define axis/edges/t=1-jan-1901:31-dec-1901/npoints=`4` myaxis*
>  !-> define axis/edges/t=1-jan-1901:31-dec-1901/npoints=4 myaxis
> *let pre2=pre[gt=myaxis@ave]*
> *list/x=97.25/y=33.25 pre[l=1:12]*
>              VARIABLE : Precipitation (mm/month)
>              FILENAME : pre.nc
>              SUBSET   : 12 points (TIME)
>              LONGITUDE: 97.2E
>              LATITUDE : 33.2N
>                     97.25E
>                     555
>  15-JAN-1901 /  1:   2.00
>  14-FEB-1901 /  2:   3.10
>  17-MAR-1901 /  3:   7.00
>  16-APR-1901 /  4:  11.90
>  16-MAY-1901 /  5:  36.90
>  16-JUN-1901 /  6:  77.80
>  16-JUL-1901 /  7:  75.60
>  16-AUG-1901 /  8:  57.20
>  15-SEP-1901 /  9:  64.00
>  16-OCT-1901 / 10:  22.70
>  15-NOV-1901 / 11:   3.90
>  16-DEC-1901 / 12:   1.90
> *list/x=97.25/y=33.25 pre2*
>              VARIABLE : PRE[GT=MYAXIS@AVE]
>              FILENAME : pre.nc
>              SUBSET   : 4 points (TIME)
>              LONGITUDE: 97.2E
>              LATITUDE : 33.2N
>                    97.25E
>                    555
>  15-FEB-1901 / 1:   4.11
>  17-MAY-1901 / 2:  42.55
>  16-AUG-1901 / 3:  65.54
>  15-NOV-1901 / 4:   9.52
> 
> 


[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement