ufs2arco.utils.expand_anemoi_dataset

ufs2arco.utils.expand_anemoi_dataset#

ufs2arco.utils.expand_anemoi_dataset(ads: Dataset, name: str, variable_names: list[str]) Dataset#

Expand the anemoi dataset “variable” dimension to individual variables.

Converts a DataArray within the anemoi dataset, with any subset of dimensions [time, variable, ensemble, cell] into an xarray.Dataset where each variable has dimensions [time, cell] for 2D variables, or [time, level, cell] for 3D variables.

Note that this renames “latitudes” to “latitude”, “longitudes” to “longitude”, and swaps the logical “time” dimension with “dates”, and renames “dates” to “time”.

Example

>>> import xarray as xr
>>> from ufs2arco.utils import expand_anemoi_dataset
>>> ads = xr.open_zarr("/path/to/my-anemoi-dataset.zarr")
>>> the_data = expand_anemoi_dataset(ads, "data", ads.attrs["variables"])
>>> maximum_values = expand_anemoi_dataset(ads, "maximum", ads.attrs["variables"])
Parameters:
  • ads (xr.Dataset) – anemoi dataset, opened with xarray

  • name (str) – name of the array within the anemoi dataset to expand, e.g. “data” or any of the statistics (“maximum”, “minimum”, “squares”, “mean”, etc)

  • variable_names (list[str]) – A list of variable names corresponding to the ‘variable’ dimension.

Returns:

xr.Dataset – A dataset with each variable as a [time, cell] DataArray.