Loading model data with 360_day calendar using datetime.datetime objects

135 views
Skip to first unread message

Adrian Matthews

unread,
Dec 12, 2019, 9:09:28 AM12/12/19
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hello,

I am trying to read in model data with a 360_day calendar for the first time in iris. I  have always used datetime.datetime objects to set a time constraint (using data with a Gregorian calendar) but this now fails with the error
TypeError: Cannot determine the order of cftime.datetime objects

Can I use datetime.datetime objects to load in data with a 360_day calendar? (Note I am using sensible times that do exist in the data, not eg 31 Dec). If not, what is the best way to set a time constraint to load in data on a 360_day calendar eg between 1986-01-01 and 1986-12-30?

Thanks

Adrian

Adrian Matthews

unread,
Dec 17, 2019, 8:22:44 AM12/17/19
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Many thanks to Andrew Dawson for providing the following solution. The key is to use cftime.Datetime360day objects instead of datetime.datetime objects, and to set the iris time Constraint on the numerical values (i.e. the point attributes) on the time coordinate, rather than the default datetime like values. Sample code below for anyone else with this problem.

start = cftime.Datetime360Day(1985, 1, 1)
end = cftime.Datetime360Day(1985, 12, 30)
time_selection = iris.Constraint(time=lambda c: start <= c.point <= end)
iris.load_cube('my_filename.nc', time_selection)

Happy Christmas

Adrian
Reply all
Reply to author
Forward
0 new messages