cf.Field.subset

Field.subset

Return a new field whose data and space are subsetted in a consistent manner.

This attribute may be indexed to select a subset from dimension index values (square brackets: f.subset[indices]) or called to select a subset from dimension coordinate array values (round brackets: f.subset(coordinate_values))

Subsetting by indexing

Subsetting by dimension indices uses an extended Python slicing syntax, which is similar numpy array indexing. There are two extensions to the numpy indexing functionality:

  • Size 1 dimensions are never removed.

    An integer index i takes the i-th element but does not reduce the rank of the output array by one.

  • When advanced indexing is used on more than one dimension, the advanced indices work independently.

    When more than one dimension’s slice is a 1-d boolean array or 1-d sequence of integers, then these indices work independently along each dimension (similar to the way vector subscripts work in Fortran), rather than by their elements.

Subsetting by coordinate values

Subsetting by coordinate values allows a subsetted field to be defined by particular coordinate values of its space.

Subsetting by coordinate values is functionally equivalent to subsetting by indexing - internally, the selected coordinate values are in fact converted to dimension indices.

Coordinate values are provided as arguments to a call to the subset method.

The benefits to subsetting in this fashion are:

  • The dimensions to be subsetted are identified by name.
  • The position in the data array of each dimension need not be known.
  • Dimensions for which no subsetting is required need not be specified.
  • Size 1 dimensions of the space which are not spanned by the data array may be specified.

Examples

Previous topic

cf.Field.size

Next topic

cf.Field.Units

This Page