- sherpa.ui.set_model(id, model=None)
Set the source model expression for a data set.
The function is available as both
set_source. The model fit to the data can be further modified by instrument responses which can be set explicitly - e.g. by
set_psf- or be defined automatically by the type of data being used (e.g. the ARF and RMF of a PHA data set). The
set_full_modelcommand can be used to explicitly include the instrument response if necessary.
model (str or sherpa.models.Model object) – This defines the model used to fit the data. It can be a Python expression or a string version of it.
Delete the model expression from a data set.
Fit one or more data sets.
Fix model parameters so they are not changed by a fit.
Return the source model expression for a data set.
Integrate 1D source expressions.
Set the background model expression for a data set.
Define the convolved model expression for a data set.
Display the source model expression for a data set.
Set the value, limits, or behavior of a model parameter.
Allow model parameters to be varied during a fit.
The function does not follow the normal Python standards for parameter use, since it is designed for easy interactive use. When called with a single un-named argument, it is taken to be the
modelparameter. If given two un-named arguments, then they are interpreted as the
PHA data sets will automatically apply the instrumental response (ARF and RMF) to the source expression. For some cases this is not useful - for example, when different responses should be applied to different model components - in which case
set_full_modelshould be used instead.
Model caching is available via the model
cacheattribute. A non-zero value for this attribute means that the results of evaluating the model will be cached if all the parameters are frozen, which may lead to a reduction in the time taken to evaluate a fit. A zero value turns off the caching. The default setting for X-Spec and 1D analytic models is that
0for the 2D analytic models.
integrate1dmodel can be used to apply a numerical integration to an arbitrary model expression.
Create an instance of the
powlaw1dmodel type, called
pl, and use it as the model for the default data set.
Create a model for the default dataset which is the
xsphabsmodel multiplied by the sum of an
powlaw1dmodels (the model components are identified by the labels
>>> set_model(xsphabs.gal * (xsapec.clus + powlaw1d.pl))
Repeat the previous example, using a string to define the model expression:
>>> set_model('xsphabs.gal * (xsapec.clus + powlaw1d.pl)')
Use the same model component (
gauss2dmodel) for the two data sets (‘src1’ and ‘src2’).
>>> set_model('src1', gauss2d.src + const2d.bgnd1) >>> set_model('src2', src + const2d.bgnd2)
Share an expression - in this case three gaussian lines - between three data sets. The normalization of this line complex is allowed to vary in data sets 2 and 3 (the
norm3components of the
const1dmodel), and each data set has a separate
c1parameters of the
polynom1dmodel components are thawed and then linked together (to reduce the number of free parameters):
>>> lines = gauss1d.l1 + gauss1d.l2 + gauss1d.l3 >>> set_model(1, lines + polynom1d.bgnd1) >>> set_model(2, lines * const1d.norm2 + polynom1d.bgnd2) >>> set_model(3, lines * const1d.norm3 + polynom1d.bgnd3) >>> thaw(bgnd1.c1, bgnd2.c1, bgnd3.c1) >>> link(bgnd2.c2, bgnd1.c1) >>> link(bgnd3.c3, bgnd1.c1)
For this expression, the
galcomponent is frozen, so it is not varied in the fit. The
cacheattribute is set to a non-zero value to ensure that it is cached during a fit (this is actually the default value for this model so it not normally needed).
>>> set_model(xsphabs.gal * (xsapec.clus + powlaw1d.pl)) >>> gal.nh = 0.0971 >>> freeze(gal) >>> gal.cache = 1