/usr/include/casacore/scimath/Mathematics/InterpolateArray1D.h is in casacore-dev 2.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | //# Interpolate1DArray.h: Interpolation in last dimension of an Array
//# Copyright (C) 1997,1999,2000,2001
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id: Interpolate1DArray.h,v 8.1 1997/05/21 22:59:29 rm
#ifndef SCIMATH_INTERPOLATEARRAY1D_H
#define SCIMATH_INTERPOLATEARRAY1D_H
#include <casacore/casa/aips.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
template <class T> class PtrBlock;
template <class T> class Block;
template <class T> class Array;
template <class T> class Vector;
template <class T> class Cube;
// <summary> Interpolate in one dimension </summary>
// <use visibility=export>
// <reviewed reviewer="" date="" tests="" demos="">
// </reviewed>
// <prerequisite>
// <li> <linkto class=Array>Array</linkto>
// <li> <linkto class=Vector>Vector</linkto>
// </prerequisite>
// <etymology>
// The InterpolateArray1D class does interpolation in one dimension of
// an Array only.
// </etymology>
// <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:
// <ul>
// <li> Nearest Neighbour
// <li> Linear (default unless there is only one data point)
// <li> Cubic Polynomial
// <li> Natural Cubic Spline
// </ul>
//
// 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
// <linkto class=Interpolate1D>Interpolate1D</linkto>
// 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.
// </synopsis>
// <example>
// This code fragment does cubic interpolation on (xin,yin) pairs to
// produce (xout,yout) pairs.
// <srcblock>
// 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);
// </srcblock>
// </example>
// <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.
// </motivation>
// <templating arg=Domain>
// <li> The Domain class must be a type that can be ordered in a mathematical
// sense. This includes uInt, Int, Float, Double, but not Complex.
// </templating>
// <templating arg=Range>
// <li> 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.
// </templating>
// <thrown>
// <li> AipsError
// </thrown>
// <todo asof="1997/06/17">
// <li> Implement flagging in cubic and spline interpolation
// </todo>
template <class Domain, class Range>
class InterpolateArray1D
{
public:
// Interpolation methods
enum InterpolationMethod {
// nearest neighbour
nearestNeighbour,
// linear
linear,
// cubic
cubic,
// cubic spline
spline
};
// 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.
static void interpolate(Array<Range>& yout,
const Vector<Domain>& xout,
const Vector<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,
const Block<Domain>& xout,
const Block<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.
// 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).
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);
// 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 Block<Domain>& xout,
const Block<Domain>& xin,
const Array<Range>& yin,
const Array<Bool>& yinFlags,
Int method,
Bool goodIsTrue=False,
Bool extrapolate=False);
// 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.
static void interpolatey(Cube<Range>& yout,
const Vector<Domain>& xout,
const Vector<Domain>& xin,
const Cube<Range>& yin,
Int method);
// 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.
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);
private:
// Interpolate the y-vectors of length ny from x values xin to xout.
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.
// Take flagging into account
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 along yaxis
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);
// Take flagging into account
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);
// Interpolate the y-vectors of length ny from x values xin to xout
// using polynomial interpolation with specified order.
static void polynomialInterpolation(PtrBlock<Range*>& yout,
Int ny,
const Vector<Domain>& xout,
const Vector<Domain>& xin,
const PtrBlock<const Range*>& yin,
Int order);
};
} //# NAMESPACE CASACORE - END
#ifndef CASACORE_NO_AUTO_TEMPLATES
#include <casacore/scimath/Mathematics/InterpolateArray1D.tcc>
#endif //# CASACORE_NO_AUTO_TEMPLATES
#endif
|