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