Iris: Convert 'standard' calendar to 'gregorian' and visa versa

Created on 18 Jul 2018  路  5Comments  路  Source: SciTools/iris

Although standard and Gregorian calendars are equivalent, when plotting time series, we need the two strings to compare. To facilitate this, we should add two new functions cal2std and cal2greg that make it easy to change the calendar name. This has to be done by making a new cordinate and deleting the old one.

Question

Most helpful comment

FWIW in cf-units 2 we introduced calendar aliases so that Gregorian is standard.

>>> import cf_units
>>> cf_units.__version__
'2.0.1'
>>> a = cf_units.Unit('days since 2000-01-01', calendar='standard')
>>> b = cf_units.Unit('days since 2000-01-01', calendar='gregorian')
>>> a == b
True
>>> a
Unit('days since 2000-01-01', calendar='gregorian')
>>> b
Unit('days since 2000-01-01', calendar='gregorian')

cf-units 2 is part of the Iris 2.1 release, and will be rolling out to an organisation near you soon 馃槈. Even sooner if you make use of "experimental" type software environments 馃槈

would it be worth making a section in "Iris examples" for this type of thing?

This isn't really something that documents that well. Truth is it would be best documented in somewhere like StackOverflow where it would be optimally indexed by Google.

Thanks for raising @nhsavage, and thanks for answering @rcomer!

All 5 comments

I don't think you need to create a new coordinate, just replace the units on your existing coordinate. Does this work?

tcoord = cube.coord('time')
tcoord.units = cf_units.Unit(tcoord.units.origin, calendar='gregorian')

Thanks. I'll rethink this. Probably not a code change as you say. Do we have an appropriate place to stick "useful bits of Iris code"? FWIW, we might also want to note that there are 2 other aliases in the CF definition noleap or 365_day and all_leap or 366_day

would it be worth making a section in "Iris examples" for this type of thing?

FWIW in cf-units 2 we introduced calendar aliases so that Gregorian is standard.

>>> import cf_units
>>> cf_units.__version__
'2.0.1'
>>> a = cf_units.Unit('days since 2000-01-01', calendar='standard')
>>> b = cf_units.Unit('days since 2000-01-01', calendar='gregorian')
>>> a == b
True
>>> a
Unit('days since 2000-01-01', calendar='gregorian')
>>> b
Unit('days since 2000-01-01', calendar='gregorian')

cf-units 2 is part of the Iris 2.1 release, and will be rolling out to an organisation near you soon 馃槈. Even sooner if you make use of "experimental" type software environments 馃槈

would it be worth making a section in "Iris examples" for this type of thing?

This isn't really something that documents that well. Truth is it would be best documented in somewhere like StackOverflow where it would be optimally indexed by Google.

Thanks for raising @nhsavage, and thanks for answering @rcomer!

I eventually found this and it was super useful. If any of you want to answer, here's a stack overflow question https://stackoverflow.com/q/52702433/10473080

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pelson picture pelson  路  4Comments

rcomer picture rcomer  路  3Comments

larsbarring picture larsbarring  路  5Comments

pp-mo picture pp-mo  路  5Comments

jupalm picture jupalm  路  3Comments