Skip to content

iris.util.mask_cube wish list #3936

Description

@rcomer

✨ 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 and points_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 via iris.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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions