Bins

class gdt.core.data_primitives.Bins(counts, lo_edges, hi_edges, count_uncerts=None)[source]

Bases: object

A primitive class defining a set of histogram bins. The number of counts in each bin are assumed to be represented by a Poisson distribution unless the count_uncerts argument is specified with the defined count uncertainties.

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

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

Attributes Summary

centroids

The centroids of the bins

count_uncertainty

The count uncertainty in each bin

counts

The counts in each bin

hi_edges

The high-value edges of the bins

lo_edges

The low-value edges of the bins

range

The range of the bin edges

rate_uncertainty

The count rate uncertainty of each bin

rates

The count rate of each bin; counts/width

size

Number of bins

widths

The widths of the bins

Methods Summary

closest_edge(val[, which])

Return the closest bin edge

from_rates(rates, rate_uncerts, lo_edges, ...)

Create a Bins object from count rates and uncertainties.

slice(lo_edge, hi_edge)

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

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)

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)

rates

The count rate of each bin; counts/width

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')[source]

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)

classmethod from_rates(rates, rate_uncerts, lo_edges, hi_edges)[source]

Create a Bins 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

Returns:

(Bins)

slice(lo_edge, hi_edge)[source]

Perform a slice over the range of the bins and return a new Bins object. Note that lo_edge and hi_edge values that fall inside a bin will result in that bin being included.

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

  • hi_edge (float) – The end of the slice

Returns:

(Bins)