sherpa.astro.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.

  • 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 a model component.


List the available model types.


Load tabular data and use it as a model component.


Create a user-defined model.


Set the source model expression for a data set.


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.


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)