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:
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]DimCoord.points.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
Most helpful comment
As described, definitely a bug !!
I think so, yes. Therefore the comment on the preceding line is also wrong !!