Re: ut_calendar

From: Rick Grubin (grubin AT XXXXXX)
Date: Mon Dec 22 2003 - 09:44:05 MST

  • Next message: Sylvia Murphy: "Re: Polygon plots"

    Hi Derrick,

    As we discussed a bit last week, and as Mary has stated, there's a
    distinct difference between Matlab and NCL (via udunits) with regard to
    handling time referenced as "year 0(000)." From NCL's point of view,
    this is strictly a udunits issue: NCL supports udunits directly, and
    when those functions are called, the return information is passed through
    NCL untouched to the user.

    You wrote:
    > > Regarding the ut_calendar function, I have a netcdf file with the time
    > > units attribute defined as
    > >
    > > time@units = "Days since 0000-1-1 00:00:00 -0.00"

    > > In NCL I try
    > >
    > > time = 731200.0
    > > time@units = "Days since 0000-1-1 00:00:00 -0.00"
    > > print(ut_calendar(time,0))
    > >
    > > and get
    > >
    > > (0,0) 2002
    > > (0,1) 12
    > > (0,2) 15
    > > (0,3) 0
    > > (0,4) 0
    > > (0,5) 0

    and Mary said:
    > It is my understanding that in Udunits year 0000 is treated as year 0001.

    I confirmed with the folks at Unidata, who created and support udunits.
    Udunits does not recognise that there is a "year 0" -- it is based on
    the assumption that before year 0 is year 1 BCE, and after year 0 is
    year 1 CE, and so on.

    Also note that udunits uses a mixed Gregorian/Julian calendar, and that
    it's possible to see "unexpected" or "strange" behavior when working with
    dates prior to 1582-10-15 (or around that date).

    > > These data were created in Matlab using the Matlab default function
    > > datenum. This calendar function creates a serial date which is defined
    > > exactly as above, at least that's what the documentation says.

    Indeed, from within Matlab:

    >> help datenum

     DATENUM Serial date number.
        N = DATENUM(S) converts the string S into a serial date number.
        Date numbers are serial days where 1 corresponds to 1-Jan-0000.

    and Mary noted:
    > In fact, according to the Matlab "datenum" documentation, it states:
    >
    > "By default, the serial day 1 corresponds to 1-Jan-0000."

    The helpdesk folks at Matlab have also confirmed that Matlab does
    indeed view "year 0" as valid.

    It seems clear that udunits and Matlab have differing notions of what
    "year 0" means.

    Where ferret is concerned, you note:
    > > If I generate a plot in ferret (another graphics package which deals
    > > with netcdf files) I get what I'm looking for. That is the serial
    > > date number (for example 731200.0000 corresponds to Dec 15, 2001)

    and Mary pointed out:

    > Also, I saw a reference to Udunits and Ferret in a Ferret FAQ:
    >
    > http://ferret.pmel.noaa.gov/Ferret/Mail_Archives/fu_99/msg00060.html
    >
    > Note that it talks about a hack to the Udunits interface.

    Ferret's documentation
      http://ferret.wrc.noaa.gov/Ferret/Documentation/Users_Guide/v55/fer_html.htm
      (May.2003)

    makes these notes:

      The default calendar in Ferret is the Gregorian calendar. This is implemented
      as a "proleptic" calendar, where the definition of a year is consistent
      throughout time and does not have an offset in the 1500's as the historical
      calendars did.

    and

      Data, particularly outputs from models, may be defined with time axes that
      are not on the standard Gregorian calendar. The NetCDF conventions document
      discusses and defines usage for different calendars. These conventions for
      calendars are implemented in Ferret version 5.3 See:
          http://www.cgd.ucar.edu/cms/eaton/cf-metadata/CF-current.html (Oct.2003)

    In this document, you will find: section 4.4 Time Coordinate
                                     subsection 4.4.1 Calendar

      In order to calculate a new date and time given a base date, base time
      and a time increment one must know what calendar to use. [...]

      gregorian or standard
          Mixed Gregorian/Julian calendar as defined by Udunits. This is the default.
      [...]

    I think these two statements are at odds with each other.

    As Mary states, and I concur:

    > If Matlab and Ferret are producing different results than NCL and
    > Ncview, then they might doing something additional when they encounter
    > a start year of 0000.

    Different pieces of software (udunits, Matlab, ferret) handle the issue of
    "year 0" differently, primarily due (according to documentation) to the way
    historical calendars are interpreted.

    It seems clear that Matlab accepts and uses "year 0" as valid. Unidata,
    via udunits, does not define "year 0," and uses a mixed Gregorian/Julian
    calendar. Ferret states its default calendar is Gregorian only, and that
    does seem to be the behavior you're seeing.

    I don't claim to know who is "right" or "wrong" in this matter. NCL is
    based on udunits, and thus you'll see that defined behavior in NCL. Matlab
    clearly seems to recognise "year 0" as valid. Ferret's documentation
    (I think) contradicts itself, you I suggest you contact those folks
    directly for their interpretation.

    -Rick.

    --
    Rick Grubin                     Visualization + Enabling Technologies
    Scientific Computing Division   National Center for Atmospheric Research   
    grubin@ucar.edu                 303.497.1832
    



    This archive was generated by hypermail 2b29 : Mon Dec 22 2003 - 09:30:29 MST