webbpsf_ext.maths.hist_indices

webbpsf_ext.maths.hist_indices(values, bins=10, return_more=False)[source]

Histogram indices

This function bins an input of values and returns the indices for each bin. This is similar to the reverse indices functionality of the IDL histogram routine. It’s also much faster than doing a for loop and creating masks/indices at each iteration, because we utilize a sparse matrix constructor.

Returns a list of indices grouped together according to the bin. Only works for evenly spaced bins.

Parameters
  • values (ndarray) – Input numpy array. Should be a single dimension.

  • 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. In the latter case, the bins must encompass all values.

  • return_more (bool) – Option to also return the values organized by bin and the value of the centers (igroups, vgroups, center_vals).

Example

Find the standard deviation at each radius of an image

>>> rho = dist_image(image)
>>> binsize = 1
>>> bins = np.arange(rho.min(), rho.max() + binsize, binsize)
>>> igroups, vgroups, center_vals = hist_indices(rho, bins, True)
>>> # Get the standard deviation of each bin in image
>>> std = binned_statistic(igroups, image, func=np.std)