Create a one dimensional model from a user defined function. The parameters of the model will be inferred from the arguments of the function.
Note
All model parameters have to be defined as keyword arguments with default values in the model function.
If you want to use parameter sets in the model, the parameters should be treated as lists or arrays.
Parameters: | func : function
func_fit_deriv : function, optional
|
---|
Examples
Define a sinusoidal model function as a custom 1D model:
>>> from astropy.modeling.models import custom_model_1d
>>> import numpy as np
>>> def sine_model(x, amplitude=1., frequency=1.):
... return amplitude * np.sin(2 * np.pi * frequency * x)
>>> def sine_deriv(x, amplitude=1., frequency=1.):
... return 2 * np.pi * amplitude * np.cos(2 * np.pi * frequency * x)
>>> SineModel = custom_model_1d(sine_model, func_fit_deriv=sine_deriv)
Create an instance of the custom model and evaluate it:
>>> model = SineModel()
>>> model(0.25)
1.0
This model instance can now be used like a usual astropy model.