xoa.cf.CFSpecs.search_data_var

CFSpecs.search_data_var(obj, cf_name=None, loc='any', get='obj', single=True, errors='warn')[source]

Search for a data_var 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]: data = xr.DataArray(
   ...:     [0, 1], dims=('x'),
   ...:     attrs={'standard_name': 'sea_water_temperature'})
   ...: 

In [2]: ds = xr.Dataset({'foo': data})

In [3]: cfspecs = get_cf_specs()

In [4]: cfspecs.search_data_var(ds, "temp")
Out[4]: 
<xarray.DataArray 'foo' (x: 2)>
array([0, 1])
Dimensions without coordinates: x
Attributes:
    standard_name:  sea_water_temperature

In [5]: cfspecs.search_data_var(ds, "temp", get="cf_name")
Out[5]: 'temp'

In [6]: cfspecs.search_data_var(ds, "sal")