Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is PrePARE OK with leap years ? #325

Closed
senesis opened this issue Mar 20, 2018 · 5 comments
Closed

Is PrePARE OK with leap years ? #325

senesis opened this issue Mar 20, 2018 · 5 comments

Comments

@senesis
Copy link

senesis commented Mar 20, 2018

Using two distinct libraries (python/datetime and Xios), it seems that gregorian calendar has 127835 days between 1500-01-01 and 1850-01-01

>>> import datetime
>>> j1850=datetime.datetime(1850,1,1)
>>> j1500=datetime.datetime(1500,1,1)
>>> (j1850-j1500).days
127835

However, when PrePARE is fed with a file having the time variable dumped below, it complains in a way which implies that there is a 9 days discrepancy with its own calculation .

Which library is right ?

! Error: Your filename 
! "clt_day_CNRM-CM6-1_piControl_r1i1p1f2_gr_18500101-18501231.nc" 
! does not match the CMIP6 requirement.
! 
! Your output filename should be: 
! "clt_day_CNRM-CM6-1_piControl_r1i1p1f2_gr_18500110-18510109.nc"
double time(time) ;
                ...
		time:calendar = "gregorian" ;
		time:units = "days since 1500-01-01 00:00:00" ;
		time:time_origin = "1500-01-01 00:00:00" ;
data:
 time = 127835.5, 127836.5, 127837.5, 127838.5, 127839.5, 127840.5, 127841.5, 

@taylor13
Copy link
Collaborator

The problem can be addressed by paying attention to the description of calendars at the end of http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#calendar . When a simulation spans a period crossing the date when the Gregorian Calendar was first adopted (i.e., 1582-10-15), you need to set calendar="proleptic_gregorian". Otherwise a 9-day discrepancy is found.

By the way, according to this calendar, leap years occur in years evenly divisible by 4 except years evenly divisible by 100 and not evenly divisible by 400. By my reckoning, that gives us int((1850-1500)/4+1) - 3 (to account for century adjustments) = 85 leap years for years 1500 through 1850 (inclusive). So the number of days in that period should be: 351*365 + 85 = 128200, and the first time sample for year 1850 should be 128200 - 365 + 0.5 (for the middle of the day) = 127835.5.
So, it appears that at least the first day of 1850 found in your netcdf file is consistent with a proleptic_gregorian calendar.

@taylor13
Copy link
Collaborator

This issue was also noted in item 17c of global attributes section of https://goo.gl/neswPr . Is there a way to make that information more prominent?

@senesis
Copy link
Author

senesis commented Mar 21, 2018

Thanks for this clear explanation. I had never dig that question, and didn't notice that the Python datetime library states that it is:

An idealized naive date, assuming the current Gregorian calendar always was, and always will be, in effect

and that Xios , when instructed to use a gregorian calendar, actually behaves as if a proleptic_gregorian option was used
The document quoted above is clear enough, and the myriad of specifications cannot all be made prominent !

@senesis
Copy link
Author

senesis commented Mar 21, 2018

And PrePARE duly decalres that the data is correct once the value of calendar_type is changed to proleptic_gregorian.
Thanks

@taylor13
Copy link
Collaborator

this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants