miscΒΆ

Auxiliary functions with miscellaneous use.

FunctionsΒΆ

kde(data[, weights])

Calculate a Kernel Density Estimate (KDE) distribution for a given dataset.

get_array_extremum(arrays[, get_max])

Get maximum or minimum value of the set with all values of all provided arrays.

round_to_nearest_multiple(n, factor[, up])

Round a number to the nearest (up or down) multiple of a given factor.

Module ContentsΒΆ

ensemblify.utils.misc.kde(data, weights=None)ΒΆ

Calculate a Kernel Density Estimate (KDE) distribution for a given dataset.

Weights for the given dataset can be provided to alter the contribution of each data point to the KDE distribution.

Parameters:
  • data (np.ndarray) – Dataset to calculate KDE values for.

  • weights (list, optional) – Array with weights for each data point. Defaults to uniform weights.

Returns:

x_coords (np.ndarray):

X axis coordinates corresponding to the calculated kde distribution.

norm_kde (np.ndarray):

Normalized kde distribution.

weighted_average (float):

Weighted average of the given dataset.

weighted_standard_error (float):

Weighted standard error of the calculated average.

Return type:

tuple[np.ndarray,np.ndarray,float,float]

Adapted from:

https://github.com/FrPsc/EnsembleLab/blob/main/EnsembleLab.ipynb

Reference for standard error of weighted average:

https://seismo.berkeley.edu/~kirchner/Toolkits/Toolkit_12.pdf Copyright Β© 2006 Prof. James Kirchner

ensemblify.utils.misc.get_array_extremum(arrays, get_max=True)ΒΆ

Get maximum or minimum value of the set with all values of all provided arrays.

Parameters:
  • arrays (list[np.ndarray]) – List of arrays to analyze.

  • get_max (bool, optional) – Whether to get the maximum or minimum (if False) value. Defaults to True.

Returns:

Maximum or minimum value.

Return type:

float

ensemblify.utils.misc.round_to_nearest_multiple(n, factor, up=True)ΒΆ

Round a number to the nearest (up or down) multiple of a given factor.

Parameters:
  • n (int) – Number to round.

  • factor (int) – The number n will be rounded to a multiple of factor.

  • up (bool, optional) – Whether to round up or down (if False). Defaults to True.

Returns:

rounded number.

Return type:

rounded