You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A user enquiry revealed that at least some extractions from bounded time coordinates are "banned".
There is a specific test+fail in place for these cases. We think that this restriction can now be removed, as the various time objects all now provide reliable comparison operations. (see below)
This was revealed when trying to extract a timepoint matching one from another cube, like this ...
>>> import iris
>>> from iris.cube import Cube
>>> from iris.coords import DimCoord
>>> from cf_units import Unit
>>>
>>> co_time = DimCoord(
... [0., 1],
... standard_name='time',
... units=Unit('hours since 1970-01-01', calendar='standard')
... )
>>>
>>> times_cube = Cube([0, 1])
>>> times_cube.add_dim_coord(co_time, (0,))
>>> print(times_cube)
unknown / (unknown) (time: 2)
Dimension coordinates:
time x
>>>
>>> time_point = co_time.units.num2date(co_time.points[0])
>>> constraint = iris.Constraint(time=time_point)
>>> print(time_point)
1970-01-01 00:00:00
>>>
>>> extract = times_cube.extract(constraint)
>>> print(extract)
unknown / (unknown) (scalar cube)
Scalar coordinates:
time 1970-01-01 00:00:00
>>>
>>> times_cube.coord('time').bounds = [[0., 1], [1, 2]]
>>> extract = times_cube.extract(constraint)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../iris/cube.py", line 2615, in extract
return constraint.extract(self)
File ".../iris/_constraints.py", line 165, in extract
resultant_CIM = self._CIM_extract(cube)
File ".../iris/_constraints.py", line 189, in _CIM_extract
resultant_CIM = resultant_CIM & coord_constraint.extract(cube)
File ".../iris/_constraints.py", line 323, in extract
r = np.array([call_func(cell) for cell in coord.cells()])
File ".../iris/_constraints.py", line 323, in <listcomp>
r = np.array([call_func(cell) for cell in coord.cells()])
File ".../iris/_constraints.py", line 306, in call_func
return c == self._coord_thing
File ".../iris/coords.py", line 1359, in __eq__
return self.contains_point(other)
File ".../iris/coords.py", line 1533, in contains_point
raise TypeError(
TypeError: Cannot determine whether a point lies within a bounded region for datetime-like objects.
>>>
The key problem is here in iris.coords.Cell.contains_point()
It seems this "blanket ban" was introduced by #1016 in response to #984
In catching any use of a datetime-like object, as something posessing a 'timetuple' property, it also includes PartialDateTime which also provide that property (for some compatibility reasons, not made entirely clear!).
@rcomer suggests that, when this was added, it was a key problem that 'netcdftime.datetime' objects provided a seriously "broken" comparison operation.
We think that this test+fail can now be removed, as the other time objects now provide reliable comparison operations.
The objects we now have to deal with in this code are datetime.datetime, cftime.datetime (and it's deprecated subclasses..), and a PartialDateTime.
notable:
PartialDateTime offers comparison on selected time/date fields, e.g. PDT(year=2000, month=3) <= X < PDT(year=2011, month=6)
all the datatime.datetime and cftime.datetime objects are now calendar-aware and refuse (correctly) to compare if calendars don't match
... we think (needs full testing!)
The text was updated successfully, but these errors were encountered:
A user enquiry revealed that at least some extractions from bounded time coordinates are "banned".
There is a specific test+fail in place for these cases.
We think that this restriction can now be removed, as the various time objects all now provide reliable comparison operations. (see below)
This was revealed when trying to extract a timepoint matching one from another cube, like this ...
The key problem is here in iris.coords.Cell.contains_point()
It seems this "blanket ban" was introduced by #1016 in response to #984
In catching any use of a datetime-like object, as something posessing a 'timetuple' property, it also includes PartialDateTime which also provide that property (for some compatibility reasons, not made entirely clear!).
@rcomer suggests that, when this was added, it was a key problem that 'netcdftime.datetime' objects provided a seriously "broken" comparison operation.
We think that this test+fail can now be removed, as the other time objects now provide reliable comparison operations.
The objects we now have to deal with in this code are datetime.datetime, cftime.datetime (and it's deprecated subclasses..), and a PartialDateTime.
notable:
PDT(year=2000, month=3) <= X < PDT(year=2011, month=6)
The text was updated successfully, but these errors were encountered: