pysteps.utils.dimension.aggregate_fields

pysteps.utils.dimension.aggregate_fields#

pysteps.utils.dimension.aggregate_fields(dataset: Dataset, window_size, dim='x', method='mean', velocity_method='mean', trim=False) → Dataset#

Aggregate fields along a given direction.

It attempts to aggregate the given dataset dim in an integer number of sections of length = window_size. If such a aggregation is not possible, an error is raised unless trim set to True, in which case the dim is trimmed (from the end) to make it perfectly divisible”.

Parameters:
  • dataset (xarray.Dataset) – Dataset containing the input fields as described in the documentation of pysteps.io.importers.

  • window_size (int or array-like of ints) –

    The length of the window that is used to aggregate the fields. If a single integer value is given, the same window is used for all the selected dim.

    If window_size is a 1D array-like, each element indicates the length of the window that is used to aggregate the fields along each dim. In this case, the number of elements of ‘window_size’ must be the same as the elements in the dim argument.

  • dim (str or array-like of strs) – Dim or dims where to perform the aggregation. If this is an array-like of strs, the aggregation is performed over multiple dims, instead of a single dim

  • method (string, optional) – Optional argument that specifies the operation to use to aggregate the precipitation values within the window. Default to mean operator.

  • velocity_method (string, optional) – Optional argument that specifies the operation to use to aggregate the velocity values within the window. Default to mean operator.

  • trim (bool) –

    In case that the data is not perfectly divisible by window_size along the selected dim:

    • trim=True: the data will be trimmed (from the end) along that dim to make it perfectly divisible.

    • trim=False: a ValueError exception is raised.

Returns:

dataset – The new dataset.

Return type:

xarray.Dataset