# Re: monthly averages from daily

 Hi Steve, First, a few general things about calendars. By default, Ferret uses a Gregorian calendar.  That is, it takes into account leap years, and also the corrections to leap years every century that are in standard use.  Ferret also allows for the use of several other calendars, to accomodate models that use simplified definitions of the time. Look up "time, calendars" for a section in the Users Guide on this. Also see "time axis, defining" for more about creating time axes. Please also see the entries under "monthly axis"  for more discussion. Monthly axes are always problematic, as "month" is a unit whose length varies.  By default Ferret makes an axis with equal length months, 1/12 of the total length of the year. The axis you define is not really a monthly time axis. When you give a start and end point and /npoints=12  then the start and end points that you list are the first and last COORDINATE points, rather than the edges of  the grid cells as I think you probably intended.  I've made some examples here - I use a unit of days so we can see the time coordiate more easily.  Ferret can regrid among time axes no matter what the time unit is.  Compare:    ! original definition yes? def axis/t="1-jan-1979":"31-dec-1979"/t0="1-jan-1979"/npoints=12/units=days tmonth yes? list t[gt=tmonth]              VARIABLE : T                         axis TMONTH              SUBSET   : 12 points (TIME)  01-JAN-1979 /  1:    0.0  03-FEB-1979 /  2:   33.1  08-MAR-1979 /  3:   66.2  10-APR-1979 /  4:   99.3  13-MAY-1979 /  5:  132.4  15-JUN-1979 /  6:  165.5  18-JUL-1979 /  7:  198.5  20-AUG-1979 /  8:  231.6  22-SEP-1979 /  9:  264.7  25-OCT-1979 / 10:  297.8  27-NOV-1979 / 11:  330.9  31-DEC-1979 / 12:  364.0 ! The above axis extends from mid-December 1978 to ! mid-January 1980. This makes the length of your months ! 33 days as is seen by the first two points listed above. ! If we use the /EDGES qualifier, then Ferret knows to ! use the dates you specify as the start of the first grid ! cell and the end of the last grid cell.  We should also ! specify the hour and minute of the beginning and end of ! the days (or you could end with 1-jan-1980). yes? def axis/t="1-jan-1979:00:00":"31-dec-1979:23:23"/t0="1-jan-1979:00:00"/npoints=12/ edges/units=days tmonth yes?  list t[gt=tmonth]              VARIABLE : T                         axis TMONTH              SUBSET   : 12 points (TIME)  16-JAN-1979 /  1:   15.2  15-FEB-1979 /  2:   45.6  18-MAR-1979 /  3:   76.0  17-APR-1979 /  4:  106.5  17-MAY-1979 /  5:  136.9  17-JUN-1979 /  6:  167.3  17-JUL-1979 /  7:  197.7  17-AUG-1979 /  8:  228.1  16-SEP-1979 /  9:  258.5  16-OCT-1979 / 10:  288.9  16-NOV-1979 / 11:  319.4  16-DEC-1979 / 12:  349.8 To see more about this axis, let's list the pseudo-variables tbox, tboxlo, and tboxhi yes? list t[gt=tmonth], tbox[gt=tmonth], tboxlo[gt=tmonth], tboxhi[gt=tmonth]              TIME: 01-JAN-1979 00:00 to 31-DEC-1979 23:23  Column  1: T is T (axis TMONTH)  Column  2: TBOX is TBOX (axis TMONTH)  Column  3: TBOXLO is TBOXLO (axis TMONTH)  Column  4: TBOXHI is TBOXHI (axis TMONTH)                       T   TBOX TBOXLO TBOXHI 16-JAN-1979 /  1:   15.2  30.41    0.0   30.4 15-FEB-1979 /  2:   45.6  30.41   30.4   60.8 18-MAR-1979 /  3:   76.0  30.41   60.8   91.2 17-APR-1979 /  4:  106.5  30.41   91.2  121.7 17-MAY-1979 /  5:  136.9  30.41  121.7  152.1 17-JUN-1979 /  6:  167.3  30.41  152.1  182.5 17-JUL-1979 /  7:  197.7  30.41  182.5  212.9 17-AUG-1979 /  8:  228.1  30.41  212.9  243.3 16-SEP-1979 /  9:  258.5  30.41  243.3  273.7 16-OCT-1979 / 10:  288.9  30.41  273.7  304.1 16-NOV-1979 / 11:  319.4  30.41  304.1  334.6 16-DEC-1979 / 12:  349.8  30.41  334.6  365.0 When you were comparing results, you did two different averages.  The axis you defined put the center of the first grid box at January 1, so when you look at the first point of the variable mtmax, it's the average of the daily data from the start of the data (January 1?) to the end of the first grid box, in mid-January. The second average you computed is the true January average, from January 1 to January 31.  Ansley Manke Steve Knox wrote: I have daily NetCDF data with a time dimension defined as "hours since...". The time variable thus goes in  increments of 24 hours. How do I compute monthly averages from these daily data.   I tried the following but it doesn't give the expected results:    use tmax    set region/x=-100/y=40    def axis/t0=01-jan-1979/t="01-JAN-1979":"31-dec-1979"/npoints=12 mtax    def grid/t=mtax mgrid    let mtmax = tmax[gt=mgrid@ave    list mtmax list mtmax              VARIABLE : TMAX[GT=MGRID@AVE]              DATA SET : Daily NCEP/DOE Reanalysis 2              FILENAME : tmax.cdf              SUBSET   : 12 points (TIME)              LONGITUDE: 99.4W(-99.4)              LATITUDE : 41N              Z (m)    : 2                     99.4W                      -52  01-JAN-1979 /  1:  262.8  03-FEB-1979 /  2:  268.3  ......  31-DEC-1979 / 12:  279.0 But if I compute the ave for just january 1979 I get this:  yes? list tmax[t=1-jan-1979:31-jan-1979@ave]                TIME     : 01-JAN-1979 00:00 to 31-JAN-1979 00:00 (averaged)           265.3 This calendar business is very confusing! I've looked at many examples in the archives but still am confused about this. For instance, does FERRET handle leap years so that the number of days in FEB is correct? ```-- Steve Knox Natural Resource Ecology Laboratory Colorado State University Fort Collins, CO 80523-1499 stevek@nrel.colostate.edu ```

Dept of Commerce / NOAA / OAR / PMEL / TMAP