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

For modern data allow unit conversion between standard and proleptic_gregorian calendars #185

Closed
larsbarring opened this issue Jul 2, 2021 · 3 comments

Comments

@larsbarring
Copy link
Contributor

larsbarring commented Jul 2, 2021

✨ Feature Request

For modern data allow unit conversion between standard and proleptic_gregorian calendars. "Modern data" is data sources that do not span the Julian/Gregorian transition.

Motivation

When using iris to analyse data from different sources, or to build a multi-model ensemble cube, it often happens that one input source is based on the standard calendar, and another on the proleptic_gregorian calendar. For data that spans the Julian/Gregorian transition these calendars are clearly not compatible, and conversion is of course not possible.

From the perspective of the producer of the data there might be very good reasons for choosing one or the other calendar. E.g. a modelling centre might want to have only one calendar irrespective of whether a simulation covers only the Gregorian era or spans the Julian/Gregorian transition. And a centre dealing with observational data would want to rely on a calendar that follows the real world calendar even for the very longest time-series. But from the analyst's perspective, when fusing modern datasets it should be easy to harmonise the calendars.

After all the standard calendar is the mixed Julian/Gregorian calendar, and the proleptic_gregorian calendar is the Gregorian calendar extended backwards in time. That is, for the modern [post Julian] period they are the same calendar.

EDIT: In principle one could argue that a corresponding conversion should be possible between the standard calendar and the Julian calendar, but I imagine there is much less demand for this because the vast majority of relevant datasets cover the modern period.

@larsbarring
Copy link
Contributor Author

@rcomer, following up on the comments in PR #215 I found that all this might be much simplified by just using cftime.datetime.change_calendar. On the other hand, it seems that cf-units is not applying any sanity checks to the date of the unit string (#216). And this may cause problem here.

Is there already a string decoder somewhere in scitools capable of handling "CF-formatted" date/time strings, i.e. not zero-padded and not making assumptions about which millennium?

@rcomer
Copy link
Member

rcomer commented Feb 25, 2022

Nice, I didn't know about the change_calendar method, and I agree that looks like a good approach. I'm not sure about a string decoder, but maybe it would be easiest to get the reference date as a datetime object by

ref_date = u.num2date(0)

I tried this with your examples from #216, and the num2date step does seem to throw error for most of the cases it should. Does that help?

@trexfeathers trexfeathers removed the New: Feature Highlight a new community raised "feature request" issue label Apr 27, 2022
@larsbarring
Copy link
Contributor Author

I am closing this issue because already some time ago the requested functionality was implemented. Thanks @rcomer !

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

Successfully merging a pull request may close this issue.

3 participants