webbpsf_ext.maths.binned_statistic

webbpsf_ext.maths.binned_statistic(x, values, func=<function mean>, bins=10)[source]

Binned statistic

Compute a binned statistic for a set of data. Drop-in replacement for scipy.stats.binned_statistic.

Parameters
  • x (ndarray) – A sequence of values to be binned. Or a list of binned indices from hist_indices().

  • values (ndarray) – The values on which the statistic will be computed.

  • func (func) – The function to use for calculating the statistic.

  • bins (int or ndarray) – If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges, including the rightmost edge. This doesn’t do anything if x is a list of indices.

Example

Find the standard deviation at each radius of an image

>>> rho = dist_image(image)
>>> binsize = 1
>>> radial_bins = np.arange(rho.min(), rho.max() + binsize, binsize)
>>> radial_stds = binned_statistic(rho, image, func=np.std, bins=radial_bins)