calculate_bin_indices

pyirf.binning.calculate_bin_indices(data, bins)[source]

Calculate bin indices of inidividula entries of the given data array using the supplied binning. Underflow will be indicated by UNDERFLOW_INDEX and overflow by OVERFLOW_INDEX.

If the bins already include underflow / overflow bins, e.g. bins[0] = -np.inf and bins[-1] = np.inf, using the result of this function will always be a valid index into the resulting histogram.

Parameters:
data: ``~np.ndarray`` or ``~astropy.units.Quantity``

Array with the data

bins: ``~np.ndarray`` or ``~astropy.units.Quantity``

Array or Quantity of bin edges. Must have the same unit as data if a Quantity.

Returns:
bin_index: np.ndarray[int]

Indices of the histogram bin the values in data belong to. Under- and overflown values will have values of UNDERFLOW_INDEX and OVERFLOW_INDEX respectively.

valid: np.ndarray[bool]

Boolean mask indicating if a given value belongs into one of the defined bins. False indicates that an entry fell into the over- or underflow bins.