cf_xarray.vertices_to_bounds

cf_xarray.vertices_to_bounds(vertices, out_dims=('bounds', 'x', 'y'))[source]

Convert vertices to CF-compliant bounds.

There are 2 covered cases:
  • 1D coordinates, with vertices of shape (N+1,), converted to bounds of shape (N, 2)

  • 2D coordinates, with vertices of shape (N+1, M+1). converted to bounds of shape (N, M, 4).

Parameters:
verticesDataArray

The vertices to convert. Must be of shape (N + 1) or (N + 1, M + 1).

out_dimsSequence[str],

The name of the dimension in the output. The first is the ‘bounds’ dimension and the following are the coordinate dimensions.

Returns:
DataArray

The CF-compliant bounds, either of shape (2, N) or (4, N, M).

See also

bounds_to_vertices

The inverse operation.

References

Please refer to the CF conventions document : http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#cell-boundaries.

Examples

>>> import xarray as xr
>>> vertices = xr.DataArray([0, 1, 2, 3], dims="x")
>>> vertices_to_bounds(vertices)
<xarray.DataArray (x: 3, bounds: 2)> Size: 48B
array([[0, 1],
       [1, 2],
       [2, 3]])
Dimensions without coordinates: x, bounds