bxa.sherpa package



bxa.sherpa.cachedmodel module

class bxa.sherpa.cachedmodel.VariableCachedModel(othermodel)[source]

Bases: list, object

Wrapper that caches the most recent model call.

othermodel can be any sherpa model

calc(p, left, right, *args, **kwargs)[source]
guess(dep, *args, **kwargs)[source]
class bxa.sherpa.cachedmodel.CachedModel(othermodel)[source]

Bases: list, object

Wrapper that caches the first model call forever.

othermodel can be any sherpa model

calc(*args, **kwargs)[source]
guess(dep, *args, **kwargs)[source]

bxa.sherpa.galabs module


bxa.sherpa.invgauss module

bxa.sherpa.invgauss.get_invgauss_func(mu, sigma)[source]

bxa.sherpa.priors module


Use for location variables (position) The uniform prior gives equal weight in non-logarithmic scale.


parameter – Parameter to create a prior for. E.g. xspowerlaw.mypowerlaw.PhoIndex


deprecated name for create_loguniform_prior_for


Use for scale variables (order of magnitude) The Jeffreys prior gives equal weight to each order of magnitude between the minimum and maximum value. Flat in logarithmic scale.


parameter – Parameter to create a prior for. E.g. xspowerlaw.mypowerlaw.norm

It is usually easier to create an ancillary parameter, and link the actual parameter, like so:

from sherpa.models.parameter import Parameter
lognorm = Parameter(modelname='mycomponent', name='lognorm', val=-5, min=-4*2, max=0)
powerlaw.norm = 10**lognorm
bxa.sherpa.priors.create_gaussian_prior_for(parameter, mean, std)[source]

Use for informed variables. The Gaussian prior weights by a Gaussian in the parameter. If you would like the logarithm of the parameter to be weighted by a Gaussian, create a ancillary parameter (see create_jeffreys_prior_for).

  • parameter – Parameter to create a prior for. E.g. xspowerlaw.mypowerlaw.PhoIndex

  • mean – Mean of the Gaussian

  • std – Standard deviation of the Gaussian

bxa.sherpa.priors.prior_from_file(filename, parameter)[source]

Read a custom prior distribution from a file. The file should have two columns: cumulative probability and value, in ascii format. The cumulative probability has to be equally spaced and should exclude 0 and 1.

Returns a sherpa parameter, a list with that parameter inside, and the prior function.

If the file only constains a single value, that value is returned along with two empty lists.

bxa.sherpa.priors.create_prior_function(priors=[], parameters=None)[source]

Combine the prior transformations into a single function.

This assumes factorized (independent) priors.

  • priors – individual prior transforms to combine into one function. If priors is empty, uniform priors are used on all passed parameters

  • parameters – If priors is empty, specify the list of parameters. Uniform priors will be created for them.

bxa.sherpa.qq module

QQ plots and goodness of fit

bxa.sherpa.qq.KSstat(data, model, staterror=None, syserror=None, weight=None)[source]
bxa.sherpa.qq.CvMstat(data, model, staterror=None, syserror=None, weight=None)[source]
bxa.sherpa.qq.ADstat(data, model, staterror=None, syserror=None, weight=None)[source]
bxa.sherpa.qq.qq_export(id=None, bkg=False, outfile='qq.txt', elow=None, ehigh=None)[source]

Export Q-Q plot into a file for plotting.

  • id – spectrum id to use (see get_bkg_plot/get_data_plot)

  • bkg – whether to use get_bkg_plot or get_data_plot

  • outfile – filename to write results into

  • elow – low energy limit

  • ehigh – low energy limit


qq.qq_export('bg', outfile='my_bg_qq', elow=0.2, ehigh=10)

bxa.sherpa.rebinnedmodel module

class bxa.sherpa.rebinnedmodel.RebinnedModel(slowmodel, ebins, parameters, filename, modelname='rebinnedmodel')[source]

Bases: object

init(modelname, x, data, parameters)[source]
calc(p, left, right, *args, **kwargs)[source]

bxa.sherpa.solver module

BXA (Bayesian X-ray Analysis) for Sherpa

Copyright: Johannes Buchner (C) 2013-2020

bxa.sherpa.solver.photon_flux_histogram(distribution, nbins=None)[source]
bxa.sherpa.solver.energy_flux_histogram(distribution, nbins=None)[source]
class bxa.sherpa.solver.BXASolver(id=None, otherids=(), prior=None, parameters=None, outputfiles_basename='chains/', resume_from=None)[source]

Bases: object

Set up Bayesian analysis with specified parameters+transformations.

  • id – See the sherpa documentation of calc_stat.

  • otherids – See the sherpa documentation of calc_stat.

  • prior – prior function created with create_prior_function.

  • parameters – List of parameters to analyse.

  • outputfiles_basename – prefix for output filenames.

  • resume_from – prefix for output filenames of a previous run with similar posterior from which to resume

If prior is None, uniform priors are used on the passed parameters. If parameters is also None, all thawed parameters are used.


unit cube transformation.

see https://johannesbuchner.github.io/UltraNest/priors.html#Dependent-priors


returns -0.5 of the fit statistic.

run(sampler_kwargs={'resume': 'overwrite'}, run_kwargs={'Lepsilon': 0.1}, speed='safe', resume=None, n_live_points=None, frac_remain=None, Lepsilon=0.1, evidence_tolerance=None)[source]

Run nested sampling with ultranest.


arguments passed to ReactiveNestedSampler (see ultranest documentation)


arguments passed to ReactiveNestedSampler.run() (see ultranest documentation)

The following arguments are also available directly for backward compatibility:

  • resume – sets sampler_kwargs[‘resume’]=’resume’ if True, otherwise ‘overwrite’

  • n_live_points – sets run_kwargs[‘min_num_live_points’]

  • evidence_tolerance – sets run_kwargs[‘dlogz’]

  • Lepsilon – sets run_kwargs[‘Lepsilon’]

  • frac_remain – sets run_kwargs[‘frac_remain’]


Sets model to the best fit values.

get_distribution_with_fluxes(elo=None, ehi=None)[source]

Computes flux posterior samples.

Returns an array of equally weighted posterior samples (parameter values) with two additional columns: the photon fluxes and the energy fluxes.

The values will be correctly distributed according to the analysis run before.

Module contents

BXA (Bayesian X-ray Analysis) for Sherpa

Copyright: Johannes Buchner (C) 2013-2019

bxa.sherpa.nested_run(id=None, otherids=(), prior=None, parameters=None, sampling_efficiency=0.3, evidence_tolerance=0.5, n_live_points=400, outputfiles_basename='chains/', **kwargs)[source]

deprecated, use BXASolver instead.