wrf.metadecorators.copy_and_set_metadata

wrf.metadecorators.copy_and_set_metadata(copy_varname=None, delete_attrs=None, name=None, remove_dims=None, dimnames=None, coords=None, **fixed_attrs)

A decorator that sets the metadata for a wrapped function’s output.

Generally, the metadata is copied from the variable specified by copy_varname, with other fixed fields set by the other decorator arguments.

The cache argument used by most diagnostic routines is supplied by this decorator when the copy_varname variable is extracted, in order to prevent the variable from being extracted again by the wrapped function.

If the wrapped function’s meta argument is False, then this decorator returns the wrapped function output without applying the metadata.

Parameters:
  • copy_varname (str, optional) – The NetCDF variable name to copy. Default is None.

  • delete_attrs (sequence of str, optional) – A sequence of key names to remove from the xarray.DataArray.attrs attribute in the wrapped function output (after being copied from copy_varname). Default is None.

  • name (str) – The name to use for the xarray.DataArray.name attribute.

  • remove_dims (sequence of int, optional) – A sequence of dimension indexes to be removed from the wrapped function output (after being copied from copy_varname). This is useful when the copy variable is three dimensional but the wrapped function output is two dimensional, and you still want to keep the names of the rightmost two dimensions. Default is None.

  • dimnames (sequence of str, optional) – A sequence of dimension names in order to manually set the xarray.DataArray.dims attribute. Default is None.

  • coords (dict) – A mapping of coordinate name to coordinate value to manually specify the xarray.DataArray.coords attribute. Default is None.

  • **fixed_attrs – These keyword arguments are added to the xarray.DataArray.attrs attribute.

Returns:

The wrapped function output with or without metadata. If xarray is enabled and the meta parameter is True, then the result will be a xarray.DataArray object. Otherwise, the result will be a numpy.ndarray object with no metadata.

Return type:

xarray.DataArray or numpy.ndarray