-
Notifications
You must be signed in to change notification settings - Fork 284
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
BUG: iris pp treats standard calendar as a proleptic gregorian and ignores real proleptic gregorian calendars #3561
Comments
In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity. If this issue is still important to you, then please comment on this issue and the stale label will be removed. Otherwise this issue will be automatically closed in 28 days time. |
this is still important but I don't have any time to fix it myself |
If I understand this issue and the PP spec correctly, it isn't possible to save a PP file with a non-Proleptic Gregorian calendar. Possibly behaviours for Iris when asked to save a cube with a Standard calendar seems limited to
Are there other alternatives? Which of these would be preferred? |
taking this back to basics. The problem is that the orginal UMDP F3 which was the basis of the pp load and save rules was somewhat lose in its teminology and referrred to the UM's calendar as a Standard calendar in one place and Proleptic Gregorian somewhere else. On closer inspection, I determined that it is in fact Proleptic Greogrian. However, the pp load and save rules are treating it as Standard This means there is a symetrical error here: I thefore think there are actually two changes needed here which should cancel out in all round trip pp tests: in pp.py change
and in pp_save_rules.py change
to
|
assuming a round trip with pp data is unchanged, then there are two other cases:
|
What I could probably do is make the above changes (except the conversion of standard calendar) and then see which, if any, of the tests break |
SciTools/cf-units#203 currently needs parallel changes in Iris, which seem quite relevant here - notably that pp files don't handle cf's "standard" calendar |
I agree that this is a bug fix. Given the likelihood that downstream users have a workaround it seems like a breaking change. We could look at hiding it behind a FUTURE flag or something (though I'm not 100% on what that entails)
I'd be happy converting to the right calendar and then doing the save without asking the user. I think this is breaking in the same way as the other effect - it invalidates workarounds / changes results that should be reproducible. |
Sorry I’ve not read this thread in detail, but SciTools/cf-units#185 seems relevant, and I understand @larsbarring already has a branch for it. |
I think this will break more than just saving to other formats. For example, if you plot a time series and your calendar is "standard", the values are converted to Lines 590 to 608 in 75c7570
For many (most?) UM applications, the data won't go back far enough for the standard/proleptic_gregorian distinction to be meaningful, so I think it would be good to permanently retain the option of cubes loaded from PP having the "standard" calendar. |
it sounds like this is an issue we will have to live with. Trying to make this backward compatible seems very hard but there is no consensus to make it a breaking change, so we will have to live with it. I propose to close this issue as "won't be fixed" |
As I understand it, we are only just now starting to have climate configurations with a proper calendar, whereas historically they were 360_day. So the issue could start to become a genuine problem where it wasn't before (though I'm not sure how far back even the climate experiments go). |
We make breaking changes sometimes, and with good reasons. This will be a useful place to start if in future it becomes more important to match the actual meaning of pp dates. In the meantime, would a warning be helpful, so that users this is affecting have a pointer towards where the bug is coming from in their code that assumes Iris does this correctly? |
No one ever looks at warnings. |
I've just learned something... from cf_units import Unit
u = Unit("days since 1970-01-01", calendar="standard")
gap_dates = range(-141430, -141420)
print(u.num2date(gap_dates)) shows Julian/Gregorian gap as expected
but print(u.num2pydate(gap_dates)) shows no gap, because the
which rather points to the plotting code being wrong. Possibly there are other implications but my brain hasn't got there yet... |
I wonder if we could actually have our cake and eat it here. Noting that
So, once we have converted our pp time headers into a coordinate with unit "hours since 1970-01-01 00:00:00", it is somewhat arbitrary whether we label it "proleptic_gregorian" or "standard". Would it therefore be reasonable to use the Proleptic Gregorian calendar to do the conversion from pp-header to coordinate, but still label the coordinate with the "standard" calendar? It would be a bit of a fudge, but would mean any change in behaviour would be limited to dates before 15th October 1582, and therefore a bugfix. Based on #3561 (comment), pp-saving could use |
I have to admit, I am now getting a bit lost with all of this. It came about because I needed to convert some netCDF data from the ACCESS model to ancils. That model stored the date with a time of "days since 1-1-1 0:00" or similar and when it was saved to ancil, the time was shifted. I worked around this by converting the time units to be post 1582. I am not sure if this fix would still be needed with your proposed cake fix? |
Hmmm. It looks like import cf_units
tunit = cf_units.Unit("days since 1-1-1 0:00")
tunit.num2pydate(42)
But since cf_units v3.1 we can do new_unit = tunit.change_calendar("proleptic_gregorian")
print(new_unit.num2date(0))
So maybe pp-saving should enforce a Proleptic Gregorian calendar before doing its conversions to headers. I need more caffeine... |
Noting that the calendar previously called "gregorian" in the cf-conventions is now called "standard", I've updated the comments through this issue to hopefully reduce confusion. |
This no longer needs a team discussion of the principles, it needs a concrete proposal for people to discuss. So something to assign as a project for someone in future. If we can't find someone to assign, I will close this (unless it gets enough votes). |
proposal in pp.py change calendar = cf_units.CALENDAR_STANDARD and in pp_save_rules.py change elif time_coord.units.calendar == 'standard': to elif time_coord.units.calendar == 'proleptic_gregorian': then we have to decide how to handle files in a standard a calendar option 1: error |
|
I have stuck up a PR based on my comments above at #5138 |
In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity. If this issue is still important to you, then please comment on this issue and the stale label will be removed. Otherwise this issue will be automatically closed in 28 days time. |
iris/lib/iris/fileformats/pp_save_rules.py
Lines 398 to 404 in 75c7570
Standard calendar cannot be treated as a Proleptic Gregorian for dates
1582-01-01
More context here: ancil/ticket #1159
UM F03 more recently clarified that the calendar it expects isn't Standard but a Proleptic Gregorian. Not only is iris pp save ignoring time coordinates with
proleptic_gregorian
calendars entirely, it also allows saving Standard dates prior to1582-01-01
(as though they are proleptic gregorian dates when they are not).The text was updated successfully, but these errors were encountered: