#!/usr/bin/env python
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
from scipy.interpolate import interp1d
[docs]class spectrum_interpolator( BaseEstimator, TransformerMixin ):
"""
Interpolates supplied spectra to a certain range and size using cubic splines.
Parameters
----------
lambda_min : float
Minimum wavelength.
lambda_max : float
Maximum wavelength.
steps : integer
Number of interpolation steps.
"""
def __init__( self, lambda_min, lambda_max, steps ):
self._lambda_min = lambda_min
self._lambda_max = lambda_max
self._steps = steps
self._f = lambda x: x
# X are the signals, y are the units
[docs] def fit( self, X, y ):
"""
Creates a cubic spline function fitting the supplied spectrum data.
Parameters
----------
X : numpy.ndarray
Array of spectra to interpolate (rows are different spectra and columns are wavelength bins)
y: float
List of wavelength units.
Returns
-------
spectrum_interpolator
This object with fitted variables.
"""
self._f = interp1d( y, X, kind="linear" )
return self
[docs] def get_coordinates( self ):
"""
Gets the units of the interpolated spectrum.
Returns
-------
float
List of wavelengths for each bin.
"""
return np.linspace( self._lambda_min, self._lambda_max, num=self._steps )