SplineFit — Continuum subtraction using a spline fit.

Module for doing spline fitting to the continuum of a 1D spectrum.

class admit.util.continuumsubtraction.spectral.algorithms.SplineFit.SplineFit(x, y)[source]

Class which calculates the continuum of a 1D spectrum by fitting a spline to the continuum channels. The algorithm can be controlled by arguments to the run() method.

Parameters:

x : numpy array

An array containing the x coordinates.

y : masked array

A masked array containing the y coordinates with any strong emission masked.

Attributes

None  

Methods

run(\*\*keyval) Method to calculate the continuum from the given masked spectrum.
run(**keyval)[source]

Method to calculate the continuum from the given masked spectrum. If search=True is given as an argument then the algorithm will iterate through the different order splines to find the best fit, based on noise level.

Parameters:

keyval : dictionary

Dictionary containing the keyword value pair arguments

Returns:

numpy array containing the best fit continuum

Notes

Arguments for the run method:

  • search : bool, whether or not to search for the best fit. Default: False

  • bbox : array_like, 2-sequence specifying the boundary of the approximation interval. If None (default), bbox=[x[0], x[-1]].

  • k : int 1 < k <= 5, the degree of spline smoothing to use, Defualt: 3

  • s : float or None Positive smoothing factor used to choose the number of knots. Number of knots will be increased until the smoothing condition is satisfied:

    sum((w[i] * (y[i]-spl(x[i])))**2, axis=0) <= s
    

    If None (default), s = len(w) which should be a good value if 1/w[i] is an estimate of the standard deviation of y[i]. If 0, spline will interpolate through all data points.

  • ext : int or str Controls the extrapolation mode for elements not in the interval defined by the knot sequence.

    • if ext=0 or ‘extrapolate’, return the extrapolated value.
    • if ext=1 or ‘zeros’, return 0
    • if ext=2 or ‘raise’, raise a ValueError
    • if ext=3 of ‘const’, return the boundary value.

    The default value is 0.

  • check_finite : bool Whether to check that the input arrays contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination or non-sensical results) if the inputs do contain infinities or NaNs. Default is False.