grid_process.ds_utils#

Module with general utility functions that operate on xarray.Dataset

Attributes#

Functions#

ds_to_da(→ tuple[xarray.DataArray, ...)

Transform a dataset containing model data and one or several data

cast_dtype(→ None)

Cast back each data variable in the output dataset to the original dtype

Module Contents#

logger#
ds_to_da(ds: xarray.Dataset) → tuple[xarray.DataArray, dict[collections.abc.Hashable, dict[collections.abc.Hashable, Any]]][source]#

Transform a dataset containing model data and one or several data variables to a dataarray with the variables stacked as a new dimension. The function also returns the attributes of the data variables for further use.

Parameters:

ds (xarray.Dataset) – contain one or more variables

Returns:

  • da (xarray.DataArray) – contains the data variables from the input dataset stacked in a new variable dimension

  • vars_attrs (dictionary) – contains the attributes of each data variables in the input dataset.

See also

da_to_ds()

cast_dtype(ds_out: xarray.Dataset, ds_in: xarray.Dataset) → None[source]#

Cast back each data variable in the output dataset to the original dtype of the input dataset. The operation is done in-place.