EnergyBins¶
- class gdt.core.data_primitives.EnergyBins(counts, lo_edges, hi_edges, exposure, **kwargs)[source]¶
Bases:
ExposureBinsA class defining a set of Energy (count spectra) bins.
- Parameters:
counts (np.array) – The array of counts in each bin
lo_edges (np.array) – The low-value edges of the bins
hi_edges (np.array) – The high-value edges of the bins
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.
precalc_good_segments (bool, optional) – If True, calculates contiguous bin segments on initialization. Default is True.
Attributes Summary
The centroids of the bins
The count uncertainty in each bin
The counts in each bin
The exposure of each bin
The high-value edges of the bins
The low-value edges of the bins
The range of the bin edges
The count rate uncertainty of each bin
Differential rate uncertainty
counts/exposure
Differential count rate
Number of bins
The widths of the bins
Methods Summary
closest_edge(val[, which])Return the closest bin edge
Return a list of ExposureBins, each one containing a continuous segment of data.
from_rates(rates, rate_uncerts, lo_edges, ...)Create an ExposureBins object from count rates and uncertainties.
merge(histos, **kwargs)Merge multiple ExposureBins together.
rebin(method, *args[, emin, emax])Rebin the EnergyBins object in given a binning function and return a a new EnergyBins object
slice(tstart, tstop)Perform a slice over a range and return a new ExposureBins object.
sum(histos)Sum multiple EnergyBins together if they have the same energy range (support).
Attributes Documentation
- centroids¶
The centroids of the bins
- 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 range of the bin edges
- Type:
(float, float)
- rate_uncertainty¶
The count rate uncertainty of each bin
- Type:
(np.array)
- rate_uncertainty_per_kev¶
Differential rate uncertainty
- Type:
(np.array)
- rates¶
counts/exposure
- Type:
(np.array)
- Type:
The count rate of each bin
- rates_per_kev¶
Differential count rate
- Type:
(np.array)
- 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 from_rates(rates, rate_uncerts, lo_edges, hi_edges, exposure, **kwargs)¶
Create an ExposureBins object from count rates and uncertainties.
- Parameters:
rates (np.array) – The count rates
rate_uncerts (np.array) – The count rate uncertainties
lo_edges (np.array) – The low-value edges of the bins
hi_edges (np.array) – The high-value edges of the bins
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:
- 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:
- rebin(method, *args, emin=None, emax=None)[source]¶
Rebin the EnergyBins object in given a binning function and return a a new EnergyBins 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.
- Parameters:
method (<function>) – A binning function
*args – Arguments to be passed to the binning function
emin (float, optional) – If set, defines the starting energy of the EnergyBins to be binned, otherwise binning will begin at the first bin edge.
emax (float, optional) – If set, defines the ending energy of the EnergyBins to be binned, otherwise binning will end at the last bin edge.
- Returns:
- slice(tstart, tstop)¶
Perform a slice over a range and return a new ExposureBins object. Note that tstart and tstop values that fall inside a bin will result in that bin being included.
- Parameters:
tstart (float) – The start of the slice
tstop (float) – The end of the slice
- Returns:
- classmethod sum(histos)[source]¶
Sum multiple EnergyBins together if they have the same energy range (support). Example use would be summing two count spectra.
Note
Count uncertainties are summed in quadrature.
- Parameters:
histos (list of
EnergyBins) – A list containing the EnergyBins to be summed- Returns: