sample_energy_flux

sherpa.astro.ui.sample_energy_flux(lo=None, hi=None, id=None, num=1, scales=None, correlated=False, numcores=None, bkg_id=None)

Return the energy flux distribution of a model.

For each iteration, draw the parameter values of the model from a normal distribution, evaluate the model, and sum the model over the given range (the flux). The return array contains the flux and parameter values for each iteration. The units for the flux are as returned by calc_energy_flux.

Parameters:
  • lo (number, optional) – The lower limit to use when summing up the signal. If not given then the lower value of the data grid is used.
  • hi (optional) – The upper limit to use when summing up the signal. If not guven then the upper value of the data grid is used.
  • id (int or string, optional) – The identifier of the data set to use. The default value (None) means that the default identifier, as returned by get_default_id, is used.
  • num (int, optional) – The number of samples to create. The default is 1.
  • scales (array, optional) – The scales used to define the normal distributions for the parameters. The form depends on the correlated parameter: when True, the array should be a symmetric positive semi-definite (N,N) array, otherwise a 1D array of length N, where N is the number of free parameters.
  • correlated (bool, optional) – If True (the default is False) then scales is the full covariance matrix, otherwise it is just a 1D array containing the variances of the parameters (the diagonal elements of the covariance matrix).
  • numcores (optional) – The number of CPU cores to use. The default is to use all the cores on the machine.
  • bkg_id (int or string, optional) – The identifier of the background component to use. This should only be set when the line to be measured is in the background model.
Returns:

The return array has the shape (num, N+1), where N is the number of free parameters and num is the num parameter. The rows of this array contain the flux value, as calculated by calc_energy_flux, followed by the values of the thawed parameters used for that iteration. The order of the parameters matches the data returned by get_fit_results.

Return type:

vals

See also

calc_photon_flux()
Integrate the source model over a pass band.
calc_energy_flux()
Integrate the source model over a pass band.
covar()
Estimate the confidence intervals using the confidence method.
plot_cdf()
Plot the cumulative density function of an array.
plot_pdf()
Plot the probability density function of an array.
plot_energy_flux()
Display the energy flux distribution.
plot_photon_flux()
Display the photon flux distribution.
plot_trace()
Create a trace plot of row number versus value.
sample_photon_flux()
Return the flux distribution of a model.
sample_flux()
Return the flux distribution of a model.

Examples

Calculate the energy flux distribution for the range 0.5 to 7, and plot up the resulting flux distribution (as a cumulative distribution):

>>> vals = sample_energy_flux(0.5, 7, num=1000)
>>> plot_cdf(vals[:,0], name='flux')

Repeat the above, but allowing the parameters to be correlated, and then calculate the 5, 50, and 95 percent quantiles of the energy flux distribution:

>>> cvals = sample_energy_flux(.5, 7, num=1000, correlated=True)
>>> np.percentile(cvals[:,0], [5,50,95])