Interpolate1D.h

Classes

Interpolate1D -- Interpolate in one dimension (full description)

template <class Domain, class Range> class Interpolate1D :public Function1D<Domain, Range>

Types

enum Method

nearestNeighbour
Crude but sometimes useful
linear
The most common method and the Default
cubic
Fits a third order polynomial to 4 pts
spline
Natural Cubic Splines

Interface

Public Members
Interpolate1D()
Interpolate1D(const SampledFunctional<Domain> &x, const SampledFunctional<Range> &y, const Bool sorted=False, const Bool uniq=False)
void setData(const SampledFunctional<Domain> &x, const SampledFunctional<Range> &y, const Bool sorted=False, const Bool uniq=False)
Interpolate1D(const Interpolate1D<Domain, Range>& other)
Interpolate1D<Domain, Range> & operator=(const Interpolate1D<Domain, Range> & other)
~Interpolate1D()
virtual const String &name() const
virtual Range eval(typename Function1D<Domain, Range>::FunctionArg x) const
uInt getMethod() const
void setMethod(uInt method)
Vector<Domain> getX() const
Vector<Range> getY() const
virtual Function<Domain, Range> *clone() const
Private Members
Range polynomialInterpolation(const Domain x, uInt n, uInt offset) const

Description

Review Status

Reviewed By:
wyoung
Date Reviewed:
1996/10/18
Programs:
Demos:
Tests:

Prerequisite

Etymology

The Interpolate1D class does interpolation in one dimension only.

Synopsis

This class will, given the abscissa and ordinates of a set of one dimensional data, interpolate on this data set giving the value at any specified ordinate. It will extrapolate if necessary, but this is will usually give a poor result. There is no requirement for the ordinates to be regularly spaced, or even sorted in any numerical order. However each abscissa should have a unique value.

Interpolation can be done using the following methods:

  • Nearest Neighbour (default if there is one data point)
  • Linear (default unless there is only one data point)
  • Cubic Polynomial
  • Natural Cubic Spline

    The restriction that each absicssa have a unique value can be lifted by setting the uniq=True option in the appropriate functions. This imposes the followig additional restrictions on interpolation.

  • You cannot use cubic spline interpolation.
  • You cannot cannot interpolate within two data points of a repeated x-value when using cubic interpolation.
  • You cannot interpolate within one data point of a repeated x-value when using linear or nearest neighbour interpolation.

    The abscissa must be a SampledFunctional that returns a scalar value that can be ordered. ie. an uInt, Int, Float or Double (not Complex). The ordinate can be any data type that has addition, and subtraction defined as well as multiplication by a scalar. So the ordinate can be complex numbers, where the interpolation is done separately on the real and imaginary components, or an array, where the interpolation is done separately on an element by element basis.

    This class will curently make an internal copy of the data supplied to it, and sort the data if it is not told it is already sorted, by using the sorted=True flag.

    Example

    This code fragment sets the interpolation method to cubic before interpolating on the supplied (x,y) vectors.
      Vector<Float> x(4); indgen(x); 
      Vector<Double> y(4); indgen(y); y = y*y*y;
      ScalarSampledFunctional<Float> fx(x)
      ScalarSampledFunctional<Double> fy(y);
      Interpolate1D<Float, Double> gain(fx, fy);
      gain.setMethod(Interpolate1D<Float,Double>::cubic);
      for (Float xs = -1; xs < 5; xs += 0.1)
        cout << "gain(" << xs << "):" << gain(xs) << endl;
    

    Motivation

    This class is motivated by the need to interpolate over the gain solutions obtained from calibrator observations, in order to get the gain at arbitrary times.

    Template Type Argument Requirements (Domain)

    Template Type Argument Requirements (Range)

    Thrown Exceptions

    To Do

    Member Description

    enum Method

    The different interpolation methods are enumerated here

    Interpolate1D()

    The default constructor generates a useless object until the setData function has been called.

    Interpolate1D(const SampledFunctional<Domain> &x, const SampledFunctional<Range> &y, const Bool sorted=False, const Bool uniq=False)

    Construct an object with the specified data

    void setData(const SampledFunctional<Domain> &x, const SampledFunctional<Range> &y, const Bool sorted=False, const Bool uniq=False)

    Define a new data set for the class to operate on. Equivalent in many aspects to creating a new object.

    Interpolate1D(const Interpolate1D<Domain, Range>& other)
    Interpolate1D<Domain, Range> & operator=(const Interpolate1D<Domain, Range> & other)
    ~Interpolate1D()

    The standard copy constructor, assignment operator and destructor. Internal data is copied in both cases (copy semantics)

    virtual const String &name() const

    Name of function

    virtual Range eval(typename Function1D<Domain, Range>::FunctionArg x) const

    Interpolation is done using the () operator (see example above). Actual use is through the virtual eval() function.

    uInt getMethod() const
    void setMethod(uInt method)

    inquire/set the current interpolation method. uInts are used as arguments instead of the Interpolate1D::Method enumerator due to compiler limitations. See the example above (or the demo code) for the recommended way to call these functions.

    Vector<Domain> getX() const
    Vector<Range> getY() const

    Access the data set that interpolation is done over. This will usually be sorted.

    virtual Function<Domain, Range> *clone() const

    A function to copy the Interpolate1D object

    Range polynomialInterpolation(const Domain x, uInt n, uInt offset) const

    A private function for doing polynomial interpolation