astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Models and Fitting (`astropy.modeling`) »
- Reference/API »
- Spline1D

# Spline1D

class astropy.modeling.spline.Spline1D(knots=None, coeffs=None, degree=3, bounds=None, n_models=None, model_set_axis=None, name=None, meta=None)

  Bases: `_Spline`

  One dimensional Spline Model

  Parameters:
    knots optional

      Define the knots for the spline. Can be 1) the number of interior knots for the spline, 2) the array of all knots for the spline, or 3) If both bounds are defined, the interior knots for the spline

    coeffs optional

      The array of knot coefficients for the spline

    degree optional

      The degree of the spline. It must be 1 <= degree <= 5, default is 3.

    bounds optional

      The upper and lower bounds of the spline.

  Notes

  Much of the functionality of this model is provided by `scipy.interpolate.BSpline` which can be directly accessed via the bspline property.

  Fitting for this model is provided by wrappers for: `scipy.interpolate.UnivariateSpline`, `scipy.interpolate.InterpolatedUnivariateSpline`, and `scipy.interpolate.LSQUnivariateSpline`.

  If one fails to define any knots/coefficients, no parameters will be added to this model until a fitter is called. This is because some of the fitters for splines vary the number of parameters and so we cannot define the parameter set until after fitting in these cases.

  Since parameters are not necessarily known at model initialization, setting model parameters directly via the model interface has been disabled.

  Direct constructors are provided for this model which incorporate the fitting to data directly into model construction.

  Knot parameters are declared as “fixed” parameters by default to enable the use of other `astropy.modeling` fitters to be used to fit this model.

  Examples

      >>> import numpy as np
      >>> from astropy.modeling.models import Spline1D
      >>> from astropy.modeling import fitting
      >>> np.random.seed(42)
      >>> x = np.linspace(-3, 3, 50)
      >>> y = np.exp(-x**2) + 0.1 * np.random.randn(50)
      >>> xs = np.linspace(-3, 3, 1000)

  A 1D interpolating spline can be fit to data:

      >>> fitter = fitting.SplineInterpolateFitter()
      >>> spl = fitter(Spline1D(), x, y)

  Similarly, a smoothing spline can be fit to data:

      >>> fitter = fitting.SplineSmoothingFitter()
      >>> spl = fitter(Spline1D(), x, y, s=0.5)

  Similarly, a spline can be fit to data using an exact set of interior knots:

      >>> t = [-1, 0, 1]
      >>> fitter = fitting.SplineExactKnotsFitter()
      >>> spl = fitter(Spline1D(), x, y, t=t)

  Attributes Summary

  `bspline` | Scipy bspline object representation
  `c` | The coefficients vector
  `coeffs` | Dictionary of coefficient parameters
  `degree` | The degree of the spline polynomials
  `knots` | Dictionary of knot parameters
  `n_inputs` | The number of inputs.
  `n_outputs` | The number of outputs.
  `optional_inputs` |
  `t` | The knots vector
  `t_interior` | The interior knots
  `tck` | Scipy 'tck' tuple representation
  `user_knots` | If the knots have been supplied by the user

  Methods Summary

  `__call__`(*inputs[, model_set_axis, ...]) | Make model callable to model evaluation
  `antiderivative`([nu]) | Create a spline that is an antiderivative of this one
  `derivative`([nu]) | Create a spline that is the derivative of this one
  `evaluate`(*args, **kwargs) | Evaluate the spline.

  Attributes Documentation

  bspline

    Scipy bspline object representation

  c

    The coefficients vector

  coeffs

    Dictionary of coefficient parameters

  degree

    The degree of the spline polynomials

  knots

    Dictionary of knot parameters

  n_inputs = 1

    The number of inputs.

  n_outputs = 1

    The number of outputs.

  optional_inputs = {'nu': 0}
  t

    The knots vector

  t_interior

    The interior knots

  tck

    Scipy ‘tck’ tuple representation

  user_knots

    If the knots have been supplied by the user

  Methods Documentation

  __call__(*inputs, model_set_axis=None, with_bounding_box=False, fill_value=nan, equivalencies=None, inputs_map=None, **new_inputs)

    Make model callable to model evaluation

  antiderivative(nu=1)

    Create a spline that is an antiderivative of this one

    Parameters:
      nu `python:int`, optional

        Antiderivative order, default is 1.

    Notes

    Assumes constant of integration is 0

  derivative(nu=1)

    Create a spline that is the derivative of this one

    Parameters:
      nu `python:int`, optional

        Derivative order, default is 1.

  evaluate(*args, **kwargs)

    Evaluate the spline.

    Parameters:
      x

        (positional) The points where the model is evaluating the spline at

      nu optional

        (kwarg) The derivative of the spline for evaluation, 0 <= nu <= degree + 1. Default: 0.