Days per year for different calendars

Issue #4 new
Nathan Collier created an issue

When I run the following code I see unexpected number of days per year for certain calendars.

from cfunits.units import _canonical_calendar
from cfunits import Units
import numpy as np

for cal in _canonical_calendar.keys():
    t0 = Units("days since 1851-1-1",calendar=cal)
    tf = Units("days since 1850-1-1",calendar=cal)
    t  = Units.conform(np.zeros(1),t0,tf)
    print "%20s %.10f" % (cal,t[0])

yields:

             360_day 360.0000000000
                none 365.0000000000
           gregorian 365.0000000000
              julian 365.0000000000
             365_day 365.0000000000
              noleap 365.0000000000
            all_leap 366.0000000000
             366_day 366.0000000000
 proleptic_gregorian 365.0000000000
            standard 365.0000000000

It seems to be converting internally based on an integer number of days because if I change the time span to be 100 years and then divide the elapsed time by 100, I get two digits of accuracy.

for cal in _canonical_calendar.keys():
    t0 = Units("days since 1950-1-1",calendar=cal)
    tf = Units("days since 1850-1-1",calendar=cal)
    t  = Units.conform(np.zeros(1),t0,tf)
    print "%20s %.10f" % (cal,t[0]/100.)

yields:

             360_day 360.0000000000
                none 365.2400000000
           gregorian 365.2400000000
              julian 365.2500000000
             365_day 365.0000000000
              noleap 365.0000000000
            all_leap 366.0000000000
             366_day 366.0000000000
 proleptic_gregorian 365.2400000000
            standard 365.2400000000

Is this working as intended? If I change days to hours and divide the result by 24, I still get the wrong number of days per year.

Comments (3)

  1. Nathan Collier reporter

    Or perhaps it is not as I am thinking and no calendar is using a precise revolution time around the sun?

  2. David Hassell repo owner

    I think that this is OK. 1850 in the Gregorian calendar did indeed only have 365.0 days. You're right that the precise revolution (365.242198781 days) is not used in any of the CF calendars.

  3. Nathan Collier reporter

    The reason that I am asking is that I am trying to work out model-observation comparisons where we have differences in the calendars and datum. Cfunits (and I guess the underlying udunits) doesn't convert calendars. That is, the following fails:

    print Units.conform(0.,
                        Units("days since 1850-01-01 00:00:00",calendar="365_day"),
                        Units("days since 1850-01-01 00:00:00",calendar="gregorian"))
    

    Unfortunately, the reality is that I have to come up with something to handle these differences (do you have any recommendation?). So I have been playing around with different conversions, trying to understand them and wondering if I have stumbled across bugs. The following strikes me as strange:

    print Units.conform(1850.,
                        Units("years since 0000-01-01 00:00:00",calendar="365_day"),
                        Units("years since 1850-01-01 00:00:00",calendar="365_day"))
    

    yields 1.22676883122 when I was expecting 0. And it changes based on the calendar you use. Can you explain this?

  4. Log in to comment