casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Private Member Functions | Private Attributes
casa::Interpolate1D< Domain, Range > Class Template Reference

Interpolate in one dimension. More...

#include <Interpolate1D.h>

Inheritance diagram for casa::Interpolate1D< Domain, Range >:
casa::Function1D< Domain, Range > casa::Function< T, U > casa::Functional< FunctionTraits< T >::ArgType, U > casa::Functional< Vector< FunctionTraits< T >::ArgType >, U >

List of all members.

Public Types

enum  Method {
  nearestNeighbour,
  linear,
  cubic,
  spline
}
 The different interpolation methods are enumerated here. More...

Public Member Functions

 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.
 Interpolate1D (const Interpolate1D< Domain, Range > &other)
 The standard copy constructor, assignment operator and destructor.
Interpolate1D< Domain, Range > & operator= (const Interpolate1D< Domain, Range > &other)
 ~Interpolate1D ()
virtual const Stringname () const
 Name of function.
virtual Range eval (typename Function1D< Domain, Range >::FunctionArg x) const
 Interpolation is done using the () operator (see example above).
uInt getMethod () const
 inquire/set the current interpolation method.
void setMethod (uInt method)
Vector< Domain > getX () const
 Access the data set that interpolation is done over.
Vector< Range > getY () const
virtual Function< Domain, Range > * clone () const
 A function to copy the Interpolate1D object.

Private Member Functions

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

Private Attributes

uInt curMethod
uInt nElements
Block< Domain > xValues
Block< Range > yValues
Block< Range > y2Values

Detailed Description

template<class Domain, class Range>
class casa::Interpolate1D< Domain, Range >

Interpolate in one dimension.

Intended use:

Public interface

 <h3>Review Status</h3><dl><dt>Reviewed By:<dd>wyoung<dt>Date Reviewed:<dd>1996/10/18<dt>Test programs:<dd>tInterpolate1D<dt>Demo programs:<dd>dInterpolate1D</dl> 

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:

The restriction that each abcissus has a unique value can be lifted by setting the uniq=True option in the appropriate functions. This imposes the following additional restrictions on 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

Definition at line 140 of file Interpolate1D.h.


Member Enumeration Documentation

template<class Domain, class Range>
enum casa::Interpolate1D::Method

The different interpolation methods are enumerated here.

Enumerator:
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.

Definition at line 144 of file Interpolate1D.h.


Constructor & Destructor Documentation

template<class Domain, class Range>
casa::Interpolate1D< Domain, Range >::Interpolate1D ( )

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

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

Construct an object with the specified data.

template<class Domain, class Range>
casa::Interpolate1D< Domain, Range >::Interpolate1D ( const Interpolate1D< Domain, Range > &  other)

The standard copy constructor, assignment operator and destructor.

Internal data is copied in both cases (copy semantics)

template<class Domain, class Range>
casa::Interpolate1D< Domain, Range >::~Interpolate1D ( )

Member Function Documentation

template<class Domain, class Range>
virtual Function<Domain, Range>* casa::Interpolate1D< Domain, Range >::clone ( ) const [virtual]

A function to copy the Interpolate1D object.

Implements casa::Function< T, U >.

template<class Domain, class Range>
virtual Range casa::Interpolate1D< Domain, Range >::eval ( typename Function1D< Domain, Range >::FunctionArg  x) const [virtual]

Interpolation is done using the () operator (see example above).

Actual use is through the virtual eval() function.

template<class Domain, class Range>
uInt casa::Interpolate1D< Domain, Range >::getMethod ( ) const [inline]

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.

Definition at line 195 of file Interpolate1D.h.

template<class Domain, class Range>
Vector<Domain> casa::Interpolate1D< Domain, Range >::getX ( ) const

Access the data set that interpolation is done over.

This will usually be sorted.

template<class Domain, class Range>
Vector<Range> casa::Interpolate1D< Domain, Range >::getY ( ) const
template<class Domain, class Range>
virtual const String& casa::Interpolate1D< Domain, Range >::name ( ) const [inline, virtual]

Name of function.

Reimplemented from casa::Function< T, U >.

Definition at line 182 of file Interpolate1D.h.

template<class Domain, class Range>
Interpolate1D<Domain, Range>& casa::Interpolate1D< Domain, Range >::operator= ( const Interpolate1D< Domain, Range > &  other)
template<class Domain, class Range>
Range casa::Interpolate1D< Domain, Range >::polynomialInterpolation ( const Domain  x,
uInt  n,
uInt  offset 
) const [private]

   

A private function for doing polynomial interpolation

template<class Domain, class Range>
void casa::Interpolate1D< Domain, Range >::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.

template<class Domain, class Range>
void casa::Interpolate1D< Domain, Range >::setMethod ( uInt  method)

Member Data Documentation

template<class Domain, class Range>
uInt casa::Interpolate1D< Domain, Range >::curMethod [private]
template<class Domain, class Range>
uInt casa::Interpolate1D< Domain, Range >::nElements [private]

Definition at line 216 of file Interpolate1D.h.

template<class Domain, class Range>
Block<Domain> casa::Interpolate1D< Domain, Range >::xValues [private]

Definition at line 217 of file Interpolate1D.h.

template<class Domain, class Range>
Block<Range> casa::Interpolate1D< Domain, Range >::y2Values [private]

Definition at line 219 of file Interpolate1D.h.

template<class Domain, class Range>
Block<Range> casa::Interpolate1D< Domain, Range >::yValues [private]

Definition at line 218 of file Interpolate1D.h.


The documentation for this class was generated from the following file: