astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v0.3 »
- Models And Fitting (`astropy.modeling`) »
- custom_model_1d

# custom_model_1d

`astropy.modeling.functional_models.``custom_model_1d`(func, func_deriv=None)

  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

  > Function which defines the model. It should take one positional argument (the independent variable in the model), and any number of keyword arguments (the parameters). It must return the value of the model (typically as an array, but can also be a scalar for scalar inputs). This corresponds to the `ParametricModel.eval` method.

  func_deriv : function, optional

  > Function which defines the Jacobian derivative of the model. I.e., the derivive with respect to the parameters of the model. It should have the same argument signature as `func`, but should return a sequence where each element of the sequence is the derivative with respect to the correseponding argument. This corresponds to the `ParametricModel.deriv` method.

  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_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.