xugrid.UgridDataArray.from_structured2d#

static UgridDataArray.from_structured2d(da: DataArray, x: str | None = None, y: str | None = None, x_bounds: DataArray = None, y_bounds: DataArray = None) UgridDataArray[source]#

Create a UgridDataArray from a (structured) xarray DataArray.

The spatial dimensions are flattened into a single UGRID face dimension. By default, this method looks for:

  1. “x” and “y” dimensions

  2. “longitude” and “latitude” dimensions

  3. “axis” attributes of “X” or “Y” on coordinates

  4. “standard_name” attributes of “longitude”, “latitude”, “projection_x_coordinate”, or “projection_y_coordinate” on coordinate variables

Parameters:
  • da (xr.DataArray) – The structured data array to convert. The last two dimensions must be the y and x dimensions (in that order).

  • x (str, optional) – Name of the UGRID x-coordinate, or x-dimension if bounds are provided. Defaults to None.

  • y (str, optional) – Name of the UGRID y-coordinate, or y-dimension if bounds are provided. Defaults to None.

  • x_bounds (xr.DataArray, optional) – Bounds for x-coordinates. Required for non-monotonic coordinates. Defaults to None.

  • y_bounds (xr.DataArray, optional) – Bounds for y-coordinates. Required for non-monotonic coordinates. Defaults to None.

Returns:

The unstructured grid data array.

Return type:

UgridDataArray

Notes

When using bounds, they should have one of these shapes: * x bounds: (M, 2) or (N, M, 4) * y bounds: (N, 2) or (N, M, 4) where N is the number of rows (along y) and M is columns (along x). Cells with NaN bounds coordinates are omitted.

Examples

Basic usage with default coordinate detection:

>>> uda = xugrid.UgridDataArray.from_structured2d(data_array)

Specifying explicit coordinate names:

>>> uda = xugrid.UgridDataArray.from_structured2d(
...     data_array,
...     x="longitude",
...     y="latitude"
... )

Using bounds for curvilinear grids:

>>> uda = xugrid.UgridDataArray.from_structured2d(
...     data_array,
...     x="x_dim",
...     y="y_dim",
...     x_bounds=x_bounds_array,
...     y_bounds=y_bounds_array
... )