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 PtrBlock;
35template <class T> class 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
130
131template <class Domain, class Range>
133{
134public:
135 // Interpolation methods
137 // nearest neighbour
139 // linear
141 // cubic
143 // cubic spline
144 spline
145 };
146
147 // Interpolate in the last dimension of array yin whose x coordinates
148 // along this dimension are given by xin.
149 // Output array yout has interpolated values for x coordinates xout.
150 // E.g., interpolate a Cube(pol,chan,time) in the time direction, all
151 // values in the pol-chan plane are interpolated to produce the output
152 // pol-chan plane.
153 static void interpolate(Array<Range>& yout,
154 const Vector<Domain>& xout,
155 const Vector<Domain>& xin,
156 const Array<Range>& yin,
157 Int method);
158
159 // deprecated version of previous function using Blocks - no longer needed
160 // now that Vector has a fast index operator [].
161 static void interpolate(Array<Range>& yout,
162 const Block<Domain>& xout,
163 const Block<Domain>& xin,
164 const Array<Range>& yin,
165 Int method);
166
167 // Interpolate in the last dimension of array yin whose x coordinates
168 // along this dimension are given by xin.
169 // Output array yout has interpolated values for x coordinates xout.
170 // This version handles flagged data in a simple way: all outputs
171 // depending on a flagged input are flagged.
172 // If goodIsTrue==True, then that means
173 // a good data point has a flag value of True (usually for
174 // visibilities, good is False and for images good is True)
175 // If extrapolate==False, then xout points outside the range of xin
176 // will always be marked as flagged.
177 // TODO: implement flags for cubic and spline (presently input flags
178 // are copied to output).
179 static void interpolate(Array<Range>& yout,
180 Array<Bool>& youtFlags,
181 const Vector<Domain>& xout,
182 const Vector<Domain>& xin,
183 const Array<Range>& yin,
184 const Array<Bool>& yinFlags,
185 Int method,
186 Bool goodIsTrue=False,
187 Bool extrapolate=False);
188
189 // deprecated version of previous function using Blocks - no longer needed
190 // now that Vector has a fast index operator [].
191 static void interpolate(Array<Range>& yout,
192 Array<Bool>& youtFlags,
193 const Block<Domain>& xout,
194 const Block<Domain>& xin,
195 const Array<Range>& yin,
196 const Array<Bool>& yinFlags,
197 Int method,
198 Bool goodIsTrue=False,
199 Bool extrapolate=False);
200
201 // Interpolate in the middle axis in 3D array (yin) whose x coordinates along the
202 // this dimension are given by xin.
203 // Interpolate a Cube(pol,chan,time) in the chan direction.
204 // Currently only linear interpolation method is implemented.
205 // TODO: add support for nearest neiborhood, cubic, and cubic spline.
206 static void interpolatey(Cube<Range>& yout,
207 const Vector<Domain>& xout,
208 const Vector<Domain>& xin,
209 const Cube<Range>& yin,
210 Int method);
211
212 // Interpolate in the middle dimension of 3D array yin whose x coordinates
213 // along this dimension are given by xin.
214 // Output array yout has interpolated values for x coordinates xout.
215 // This version handles flagged data in a simple way: all outputs
216 // depending on a flagged input are flagged.
217 // If goodIsTrue==True, then that means
218 // a good data point has a flag value of True (usually for
219 // visibilities, good is False and for images good is True)
220 // If extrapolate==False, then xout points outside the range of xin
221 // will always be marked as flagged.
222 // Currently only linear interpolation method is implemented.
223 // TODO: add support for nearest neiborhood, cubic, and cubic spline.
224 static void interpolatey(Cube<Range>& yout,
225 Cube<Bool>& youtFlags,
226 const Vector<Domain>& xout,
227 const Vector<Domain>& xin,
228 const Cube<Range>& yin,
229 const Cube<Bool>& yinFlags,
230 Int method,
231 Bool goodIsTrue=False,
232 Bool extrapolate=False);
233
234private:
235 // Interpolate the y-vectors of length ny from x values xin to xout.
237 Int ny,
238 const Vector<Domain>& xout,
239 const Vector<Domain>& xin,
240 const PtrBlock<const Range*>& yin,
241 Int method);
242
243 // Interpolate the y-vectors of length ny from x values xin to xout.
244 // Take flagging into account
246 PtrBlock<Bool*>& youtFlags,
247 Int ny,
248 const Vector<Domain>& xout,
249 const Vector<Domain>& xin,
250 const PtrBlock<const Range*>& yin,
251 const PtrBlock<const Bool*>& yinFlags,
252 Int method, Bool goodIsTrue,
253 Bool extrapolate);
254
255 // Interpolate along yaxis
257 Int na,
258 Int nb,
259 Int nc,
260 const Vector<Domain>& xout,
261 const Vector<Domain>& xin,
262 const PtrBlock<const Range*>& yin,
263 Int method);
264
265 // Take flagging into account
267 PtrBlock<Bool*>& youtFlags,
268 Int na,
269 Int nb,
270 Int nc,
271 const Vector<Domain>& xout,
272 const Vector<Domain>& xin,
273 const PtrBlock<const Range*>& yin,
274 const PtrBlock<const Bool*>& yinFlags,
275 Int method, Bool goodIsTrue,
276 Bool extrapolate);
277
278 // Interpolate the y-vectors of length ny from x values xin to xout
279 // using polynomial interpolation with specified order.
281 Int ny,
282 const Vector<Domain>& xout,
283 const Vector<Domain>& xin,
284 const PtrBlock<const Range*>& yin,
285 Int order);
286
287};
288
289
290
291} //# NAMESPACE CASACORE - END
292
293#ifndef CASACORE_NO_AUTO_TEMPLATES
294#include <casacore/scimath/Mathematics/InterpolateArray1D.tcc>
295#endif //# CASACORE_NO_AUTO_TEMPLATES
296#endif
simple 1-D array
Definition Block.h:198
InterpolationMethod
Interpolation methods.
static void interpolateyPtr(PtrBlock< Range * > &yout, PtrBlock< Bool * > &youtFlags, Int na, Int nb, Int nc, const Vector< Domain > &xout, const Vector< Domain > &xin, const PtrBlock< const Range * > &yin, const PtrBlock< const Bool * > &yinFlags, Int method, Bool goodIsTrue, Bool extrapolate)
Take flagging into account.
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 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 interpolatePtr(PtrBlock< Range * > &yout, PtrBlock< Bool * > &youtFlags, Int ny, const Vector< Domain > &xout, const Vector< Domain > &xin, const PtrBlock< const Range * > &yin, const PtrBlock< 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 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 interpolatePtr(PtrBlock< Range * > &yout, Int ny, const Vector< Domain > &xout, const Vector< Domain > &xin, const PtrBlock< const Range * > &yin, Int method)
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...
static void interpolateyPtr(PtrBlock< Range * > &yout, Int na, Int nb, Int nc, const Vector< Domain > &xout, const Vector< Domain > &xin, const PtrBlock< const Range * > &yin, Int method)
Interpolate along yaxis
static void polynomialInterpolation(PtrBlock< Range * > &yout, Int ny, const Vector< Domain > &xout, const Vector< Domain > &xin, const PtrBlock< const Range * > &yin, Int order)
Interpolate the y-vectors of length ny from x values xin to xout using polynomial interpolation with ...
A drop-in replacement for Block<T*>.
Definition Block.h:812
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40