Return the data array indices which correspond to one dimensional coordinate object values.
If no coordinate values are specified for an axis then a full slice (slice(None)) is assumed for that axis.
Values for size 1 axes which are not spanned by the field’ data array may be specified, but only indices for axes which span the field’s data array will be returned.
The coordinate value conditions may be given in any order.
Parameters : |
|
||||
---|---|---|---|---|---|
Returns : | out : tuple |
Examples
These examples use the following field, which includes a dimension coordinate object with no identity (ncvar:model_level_number) and which has a data array which doen’t span all of the domain axes:
>>> print f
air_temperature field summary
-----------------------------
Data : air_temperature(ncvar:model_level_number(19), latitude(73), longitude(96)) K
Dimensions : ncvar:model_level_number(19) = [1, ... 19]
: latitude(73) = [-90.0, ..., 90.0] degrees_north
: longitude(96) = [0.0, ..., 356.25] degrees_east
: time(1) = [ 2004-06-01 00:00:00] noleap calendar
>>> f.items()
{'dim0': <CF DimensionCoordinate: time(1) days since 2004-01-01 noleap calendar>,
'dim1': <CF DimensionCoordinate: ncvar:model_level_number(19)>,
'dim2': <CF DimensionCoordinate: latitude(73), degree_north>,
'dim3': <CF DimensionCoordinate: latitude(96), degree_east>}
>>> f.indices(lat=0.0, lon=0.0)
(slice(0, 19, 1), slice(0, 1, 1), slice(0, 1, 1))
>>> f.indices(lon=cf.wi(0, 3.75), lat=cf.lt(0.0))
(slice(0, 19, 1), slice(0, 36, 1), slice(0, 2, 1))
>>> f.indices(lat=cf.lt(0.0), lon=cf.set([0, 356.25]))
(slice(0, 19, 1), slice(0, 36, 1), slice(0, 96, 96))
>>> f.indices(lat=cf.lt(0.0), lon=cf.set([0, 356.25, 3.75]))
(slice(0, 19, 1), slice(0, 32, 1), [0, 1, 95])
>>> f.indices(dim1=cf.wi(6, 18))
(slice(5, 19, 1), slice(0, 73, 1), slice(0, 96, 1))
>>> f.indices(dim1=19, lon=cf.ne(0, 'degrees_east'))
(slice(18, 19, 1), slice(0, 73, 1), slice(1, 96, 1))
>>> f.indices('exact', latitude=cf.lt(0.0), longitude=0)
(slice(0, 19, 1), slice(0, 32, 1), slice(0, 1, 1))
>>> f.indices('exact', lat=cf.lt(0.0), long=0)
ValueError: Can't find indices: Ambiguous indentity: 'lat'
>>> f.indices('regex', lat=cf.lt(0.0), long'=0)
(slice(0, 19, 1), slice(0, 32, 1), slice(0, 1, 1))