xarray.Dataset.bounds.add_bounds#

Dataset.bounds.add_bounds(axis)#

Add bounds for an axis using its coordinates as midpoints.

This method loops over the axis’s coordinate variables and attempts to add bounds for each of them if they don’t exist. Each coordinate point is the midpoint between their lower and upper bounds.

To add bounds for an axis its coordinates must meet the following criteria, otherwise an error is thrown:

  1. Axis is either X”, “Y”, “T”, or “Z”

  2. Coordinates are single dimensional, not multidimensional

  3. Coordinates are a length > 1 (not singleton)

  4. Bounds must not already exist

    • Coordinates are mapped to bounds using the “bounds” attr. For example, bounds exist if ds.time.attrs["bounds"] is set to "time_bnds" and ds.time_bnds is present in the dataset.

Parameters:

axis (CFAxisKey) – The CF axis key (“X”, “Y”, “T”, “Z”).

Returns:

  • xr.Dataset – The dataset with bounds added.

  • Raises