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

More...

`#include <InterpolateArray1D.h>`

## Public Types

enum | InterpolationMethod { nearestNeighbour , linear , cubic , spline }
| Interpolation methods. More...

## Static Public Member Functions

static void | interpolate (Array< Range > &yout, const Vector< Domain > &xout, const Vector< Domain > &xin, const Array< Range > &yin, Int method)
| Interpolate in the last dimension of array yin whose x coordinates along this dimension are given by xin.
static void | interpolate (Array< Range > &yout, const Block< Domain > &xout, const Block< Domain > &xin, const Array< Range > &yin, Int method)
| deprecated version of previous function using Blocks - no longer needed now that Vector has a fast index operator [].
static void | interpolate (Array< Range > &yout, Array< Bool > &youtFlags, const Vector< Domain > &xout, const Vector< Domain > &xin, const Array< Range > &yin, const Array< Bool > &yinFlags, Int method, Bool goodIsTrue=False, Bool extrapolate=False)
| Interpolate in the last dimension of array yin whose x coordinates along this dimension are given by xin.
static void | interpolate (Array< Range > &yout, Array< Bool > &youtFlags, const Block< Domain > &xout, const Block< Domain > &xin, const Array< Range > &yin, const Array< Bool > &yinFlags, Int method, Bool goodIsTrue=False, Bool extrapolate=False)
| deprecated version of previous function using Blocks - no longer needed now that Vector has a fast index operator [].
static void | interpolatey (Cube< Range > &yout, const Vector< Domain > &xout, const Vector< Domain > &xin, const Cube< Range > &yin, Int method)
| Interpolate in the middle axis in 3D array (yin) whose x coordinates along the this dimension are given by xin.
static void | interpolatey (Cube< Range > &yout, Cube< Bool > &youtFlags, const Vector< Domain > &xout, const Vector< Domain > &xin, const Cube< Range > &yin, const Cube< Bool > &yinFlags, Int method, Bool goodIsTrue=False, Bool extrapolate=False)
| Interpolate in the middle dimension of 3D array yin whose x coordinates along this dimension are given by xin.

## Static Private Member Functions

static void | interpolatePtr (Block< Range * > &yout, Int ny, const Vector< Domain > &xout, const Vector< Domain > &xin, const Block< const Range * > &yin, Int method)
| Interpolate the y-vectors of length ny from x values xin to xout.
static void | interpolatePtr (Block< Range * > &yout, Block< Bool * > &youtFlags, Int ny, const Vector< Domain > &xout, const Vector< Domain > &xin, const Block< const Range * > &yin, const Block< const Bool * > &yinFlags, Int method, Bool goodIsTrue, Bool extrapolate)
| Interpolate the y-vectors of length ny from x values xin to xout.
static void | interpolateyPtr (Block< Range * > &yout, Int na, Int nb, Int nc, const Vector< Domain > &xout, const Vector< Domain > &xin, const Block< const Range * > &yin, Int method)
| Interpolate along yaxis.
static void | interpolateyPtr (Block< Range * > &yout, Block< Bool * > &youtFlags, Int na, Int nb, Int nc, const Vector< Domain > &xout, const Vector< Domain > &xin, const Block< const Range * > &yin, const Block< const Bool * > &yinFlags, Int method, Bool goodIsTrue, Bool extrapolate)
| Take flagging into account.
static void | polynomialInterpolation (Block< Range * > &yout, Int ny, const Vector< Domain > &xout, const Vector< Domain > &xin, const Block< const Range * > &yin, Int order)
| Interpolate the y-vectors of length ny from x values xin to xout using polynomial interpolation with specified order.

## Detailed Description

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

Interpolate in one dimension

### Intended use:

Public interface

### Prerequisite

- Array
- Vector

### Etymology

The InterpolateArray1D class does interpolation in one dimension of an Array 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, however they do need to be sorted and each abscissa should have a unique value.

Interpolation can be done using the following methods:

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

The abscissa must be a simple type (scalar value) that can be ordered. ie. an uInt, Int, Float or Double (not Complex). The ordinate can be an Array of any data type that has addition, and subtraction defined as well as multiplication by a scalar of the abcissa type. So the ordinate can be complex numbers, where the interpolation is done separately on the real and imaginary components. Use of Arrays as the the Range type is discouraged, operations will be very slow, it would be better to construct a single higher dimensional array that contains all the data.

Note: this class (and these docs) are heavily based on the Interpolate1D class in aips/Functionals. That class proved to be too slow for interpolation of large data volumes (i.e. spectral line visibility datasets) mainly due to the interface which forced the creation of large numbers of temporary Vectors and Arrays. This class is 5-10 times faster than Interpolate1D in cases where large amounts of data are to be interpolated.

### Example

This code fragment does cubic interpolation on (xin,yin) pairs to produce (xout,yout) pairs.

Vector<Float> xin(4); indgen(xin);
Vector<Double> yin(4); indgen(yin); yin = yin*yin*yin;
Vector<Float> xout(20);
for (Int i=0; i<20; i++) xout(i) = 1 + i*0.1;
Vector<Double> yout;
InterpolateArray1D<Float, Double>::interpolate(yout, xout, xin, yin,
InterpolateArray1D<Float,Double>::cubic);
casacore::InterpolateArray1D::cubic
@ cubic
cubic
Definition InterpolateArray1D.h:141
casacore::InterpolateArray1D::interpolate
static void interpolate(Array< Range > &yout, const Vector< Domain > &xout, const Vector< Domain > &xin, const Array< Range > &yin, Int method)
Interpolate in the last dimension of array yin whose x coordinates along this dimension are given by ...
casacore::Vector
Definition Vector.h:82
casacore::indgen
void indgen(TableVector< T > &tv, T start, T inc)
Definition TabVecMath.h:398
casacore::Int
int Int
Definition aipstype.h:48

### Motivation

This class was motivated by the need to interpolate visibilities in frequency to allow selection and gridding in velocity space with on-the-fly doppler correction.

### 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. Use of Arrays is discouraged however.

### Thrown Exceptions

- AipsError

### To Do

- Implement flagging in cubic and spline interpolation

Definition at line 131 of file InterpolateArray1D.h.

## Member Enumeration Documentation

## InterpolationMethod

template<class Domain, class Range>

enum casacore::InterpolateArray1D::InterpolationMethod

Interpolation methods.

Enumerator
nearestNeighbour | nearest neighbour
linear | linear
cubic | cubic
spline | cubic spline

Definition at line 135 of file InterpolateArray1D.h.

## Member Function Documentation

## interpolate() [1/4]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolate | ( | Array< Range > & | yout,
|  | Array< Bool > & | youtFlags,
|  | const Block< Domain > & | xout,
|  | const Block< Domain > & | xin,
|  | const Array< Range > & | yin,
|  | const Array< Bool > & | yinFlags,
|  | Int | method,
|  | Bool | goodIsTrue = False,
|  | Bool | extrapolate = False )

static

deprecated version of previous function using Blocks - no longer needed now that Vector has a fast index operator [].

References casacore::False.

## interpolate() [2/4]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolate | ( | Array< Range > & | yout,
|  | Array< Bool > & | youtFlags,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Array< Range > & | yin,
|  | const Array< Bool > & | yinFlags,
|  | Int | method,
|  | Bool | goodIsTrue = False,
|  | Bool | extrapolate = False )

static

Interpolate in the last dimension of array yin whose x coordinates along this dimension are given by xin.

Output array yout has interpolated values for x coordinates xout. This version handles flagged data in a simple way: all outputs depending on a flagged input are flagged. If goodIsTrue==True, then that means a good data point has a flag value of True (usually for visibilities, good is False and for images good is True) If extrapolate==False, then xout points outside the range of xin will always be marked as flagged. TODO: implement flags for cubic and spline (presently input flags are copied to output).

References casacore::False.

## interpolate() [3/4]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolate | ( | Array< Range > & | yout,
|  | const Block< Domain > & | xout,
|  | const Block< Domain > & | xin,
|  | const Array< Range > & | yin,
|  | Int | method )

static

deprecated version of previous function using Blocks - no longer needed now that Vector has a fast index operator [].

## interpolate() [4/4]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolate | ( | Array< Range > & | yout,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Array< Range > & | yin,
|  | Int | method )

static

Interpolate in the last dimension of array yin whose x coordinates along this dimension are given by xin.

Output array yout has interpolated values for x coordinates xout. E.g., interpolate a Cube(pol,chan,time) in the time direction, all values in the pol-chan plane are interpolated to produce the output pol-chan plane.

## interpolatePtr() [1/2]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolatePtr | ( | Block< Range * > & | yout,
|  | Block< Bool * > & | youtFlags,
|  | Int | ny,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Block< const Range * > & | yin,
|  | const Block< const Bool * > & | yinFlags,
|  | Int | method,
|  | Bool | goodIsTrue,
|  | Bool | extrapolate )

static private

Interpolate the y-vectors of length ny from x values xin to xout.

Take flagging into account

## interpolatePtr() [2/2]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolatePtr | ( | Block< Range * > & | yout,
|  | Int | ny,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Block< const Range * > & | yin,
|  | Int | method )

static private

Interpolate the y-vectors of length ny from x values xin to xout.

## interpolatey() [1/2]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolatey | ( | Cube< Range > & | yout,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Cube< Range > & | yin,
|  | Int | method )

static

Interpolate in the middle axis in 3D array (yin) whose x coordinates along the this dimension are given by xin.

Interpolate a Cube(pol,chan,time) in the chan direction. Currently only linear interpolation method is implemented. TODO: add support for nearest neiborhood, cubic, and cubic spline.

## interpolatey() [2/2]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolatey | ( | Cube< Range > & | yout,
|  | Cube< Bool > & | youtFlags,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Cube< Range > & | yin,
|  | const Cube< Bool > & | yinFlags,
|  | Int | method,
|  | Bool | goodIsTrue = False,
|  | Bool | extrapolate = False )

static

Interpolate in the middle dimension of 3D array yin whose x coordinates along this dimension are given by xin.

Output array yout has interpolated values for x coordinates xout. This version handles flagged data in a simple way: all outputs depending on a flagged input are flagged. If goodIsTrue==True, then that means a good data point has a flag value of True (usually for visibilities, good is False and for images good is True) If extrapolate==False, then xout points outside the range of xin will always be marked as flagged. Currently only linear interpolation method is implemented. TODO: add support for nearest neiborhood, cubic, and cubic spline.

References casacore::False.

## interpolateyPtr() [1/2]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolateyPtr | ( | Block< Range * > & | yout,
|  | Block< Bool * > & | youtFlags,
|  | Int | na,
|  | Int | nb,
|  | Int | nc,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Block< const Range * > & | yin,
|  | const Block< const Bool * > & | yinFlags,
|  | Int | method,
|  | Bool | goodIsTrue,
|  | Bool | extrapolate )

static private

Take flagging into account.

## interpolateyPtr() [2/2]

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::interpolateyPtr | ( | Block< Range * > & | yout,
|  | Int | na,
|  | Int | nb,
|  | Int | nc,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Block< const Range * > & | yin,
|  | Int | method )

static private

Interpolate along yaxis.

## polynomialInterpolation()

template<class Domain, class Range>

void casacore::InterpolateArray1D< Domain, Range >::polynomialInterpolation | ( | Block< Range * > & | yout,
|  | Int | ny,
|  | const Vector< Domain > & | xout,
|  | const Vector< Domain > & | xin,
|  | const Block< const Range * > & | yin,
|  | Int | order )

static private

Interpolate the y-vectors of length ny from x values xin to xout using polynomial interpolation with specified order.

References casacore::order().

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

- scimath/Mathematics/InterpolateArray1D.h