xoa.cf.CFSpecs.search_coord
- CFSpecs.search_coord(obj, cf_name=None, loc='any', get='obj', single=True, errors='warn')[source]
Search for a coord that maches given or any specs
- Parameters:
obj (DataArray or Dataset) –
cf_name (str, dict) – A generic CF name. If not provided, all CF names are scaned.
loc (str, {"any", None}, {"", False}) –
str: one of these locations
None or “any”: any
False or “”: no location
get ({"obj", "name"}) – When found, get the object found or its name.
single (bool) – If True, return the first item found or None. If False, return a possible empty list of found items. A warning is emitted when set to True and multiple item are found.
errors ({'ignore', 'warn', 'raise'}) –
In case of errors
'ignore'
: silently ignore'warn'
: emit a warning'raise'
: raise an exception
- Returns:
None or str or object
Example
In [1]: lon = xr.DataArray([2, 3], dims='foo', ...: attrs={'standard_name': 'longitude'}) ...: In [2]: data = xr.DataArray([0, 1], dims=('foo'), coords=[lon]) In [3]: cfspecs = get_cf_specs() In [4]: cfspecs.search_coord(data, "lon") Out[4]: <xarray.DataArray 'foo' (foo: 2)> array([2, 3]) Coordinates: * foo (foo) int64 2 3 Attributes: standard_name: longitude In [5]: cfspecs.search_coord(data, "lon", get="cf_name") Out[5]: 'lon' In [6]: cfspecs.search_coord(data, "lat", errors="ignore")
See also