add_model

sherpa.ui.add_model(modelclass, args=(), kwargs={})

Create a user-defined model class.

Create a model from a class. The name of the class can then be used to create model components - e.g. with set_model or create_model_component - as with any existing Sherpa model.

Parameters:
  • modelclass – A class derived from sherpa.models.model.ArithmeticModel. This class defines the functional form and the parameters of the model.
  • args – Arguments for the class constructor.
  • kwargs – Keyword arguments for the class constructor.

See also

create_model_component()
Create a model component.
list_models()
List the available model types.
load_table_model()
Load tabular data and use it as a model component.
load_user_model()
Create a user-defined model.
set_model()
Set the source model expression for a data set.

Notes

The load_user_model function is designed to make it easy to add a model, but the interface is not the same as the existing models (such as having to call both load_user_model and add_user_pars for each new instance). The add_model function is used to add a model as a Python class, which is more work to set up, but then acts the same way as the existing models.

Examples

The following example creates a model type called “mygauss1d” which will behave excatly the same as the existing “gauss1d” model. Normally the class used with add_model would add new functionality.

>>> from sherpa.models import Gauss1D
>>> class MyGauss1D(Gauss1D):
...     pass
...
>>> add_model(MyGauss1D)
>>> set_source(mygauss1d.g1 + mygauss1d.g2)