pymodelfit.core.register_model(model, name=None, overwrite=False)[source]

Registers a model at the module package level for get_model_class() and :func`list_model`.

  • model (a class object that is a subclass of class:ParametricModel) – The model to register
  • name (string or None) – The name to assign to this model. If None, the model name will be taken as the all lowercase version of the model class name, with the substring ‘model’ removed if it is present in the name.
  • overwrite (bool) – If True, if a model already exists with the provided name, it will be silently overwritten. Otherwise a KeyError will be raised.
Raises KeyError:

If overwrite is False and a model already exists with the name provided.


>>> class MyFavoriteModel(FunctionModel1DAuto):
...     def f(self,x,c=1):
...         return x**2+c
>>> register_model(MyFavoriteModel)
>>> list_models(include=[MyFavoriteModel])
>>> class MyOtherFavoriteModel(MyFavoriteModel):
...     pass
>>> register_model(MyOtherFavoriteModel,name='myotherBestest')
>>> list_models(include=[MyOtherFavoriteModel])
>>> class MyMostFavoriteModel(MyFavoriteModel):
...     pass
>>> register_model(MyMostFavoriteModel,name=None)
>>> list_models(include=[MyMostFavoriteModel])
>>> list_models(baseclass=MyFavoriteModel)
['myotherBestest', 'mymostfavorite', 'myfavorite']

Previous topic


Next topic


This Page