casacore
Loading...
Searching...
No Matches
InterpolateArray1D.h
Go to the documentation of this file.
1// # Interpolate1DArray.h: Interpolation in last dimension of an Array
2// # Copyright (C) 1997,1999,2000,2001
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef SCIMATH_INTERPOLATEARRAY1D_H
27#define SCIMATH_INTERPOLATEARRAY1D_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31
32namespace casacore { // # NAMESPACE CASACORE - BEGIN
33
34template <class T>
35class Block;
36
37// <summary> Interpolate in one dimension </summary>
38
39// <use visibility=export>
40
41// <reviewed reviewer="" date="" tests="" demos="">
42// </reviewed>
43
44// <prerequisite>
45// <li> <linkto class=Array>Array</linkto>
46// <li> <linkto class=Vector>Vector</linkto>
47// </prerequisite>
48
49// <etymology>
50// The InterpolateArray1D class does interpolation in one dimension of
51// an Array only.
52// </etymology>
53
54// <synopsis>
55// This class will, given the abscissa and ordinates of a set of one
56// dimensional data, interpolate on this data set giving the value at any
57// specified ordinate. It will extrapolate if necessary, but this is will
58// usually give a poor result. There is no requirement for the ordinates to
59// be regularly spaced, however they do need to be sorted and each
60// abscissa should have a unique value.
61//
62// Interpolation can be done using the following methods:
63// <ul>
64// <li> Nearest Neighbour
65// <li> Linear (default unless there is only one data point)
66// <li> Cubic Polynomial
67// <li> Natural Cubic Spline
68// </ul>
69//
70// The abscissa must be a simple type (scalar value) that
71// can be ordered. ie. an uInt, Int, Float or Double (not Complex). The
72// ordinate can be an Array of any data type that has addition, and
73// subtraction defined as well as multiplication by a scalar of the abcissa
74// type.
75// So the ordinate can be complex numbers, where the interpolation is done
76// separately on the real and imaginary components.
77// Use of Arrays as the the Range type is discouraged, operations will
78// be very slow, it would be better to construct a single higher dimensional
79// array that contains all the data.
80//
81// Note: this class (and these docs) are heavily based on the
82// <linkto class=Interpolate1D>Interpolate1D</linkto>
83// class in aips/Functionals. That class proved to be
84// too slow for interpolation of large data volumes (i.e. spectral line
85// visibility datasets) mainly due to the interface which forced the
86// creation of large numbers of temporary Vectors and Arrays.
87// This class is 5-10 times faster than Interpolate1D in cases where
88// large amounts of data are to be interpolated.
89// </synopsis>
90
91// <example>
92// This code fragment does cubic interpolation on (xin,yin) pairs to
93// produce (xout,yout) pairs.
94// <srcblock>
95// Vector<Float> xin(4); indgen(xin);
96// Vector<Double> yin(4); indgen(yin); yin = yin*yin*yin;
97// Vector<Float> xout(20);
98// for (Int i=0; i<20; i++) xout(i) = 1 + i*0.1;
99// Vector<Double> yout;
100// InterpolateArray1D<Float, Double>::interpolate(yout, xout, xin, yin,
101// InterpolateArray1D<Float,Double>::cubic);
102// </srcblock>
103// </example>
104
105// <motivation>
106// This class was motivated by the need to interpolate visibilities
107// in frequency to allow selection and gridding in velocity space
108// with on-the-fly doppler correction.
109// </motivation>
110
111// <templating arg=Domain>
112// <li> The Domain class must be a type that can be ordered in a mathematical
113// sense. This includes uInt, Int, Float, Double, but not Complex.
114// </templating>
115
116// <templating arg=Range>
117// <li> The Range class must have addition and subtraction of Range objects with
118// each other as well as multiplication by a scalar defined. Besides the
119// scalar types listed above this includes Complex, DComplex, and Arrays of
120// any of these types. Use of Arrays is discouraged however.
121// </templating>
122
123// <thrown>
124// <li> AipsError
125// </thrown>
126// <todo asof="1997/06/17">
127// <li> Implement flagging in cubic and spline interpolation
128// </todo>
129
130template <class Domain, class Range>
132 public:
133 // Interpolation methods
135 // nearest neighbour
137 // linear
139 // cubic
141 // cubic spline
143 };
144
145 // Interpolate in the last dimension of array yin whose x coordinates
146 // along this dimension are given by xin.
147 // Output array yout has interpolated values for x coordinates xout.
148 // E.g., interpolate a Cube(pol,chan,time) in the time direction, all
149 // values in the pol-chan plane are interpolated to produce the output
150 // pol-chan plane.
151 static void interpolate(Array<Range>& yout, const Vector<Domain>& xout, const Vector<Domain>& xin,
152 const Array<Range>& yin, Int method);
153
154 // deprecated version of previous function using Blocks - no longer needed
155 // now that Vector has a fast index operator [].
156 static void interpolate(Array<Range>& yout, const Block<Domain>& xout, const Block<Domain>& xin,
157 const Array<Range>& yin, Int method);
158
159 // Interpolate in the last dimension of array yin whose x coordinates
160 // along this dimension are given by xin.
161 // Output array yout has interpolated values for x coordinates xout.
162 // This version handles flagged data in a simple way: all outputs
163 // depending on a flagged input are flagged.
164 // If goodIsTrue==True, then that means
165 // a good data point has a flag value of True (usually for
166 // visibilities, good is False and for images good is True)
167 // If extrapolate==False, then xout points outside the range of xin
168 // will always be marked as flagged.
169 // TODO: implement flags for cubic and spline (presently input flags
170 // are copied to output).
171 static void interpolate(Array<Range>& yout, Array<Bool>& youtFlags, const Vector<Domain>& xout,
172 const Vector<Domain>& xin, const Array<Range>& yin,
173 const Array<Bool>& yinFlags, Int method, Bool goodIsTrue = False,
174 Bool extrapolate = False);
175
176 // deprecated version of previous function using Blocks - no longer needed
177 // now that Vector has a fast index operator [].
178 static void interpolate(Array<Range>& yout, Array<Bool>& youtFlags, const Block<Domain>& xout,
179 const Block<Domain>& xin, const Array<Range>& yin,
180 const Array<Bool>& yinFlags, Int method, Bool goodIsTrue = False,
181 Bool extrapolate = False);
182
183 // Interpolate in the middle axis in 3D array (yin) whose x coordinates along the
184 // this dimension are given by xin.
185 // Interpolate a Cube(pol,chan,time) in the chan direction.
186 // Currently only linear interpolation method is implemented.
187 // TODO: add support for nearest neiborhood, cubic, and cubic spline.
188 static void interpolatey(Cube<Range>& yout, const Vector<Domain>& xout, const Vector<Domain>& xin,
189 const Cube<Range>& yin, Int method);
190
191 // Interpolate in the middle dimension of 3D array yin whose x coordinates
192 // along this dimension are given by xin.
193 // Output array yout has interpolated values for x coordinates xout.
194 // This version handles flagged data in a simple way: all outputs
195 // depending on a flagged input are flagged.
196 // If goodIsTrue==True, then that means
197 // a good data point has a flag value of True (usually for
198 // visibilities, good is False and for images good is True)
199 // If extrapolate==False, then xout points outside the range of xin
200 // will always be marked as flagged.
201 // Currently only linear interpolation method is implemented.
202 // TODO: add support for nearest neiborhood, cubic, and cubic spline.
203 static void interpolatey(Cube<Range>& yout, Cube<Bool>& youtFlags, const Vector<Domain>& xout,
204 const Vector<Domain>& xin, const Cube<Range>& yin,
205 const Cube<Bool>& yinFlags, Int method, Bool goodIsTrue = False,
206 Bool extrapolate = False);
207
208 private:
209 // Interpolate the y-vectors of length ny from x values xin to xout.
210 static void interpolatePtr(Block<Range*>& yout, Int ny, const Vector<Domain>& xout,
211 const Vector<Domain>& xin, const Block<const Range*>& yin, Int method);
212
213 // Interpolate the y-vectors of length ny from x values xin to xout.
214 // Take flagging into account
215 static void interpolatePtr(Block<Range*>& yout, Block<Bool*>& youtFlags, Int ny,
216 const Vector<Domain>& xout, const Vector<Domain>& xin,
217 const Block<const Range*>& yin, const Block<const Bool*>& yinFlags,
218 Int method, Bool goodIsTrue, Bool extrapolate);
219
220 // Interpolate along yaxis
221 static void interpolateyPtr(Block<Range*>& yout, Int na, Int nb, Int nc,
222 const Vector<Domain>& xout, const Vector<Domain>& xin,
223 const Block<const Range*>& yin, Int method);
224
225 // Take flagging into account
226 static void interpolateyPtr(Block<Range*>& yout, Block<Bool*>& youtFlags, Int na, Int nb, Int nc,
227 const Vector<Domain>& xout, const Vector<Domain>& xin,
228 const Block<const Range*>& yin, const Block<const Bool*>& yinFlags,
229 Int method, Bool goodIsTrue, Bool extrapolate);
230
231 // Interpolate the y-vectors of length ny from x values xin to xout
232 // using polynomial interpolation with specified order.
233 static void polynomialInterpolation(Block<Range*>& yout, Int ny, const Vector<Domain>& xout,
234 const Vector<Domain>& xin, const Block<const Range*>& yin,
235 Int order);
236};
237
238} // namespace casacore
239
240#ifndef CASACORE_NO_AUTO_TEMPLATES
241#include <casacore/scimath/Mathematics/InterpolateArray1D.tcc>
242#endif // # CASACORE_NO_AUTO_TEMPLATES
243#endif
InterpolationMethod
Interpolation methods.
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 give...
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 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 ...
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 giv...
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 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 ...
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 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 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 in...
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 ...
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 in...
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
uInt order() const
What is the order of the polynomial, i.e.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40