pysteps.utils.dimension.aggregate_fields

pysteps.utils.dimension.aggregate_fields#

pysteps.utils.dimension.aggregate_fields(data, window_size, axis=0, method='mean', trim=False)#

Aggregate fields along a given direction.

It attempts to aggregate the given R axis 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 axis is trimmed (from the end) to make it perfectly divisible”.

Parameters:
  • data (array-like) – Array of any shape containing the input fields.

  • window_size (int or tuple 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 axis.

    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 axis. In this case, the number of elements of ‘window_size’ must be the same as the elements in the axis argument.

  • axis (int or array-like of ints) – Axis or axes where to perform the aggregation. If this is a tuple of ints, the aggregation is performed over multiple axes, instead of a single axis

  • method (string, optional) – Optional argument that specifies the operation to use to aggregate the 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 axis:

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

    • trim=False: a ValueError exception is raised.

Returns:

new_array – The new aggregated array with shape[axis] = k, where k = R.shape[axis] / window_size.

Return type:

array-like