Iris: Coord masked points

Created on 25 Sep 2019  路  3Comments  路  Source: SciTools/iris

Stumbled across this when trying to understand #3402. If you instantiate a Coord with a masked array, the mask gets stripped off:

In [47]: time_coord = iris.coords.AuxCoord(ma.array(range(5), mask=[False, True, False, True, False]),
                                           units='days since 2001-05-01', standard_name='time')

In [48]: time_coord.points
Out[48]: array([0, 1, 2, 3, 4])
In [75]: time_coord = iris.coords.DimCoord(ma.array(range(5), mask=ma.nomask),
                                           units='days since 2001-05-01', standard_name='time')
In [76]: time_coord.points
Out[76]: array([0, 1, 2, 3, 4])

This is not the case for a dask masked array:

In [7]: time_coord = iris.coords.AuxCoord(da.ma.masked_array(da.arange(5, chunks=5)),
   ...:                                   units='days since 2001-05-01', standard_name='time')
In [8]: time_coord.has_lazy_points()
Out[8]: True

In [9]: time_coord.points
Out[9]:
masked_array(data=[0, 1, 2, 3, 4],
             mask=False,
       fill_value=999999)

I think this may be the line that converts a numpy masked array into a plain numpy array. There is nothing in the comments to suggest that this was a deliberate effect, and it seems to me that it shouldn't happen because you are probably unmasking nonsense values.

The cf conventions say that "Missing data is allowed in data variables and auxiliary coordinate variables." So I think what should happen is:

  • Modify the Coord._sanitise_array method to return a masked array if it's given a masked array. [Edit: or just throw an exception if we don't want to support that]
  • Throw an exception if you try to assign a masked array to DimCoord.points.
  • Also consider what happens to bounds.
Major Bug

Most helpful comment

As described, definitely a bug !!

I think this may be the line that converts a numpy masked array into a plain numpy array.

I think so, yes. Therefore the comment on the preceding line is also wrong !!

All 3 comments

As described, definitely a bug !!

I think this may be the line that converts a numpy masked array into a plain numpy array.

I think so, yes. Therefore the comment on the preceding line is also wrong !!

@rcomer @pp-mo I'm working on a fix for this that I'd like to get included in the imminent iris 2.3.0 release :wink:

Fixed by #3427

Was this page helpful?
0 / 5 - 0 ratings

Related issues

larsbarring picture larsbarring  路  5Comments

pelson picture pelson  路  4Comments

rcomer picture rcomer  路  5Comments

jvegasbsc picture jvegasbsc  路  3Comments

bjlittle picture bjlittle  路  5Comments