cfdm.Field.indices

Field.indices(**kwargs)[source]

Create indices that define a subspace of the field construct.

The subspace is defined by defining indices based on the positions of the given data values of 1-d metadata constructs.

The returned tuple of indices may be used to created a subspace by indexing the original field construct with them.

Metadata constructs and the conditions on their data are defined by keyword parameters.

  • Any domain axes that have not been identified remain unchanged.

  • Multiple domain axes may be subspaced simultaneously, and it doesn’t matter which order they are specified in.

  • Subspace criteria may be provided for size 1 domain axes that are not spanned by the field construct’s data.

New in version (cfdm): 1.10.0.0

See also

__getitem__, __setitem__

Parameters
kwargs: optional

Each keyword parameter specifies a value or values whose positions in the 1-d metadata construct’s data, identified by the parameter name, define the indices for that dimension.

Returns
tuple

The indices meeting the conditions.

Examples

>>> f = cfdm.example_field(0)
>>> print(f)
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), longitude(8)) 1
Cell methods    : area: mean
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(8) = [22.5, ..., 337.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]
>>> indices = f.indices(longitude=112.5)
>>> indices
(slice(None, None, None),
 array([False, False,  True, False, False, False, False, False]))
>>> print(f[indices])
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), longitude(1)) 1
Cell methods    : area: mean
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(1) = [112.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]
>>> indices = f.indices(longitude=112.5, latitude=[-45, 75])
>>> indices
(array([False,  True, False, False,  True]),
 array([False, False,  True, False, False, False, False, False]))
>>> print(f[indices])
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(2), longitude(1)) 1
Cell methods    : area: mean
Dimension coords: latitude(2) = [-45.0, 75.0] degrees_north
                : longitude(1) = [112.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]
>>> indices = f.indices(time=31)
>>> indices
(slice(None, None, None), slice(None, None, None))
>>> print(f[indices])
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), longitude(8)) 1
Cell methods    : area: mean
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(8) = [22.5, ..., 337.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]