BackgroundFitter

class gdt.core.background.fitter.BackgroundFitter[source]

Bases: object

Class for fitting a background, given a fitting algorithm, to time-energy data (e.g. Phaii, PhotonList).

When a BackgroundFitter is created, an algorithm must be specified. In particular, the algorithm must be a class that has two public methods: fit() and interpolate().

For PHAII data, the class, upon initialization, must take the following as arguments:

  • A 2D array of counts with shape (num_times, num_chans);

  • A 1D array of time bin start times, shape (num_times,);

  • A 1D array of time bin end times, shape (num_times,);

  • A 1D array of exposures for each time bin, shape (num_times,).

While for TTE data, the class, upon initialization, must take the following as an argument:

  • A list, of length num_chans, where each item is a numpy.ndarray of event times.

The fit() method takes no arguments, however, parameters that are required for the algorithm may be specified as keywords.

The interpolate() method must take in the following as arguments:

  • A 1D array of time bin start times, shape (num_times,);

  • A 1D array of time bin end times, shape (num_times,).

Any additional parameters required can be specified as keywords. The interpolate() method must return:

  • A 2D rates array, shape (num_times, num_chans);

  • A 2D rate uncertainty array, shape (num_times, num_chans).

Additionally, the class can provide the following public attributes that will be exposed by BackgroundFitter:

  • dof: The degrees of freedom of the fits, array shape (num_chans,)

  • statistic: The fit statistic for each fit, array shape (num_chans,)

  • statistic_name: A string of the fit statistic used

Attributes Summary

dof

If available, the degrees-of-freedom of the fit for each energy channel

livetime

The total livetime of the data used for the background

method

The name of the fitting algorithm class

parameters

All parameters passed to the fitting algorithm

statistic

If available, the fit statistic for each energy channel

statistic_name

If available, the name of the fit statistic

type

The type of background algorithm, either 'binned' or 'unbinned'

Methods Summary

fit(**kwargs)

Perform a background fit of the data

from_phaii(phaii, method[, time_ranges])

Create a background fitter from a PHAII object

from_tte(tte, method[, time_ranges])

Create a background fitter from a TTE object

interpolate_bins(tstart, tstop, **kwargs)

Interpolate the fitted background model over a set of bins.

interpolate_times(times, **kwargs)

Interpolate the fitted background model over a set of times.

to_bak([time_range])

Integrate over the time axis and produce a BAK object

Attributes Documentation

dof

If available, the degrees-of-freedom of the fit for each energy channel

Type:

(np.array)

livetime

The total livetime of the data used for the background

Type:

(float)

method

The name of the fitting algorithm class

Type:

(str)

parameters

All parameters passed to the fitting algorithm

Type:

(dict)

statistic

If available, the fit statistic for each energy channel

Type:

(np.array)

statistic_name

If available, the name of the fit statistic

Type:

(str)

type

The type of background algorithm, either ‘binned’ or ‘unbinned’

Type:

(str)

Methods Documentation

fit(**kwargs)[source]

Perform a background fit of the data

Parameters:

**kwargs – Options to be passed as parameters to the fitting class

classmethod from_phaii(phaii, method, time_ranges=None)[source]

Create a background fitter from a PHAII object

Parameters:
  • phaii (Phaii) – A PHAII data object

  • method (<class>) – A background fitting/estimation class for binned data

  • time_ranges ([(float, float), ...]) – The time range or time ranges over which to fit the background. If omitted, uses the full time range of the data

Returns:

(BackgroundFitter)

classmethod from_tte(tte, method, time_ranges=None)[source]

Create a background fitter from a TTE object

Parameters:
  • tte (PhotonList) – A PhotonList data object

  • method (<class>) – A background fitting/estimation class for unbinned data

  • time_ranges ([(float, float), ...]) – The time range or time ranges over which to fit the background. If omitted, uses the full time range of the data

Returns:

(BackgroundFitter)

interpolate_bins(tstart, tstop, **kwargs)[source]

Interpolate the fitted background model over a set of bins. The exposure is calculated for each bin of the background model in case the background model counts is needed.

Parameters:
  • tstart (np.array) – The starting times

  • tstop (np.array) – The ending times

  • **kwargs – Options to be passed as parameters to the interpolation method

Returns:

(BackgroundRates or BackgroundChannelRates)

interpolate_times(times, **kwargs)[source]

Interpolate the fitted background model over a set of times. Does not calculate an exposure since this returns a set of point estimates of the background rates.

Parameters:
  • tstart (np.array) – The sampling times

  • **kwargs – Options to be passed as parameters to the interpolation method

Returns:

(BackgroundRates or BackgroundChannelRates)

to_bak(time_range=None, **kwargs)[source]

Integrate over the time axis and produce a BAK object

Parameters:
  • time_range ((float, float)) – The time range to integrate over

  • **kwargs – Options to pass to Bak.from_data()

Returns:

(Bak)