Last modified: December 2020

URL: https://cxc.cfa.harvard.edu/sherpa/ahelp/set_source.html
Jump to: Description · Examples · PARAMETERS · Notes · Bugs · See Also


AHELP for CIAO 4.13 Sherpa v1

set_source

Context: modeling

Synopsis

Set the source model expression for a data set.

Syntax

set_source(id, model=None)

Alias: set_model

id - int or str, optional
model - str or sherpa.models.Model object

Description

The function is available as both `set_model` and `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_model` command can be used to explicitly include the instrument response if necessary.


Examples

Example 1

Create an instance of the `powlaw1d` model type, called pl , and use it as the model for the default data set.

>>> set_model(polynom1d.pl)

Example 2

Create a model for the default dataset which is the `xsphabs` model multiplied by the sum of an `xsapec` and `powlaw1d` models (the model components are identified by the labels gal , clus , and pl ).

>>> set_model(xsphabs.gal * (xsapec.clus + powlaw1d.pl))

Example 3

Repeat the previous example, using a string to define the model expression:

>>> set_model('xsphabs.gal * (xsapec.clus + powlaw1d.pl)')

Example 4

Use the same model component ( src , a `gauss2d` model) for the two data sets ('src1' and 'src2').

>>> set_model('src1',  gauss2d.src + const2d.bgnd1)
>>> set_model('src2', src + const2d.bgnd2)

Example 5

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 norm2 and norm3 components of the `const1d` model), and each data set has a separate `polynom1d` component ( bgnd1 , bgnd2 , and bgnd3 ). The c1 parameters of the `polynom1d` model 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)

Example 6

For this expression, the gal component is frozen, so it is not varied in the fit. The cache attribute 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

PARAMETERS

The parameters for this function are:

Parameter Definition
id The data set containing the source expression. If not given then the default identifier is used, as returned by `get_default_id` .
model This defines the model used to fit the data. It can be a Python expression or a string version of it.

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 `model` parameter. If given two un-named arguments, then they are interpreted as the `id` and `model` parameters, 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_model` should be used instead.

Model caching is available via the model cache attribute. 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 cache is 5 , but 0 for the 2D analytic models.

The `integrate1d` model can be used to apply a numerical integration to an arbitrary model expression.


Bugs

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

See Also

confidence
set_conf_opt, set_covar_opt, set_proj_opt
data
get_bkg_chisqr_plot, get_bkg_delchi_plot, get_bkg_fit_plot, get_bkg_model_plot, get_bkg_plot, get_bkg_ratio_plot, get_bkg_resid_plot, get_bkg_source_plot, set_areascal, set_arf, set_backscal, set_bkg, set_coord, set_counts, set_data, set_dep, set_exposure, set_grouping, set_quality, set_rmf, set_staterror, set_syserror
filtering
set_filter
info
list_model_ids, show_bkg_model, show_bkg_source
methods
set_iter_method, set_iter_method_opt, set_method, set_method_opt
modeling
add_model, add_user_pars, clean, create_model_component, delete_bkg_model, delete_model, delete_model_component, get_model, get_model_autoassign_func, get_model_component, get_model_component_image, get_model_component_plot, get_model_plot, get_num_par, get_num_par_frozen, get_num_par_thawed, get_order_plot, get_par, get_pileup_model, get_source, get_source_component_image, get_source_component_plot, get_source_contour, get_source_image, get_source_plot, get_xsabund, get_xscosmo, get_xsxsect, get_xsxset, image_model, image_model_component, image_source, image_source_component, integrate, link, load_table_model, load_template_interpolator, load_template_model, load_user_model, normal_sample, reset, save_model, save_source, set_bkg_model, set_bkg_source, set_full_model, set_model, set_model_autoassign_func, set_par, set_pileup_model, set_xsabund, set_xscosmo, set_xsxsect, set_xsxset, t_sample, uniform_sample
plotting
get_cdf_plot, get_pdf_plot, get_pvalue_plot, get_pvalue_results, plot_cdf, plot_model, plot_model_component, plot_pdf, plot_pvalue, plot_scatter, plot_source, plot_source_component, plot_trace
psfs
delete_psf, load_conv
saving
save_delchi, save_resid
statistics
set_prior, set_sampler, set_sampler_opt, set_stat
utilities
calc_chisqr, calc_energy_flux, calc_model_sum, calc_photon_flux, calc_source_sum, calc_stat, eqwidth, set_analysis, set_default_id
visualization
contour_model, contour_ratio, contour_resid, image_setregion