API/Reference¶

Bridge between Sherpa and Astropy modeling.

class saba.SherpaFitter(optimizer=u'levmar', statistic=u'leastsq', estmethod=u'covariance')[source]

Sherpa Fitter for astropy models.

Parameters: optimizer : string the name of a sherpa optimizer. posible options include levmar, moncar, simplex, neldermead statistic : string the name of a sherpa statistic. posible options include leastsq, chi2, chi2gehrels, chi2datavar, chi2modvar, wstat, chi2constvar, cstat, cash, chi2xspecvar estmethod : string the name of a sherpa estmethod. possible options include confidence, covariance, projection
__call__(models, x, y, z=None, xbinsize=None, ybinsize=None, err=None, bkg=None, bkg_scale=1, **kwargs)[source]

Fit the astropy model with a the sherpa fit routines.

Parameters: model to fit to x, y, z x : array or list of arrays input coordinates (independent for 1D & 2D fits) y : array or list of arrays input coordinates (dependent for 1D fits or independent for 2D fits) z : array or list of arrays (optional) input coordinates (dependent for 2D fits) xbinsize : array or list of arrays (optional) an array of xbinsizes in x - this will be x -/+ (binsize / 2.0) ybinsize : array or list of arrays (optional) an array of xbinsizes in y - this will be y -/+ (ybinsize / 2.0) err : array or list of arrays (optional) an array of errors in dependent variable bkg : array or list of arrays (optional) this will act as background data bkg_sale : float or list of floats (optional) the scaling factor for the dataset if a single value is supplied it will be copied for each dataset **kwargs : keyword arguments will be passed on to sherpa fit routine model_copy : astropy.modeling.FittableModel or a list of models. a copy of the input model with parameters set by the fitter
est_errors(sigma=None, maxiters=None, numcores=1, methoddict=None, parlist=None)[source]

Use sherpa error estimators based on the last fit.

Parameters: sigma: float this will be set as the confidance interval for which the errors are found too. maxiters: int the maximum number of iterations the error estimator will run before giving up. methoddict: dict !not quite sure couldn’t figure this one out yet! parlist: list a list of parameters to find the confidance interval of if none are provided all free parameters will be estimated.
get_sampler(*args, **kwargs)[source]
This returns and instance of SherpaMCMC with it’s self as the fitter

An interface which makes use of sherpa’s MCMC(pyBLoCXS) functionality.

Parameters: fitter: a SherpaFitter instance. used to caluate the fit statstics, must have been fit as the covariance matrix is used. sampler: string the name of a valid sherpa sampler. walker: string the name of a valid sherpa walker.
class saba.SherpaMCMC(fitter, sampler=u'mh', walker=u'mh')[source]

An interface which makes use of sherpa’s MCMC(pyBLoCXS) functionality.

Parameters: fitter: a SherpaFitter instance. used to caluate the fit statstics, must have been fit as the covariance matrix is used. sampler: string the name of a valid sherpa sampler. walker: string the name of a valid sherpa walker.
__call__(niter=200000)[source]

based on the sherpa.sim.get_draws

Parameters: niter: int the number of samples you wish to draw. stat_values: array(float) the fit statistic of the draw accepted: array(bool) if the fit was accepted parameters: dict the parameter values for each draw
accepted

The stored list of bools if each draw was accepted or not.

set_prior(parameter, prior)[source]

Set the prior function to use with a parameter. The default prior used by the SherpaMCMC function call for each parameter is flat, varying between the minimum and maximum values of the parameter (as given by the min and max attributes of the parameter object).

Parameters: par : sherpa.models.parameter.Parameter instance A parameter of a model instance. prior : function or sherpa.models.model.Model instance The function to use for a prior. It must accept a single argument and return a value of the same size as the input.

Examples

Create a function (lognorm) and use it as the prior the nH parameter

>> def lognorm(x):
sigma = 0.5 x0 = 20 dx = np.log10(x) - x0 norm = sigma / np.sqrt(2 * np.pi) return norm * np.exp(-0.5*dx*dx/(sigma*sigma))

>> mcmc.set_prior(‘nH’, lognorm)

set_sampler_options(opt, value)[source]

Set an option for the current MCMC sampler.

Parameters: opt : str The option to change. Use get_sampler to view the available options for the current sampler. value : The value for the option.

Notes

The options depend on the sampler. The options include:

defaultprior
Set to False when the default prior (flat, between the parameter’s soft limits) should not be used. Use set_prior to set the form of the prior for each parameter.
inv:
A bool, or array of bools, to indicate which parameter is on the inverse scale.
log:
A bool, or array of bools, to indicate which parameter is on the logarithm (natural log) scale.
original:
A bool, or array of bools, to indicate which parameter is on the original scale.
p_M:
The proportion of jumps generatd by the Metropolis jumping rule.
priorshape:
An array of bools indicating which parameters have a user-defined prior functions set with set_prior.
scale:
Multiply the output of covar by this factor and use the result as the scale of the t-distribution.

Examples

>> mcmc = SherpaMCMC(sfit) >> mcmc.set_sampler_opt(‘scale’, 3)

stat_values

The stored values for the fit statistic of each run.