xarray.Dataset.cf.add_bounds

Dataset.cf.add_bounds(keys, *, dim=None, output_dim='bounds')

Create a new object with bounds variables.

The bounds values are guessed assuming equal spacing on either side of a coordinate label. The linear estimation is only a coarse approximation, especially 2D bounds on curvilinear grids. It is always better to use bounds generated as part of the grid creation process. This method is purely for convenience.

Parameters:
keysstr or Iterable[str]

Either a single variable name or a list of variable names.

dimstr or Iterable[str], optional

Core dimension(s) along which to estimate bounds. For 2D bounds, it can be a list of 2 dimension names.

output_dimstr

The name of the bounds dimension to add.

Returns:
DataArray or Dataset

With bounds variables added and appropriate “bounds” attribute set.

Raises:
KeyError

Notes

The bounds variables are automatically named f"{var}_bounds" where var is a variable name.

Examples

>>> from cf_xarray.datasets import airds
>>> airds.cf.bounds
{}
>>> updated = airds.cf.add_bounds("time")
>>> updated.cf.bounds
{'T': ['time_bounds'], 'time': ['time_bounds']}