casa
$Rev:20696$
|
Interpolate in one dimension. More...
#include <Interpolate1D.h>
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 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). | |
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 |
Interpolate in one dimension.
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>
The Interpolate1D class does interpolation in one dimension only.
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.
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;
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.
Definition at line 140 of file Interpolate1D.h.
enum casa::Interpolate1D::Method |
The different interpolation methods are enumerated here.
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.
casa::Interpolate1D< Domain, Range >::Interpolate1D | ( | ) |
The default constructor generates a useless object until the setData function has been called.
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.
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)
casa::Interpolate1D< Domain, Range >::~Interpolate1D | ( | ) |
virtual Function<Domain, Range>* casa::Interpolate1D< Domain, Range >::clone | ( | ) | const [virtual] |
A function to copy the Interpolate1D object.
Implements casa::Function< T, U >.
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.
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.
Vector<Domain> casa::Interpolate1D< Domain, Range >::getX | ( | ) | const |
Access the data set that interpolation is done over.
This will usually be sorted.
Vector<Range> casa::Interpolate1D< Domain, Range >::getY | ( | ) | const |
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.
Interpolate1D<Domain, Range>& casa::Interpolate1D< Domain, Range >::operator= | ( | const Interpolate1D< Domain, Range > & | other | ) |
Range casa::Interpolate1D< Domain, Range >::polynomialInterpolation | ( | const Domain | x, |
uInt | n, | ||
uInt | offset | ||
) | const [private] |
A private function for doing polynomial interpolation
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.
void casa::Interpolate1D< Domain, Range >::setMethod | ( | uInt | method | ) |
uInt casa::Interpolate1D< Domain, Range >::curMethod [private] |
Definition at line 215 of file Interpolate1D.h.
Referenced by casa::Interpolate1D< Float, Array< Float > >::getMethod().
uInt casa::Interpolate1D< Domain, Range >::nElements [private] |
Definition at line 216 of file Interpolate1D.h.
Block<Domain> casa::Interpolate1D< Domain, Range >::xValues [private] |
Definition at line 217 of file Interpolate1D.h.
Block<Range> casa::Interpolate1D< Domain, Range >::y2Values [private] |
Definition at line 219 of file Interpolate1D.h.
Block<Range> casa::Interpolate1D< Domain, Range >::yValues [private] |
Definition at line 218 of file Interpolate1D.h.