Time constraints and "bounded region" TypeError

540 views
Skip to first unread message

maxime prignon

unread,
Jan 27, 2017, 11:14:49 AM1/27/17
to Iris
Hi,

I recently installed the Iris package. I am thus new with Iris and my knowledge in Python is not very deep. 

I was reading the user guide and trying to apply loading with time constraints on one of my files.

When I am trying to apply this loading "technique" on my file:
feb = iris.Constraint(time=iris.time.PartialDateTime(month=2))
with iris.FUTURE.context(cell_datetime_objects=True):
   
print(iris.load_cube(filename, feb).coord('time'))

I get this TypeError:
TypeError: Cannot determine whether a point lies within a bounded region for datetime-like objects.

Here is my time coordinate:
>>>print(cubes[0].coord('time'))
DimCoord([1985-01-01 00:00:00, 1985-01-01 06:00:00, 1985-01-01 12:00:00, ...,
       1985-12-31 06:00:00, 1985-12-31 12:00:00, 1985-12-31 18:00:00], bounds=[[1984-12-31 21:00:00, 1985-01-01 03:00:00],
       [1985-01-01 03:00:00, 1985-01-01 09:00:00],
       [1985-01-01 09:00:00, 1985-01-01 15:00:00],
       ..., 
       [1985-12-31 03:00:00, 1985-12-31 09:00:00],
       [1985-12-31 09:00:00, 1985-12-31 15:00:00],
       [1985-12-31 15:00:00, 1985-12-31 21:00:00]], standard_name='time', calendar='365_day', long_name='time', var_name='time')


Do someone knows what is going on here ? I looked on Google and didn't found any similar issues...

Thank you so much in advance,

Maxime

Luke Abraham

unread,
Feb 13, 2017, 7:37:39 AM2/13/17
to Iris
I am having a similar problem, as I wanted to load all files between 1995 and 2005:

date_range=iris.Constraint(time=lambda cell: iris.time.PartialDateTime(year=1995) <= cell <= iris.time.PartialDateTime(year=2005))


However, I was having the same error. I tried instead using

date_range=iris.Constraint(time=lambda cell: 1995 <= cell.point.year <= 2005)


as the constraint, and this worked. 

Perhaps if you tried setting your constraint as 

feb = iris.Constraint(time=lambda cell: cell.point.month=2)

instead?

Thanks,
Luke

Matteo De Felice

unread,
Mar 30, 2017, 7:57:39 AM3/30/17
to Iris
Thank you, 
I had the same problem and using cell.point.month instead of PartialDateTime solved the issue...
I am wondering why this happen, PartialDateTime is also used on the official documentation (http://scitools.org.uk/iris/docs/latest/userguide/loading_iris_cubes.html#loading-iris-cubes)

Andrew Dawson

unread,
Mar 30, 2017, 8:15:21 AM3/30/17
to Iris
The partial datetime functionality doesn't work with time coordinates that have bounds (I don't know why not). By using cell.point you are explicitly telling iris to ignore bounds and just use the cell centre point for comparison.

Jonny Williams

unread,
Mar 15, 2021, 9:34:49 PM3/15/21
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
this is awesome. thanks. i was just having exactly this error!
Reply all
Reply to author
Forward
0 new messages