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> class Block;
35
36// <summary> Interpolate in one dimension </summary>
37
38// <use visibility=export>
39
40// <reviewed reviewer="" date="" tests="" demos="">
41// </reviewed>
42
43// <prerequisite>
44// <li> <linkto class=Array>Array</linkto>
45// <li> <linkto class=Vector>Vector</linkto>
46// </prerequisite>
47
48// <etymology>
49// The InterpolateArray1D class does interpolation in one dimension of
50// an Array only.
51// </etymology>
52
53// <synopsis>
54// This class will, given the abscissa and ordinates of a set of one
55// dimensional data, interpolate on this data set giving the value at any
56// specified ordinate. It will extrapolate if necessary, but this is will
57// usually give a poor result. There is no requirement for the ordinates to
58// be regularly spaced, however they do need to be sorted and each
59// abscissa should have a unique value.
60//
61// Interpolation can be done using the following methods:
62// <ul>
63// <li> Nearest Neighbour
64// <li> Linear (default unless there is only one data point)
65// <li> Cubic Polynomial
66// <li> Natural Cubic Spline
67// </ul>
68//
69// The abscissa must be a simple type (scalar value) that
70// can be ordered. ie. an uInt, Int, Float or Double (not Complex). The
71// ordinate can be an Array of any data type that has addition, and
72// subtraction defined as well as multiplication by a scalar of the abcissa
73// type.
74// So the ordinate can be complex numbers, where the interpolation is done
75// separately on the real and imaginary components.
76// Use of Arrays as the the Range type is discouraged, operations will
77// be very slow, it would be better to construct a single higher dimensional
78// array that contains all the data.
79//
80// Note: this class (and these docs) are heavily based on the
81// <linkto class=Interpolate1D>Interpolate1D</linkto>
82// class in aips/Functionals. That class proved to be
83// too slow for interpolation of large data volumes (i.e. spectral line
84// visibility datasets) mainly due to the interface which forced the
85// creation of large numbers of temporary Vectors and Arrays.
86// This class is 5-10 times faster than Interpolate1D in cases where
87// large amounts of data are to be interpolated.
88// </synopsis>
89
90// <example>
91// This code fragment does cubic interpolation on (xin,yin) pairs to
92// produce (xout,yout) pairs.
93// <srcblock>
94// Vector<Float> xin(4); indgen(xin);
95// Vector<Double> yin(4); indgen(yin); yin = yin*yin*yin;
96// Vector<Float> xout(20);
97// for (Int i=0; i<20; i++) xout(i) = 1 + i*0.1;
98// Vector<Double> yout;
99// InterpolateArray1D<Float, Double>::interpolate(yout, xout, xin, yin,
100// InterpolateArray1D<Float,Double>::cubic);
101// </srcblock>
102// </example>
103
104// <motivation>
105// This class was motivated by the need to interpolate visibilities
106// in frequency to allow selection and gridding in velocity space
107// with on-the-fly doppler correction.
108// </motivation>
109
110// <templating arg=Domain>
111// <li> The Domain class must be a type that can be ordered in a mathematical
112// sense. This includes uInt, Int, Float, Double, but not Complex.
113// </templating>
114
115// <templating arg=Range>
116// <li> The Range class must have addition and subtraction of Range objects with
117// each other as well as multiplication by a scalar defined. Besides the
118// scalar types listed above this includes Complex, DComplex, and Arrays of
119// any of these types. Use of Arrays is discouraged however.
120// </templating>
121
122// <thrown>
123// <li> AipsError
124// </thrown>
125// <todo asof="1997/06/17">
126// <li> Implement flagging in cubic and spline interpolation
127// </todo>
128
129
130template <class Domain, class Range>
132{
133public:
134 // Interpolation methods
136 // nearest neighbour
138 // linear
140 // cubic
142 // cubic spline
144 };
145
146 // Interpolate in the last dimension of array yin whose x coordinates
147 // along this dimension are given by xin.
148 // Output array yout has interpolated values for x coordinates xout.
149 // E.g., interpolate a Cube(pol,chan,time) in the time direction, all
150 // values in the pol-chan plane are interpolated to produce the output
151 // pol-chan plane.
152 static void interpolate(Array<Range>& yout,
153 const Vector<Domain>& xout,
154 const Vector<Domain>& xin,
155 const Array<Range>& yin,
156 Int method);
157
158 // deprecated version of previous function using Blocks - no longer needed
159 // now that Vector has a fast index operator [].
160 static void interpolate(Array<Range>& yout,
161 const Block<Domain>& xout,
162 const Block<Domain>& xin,
163 const Array<Range>& yin,
164 Int method);
165
166 // Interpolate in the last dimension of array yin whose x coordinates
167 // along this dimension are given by xin.
168 // Output array yout has interpolated values for x coordinates xout.
169 // This version handles flagged data in a simple way: all outputs
170 // depending on a flagged input are flagged.
171 // If goodIsTrue==True, then that means
172 // a good data point has a flag value of True (usually for
173 // visibilities, good is False and for images good is True)
174 // If extrapolate==False, then xout points outside the range of xin
175 // will always be marked as flagged.
176 // TODO: implement flags for cubic and spline (presently input flags
177 // are copied to output).
178 static void interpolate(Array<Range>& yout,
179 Array<Bool>& youtFlags,
180 const Vector<Domain>& xout,
181 const Vector<Domain>& xin,
182 const Array<Range>& yin,
183 const Array<Bool>& yinFlags,
184 Int method,
185 Bool goodIsTrue=False,
186 Bool extrapolate=False);
187
188 // deprecated version of previous function using Blocks - no longer needed
189 // now that Vector has a fast index operator [].
190 static void interpolate(Array<Range>& yout,
191 Array<Bool>& youtFlags,
192 const Block<Domain>& xout,
193 const Block<Domain>& xin,
194 const Array<Range>& yin,
195 const Array<Bool>& yinFlags,
196 Int method,
197 Bool goodIsTrue=False,
198 Bool extrapolate=False);
199
200 // Interpolate in the middle axis in 3D array (yin) whose x coordinates along the
201 // this dimension are given by xin.
202 // Interpolate a Cube(pol,chan,time) in the chan direction.
203 // Currently only linear interpolation method is implemented.
204 // TODO: add support for nearest neiborhood, cubic, and cubic spline.
205 static void interpolatey(Cube<Range>& yout,
206 const Vector<Domain>& xout,
207 const Vector<Domain>& xin,
208 const Cube<Range>& yin,
209 Int method);
210
211 // Interpolate in the middle dimension of 3D array yin whose x coordinates
212 // along this dimension are given by xin.
213 // Output array yout has interpolated values for x coordinates xout.
214 // This version handles flagged data in a simple way: all outputs
215 // depending on a flagged input are flagged.
216 // If goodIsTrue==True, then that means
217 // a good data point has a flag value of True (usually for
218 // visibilities, good is False and for images good is True)
219 // If extrapolate==False, then xout points outside the range of xin
220 // will always be marked as flagged.
221 // Currently only linear interpolation method is implemented.
222 // TODO: add support for nearest neiborhood, cubic, and cubic spline.
223 static void interpolatey(Cube<Range>& yout,
224 Cube<Bool>& youtFlags,
225 const Vector<Domain>& xout,
226 const Vector<Domain>& xin,
227 const Cube<Range>& yin,
228 const Cube<Bool>& yinFlags,
229 Int method,
230 Bool goodIsTrue=False,
231 Bool extrapolate=False);
232
233private:
234 // Interpolate the y-vectors of length ny from x values xin to xout.
235 static void interpolatePtr(Block<Range*>& yout,
236 Int ny,
237 const Vector<Domain>& xout,
238 const Vector<Domain>& xin,
239 const Block<const Range*>& yin,
240 Int method);
241
242 // Interpolate the y-vectors of length ny from x values xin to xout.
243 // Take flagging into account
244 static void interpolatePtr(Block<Range*>& yout,
245 Block<Bool*>& youtFlags,
246 Int ny,
247 const Vector<Domain>& xout,
248 const Vector<Domain>& xin,
249 const Block<const Range*>& yin,
250 const Block<const Bool*>& yinFlags,
251 Int method, Bool goodIsTrue,
252 Bool extrapolate);
253
254 // Interpolate along yaxis
256 Int na,
257 Int nb,
258 Int nc,
259 const Vector<Domain>& xout,
260 const Vector<Domain>& xin,
261 const Block<const Range*>& yin,
262 Int method);
263
264 // Take flagging into account
266 Block<Bool*>& youtFlags,
267 Int na,
268 Int nb,
269 Int nc,
270 const Vector<Domain>& xout,
271 const Vector<Domain>& xin,
272 const Block<const Range*>& yin,
273 const Block<const Bool*>& yinFlags,
274 Int method, Bool goodIsTrue,
275 Bool extrapolate);
276
277 // Interpolate the y-vectors of length ny from x values xin to xout
278 // using polynomial interpolation with specified order.
280 Int ny,
281 const Vector<Domain>& xout,
282 const Vector<Domain>& xin,
283 const Block<const Range*>& yin,
284 Int order);
285
286};
287
288
289
290} //# NAMESPACE CASACORE - END
291
292#ifndef CASACORE_NO_AUTO_TEMPLATES
293#include <casacore/scimath/Mathematics/InterpolateArray1D.tcc>
294#endif //# CASACORE_NO_AUTO_TEMPLATES
295#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...
this file contains all the compiler specific defines
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