Closed
Description
✨ Feature Request
It looks like the mask_cube
function was added as a convenience as part of a larger change (#3144). However, now it's in the public API, users are having a go with it but not finding it ideal. Here are a few ideas for improvement that I think would be fairly easy to implement:
- The docstring states that both
cube
andpoints_to_mask
must be 2D but, looking at the code, I can't see why it wouldn't work as long as they are the same shape. So at very least, the docstring should be updated. - A common masking task is to apply a 2D land/ocean mask to data that has higher dimensionality. So it would be nice to be able to pass a
dim_map
, so the function could broadcast the mask out viairis.util.broadcast_to_shape
. - Enforce boolean dtype on the mask. With Iris3rc we have:
cube = iris.cube.Cube(np.arange(24).reshape(6,4))
mymask = np.array([0, 1, 0, 1])
iris.util.mask_cube(cube, mymask)
cube.data
gives
masked_array(
data=[[--, --, --, --],
[--, --, --, --],
[8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]],
mask=[[ True, True, True, True],
[ True, True, True, True],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]],
fill_value=999999)
which is not at all what I would expect (and I get this result even if I broadcast the mask before applying it).
- Handle lazy data.
Additional context
See also #3717
Metadata
Metadata
Assignees
Labels
No labels