Loading...
Searching...
No Matches
casacore::Interpolate1D< Domain, Range > Class Template Reference
scimath package (libcasa_scimath) » Functionals_module

More...

`#include <Interpolate1D.h>`

## Public Types

enum | Method { nearestNeighbour , linear , cubic , spline }
| The different interpolation methods are enumerated here. More...
Public Types inherited from casacore::Function1D< Domain, Range >
typedef const Domain * | FunctionArg
Public Types inherited from casacore::Function< Domain, Range >
typedef FunctionTraits< Domain >::ArgType | ArgType
typedef const ArgType * | FunctionArg

## 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.
Public Member Functions inherited from casacore::Function1D< Domain, Range >
| Function1D ()
| Constructors.
virtual | ~Function1D ()
| Destructor.
virtual uInt | ndim () const
| Returns the number of dimensions of function.
Public Member Functions inherited from casacore::Function< Domain, Range >
| Function ()
| Constructors.
virtual | ~Function ()
| Destructor.
uInt | nparameters () const
| Returns the number of parameters.
virtual Range | eval (FunctionArg x) const=0
| Evaluate the function object.
Domain & | operator[] (const uInt n)
| Manipulate the nth parameter (0-based) with no index check.
virtual Range | operator() () const
| Evaluate this function object at xor at x, y.
Bool & | mask (const uInt n)
| Manipulate the mask associated with the nth parameter (e.g.
const FunctionParam< Domain > & | parameters () const
| Return the parameter interface.
const Vector< ArgType > & | argp () const
| Get arg_p and parset_p.
Bool | parsetp () const
void | lockParam ()
| Compiler cannot always find the correct 'const' version of parameter access.
void | unlockParam ()
virtual void | setMode (const RecordInterface &mode)
| get/set the function mode.
virtual void | getMode (RecordInterface &mode) const
virtual Bool | hasMode () const
| return True if the implementing function supports a mode.
ostream & | print (ostream &os) const
| Print the function (i.e.
virtual Function< typename FunctionTraits< Domain >::DiffType > * | cloneAD () const
virtual Function< typename FunctionTraits< Domain >::BaseType > * | cloneNonAD () const
Public Member Functions inherited from casacore::Functional< FunctionTraits< Domain >::ArgType, Range >
virtual | ~Functional ()
| Destructor.
virtual Range | operator() (const Domain &x) const=0
| Map a Domain x into a Range y value.
Public Member Functions inherited from casacore::Functional< Vector< FunctionTraits< Domain >::ArgType >, Range >
virtual | ~Functional ()
| Destructor.
virtual Range | operator() (const Domain &x) const=0
| Map a Domain x into a Range y value.

## Private Member Functions

Range | polynomialInterpolation (const Domain x, uInt n, uInt offset) const
| A private function for doing polynomial interpolation.

## Private Attributes

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

## Additional Inherited Members

Protected Attributes inherited from casacore::Function< Domain, Range >
FunctionParam< Domain > | param_p
| The parameters and masks.
Vector< ArgType > | arg_p
| Aid for non-contiguous argument storage.
Bool | parset_p
| Indicate parameter written.
Bool | locked_p
| Indicate that parameters are expected to be locked from changing.

## Detailed Description

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

Interpolate in one dimension

### Intended use:

Public interface

### Review Status

Reviewed By:
  wyoung
Date Reviewed:
  1996/10/18
Test programs:
  tInterpolate1D
Demo programs:
  dInterpolate1D

### Prerequisite

- SampledFunctional
- Function1D

### 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 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.

- 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;
casacore::Interpolate1D::cubic
@ cubic
Fits a third order polynomial to 4 pts.
Definition Interpolate1D.h:149
casacore::Interpolate1D::Interpolate1D
Interpolate1D()
The default constructor generates a useless object until the setData function has been called.
casacore::ScalarSampledFunctional
Definition ScalarSampledFunctional.h:118
casacore::Vector
Definition Vector.h:82
casacore::indgen
void indgen(TableVector< T > &tv, T start, T inc)
Definition TabVecMath.h:398
casacore::Float
float Float
Definition aipstype.h:52

### 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)

- The Domain class must be a type that can be ordered in a mathematical sense. This includes uInt, Int, Float, Double, but not Complex.

### Template Type Argument Requirements (Range)

- The Range class must have addition and subtraction of Range objects with each other as well as multiplication by a scalar defined. Besides the scalar types listed above this includes Complex, DComplex, and Arrays of any of these types.

### Thrown Exceptions

- AipsError

### To Do

- avoid an internal copy of the data and have an index array as the only private data (plus the interpolation method and pointers to the actual data).
- Review the use of copy semantics in the copy constructor & assignment operator after making the above change.

Definition at line 139 of file Interpolate1D.h.

## Member Enumeration Documentation

## Method

template<class Domain, class Range>

enum casacore::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 143 of file Interpolate1D.h.

## Constructor & Destructor Documentation

## Interpolate1D() [1/3]

template<class Domain, class Range>

casacore::Interpolate1D< Domain, Range >::Interpolate1D | ( |  | ) |

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

Referenced by Interpolate1D(), and operator=().

## Interpolate1D() [2/3]

template<class Domain, class Range>

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

References casacore::False.

## Interpolate1D() [3/3]

template<class Domain, class Range>

casacore::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)

References Interpolate1D().

## ~Interpolate1D()

template<class Domain, class Range>

casacore::Interpolate1D< Domain, Range >::~Interpolate1D | ( |  | ) |

## Member Function Documentation

## clone()

template<class Domain, class Range>

virtual Function< Domain, Range > * casacore::Interpolate1D< Domain, Range >::clone | ( |  | ) | const

virtual

A function to copy the Interpolate1D object.

Implements casacore::Function< Domain, Range >.

## eval()

template<class Domain, class Range>

virtual Range casacore::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.

## getMethod()

template<class Domain, class Range>

uInt casacore::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 194 of file Interpolate1D.h.

References curMethod.

## getX()

template<class Domain, class Range>

Vector< Domain > casacore::Interpolate1D< Domain, Range >::getX | ( |  | ) | const

Access the data set that interpolation is done over.

This will usually be sorted.

## getY()

template<class Domain, class Range>

Vector< Range > casacore::Interpolate1D< Domain, Range >::getY | ( |  | ) | const

## name()

template<class Domain, class Range>

virtual const String & casacore::Interpolate1D< Domain, Range >::name | ( |  | ) | const

inline virtual

Name of function.

Reimplemented from casacore::Function< Domain, Range >.

Definition at line 181 of file Interpolate1D.h.

## operator=()

template<class Domain, class Range>

Interpolate1D< Domain, Range > & casacore::Interpolate1D< Domain, Range >::operator= | ( | const Interpolate1D< Domain, Range > & | other | ) |

References Interpolate1D().

## polynomialInterpolation()

template<class Domain, class Range>

Range casacore::Interpolate1D< Domain, Range >::polynomialInterpolation | ( | const Domain | x,
|  | uInt | n,
|  | uInt | offset ) const

private

A private function for doing polynomial interpolation.

References casacore::offset().

## setData()

template<class Domain, class Range>

void casacore::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.

References casacore::False.

## setMethod()

template<class Domain, class Range>

void casacore::Interpolate1D< Domain, Range >::setMethod | ( | uInt | method | ) |

## Member Data Documentation

## curMethod

template<class Domain, class Range>

uInt casacore::Interpolate1D< Domain, Range >::curMethod

private

Definition at line 214 of file Interpolate1D.h.

Referenced by getMethod().

## nElements

template<class Domain, class Range>

uInt casacore::Interpolate1D< Domain, Range >::nElements

private

Definition at line 215 of file Interpolate1D.h.

## xValues

template<class Domain, class Range>

Block<Domain> casacore::Interpolate1D< Domain, Range >::xValues

private

Definition at line 216 of file Interpolate1D.h.

## y2Values

template<class Domain, class Range>

Block<Range> casacore::Interpolate1D< Domain, Range >::y2Values

private

Definition at line 218 of file Interpolate1D.h.

## yValues

template<class Domain, class Range>

Block<Range> casacore::Interpolate1D< Domain, Range >::yValues

private

Definition at line 217 of file Interpolate1D.h.

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

- coordinates/Coordinates/TabularCoordinate.h
- scimath/Functionals/Interpolate1D.h