threeML.utils.binner module

exception threeML.utils.binner.NotEnoughData[source]

Bases: RuntimeError

class threeML.utils.binner.Rebinner(vector_to_rebin_on, min_value_per_bin, mask=None)[source]

Bases: object

A class to rebin vectors keeping a minimum value per bin. It supports array with a mask, so that elements excluded through the mask will not be considered for the rebinning

get_new_start_and_stop(old_start, old_stop)[source]
property grouping
property n_bins

Returns the number of bins defined.



Rebin errors by summing the squares




array of rebinned errors

class threeML.utils.binner.TemporalBinner(list_of_intervals=())[source]

Bases: TimeIntervalSet

An extension of the TimeInterval set that includes binning capabilities

classmethod bin_by_bayesian_blocks(arrival_times, p0, bkg_integral_distribution=None)[source]

Divide a series of events characterized by their arrival time in blocks of perceptibly constant count rate. If the background integral distribution is given, divide the series in blocks where the difference with respect to the background is perceptibly constant.

  • arrival_times – An iterable (list, numpy.array…) containing the arrival time of the events. NOTE: the input array MUST be time-ordered, and without duplicated entries. To ensure this, you may execute the following code: tt_array = numpy.asarray(self._arrival_times) tt_array = numpy.unique(tt_array) tt_array.sort() before running the algorithm.

  • p0 – The probability of finding a variations (i.e., creating a new block) when there is none. In other words, the probability of a Type I error, i.e., rejecting the null-hypothesis when is true. All found variations will have a post-trial significance larger than p0.

:param bkg_integral_distributionthe integral distribution for the

background counts. It must be a function of the form f(x), which must return the integral number of counts expected from the background component between time 0 and x.

classmethod bin_by_constant(arrival_times, dt)[source]

Create bins with a constant dt


dt – temporal spacing of the bins



classmethod bin_by_custom(starts, stops)[source]

Simplicity function to make custom bins. This form keeps introduction of custom bins uniform for other binning methods

  • start – start times of the bins

  • stop – stop times of the bins


classmethod bin_by_significance(arrival_times, background_getter, background_error_getter=None, sigma_level=10, min_counts=1, tstart=None, tstop=None)[source]

Bin the data to a given significance level for a given background method and sigma method. If a background error function is given then it is assumed that the error distribution is gaussian. Otherwise, the error distribution is assumed to be Poisson.

  • background_getter – function of a start and stop time that returns background counts

  • background_error_getter – function of a start and stop time that returns background count errors

  • sigma_level – the sigma level of the intervals

  • min_counts – the minimum counts per bin