cf.Field.subspace

Field.subspace()

Return a subspace of the field defined by metadata values

A subspace may be defined via data array values of its metadata items (dimension coordinate, auxiliary coordinate, cell measure, field ancillary objects, etc.).

Subspacing by values of 1-d coordinates allows a subspaced field to be defined via coordinate values of its domain. The benefits of subspacing in this fashion are:

  • The axes to be subspaced may identified by name.
  • The position in the data array of each axis need not be known and the axes to be subspaced may be given in any order.
  • Axes for which no subspacing is required need not be specified.
  • Size 1 axes in the subspaced field are always retained, but may be subsequently removed with the squeeze method.
  • Size 1 axes of the domain which are not spanned by the data array may be specified.

Metadata values are provided as keyword arguments. Metadata items are identified by their identity or their axis’s identifier in the field.

f.subspace(*args, **kwargs) is equivalent to f[f.indices(*args, **kwargs)]. See cf.Field.indices for details.

Examples:
>>> f,shape
(12, 73, 96)
>>> f.subspace().shape
(12, 73, 96)
>>> f.subspace(latitude=0).shape
(12, 1, 96)
>>> f.subspace(latitude=cf.wi(-30, 30)).shape
(12, 25, 96)
>>> f.subspace(long=cf.ge(270, 'degrees_east'), lat=cf.set([0, 2.5, 10])).shape
(12, 3, 24)
>>> f.subspace(latitude=cf.lt(0, 'degrees_north'))
(12, 36, 96)
>>> f.subspace(latitude=[cf.lt(0, 'degrees_north'), 90])
(12, 37, 96)
>>> import math
>>> f.subspace('exact', longitude=cf.lt(math.pi, 'radian'), height=2)
(12, 73, 48)
>>> f.subspace(height=cf.gt(3))
IndexError: No indices found for 'height' values gt 3
>>> f.subspace(dim2=3.75).shape
(12, 1, 96)
>>> f.subspace(time=cf.le(cf.dt('1860-06-16 12:00:00')).shape
(6, 73, 96)
>>> f.subspace(time=cf.gt(cf.dt(1860, 7)),shape
(5, 73, 96)

Note that if a comparison function (such as cf.wi) does not specify any units, then the units of the named item are assumed.