guess

sherpa.astro.ui.guess(id=None, model=None, limits=True, values=True)

Estimate the parameter values and ranges given the loaded data.

The guess function can change the parameter values and limits to match the loaded data. This is generally limited to changing the amplitude and position parameters (sometimes just the values and sometimes just the limits). The parameters that are changed depend on the type of model.

Changed in version 4.17.0: The guess routine will now work with composite models and those which include an instrumental response, such as an ARF. It only works on individual models, so the values, and limits, guessed are only approximate.

Parameters:
  • id (int or str, optional) – The data set that provides the data. If not given then the default identifier is used, as returned by get_default_id.

  • model – Change the parameters of this model component. If None, then the source expression is assumed to consist of a single component, and that component is used.

  • limits (bool) – Should the parameter limits be changed? The default is True.

  • values (bool) – Should the parameter values be changed? The default is True.

See also

get_default_id

Return the default data set identifier.

reset

Reset the model parameters to their default settings.

set_par

Set the value, limits, or behavior of a model parameter.

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.

The guess function can reduce the time required to fit a data set by moving the parameters closer to a realistic solution. It can also be useful because it can set bounds on the parameter values based on the data: for instance, many two-dimensional models will limit their xpos and ypos values to lie within the data area. This can be done manually, but guess simplifies this, at least for those parameters that are supported. Instrument models - such as an ARF and RMF - should be set up before calling guess.

Examples

Since the source expression contains only one component, guess can be called with no arguments:

>>> set_source(polynom1d.poly)
>>> guess()

Both components - that is, gal and pl - will be passed to the guess routine, but not all models can have their parameters guessed, and there is no attempt to recognize that the models are combined (in this case by multiplication):

>>> set_source(xsphabs.gal * powlaw1d.pl)
>>> guess()

In this case, guess is called on each component separately.

>>> set_source(gauss1d.line + powlaw1d.cont)
>>> guess(line)
>>> guess(cont)

In this example, the values of the src model component are guessed from the “src” data set, whereas the bgnd component is guessed from the “bgnd” data set.

>>> set_source("src", gauss2d.src + const2d.bgnd)
>>> set_source("bgnd", bgnd)
>>> guess("src", src)
>>> guess("bgnd", bgnd)

The above could also have been written as:

>>> guess("src", src)
>>> guess("bgnd")

Set the source model for the default dataset. Guess is run to determine the values of the model component “p1” and the limits of the model component “g1”:

>>> set_source(powlaw1d.p1 + gauss1d.g1)
>>> guess(p1, limits=False)
>>> guess(g1, values=False)