The Bayesian Blocks algorithm (pwkit.bblocks)

pwkit.bblocks - Bayesian Blocks analysis, with a few extensions.

Bayesian Blocks analysis for the “time tagged” case described by Scargle+ 2013. Inspired by the bayesian_blocks implementation by Jake Vanderplas in the AstroML package, but that turned out to have some limitations.

We have iterative determination of the best number of blocks (using an ad-hoc routine described in Scargle+ 2013) and bootstrap-based determination of uncertainties on the block heights (ditto).

Functions are:

bin_bblock()

Bayesian Blocks analysis with counts and bins.

tt_bblock()

BB analysis of time-tagged events.

bs_tt_bblock()

Like tt_bblock() with bootstrap-based uncertainty assessment. NOTE: the uncertainties are not very reliable!

pwkit.bblocks.bin_bblock(widths, counts, p0=0.05)[source]

Fundamental Bayesian Blocks algorithm. Arguments:

widths - Array of consecutive cell widths. counts - Array of numbers of counts in each cell. p0=0.05 - Probability of preferring solutions with additional bins.

Returns a Holder with:

blockstarts - Start times of output blocks. counts - Number of events in each output block. finalp0 - Final value of p0, after iteration to minimize nblocks. nblocks - Number of output blocks. ncells - Number of input cells/bins. origp0 - Original value of p0. rates - Event rate associated with each block. widths - Width of each output block.

pwkit.bblocks.bs_tt_bblock(times, tstarts, tstops, p0=0.05, nbootstrap=512)[source]

Bayesian Blocks for time-tagged events with bootstrapping uncertainty assessment. THE UNCERTAINTIES ARE NOT VERY GOOD! Arguments:

tstarts - Array of input bin start times. tstops - Array of input bin stop times. times - Array of event arrival times. p0=0.05 - Probability of preferring solutions with additional bins. nbootstrap=512 - Number of bootstrap runs to perform.

Returns a Holder with:

blockstarts - Start times of output blocks. bsrates - Mean event rate in each bin from bootstrap analysis. bsrstds - ~Uncertainty: stddev of event rate in each bin from bootstrap analysis. counts - Number of events in each output block. finalp0 - Final value of p0, after iteration to minimize nblocks. ledges - Times of left edges of output blocks. midpoints - Times of midpoints of output blocks. nblocks - Number of output blocks. ncells - Number of input cells/bins. origp0 - Original value of p0. rates - Event rate associated with each block. redges - Times of right edges of output blocks. widths - Width of each output block.

pwkit.bblocks.tt_bblock(tstarts, tstops, times, p0=0.05, intersect_with_bins=False)[source]

Bayesian Blocks for time-tagged events. Arguments:

tstarts

Array of input bin start times.

tstops

Array of input bin stop times.

times

Array of event arrival times.

p0 = 0.05

Probability of preferring solutions with additional bins.

intersect_with_bins = False

If true, intersect bblock bins with input bins; can result in more bins than bblocks wants; they will have the same rate values.

Returns a Holder with:

counts

Number of events in each output block.

finalp0

Final value of p0, after iteration to minimize nblocks.

ledges

Times of left edges of output blocks.

midpoints

Times of midpoints of output blocks.

nblocks

Number of output blocks.

ncells

Number of input cells/bins.

origp0

Original value of p0.

rates

Event rate associated with each block.

redges

Times of right edges of output blocks.

widths

Width of each output block.

Bin start/stop times are best derived from a 1D Voronoi tesselation of the event arrival times, with some kind of global observation start/stop time setting the extreme edges. Or they can be set from “good time intervals” if observations were toggled on or off as in an X-ray telescope.

If intersect_with_bins is True, the true Bayesian Blocks bins (BBBs) are intersected with the “good time intervals” (GTIs) defined by the tstarts and tstops variables. One GTI may contain multiple BBBs if the event rate appears to change within the GTI, and one BBB may span multiple GTIs if the event date does not appear to change between the GTIs. The intersection will ensure that no BBB intervals cross the edge of a GTI. If this would happen, the BBB is split into multiple, partially redundant records. Each of these records will have the same value for the counts, rates, and widths values. However, the ledges, redges, and midpoints values will be recalculated. Note that in this mode, it is not necessarily true that widths = ledges - redges as is usually the case. When this flag is true, keep in mind that multiple bins are therefore not necessarily independent statistical samples.