set_model
- sherpa.ui.set_model(id, model=None)
Set the source model expression for a data set.
The function is available as both
set_modelandset_source. The model fit to the data can be further modified by instrument responses which can be set explicitly - e.g. byset_psf- or be defined automatically by the type of data being used (e.g. the ARF and RMF of a PHA data set). Theset_full_modelcommand can be used to explicitly include the instrument response if necessary.- Parameters:
id (int or str, optional) – The data set containing the source expression. If not given then the default identifier is used, as returned by
get_default_id.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.
See also
delete_modelDelete the model expression from a data set.
fitFit one or more data sets.
freezeFix model parameters so they are not changed by a fit.
get_sourceReturn the source model expression for a data set.
integrate1dIntegrate 1D source expressions.
sherpa.astro.ui.set_bkg_modelSet the background model expression for a data set.
set_full_modelDefine the convolved model expression for a data set.
show_modelDisplay the source model expression for a data set.
set_parSet the value, limits, or behavior of a model parameter.
thawAllow model parameters to be varied during a fit.
Notes
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 theidandmodelparameters, respectively.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 thatcacheis5, but0for the 2D analytic models.The
integrate1dmodel can be used to apply a numerical integration to an arbitrary model expression.Examples
Create an instance of the
powlaw1dmodel type, calledpl, and use it as the model for the default data set.>>> set_model(polynom1d.pl)
Create a model for the default dataset which is the
xsphabsmodel multiplied by the sum of anxsapecandpowlaw1dmodels (the model components are identified by the labelsgal,clus, andpl).>>> 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 (
src, agauss2dmodel) 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
norm2andnorm3components of theconst1dmodel), and each data set has a separatepolynom1dcomponent (bgnd1,bgnd2, andbgnd3). Thec1parameters of thepolynom1dmodel 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. Thecacheattribute 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