MaskArrMath.h

Go to the documentation of this file.
00001 //# MaskArrMath.h: Simple mathematics done with MaskedArray's.
00002 //# Copyright (C) 1993,1994,1995,1996,1999,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef CASA_MASKARRMATH_H
00029 #define CASA_MASKARRMATH_H
00030 
00031 
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/BasicMath/Math.h>
00034 #include <casacore/casa/Arrays/Array.h>
00035 #include <casacore/casa/Arrays/MaskedArray.h>
00036 #include <casacore/casa/Arrays/IPosition.h>
00037 //# Needed to get the proper Complex typedef's
00038 #include <casacore/casa/BasicSL/Complex.h>
00039 
00040 
00041 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00042 
00043 // <summary> Mathematical operations for MaskedArrays (and with Arrays) </summary>
00044 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMaskArrMath0 tMaskArrMath1 tMaskArrMath2 tMaskArrExcp">
00045 //
00046 // <prerequisite>
00047 //   <li> <linkto class=Array>Array</linkto>
00048 //   <li> <linkto class=MaskedArray>MaskedArray</linkto>
00049 // </prerequisite>
00050 //
00051 // <etymology>
00052 // MaskArrMath is short for MaskedArrayMath, which is too long by the old
00053 // AIPS++ file naming conventions.  This file contains global functions
00054 // which perform element by element mathematical operations on masked arrays.
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // These functions perform element by element mathematical operations on
00059 // masked arrays.  With two arrays, they must both conform, and the result
00060 // is done element by element, for those locations where the mask of the
00061 // MaskedArray is True.  For two MaskedArrays, the "and" of the masks is used.
00062 // </synopsis>
00063 //
00064 // <example>
00065 // <srcblock>
00066 //   Vector<Int> a(10);
00067 //   Vector<Int> b(10);
00068 //   Vector<Int> c(10);
00069 //      . . .
00070 //   c = a(a>0) + b(b>0);
00071 // </srcblock>
00072 // This example sets those elements of c where ((a>0) && (b>0)) to (a+b).
00073 // Elements of c where !((a>0) && (b>0)) are unchanged.  The result of
00074 // this operation is a MaskedArray.  The assignment from this
00075 // MaskedArray to the Vector c only assigns those elements
00076 // where the mask is True.
00077 // </example>
00078 //
00079 // <example>
00080 // <srcblock>
00081 //   Vector<Double> a(10);
00082 //   Vector<Double> b(10);
00083 //   Vector<Double> c(10);
00084 //      . . .
00085 //   c = atan2 (a, b(b>0);
00086 // </srcblock>
00087 // This example sets those elements of c where (b>0) to atan2 (a,b).
00088 // Elements of c where !(b>0) are unchanged.  The result of
00089 // this operation is a MaskedArray.  The assignment from this
00090 // MaskedArray to the Vector c only assigns those elements
00091 // where the mask is True.
00092 // </example>
00093 //
00094 // <example>
00095 // <srcblock>
00096 //   Vector<Int> a(10);
00097 //   Int result;
00098 //      . . .
00099 //   result = sum (a(a>0));
00100 // </srcblock>
00101 // This example sums a, for those elements of a which are greater than 0.
00102 // </example>
00103 //
00104 // <motivation>
00105 // One wants to be able to mask arrays and perform mathematical operations on
00106 // those masked arrays.  Since the masked arrays are only defined where
00107 // the masks are True, the result must be a MaskedArray, or a simple number.
00108 // </motivation>
00109 //
00110 // <linkfrom anchor="MaskedArray mathematical operations" classes="MaskedArray Array Vector Matrix Cube">
00111 //    <here>MaskedArray mathematical operations</here> -- Mathematical
00112 //    operations for MaskedArrays, and between MaskedArrays and Arrays.
00113 // </linkfrom>
00114 //
00115 // <group name="MaskedArray mathematical operations">
00116 
00117 // Element by element arithmetic modifying left in-place. left and other
00118 // must be conformant.
00119 // 
00120 // <thrown>
00121 //   <li> ArrayConformanceError
00122 // </thrown>
00123 //
00124 // <group>
00125 template<class T> const MaskedArray<T> & operator+= (const MaskedArray<T> &left, const Array<T> &other);
00126 template<class T> const MaskedArray<T> & operator-= (const MaskedArray<T> &left, const Array<T> &other);
00127 template<class T> const MaskedArray<T> & operator*= (const MaskedArray<T> &left, const Array<T> &other);
00128 template<class T> const MaskedArray<T> & operator/= (const MaskedArray<T> &left, const Array<T> &other);
00129 template<class T> Array<T> & operator+= (Array<T> &left, const MaskedArray<T> &other);
00130 template<class T> Array<T> & operator-= (Array<T> &left, const MaskedArray<T> &other);
00131 template<class T> Array<T> & operator*= (Array<T> &left, const MaskedArray<T> &other);
00132 template<class T> Array<T> & operator/= (Array<T> &left, const MaskedArray<T> &other);
00133 template<class T> const MaskedArray<T> & operator+= (const MaskedArray<T> &left, const MaskedArray<T> &other);
00134 template<class T> const MaskedArray<T> & operator-= (const MaskedArray<T> &left, const MaskedArray<T> &other);
00135 template<class T> const MaskedArray<T> & operator*= (const MaskedArray<T> &left, const MaskedArray<T> &other);
00136 template<class T> const MaskedArray<T> & operator/= (const MaskedArray<T> &left,const MaskedArray<T> &other);
00137 template<class T,class S> const MaskedArray<T> & operator/= (const MaskedArray<T> &left,const MaskedArray<S> &other);
00138 // </group>
00139 
00140 // 
00141 // Element by element arithmetic modifying left in-place. The scalar "other"
00142 // behaves as if it were a conformant Array to left filled with constant values.
00143 // <group>
00144 template<class T> const MaskedArray<T> & operator+= (const MaskedArray<T> &left,const T &other);
00145 template<class T> const MaskedArray<T> & operator-= (const MaskedArray<T> &left,const T &other);
00146 template<class T> const MaskedArray<T> & operator*= (const MaskedArray<T> &left,const T &other);
00147 template<class T> const MaskedArray<T> & operator/= (const MaskedArray<T> &left,const T &other);
00148 // </group>
00149 
00150 // Unary arithmetic operation.
00151 // 
00152 // <group>
00153 template<class T> MaskedArray<T> operator+(const MaskedArray<T> &a);
00154 template<class T> MaskedArray<T> operator-(const MaskedArray<T> &a);
00155 // </group>
00156 
00157 // 
00158 // Element by element arithmetic on MaskedArrays, returns a MaskedArray.
00159 //
00160 // <thrown>
00161 //   <li> ArrayConformanceError
00162 // </thrown>
00163 //
00164 // <group>
00165 template<class T> MaskedArray<T> operator+ (const MaskedArray<T> &left, const Array<T> &right);
00166 template<class T> MaskedArray<T> operator- (const MaskedArray<T> &left, const Array<T> &right);
00167 template<class T> MaskedArray<T> operator* (const MaskedArray<T> &left, const Array<T> &right);
00168 template<class T> MaskedArray<T> operator/ (const MaskedArray<T> &left, const Array<T> &right);
00169 template<class T> MaskedArray<T> operator+ (const Array<T> &left, const MaskedArray<T> &right);
00170 template<class T> MaskedArray<T> operator- (const Array<T> &left, const MaskedArray<T> &right);
00171 template<class T> MaskedArray<T> operator* (const Array<T> &left, const MaskedArray<T> &right);
00172 template<class T> MaskedArray<T> operator/ (const Array<T> &left, const MaskedArray<T> &right);
00173 template<class T> MaskedArray<T> operator+ (const MaskedArray<T> &left,const MaskedArray<T> &right);
00174 template<class T> MaskedArray<T> operator- (const MaskedArray<T> &left,const MaskedArray<T> &right);
00175 template<class T> MaskedArray<T> operator* (const MaskedArray<T> &left,const MaskedArray<T> &right);
00176 template<class T> MaskedArray<T> operator/ (const MaskedArray<T> &left,const MaskedArray<T> &right);
00177 // </group>
00178 
00179 // 
00180 // Element by element arithmetic between a MaskedArray and a scalar, returning
00181 // a MaskedArray.
00182 // <group>
00183 template<class T> MaskedArray<T> operator+ (const MaskedArray<T> &left, const T &right);
00184 template<class T> MaskedArray<T> operator- (const MaskedArray<T> &left, const T &right);
00185 template<class T> MaskedArray<T> operator* (const MaskedArray<T> &left, const T &right);
00186 template<class T> MaskedArray<T> operator/ (const MaskedArray<T> &left, const T &right);
00187                   MaskedArray<Complex> operator* (const MaskedArray<Complex> &left, const Float &right);
00188 // </group>
00189 
00190 // 
00191 // Element by element arithmetic between a scalar and a MaskedArray, returning
00192 // a MaskedArray.
00193 // <group>
00194 template<class T>  MaskedArray<T> operator+ (const T &left, const MaskedArray<T> &right);
00195 template<class T>  MaskedArray<T> operator- (const T &left, const MaskedArray<T> &right);
00196 template<class T>  MaskedArray<T> operator* (const T &left, const MaskedArray<T> &right);
00197 template<class T>  MaskedArray<T> operator/ (const T &left, const MaskedArray<T> &right);
00198                    MaskedArray<Complex> operator* (const Float &left, const MaskedArray<Complex> &right);
00199 // </group>
00200 
00201 // 
00202 // Transcendental function applied to the array on an element-by-element
00203 // basis. Although a template function, this may not make sense for all
00204 // numeric types.
00205 // <group>
00206 template<class T> MaskedArray<T> sin(const MaskedArray<T> &left);
00207 template<class T> MaskedArray<T> cos(const MaskedArray<T> &left);
00208 template<class T> MaskedArray<T> tan(const MaskedArray<T> &left);
00209 template<class T> MaskedArray<T> asin(const MaskedArray<T> &left);
00210 template<class T> MaskedArray<T> acos(const MaskedArray<T> &left);
00211 template<class T> MaskedArray<T> atan(const MaskedArray<T> &left);
00212 template<class T> MaskedArray<T> sinh(const MaskedArray<T> &left);
00213 template<class T> MaskedArray<T> cosh(const MaskedArray<T> &left);
00214 template<class T> MaskedArray<T> tanh(const MaskedArray<T> &left);
00215 template<class T> MaskedArray<T> exp(const MaskedArray<T> &left);
00216 template<class T> MaskedArray<T> log(const MaskedArray<T> &left);
00217 template<class T> MaskedArray<T> log10(const MaskedArray<T> &left);
00218 template<class T> MaskedArray<T> sqrt(const MaskedArray<T> &left);
00219 template<class T> MaskedArray<T> abs(const MaskedArray<T> &left);
00220 template<class T> MaskedArray<T> fabs(const MaskedArray<T> &left);
00221 template<class T> MaskedArray<T> ceil(const MaskedArray<T> &left);
00222 template<class T> MaskedArray<T> floor(const MaskedArray<T> &left);
00223 // </group>
00224 
00225 // Transcendental functions requiring two arguments applied on an element-by-element
00226 // basis. Although a template function, this may not make sense for all
00227 // numeric types.
00228 // <thrown>
00229 //   <li> ArrayConformanceError
00230 // </thrown>
00231 //
00232 // <group>
00233 template<class T> MaskedArray<T> atan2(const MaskedArray<T> &left, const Array<T> &right);
00234 template<class T> MaskedArray<T> fmod(const MaskedArray<T> &left, const Array<T> &right);
00235 template<class T> MaskedArray<T> atan2(const Array<T> &left, const MaskedArray<T> &right);
00236 template<class T> MaskedArray<T> fmod(const Array<T> &left, const MaskedArray<T> &right);
00237 template<class T> MaskedArray<T> atan2(const MaskedArray<T> &left,const MaskedArray<T> &right);
00238 template<class T> MaskedArray<T> fmod(const MaskedArray<T> &left,const MaskedArray<T> &right);
00239 template<class T> MaskedArray<T> atan2(const MaskedArray<T> &left, const T &right);
00240 template<class T> MaskedArray<T> fmod(const MaskedArray<T> &left, const T &right);
00241 template<class T> MaskedArray<T> atan2(const T &left, const MaskedArray<T> &right);
00242 template<class T> MaskedArray<T> fmod(const T &left, const MaskedArray<T> &right);
00243 template<class T, class U> MaskedArray<T> pow(const MaskedArray<T> &left, const Array<U> &right);
00244 template<class T, class U> MaskedArray<T> pow(const Array<T> &left, const MaskedArray<U> &right);
00245 template<class T, class U> MaskedArray<T> pow(const MaskedArray<T> &left,const MaskedArray<U> &right);
00246 template<class T> MaskedArray<T> pow(const MaskedArray<T> &left, const Double &right);
00247 // </group>
00248 
00249 // 
00250 // Find the minimum and maximum values of a MaskedArray.
00251 // Also find the IPositions of the minimum and maximum values.
00252 //
00253 // <thrown>
00254 //    <li> ArrayError
00255 // </thrown>
00256 //
00257 // <group>
00258 template<class T> void minMax(T &minVal, T &maxVal, IPosition &minPos, IPosition &maxPos,const MaskedArray<T> &marray);
00259 template<class T> void minMax(T &minVal, T &maxVal,const MaskedArray<T> &marray);
00260 // </group>
00261 
00262 
00263 // 
00264 // The "min" and "max" functions require that the type "T" have comparison 
00265 // operators.
00266 // The minimum element of the array.
00267 template<class T> T min(const MaskedArray<T> &left);
00268 
00269 
00270 // Return an array that contains the minimum of "left" and "right" at each
00271 // position.
00272 //
00273 // "left" and "right" must be conformant.
00274 //
00275 // <thrown>
00276 //    <li> ArrayError
00277 // </thrown>
00278 // <group>
00279 template<class T> MaskedArray<T> min(const MaskedArray<T> &left, const Array<T> &right);
00280 template<class T> MaskedArray<T> min(const Array<T> &left, const MaskedArray<T> &right);
00281 template<class T> MaskedArray<T> min(const MaskedArray<T> &left, const MaskedArray<T> &right);
00282 template<class T> MaskedArray<T> min(const T &left, const MaskedArray<T> &right);
00283 template<class T> MaskedArray<T> min(const MaskedArray<T> &left, const T &right);
00284 // </group>
00285 
00286 
00287 // "result" contains the minimum of "left" and "right" at each position.
00288 // "result", "left", and "right" must be conformant.
00289 //
00290 // <thrown>
00291 //   <li> ArrayConformanceError
00292 // </thrown>
00293 //
00294 template<class T> void min(const MaskedArray<T> &result, const Array<T> &left, const Array<T> &right);
00295 
00296 
00297 // The maximum element of the array.
00298 template<class T> T max(const MaskedArray<T> &left);
00299 
00300 
00301 // Return an array that contains the maximum of "left" and "right" at each
00302 // position.
00303 //
00304 // "left" and "right" must be conformant.
00305 // <thrown>
00306 //    <li> ArrayError
00307 // </thrown>
00308 //
00309 // <group>
00310 template<class T> MaskedArray<T> max(const MaskedArray<T> &left, const Array<T> &right);
00311 template<class T> MaskedArray<T> max(const Array<T> &left, const MaskedArray<T> &right);
00312 template<class T> MaskedArray<T> max(const MaskedArray<T> &left, const MaskedArray<T> &right);
00313 template<class T> MaskedArray<T> max(const T &left, const MaskedArray<T> &right);
00314 template<class T> MaskedArray<T> max(const MaskedArray<T> &left, const T &right);
00315 // </group>
00316 
00317 
00318 // "result" contains the maximum of "left" and "right" at each position.
00319 // "result", "left", and "right" must be conformant.
00320 //
00321 // <thrown>
00322 //   <li> ArrayConformanceError
00323 // </thrown>
00324 //
00325 template<class T> void max(const MaskedArray<T> &result,const Array<T> &left, const Array<T> &right);
00326 
00327 // 
00328 // Fills all elements of "array" where the mask is True with a sequence
00329 // starting with "start" and incrementing by "inc" for each element
00330 // where the mask is True.
00331 // The first axis varies most rapidly.
00332 template<class T> void indgen(MaskedArray<T> &a, T start, T inc);
00333 
00334 // 
00335 // Fills all elements of "array" where the mask is True with a sequence
00336 // starting with 0 and incremented by one for each element
00337 // where the  mask is True.
00338 // The first axis varies most rapidly.
00339 template<class T>  void indgen(MaskedArray<T> &a);
00340 
00341 // 
00342 // Fills all elements of "array" where the mask is True with a sequence
00343 // starting with "start" and incremented by one for each element
00344 // where the  mask is True.
00345 // The first axis varies most rapidly.
00346 template<class T>  void indgen(MaskedArray<T> &a, T start);
00347 
00348 
00349 // <thrown>
00350 //    <li> ArrayError
00351 // </thrown>
00352 //
00353 // Sum of every element of the MaskedArray where the Mask is True.
00354 template<class T> T sum(const MaskedArray<T> &a);
00355 
00356 // 
00357 // Sum of the squares of every element of the MaskedArray where the Mask is True.
00358 template<class T> T sumsquares(const MaskedArray<T> &a);
00359 
00360 // 
00361 // Product of every element of the MaskedArray where the Mask is True.
00362 // This could of course easily overflow.
00363 template<class T> T product(const MaskedArray<T> &a);
00364 
00365 // 
00366 // The mean of "a" is the sum of all elements of "a" divided by the number
00367 // of elements of "a".
00368 template<class T> T mean(const MaskedArray<T> &a);
00369 
00370 // 
00371 // The variance of "a" is the sum of (a(i) - mean(a))**2/(a.nelements() - 1).
00372 // N.B. N-1, not N in the denominator).
00373 template<class T> T variance(const MaskedArray<T> &a);
00374 
00375 // 
00376 // The variance of "a" is the sum of (a(i) - mean(a))**2/(a.nelements() - 1).
00377 // N.B. N-1, not N in the denominator).
00378 // Rather than using a computed mean, use the supplied value.
00379 template<class T> T variance(const MaskedArray<T> &a, T mean);
00380 
00381 // 
00382 // The standard deviation of "a" is the sqare root of its variance.
00383 template<class T> T stddev(const MaskedArray<T> &a);
00384 
00385 // 
00386 // The standard deviation of "a" is the sqare root of its variance.
00387 // Rather than using a computed mean, use the supplied value.
00388 template<class T> T stddev(const MaskedArray<T> &a, T mean);
00389 
00390 // 
00391 // The average deviation of "a" is the sum of abs(a(i) - mean(a))/N. (N.B.
00392 // N, not N-1 in the denominator).
00393 template<class T> T avdev(const MaskedArray<T> &a);
00394 
00395 // 
00396 // The average deviation of "a" is the sum of abs(a(i) - mean(a))/N. (N.B.
00397 // N, not N-1 in the denominator).
00398 // Rather than using a computed mean, use the supplied value.
00399 template<class T> T avdev(const MaskedArray<T> &a,T mean);
00400 
00401 // 
00402 // The root-mean-square of "a" is the sqrt of sum(a*a)/N.
00403 template<class T> T rms(const MaskedArray<T> &a);
00404 
00405 // 
00406 // The median of "a" is a(n/2).
00407 // When a has an even number of elements and the switch takeEvenMean is set,
00408 // the median is 0.5*(a(n/2) + a((n+1)/2)).
00409 // According to Numerical Recipes (2nd edition) it makes little sense to take
00410 // the mean when the array is large enough (> 100 elements). Therefore
00411 // the default for takeEvenMean is False when the array has > 100 elements,
00412 // otherwise it is True.
00413 // <br>If "sorted"==True we assume the data is already sorted and we
00414 // compute the median directly. Otherwise the function GenSort::kthLargest
00415 // is used to find the median (kthLargest is about 6 times faster
00416 // than a full quicksort).
00417 // <group>
00418 template<class T> inline T median(const MaskedArray<T> &a, Bool sorted=False)
00419     { return median (a, sorted, (a.nelements() <= 100)); }
00420 template<class T> T median(const MaskedArray<T> &a, Bool sorted,
00421                            Bool takeEvenMean);
00422 // </group>
00423 
00424 // The median absolute deviation from the median. Interface is as for
00425 // the median functions
00426 // <group>
00427 template<class T> inline T madfm(const MaskedArray<T> &a, Bool sorted=False)
00428     { return madfm (a, sorted, (a.nelements() <= 100)); }
00429 template<class T> T madfm(const MaskedArray<T> &a, Bool sorted,
00430                           Bool takeEvenMean);
00431 // </group>
00432  
00433 
00434 // Returns a MaskedArray where every element is squared.
00435 template<class T> MaskedArray<T> square(const MaskedArray<T> &val);
00436 
00437 // Returns a MaskedArray where every element is cubed.
00438 template<class T> MaskedArray<T> cube(const MaskedArray<T> &val);
00439 
00440 // </group>
00441 
00442 
00443 template<typename T> class MaskedSumFunc {
00444 public:
00445   T operator() (const MaskedArray<T>& arr) const { return sum(arr); }
00446 };
00447 template<typename T> class MaskedProductFunc {
00448 public:
00449   T operator() (const MaskedArray<T>& arr) const { return product(arr); }
00450 };
00451 template<typename T> class MaskedMinFunc {
00452 public:
00453   T operator() (const MaskedArray<T>& arr) const { return min(arr); }
00454 };
00455 template<typename T> class MaskedMaxFunc {
00456 public:
00457   T operator() (const MaskedArray<T>& arr) const { return max(arr); }
00458 };
00459 template<typename T> class MaskedMeanFunc {
00460 public:
00461   T operator() (const MaskedArray<T>& arr) const { return mean(arr); }
00462 };
00463 template<typename T> class MaskedVarianceFunc {
00464 public:
00465   T operator() (const MaskedArray<T>& arr) const { return variance(arr); }
00466 };
00467 template<typename T> class MaskedStddevFunc {
00468 public:
00469   T operator() (const MaskedArray<T>& arr) const { return stddev(arr); }
00470 };
00471 template<typename T> class MaskedAvdevFunc {
00472 public:
00473   T operator() (const MaskedArray<T>& arr) const { return avdev(arr); }
00474 };
00475 template<typename T> class MaskedRmsFunc {
00476 public:
00477   T operator() (const MaskedArray<T>& arr) const { return rms(arr); }
00478 };
00479 template<typename T> class MaskedMedianFunc {
00480 public:
00481   explicit MaskedMedianFunc (Bool sorted=False, Bool takeEvenMean=True)
00482     : itsSorted(sorted), itsTakeEvenMean(takeEvenMean) {}
00483   T operator() (const MaskedArray<T>& arr) const
00484     { return median(arr, itsSorted, itsTakeEvenMean); }
00485 private:
00486   Bool     itsSorted;
00487   Bool     itsTakeEvenMean;
00488   Bool     itsInPlace;
00489 };
00490 template<typename T> class MaskedMadfmFunc {
00491 public:
00492   explicit MaskedMadfmFunc(Bool sorted=False, Bool takeEvenMean=True)
00493     : itsSorted(sorted), itsTakeEvenMean(takeEvenMean) {}
00494   Float operator()(const MaskedArray<Float>& arr) const
00495     { return madfm(arr, itsSorted, itsTakeEvenMean); }
00496 private:
00497   Bool     itsSorted;
00498   Bool     itsTakeEvenMean;
00499   Bool     itsInPlace;
00500 };
00501 
00502 // Apply the given ArrayMath reduction function objects
00503 // to each box in the array.
00504 // <example>
00505 // Downsample an array by taking the mean of every [25,25] elements.
00506 // <srcblock>
00507 //    Array<Float> downArr = boxedArrayMath(in, IPosition(2,25,25),
00508 //                                          MaskedMeanFunc<Float>());
00509 // </srcblock>
00510 // </example>
00511 // The dimensionality of the array can be larger than the box; in that
00512 // case the missing axes of the box are assumed to have length 1.
00513 // A box axis length <= 0 means the full array axis.
00514 template <typename T, typename FuncType>
00515 MaskedArray<T> boxedArrayMath (const MaskedArray<T>& array,
00516                                const IPosition& boxSize,
00517                                const FuncType& funcObj);
00518 
00519 // Apply for each element in the array the given ArrayMath reduction function
00520 // object to the box around that element. The full box is 2*halfBoxSize + 1.
00521 // It can be used for arrays and boxes of any dimensionality; missing
00522 // halfBoxSize values are set to 1.
00523 // <example>
00524 // Determine for each element in the array the median of a box
00525 // with size [51,51] around that element:
00526 // <srcblock>
00527 //    Array<Float> medians = slidingArrayMath(in, IPosition(2,25,25),
00528 //                                            MaskedMedianFunc<Float>());
00529 // </srcblock>
00530 // This is a potentially expensive operation. On a high-end PC it took
00531 // appr. 27 seconds to get the medians for an array of [1000,1000] using
00532 // a halfBoxSize of [50,50].
00533 // </example>
00534 // <br>The fillEdge argument determines how the edge is filled where
00535 // no full boxes can be made. True means it is set to zero; False means
00536 // that the edge is removed, thus the output array is smaller than the
00537 // input array.
00538 // <note> This brute-force method of determining the medians outperforms
00539 // all kinds of smart implementations. For a vector it is about as fast
00540 // as class <linkto class=MedianSlider>MedianSlider</linkto>, for a 2D array
00541 // it is much, much faster.
00542 // </note>
00543 template <typename T, typename FuncType>
00544 Array<T> slidingArrayMath (const MaskedArray<T>& array,
00545                            const IPosition& halfBoxSize,
00546                            const FuncType& funcObj,
00547                            Bool fillEdge=True);
00548 
00549 
00550 } //# NAMESPACE CASACORE - END
00551 
00552 #ifndef CASACORE_NO_AUTO_TEMPLATES
00553 #include <casacore/casa/Arrays/MaskArrMath.tcc>
00554 #endif //# CASACORE_NO_AUTO_TEMPLATES
00555 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1