Skip to content

Provide a slice tuple equivalent to a coordinate constraint #6617

@jrackham-mo

Description

@jrackham-mo

✨ Feature Request

Functionality to generate a slice tuple that can be used to subset a cube with a given constraint. This could be a standalone function, or a method on iris.Constraint. Usage might look like this:

height_constraint = iris.Constraint(height=9000)
slices_tuple = height_constraint.as_slices_tuple(cube)
subset_cube = cube[slices_tuple]
# Equivalent to:
subset_cube = height_contstraint.extract(cube)

Motivation

This would allow for assigning data to a subset of a cube directly, rather than operating on a copy of the cube region. For example, setting all points at height=9000 to zero:

cube[slices_tuple] = 0

Additional context

Click to expand this section...

It looks like ‎_ColumnIndexManager.as_slice already provides this functionality, but it is not part of the public API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions