ChannelBins

class gdt.core.data_primitives.ChannelBins(counts, lo_edges, hi_edges, exposure, count_uncerts=None, precalc_good_segments=True)[source]

Bases: ExposureBins

A class defining a set of Energy Channel bins.

Attributes Summary

centroids

The centroids of the bins

chan_nums

The channel numbers

count_uncertainty

The count uncertainty in each bin

counts

The counts in each bin

exposure

The exposure of each bin

hi_edges

The high-value edges of the bins

lo_edges

The low-value edges of the bins

range

The channel range

rate_uncertainty

The count rate uncertainty of each bin

rates

counts/exposure

size

Number of bins

widths

The widths of the bins

Methods Summary

closest_edge(val[, which])

Return the closest bin edge

contiguous_bins()

Return a list of ExposureBins, each one containing a continuous segment of data.

create(counts, chan_nums, exposure[, continuous])

Create a ChannelBins object from a list of channel numbers.

from_rates(rates, rate_uncerts, chan_nums, ...)

Create an ChannelBins object from count rates and uncertainties.

merge(histos, **kwargs)

Merge multiple ExposureBins together.

rebin(method, *args[, chan_min, chan_max])

Rebin the ChannelBins object given a binning function and return a new ChannelBins object

slice(chan_min, chan_max)

Perform a slice over the range of the bins and return a new ChannelBins object.

sum(histos)

Sum multiple ExposureBins together if they have the same bin edges.

Attributes Documentation

centroids

The centroids of the bins

Type:

(np.array)

chan_nums

The channel numbers

Type:

(np.array)

count_uncertainty

The count uncertainty in each bin

Type:

(np.array)

counts

The counts in each bin

Type:

(np.array)

exposure

The exposure of each bin

Type:

(np.array)

hi_edges

The high-value edges of the bins

Type:

(np.array)

lo_edges

The low-value edges of the bins

Type:

(np.array)

range

The channel range

Type:

(int, int)

rate_uncertainty

The count rate uncertainty of each bin

Type:

(np.array)

rates

counts/exposure

Type:

(np.array)

Type:

The count rate of each bin

size

Number of bins

Type:

(int)

widths

The widths of the bins

Type:

(np.array)

Methods Documentation

closest_edge(val, which='either')

Return the closest bin edge

Parameters:
  • val (float) – Input value

  • which (str, optional) –

    Options are:

    • ’either’ - closest edge to val;

    • ’low’ - closest edge lower than val; or

    • ’high’ - closest edge higher than val. Default is ‘either’

Returns:

(float)

contiguous_bins()

Return a list of ExposureBins, each one containing a continuous segment of data. This is done by comparing the edges of each bin, and if there is a gap between edges, the data is split into separate ExposureBin objects, each containing a contiguous set of data.

Returns

(list of ExposureBins)

classmethod create(counts, chan_nums, exposure, continuous=True, **kwargs)[source]

Create a ChannelBins object from a list of channel numbers.

Parameters:
  • counts (np.array) – The array of counts in each bin

  • chan_nums (np.array) – The energy channel numbers

  • exposure (np.array) – The exposure of each bin

  • count_uncerts (np.array, optional) – An array the same length as counts if the uncertainty is not Poisson.

  • continuous (bool, optional) – [Experimental] Whether the bins are continuous (meaning no gaps between channels).

  • precalc_good_segments (bool, optional) – If True, calculates contiguous bin segments on initialization. Default is True.

Returns:

(ChannelBins)

classmethod from_rates(rates, rate_uncerts, chan_nums, exposure, **kwargs)[source]

Create an ChannelBins object from count rates and uncertainties.

Parameters:
  • rates (np.array) – The count rates

  • rate_uncerts (np.array) – The count rate uncertainties

  • chan_nums (np.array) – The energy channel numbers

  • exposure (np.array) – The exposure of each bin

  • precalc_good_segments (bool, optional) – If True, calculates contiguous bin segments on initialization. Default is True.

Returns:

(ChannelBins)

classmethod merge(histos, **kwargs)

Merge multiple ExposureBins together. Note that the ExposureBins to merged must be strictly non-overlapping. The end of the range for one ExposureBins may be equal to the start of the range for another, or there may be a gap between the end of one or beginning of another, but there cannot be an overlap. If you need to sum the counts between multiple ExposureBins with the same bin edges, see the sum() method.

Parameters:

histos (list of ExposureBins) – A list containing the ExposureBins to be merged

Returns:

(ExposureBins)

rebin(method, *args, chan_min=None, chan_max=None)[source]

Rebin the ChannelBins object given a binning function and return a new ChannelBins object

The binning function should take as input an array of counts, array of exposures, and an array of bin edges. Additional arguments specific to the function are allowed. The function should return an array of the new counts, new exposure, and new edges.

Note::

Edges for energy channels are treated as [chan_num, chan_num+1]

Parameters:
  • method (<function>) – A binning function

  • *args – Arguments to be passed to the binning function

  • chan_min (float, optional) – If set, defines the minimum channel number of the ChannelBins to be binned, otherwise binning will begin at the first channel number.

  • chan_max (float, optional) – If set, defines the maximum channel of the ChannelBins to be binned, otherwise binning will end at the last channel number.

Returns:

(ChannelBins)

slice(chan_min, chan_max)[source]

Perform a slice over the range of the bins and return a new ChannelBins object.

Parameters:
  • lo_edge (float) – The start of the slice

  • hi_edge (float) – The end of the slice

Returns:

(ChannelBins)

classmethod sum(histos)

Sum multiple ExposureBins together if they have the same bin edges. If the exposures are different between the histograms, they will be averaged.

Note

Count uncertainties are summed in quadrature.

Parameters:

histos (list of ExposureBins) – A list containing the ExposureBins to be summed

Returns:

(ExposureBins)