casacore
MaskArrMath.h
Go to the documentation of this file.
1 //# MaskArrMath.h: Simple mathematics done with MaskedArray's.
2 //# Copyright (C) 1993,1994,1995,1996,1999,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$
27 
28 #ifndef CASA_MASKARRMATH_2_H
29 #define CASA_MASKARRMATH_2_H
30 
31 #include "Array.h"
32 #include "MaskedArray.h"
33 #include "IPosition.h"
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 // <summary> Mathematical operations for MaskedArrays (and with Arrays) </summary>
38 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMaskArrMath0 tMaskArrMath1 tMaskArrMath2 tMaskArrExcp">
39 //
40 // <prerequisite>
41 // <li> <linkto class=Array>Array</linkto>
42 // <li> <linkto class=MaskedArray>MaskedArray</linkto>
43 // </prerequisite>
44 //
45 // <etymology>
46 // MaskArrMath is short for MaskedArrayMath, which is too long by the old
47 // AIPS++ file naming conventions. This file contains global functions
48 // which perform element by element mathematical operations on masked arrays.
49 // </etymology>
50 //
51 // <synopsis>
52 // These functions perform element by element mathematical operations on
53 // masked arrays. With two arrays, they must both conform, and the result
54 // is done element by element, for those locations where the mask of the
55 // MaskedArray is true. For two MaskedArrays, the "and" of the masks is used.
56 // </synopsis>
57 //
58 // <example>
59 // <srcblock>
60 // Vector<int> a(10);
61 // Vector<int> b(10);
62 // Vector<int> c(10);
63 // . . .
64 // c = a(a>0) + b(b>0);
65 // </srcblock>
66 // This example sets those elements of c where ((a>0) && (b>0)) to (a+b).
67 // Elements of c where !((a>0) && (b>0)) are unchanged. The result of
68 // this operation is a MaskedArray. The assignment from this
69 // MaskedArray to the Vector c only assigns those elements
70 // where the mask is true.
71 // </example>
72 //
73 // <example>
74 // <srcblock>
75 // Vector<double> a(10);
76 // Vector<double> b(10);
77 // Vector<double> c(10);
78 // . . .
79 // c = atan2 (a, b(b>0);
80 // </srcblock>
81 // This example sets those elements of c where (b>0) to atan2 (a,b).
82 // Elements of c where !(b>0) are unchanged. The result of
83 // this operation is a MaskedArray. The assignment from this
84 // MaskedArray to the Vector c only assigns those elements
85 // where the mask is true.
86 // </example>
87 //
88 // <example>
89 // <srcblock>
90 // Vector<int> a(10);
91 // int result;
92 // . . .
93 // result = sum (a(a>0));
94 // </srcblock>
95 // This example sums a, for those elements of a which are greater than 0.
96 // </example>
97 //
98 // <motivation>
99 // One wants to be able to mask arrays and perform mathematical operations on
100 // those masked arrays. Since the masked arrays are only defined where
101 // the masks are true, the result must be a MaskedArray, or a simple number.
102 // </motivation>
103 //
104 // <linkfrom anchor="MaskedArray mathematical operations" classes="MaskedArray Array Vector Matrix Cube">
105 // <here>MaskedArray mathematical operations</here> -- Mathematical
106 // operations for MaskedArrays, and between MaskedArrays and Arrays.
107 // </linkfrom>
108 //
109 // <group name="MaskedArray mathematical operations">
110 
111 // Element by element arithmetic modifying left in-place. left and other
112 // must be conformant.
113 //
114 // <thrown>
115 // <li> ArrayConformanceError
116 // </thrown>
117 //
118 // <group>
119 template<class T> const MaskedArray<T> & operator+= (const MaskedArray<T> &left, const Array<T> &other);
120 template<class T> const MaskedArray<T> & operator-= (const MaskedArray<T> &left, const Array<T> &other);
121 template<class T> const MaskedArray<T> & operator*= (const MaskedArray<T> &left, const Array<T> &other);
122 template<class T> const MaskedArray<T> & operator/= (const MaskedArray<T> &left, const Array<T> &other);
123 template<class T> Array<T> & operator+= (Array<T> &left, const MaskedArray<T> &other);
124 template<class T> Array<T> & operator-= (Array<T> &left, const MaskedArray<T> &other);
125 template<class T> Array<T> & operator*= (Array<T> &left, const MaskedArray<T> &other);
126 template<class T> Array<T> & operator/= (Array<T> &left, const MaskedArray<T> &other);
127 template<class T> const MaskedArray<T> & operator+= (const MaskedArray<T> &left, const MaskedArray<T> &other);
128 template<class T> const MaskedArray<T> & operator-= (const MaskedArray<T> &left, const MaskedArray<T> &other);
129 template<class T> const MaskedArray<T> & operator*= (const MaskedArray<T> &left, const MaskedArray<T> &other);
130 template<class T> const MaskedArray<T> & operator/= (const MaskedArray<T> &left,const MaskedArray<T> &other);
131 template<class T,class S> const MaskedArray<T> & operator/= (const MaskedArray<T> &left,const MaskedArray<S> &other);
132 // </group>
133 
134 //
135 // Element by element arithmetic modifying left in-place. The scalar "other"
136 // behaves as if it were a conformant Array to left filled with constant values.
137 // <group>
138 template<class T> const MaskedArray<T> & operator+= (const MaskedArray<T> &left,const T &other);
139 template<class T> const MaskedArray<T> & operator-= (const MaskedArray<T> &left,const T &other);
140 template<class T> const MaskedArray<T> & operator*= (const MaskedArray<T> &left,const T &other);
141 template<class T> const MaskedArray<T> & operator/= (const MaskedArray<T> &left,const T &other);
142 // </group>
143 
144 // Unary arithmetic operation.
145 //
146 // <group>
147 template<class T> MaskedArray<T> operator+(const MaskedArray<T> &a);
148 template<class T> MaskedArray<T> operator-(const MaskedArray<T> &a);
149 // </group>
150 
151 //
152 // Element by element arithmetic on MaskedArrays, returns a MaskedArray.
153 //
154 // <thrown>
155 // <li> ArrayConformanceError
156 // </thrown>
157 //
158 // <group>
159 template<class T> MaskedArray<T> operator+ (const MaskedArray<T> &left, const Array<T> &right);
160 template<class T> MaskedArray<T> operator- (const MaskedArray<T> &left, const Array<T> &right);
161 template<class T> MaskedArray<T> operator* (const MaskedArray<T> &left, const Array<T> &right);
162 template<class T> MaskedArray<T> operator/ (const MaskedArray<T> &left, const Array<T> &right);
163 template<class T> MaskedArray<T> operator+ (const Array<T> &left, const MaskedArray<T> &right);
164 template<class T> MaskedArray<T> operator- (const Array<T> &left, const MaskedArray<T> &right);
165 template<class T> MaskedArray<T> operator* (const Array<T> &left, const MaskedArray<T> &right);
166 template<class T> MaskedArray<T> operator/ (const Array<T> &left, const MaskedArray<T> &right);
167 template<class T> MaskedArray<T> operator+ (const MaskedArray<T> &left,const MaskedArray<T> &right);
168 template<class T> MaskedArray<T> operator- (const MaskedArray<T> &left,const MaskedArray<T> &right);
169 template<class T> MaskedArray<T> operator* (const MaskedArray<T> &left,const MaskedArray<T> &right);
170 template<class T> MaskedArray<T> operator/ (const MaskedArray<T> &left,const MaskedArray<T> &right);
171 // </group>
172 
173 //
174 // Element by element arithmetic between a MaskedArray and a scalar, returning
175 // a MaskedArray.
176 // <group>
177 template<class T> MaskedArray<T> operator+ (const MaskedArray<T> &left, const T &right);
178 template<class T> MaskedArray<T> operator- (const MaskedArray<T> &left, const T &right);
179 template<class T> MaskedArray<T> operator* (const MaskedArray<T> &left, const T &right);
180 template<class T> MaskedArray<T> operator/ (const MaskedArray<T> &left, const T &right);
181  MaskedArray<std::complex<float>> operator* (const MaskedArray<std::complex<float>> &left, const float &right);
182 // </group>
183 
184 //
185 // Element by element arithmetic between a scalar and a MaskedArray, returning
186 // a MaskedArray.
187 // <group>
188 template<class T> MaskedArray<T> operator+ (const T &left, const MaskedArray<T> &right);
189 template<class T> MaskedArray<T> operator- (const T &left, const MaskedArray<T> &right);
190 template<class T> MaskedArray<T> operator* (const T &left, const MaskedArray<T> &right);
191 template<class T> MaskedArray<T> operator/ (const T &left, const MaskedArray<T> &right);
192  MaskedArray<std::complex<float>> operator* (const float &left, const MaskedArray<std::complex<float>> &right);
193 // </group>
194 
195 //
196 // Transcendental function applied to the array on an element-by-element
197 // basis. Although a template function, this may not make sense for all
198 // numeric types.
199 // <group>
200 template<class T> MaskedArray<T> sin(const MaskedArray<T> &left);
201 template<class T> MaskedArray<T> cos(const MaskedArray<T> &left);
202 template<class T> MaskedArray<T> tan(const MaskedArray<T> &left);
203 template<class T> MaskedArray<T> asin(const MaskedArray<T> &left);
204 template<class T> MaskedArray<T> acos(const MaskedArray<T> &left);
205 template<class T> MaskedArray<T> atan(const MaskedArray<T> &left);
206 template<class T> MaskedArray<T> sinh(const MaskedArray<T> &left);
207 template<class T> MaskedArray<T> cosh(const MaskedArray<T> &left);
208 template<class T> MaskedArray<T> tanh(const MaskedArray<T> &left);
209 template<class T> MaskedArray<T> exp(const MaskedArray<T> &left);
210 template<class T> MaskedArray<T> log(const MaskedArray<T> &left);
211 template<class T> MaskedArray<T> log10(const MaskedArray<T> &left);
212 template<class T> MaskedArray<T> sqrt(const MaskedArray<T> &left);
213 template<class T> MaskedArray<T> abs(const MaskedArray<T> &left);
214 template<class T> MaskedArray<T> fabs(const MaskedArray<T> &left);
215 template<class T> MaskedArray<T> ceil(const MaskedArray<T> &left);
216 template<class T> MaskedArray<T> floor(const MaskedArray<T> &left);
217 // </group>
218 
219 // Transcendental functions requiring two arguments applied on an element-by-element
220 // basis. Although a template function, this may not make sense for all
221 // numeric types.
222 // <thrown>
223 // <li> ArrayConformanceError
224 // </thrown>
225 //
226 // <group>
227 template<class T> MaskedArray<T> atan2(const MaskedArray<T> &left, const Array<T> &right);
228 template<class T> MaskedArray<T> fmod(const MaskedArray<T> &left, const Array<T> &right);
229 template<class T> MaskedArray<T> atan2(const Array<T> &left, const MaskedArray<T> &right);
230 template<class T> MaskedArray<T> fmod(const Array<T> &left, const MaskedArray<T> &right);
231 template<class T> MaskedArray<T> atan2(const MaskedArray<T> &left,const MaskedArray<T> &right);
232 template<class T> MaskedArray<T> fmod(const MaskedArray<T> &left,const MaskedArray<T> &right);
233 template<class T> MaskedArray<T> atan2(const MaskedArray<T> &left, const T &right);
234 template<class T> MaskedArray<T> fmod(const MaskedArray<T> &left, const T &right);
235 template<class T> MaskedArray<T> atan2(const T &left, const MaskedArray<T> &right);
236 template<class T> MaskedArray<T> fmod(const T &left, const MaskedArray<T> &right);
237 template<class T, class U> MaskedArray<T> pow(const MaskedArray<T> &left, const Array<U> &right);
238 template<class T, class U> MaskedArray<T> pow(const Array<T> &left, const MaskedArray<U> &right);
239 template<class T, class U> MaskedArray<T> pow(const MaskedArray<T> &left,const MaskedArray<U> &right);
240 template<class T> MaskedArray<T> pow(const MaskedArray<T> &left, const double &right);
241 // </group>
242 
243 
244 // Extracts the real part of a complex array into an array of floats.
245 template<class T>
246 MaskedArray<T> real(const MaskedArray<std::complex<T>> &carray)
247  { return MaskedArray<T> (real(carray.getArray()), carray.getMask()); }
248 
249 //
250 // Extracts the imaginary part of a complex array into an array of floats.
251 template<class T>
252 MaskedArray<T> imag(const MaskedArray<std::complex<T>> &carray)
253  { return MaskedArray<T> (imag(carray.getArray()), carray.getMask()); }
254 
255 
256 //
257 // Find the minimum and maximum values of a MaskedArray.
258 // Also find the IPositions of the minimum and maximum values.
259 //
260 // <thrown>
261 // <li> ArrayError
262 // </thrown>
263 //
264 // <group>
265 template<class T> void minMax(T &minVal, T &maxVal, IPosition &minPos, IPosition &maxPos,const MaskedArray<T> &marray);
266 template<class T> void minMax(T &minVal, T &maxVal,const MaskedArray<T> &marray);
267 // </group>
268 
269 
270 //
271 // The "min" and "max" functions require that the type "T" have comparison
272 // operators.
273 // The minimum element of the array.
274 template<class T> T min(const MaskedArray<T> &left);
275 
276 
277 // Return an array that contains the minimum of "left" and "right" at each
278 // position.
279 //
280 // "left" and "right" must be conformant.
281 //
282 // <thrown>
283 // <li> ArrayError
284 // </thrown>
285 // <group>
286 template<class T> MaskedArray<T> min(const MaskedArray<T> &left, const Array<T> &right);
287 template<class T> MaskedArray<T> min(const Array<T> &left, const MaskedArray<T> &right);
288 template<class T> MaskedArray<T> min(const MaskedArray<T> &left, const MaskedArray<T> &right);
289 template<class T> MaskedArray<T> min(const T &left, const MaskedArray<T> &right);
290 template<class T> MaskedArray<T> min(const MaskedArray<T> &left, const T &right);
291 // </group>
292 
293 
294 // "result" contains the minimum of "left" and "right" at each position.
295 // "result", "left", and "right" must be conformant.
296 //
297 // <thrown>
298 // <li> ArrayConformanceError
299 // </thrown>
300 //
301 template<class T> void min(const MaskedArray<T> &result, const Array<T> &left, const Array<T> &right);
302 
303 
304 // The maximum element of the array.
305 template<class T> T max(const MaskedArray<T> &left);
306 
307 
308 // Return an array that contains the maximum of "left" and "right" at each
309 // position.
310 //
311 // "left" and "right" must be conformant.
312 // <thrown>
313 // <li> ArrayError
314 // </thrown>
315 //
316 // <group>
317 template<class T> MaskedArray<T> max(const MaskedArray<T> &left, const Array<T> &right);
318 template<class T> MaskedArray<T> max(const Array<T> &left, const MaskedArray<T> &right);
319 template<class T> MaskedArray<T> max(const MaskedArray<T> &left, const MaskedArray<T> &right);
320 template<class T> MaskedArray<T> max(const T &left, const MaskedArray<T> &right);
321 template<class T> MaskedArray<T> max(const MaskedArray<T> &left, const T &right);
322 // </group>
323 
324 
325 // "result" contains the maximum of "left" and "right" at each position.
326 // "result", "left", and "right" must be conformant.
327 //
328 // <thrown>
329 // <li> ArrayConformanceError
330 // </thrown>
331 //
332 template<class T> void max(const MaskedArray<T> &result,const Array<T> &left, const Array<T> &right);
333 
334 //
335 // Fills all elements of "array" where the mask is true with a sequence
336 // starting with "start" and incrementing by "inc" for each element
337 // where the mask is true.
338 // The first axis varies most rapidly.
339 template<class T> void indgen(MaskedArray<T> &a, T start, T inc);
340 
341 //
342 // Fills all elements of "array" where the mask is true with a sequence
343 // starting with 0 and incremented by one for each element
344 // where the mask is true.
345 // The first axis varies most rapidly.
346 template<class T> void indgen(MaskedArray<T> &a);
347 
348 //
349 // Fills all elements of "array" where the mask is true with a sequence
350 // starting with "start" and incremented by one for each element
351 // where the mask is true.
352 // The first axis varies most rapidly.
353 template<class T> void indgen(MaskedArray<T> &a, T start);
354 
355 
356 // <thrown>
357 // <li> ArrayError
358 // </thrown>
359 //
360 // Sum of every element of the MaskedArray where the Mask is true.
361 template<class T> T sum(const MaskedArray<T> &a);
362 
363 //
364 // Sum of the squares of every element of the MaskedArray where the Mask is true.
365 template<class T> T sumsquares(const MaskedArray<T> &a);
366 
367 //
368 // Product of every element of the MaskedArray where the Mask is true.
369 // This could of course easily overflow.
370 template<class T> T product(const MaskedArray<T> &a);
371 
372 //
373 // The mean of "a" is the sum of all elements of "a" divided by the number
374 // of elements of "a".
375 template<class T> T mean(const MaskedArray<T> &a);
376 
377 //
378 // The variance of "a" is the sum of (a(i) - mean(a))**2/(a.nelements() - ddof).
379 // Similar to numpy the argument ddof tells if the population variance (ddof=0)
380 // or the sample variance (ddof=1) is taken.
381 // The variance functions proper use ddof=1.
382 // <br>Note that for a complex valued T the absolute values are used; in that way
383 // the variance is equal to the sum of the variances of the real and imaginary parts.
384 // Hence the imaginary part in the return value is 0.
385 template<class T> T variance(const MaskedArray<T> &a);
386 template<class T> T pvariance(const MaskedArray<T> &a, size_t ddof=0);
387 // Rather than using a computed mean, use the supplied value.
388 template<class T> T variance(const MaskedArray<T> &a, T mean);
389 template<class T> T pvariance(const MaskedArray<T> &a, T mean, size_t ddof=0);
390 
391 // The standard deviation of "a" is the square root of its variance.
392 template<class T> T stddev(const MaskedArray<T> &a);
393 template<class T> T pstddev(const MaskedArray<T> &a, size_t ddof=0);
394 template<class T> T stddev(const MaskedArray<T> &a, T mean);
395 template<class T> T pstddev(const MaskedArray<T> &a, T mean, size_t ddof=0);
396 
397 //
398 // The average deviation of "a" is the sum of abs(a(i) - mean(a))/N. (N.B.
399 // N, not N-1 in the denominator).
400 template<class T> T avdev(const MaskedArray<T> &a);
401 
402 //
403 // The average deviation of "a" is the sum of abs(a(i) - mean(a))/N. (N.B.
404 // N, not N-1 in the denominator).
405 // Rather than using a computed mean, use the supplied value.
406 template<class T> T avdev(const MaskedArray<T> &a,T mean);
407 
408 //
409 // The root-mean-square of "a" is the sqrt of sum(a*a)/N.
410 template<class T> T rms(const MaskedArray<T> &a);
411 
412 //
413 // The median of "a" is a(n/2).
414 // When a has an even number of elements and the switch takeEvenMean is set,
415 // the median is 0.5*(a(n/2) + a((n+1)/2)).
416 // According to Numerical Recipes (2nd edition) it makes little sense to take
417 // the mean when the array is large enough (> 100 elements). Therefore
418 // the default for takeEvenMean is false when the array has > 100 elements,
419 // otherwise it is true.
420 // <br>If "sorted"==true we assume the data is already sorted and we
421 // compute the median directly. Otherwise the function GenSort::kthLargest
422 // is used to find the median (kthLargest is about 6 times faster
423 // than a full quicksort).
424 // <group>
425 template<class T> inline T median(const MaskedArray<T> &a, bool sorted=false)
426  { return median (a, sorted, (a.nelements() <= 100)); }
427 template<class T> T median(const MaskedArray<T> &a, bool sorted,
428  bool takeEvenMean);
429 // </group>
430 
431 // The median absolute deviation from the median. Interface is as for
432 // the median functions
433 // <group>
434 template<class T> inline T madfm(const MaskedArray<T> &a, bool sorted=false)
435  { return madfm (a, sorted, (a.nelements() <= 100)); }
436 template<class T> T madfm(const MaskedArray<T> &a, bool sorted,
437  bool takeEvenMean);
438 // </group>
439 
440 
441 // Returns a MaskedArray where every element is squared.
442 template<class T> MaskedArray<T> square(const MaskedArray<T> &val);
443 
444 // Returns a MaskedArray where every element is cubed.
445 template<class T> MaskedArray<T> cube(const MaskedArray<T> &val);
446 
447 // </group>
448 
449 
450 template<typename T> class MaskedSumFunc {
451 public:
452  T operator() (const MaskedArray<T>& arr) const { return sum(arr); }
453 };
454 template<typename T> class MaskedProductFunc {
455 public:
456  T operator() (const MaskedArray<T>& arr) const { return product(arr); }
457 };
458 template<typename T> class MaskedMinFunc {
459 public:
460  T operator() (const MaskedArray<T>& arr) const { return min(arr); }
461 };
462 template<typename T> class MaskedMaxFunc {
463 public:
464  T operator() (const MaskedArray<T>& arr) const { return max(arr); }
465 };
466 template<typename T> class MaskedMeanFunc {
467 public:
468  T operator() (const MaskedArray<T>& arr) const { return mean(arr); }
469 };
470 template<typename T> class MaskedVarianceFunc {
471 public:
472  T operator() (const MaskedArray<T>& arr) const { return variance(arr); }
473 };
474 template<typename T> class MaskedStddevFunc {
475 public:
476  T operator() (const MaskedArray<T>& arr) const { return stddev(arr); }
477 };
478 template<typename T> class MaskedAvdevFunc {
479 public:
480  T operator() (const MaskedArray<T>& arr) const { return avdev(arr); }
481 };
482 template<typename T> class MaskedRmsFunc {
483 public:
484  T operator() (const MaskedArray<T>& arr) const { return rms(arr); }
485 };
486 template<typename T> class MaskedMedianFunc {
487 public:
488  explicit MaskedMedianFunc (bool sorted=false, bool takeEvenMean=true)
489  : itsSorted(sorted), itsTakeEvenMean(takeEvenMean) {}
490  T operator() (const MaskedArray<T>& arr) const
491  { return median(arr, itsSorted, itsTakeEvenMean); }
492 private:
493  bool itsSorted;
496 };
497 template<typename T> class MaskedMadfmFunc {
498 public:
499  explicit MaskedMadfmFunc(bool sorted=false, bool takeEvenMean=true)
500  : itsSorted(sorted), itsTakeEvenMean(takeEvenMean) {}
501  float operator()(const MaskedArray<float>& arr) const
502  { return madfm(arr, itsSorted, itsTakeEvenMean); }
503 private:
504  bool itsSorted;
507 };
508 
509 // Apply the given ArrayMath reduction function objects
510 // to each box in the array.
511 // <example>
512 // Downsample an array by taking the mean of every [25,25] elements.
513 // <srcblock>
514 // Array<float> downArr = boxedArrayMath(in, IPosition(2,25,25),
515 // MaskedMeanFunc<float>());
516 // </srcblock>
517 // </example>
518 // The dimensionality of the array can be larger than the box; in that
519 // case the missing axes of the box are assumed to have length 1.
520 // A box axis length <= 0 means the full array axis.
521 template <typename T, typename FuncType>
523  const IPosition& boxSize,
524  const FuncType& funcObj);
525 
526 // Apply for each element in the array the given ArrayMath reduction function
527 // object to the box around that element. The full box is 2*halfBoxSize + 1.
528 // It can be used for arrays and boxes of any dimensionality; missing
529 // halfBoxSize values are set to 1.
530 // <example>
531 // Determine for each element in the array the median of a box
532 // with size [51,51] around that element:
533 // <srcblock>
534 // Array<float> medians = slidingArrayMath(in, IPosition(2,25,25),
535 // MaskedMedianFunc<float>());
536 // </srcblock>
537 // This is a potentially expensive operation. On a high-end PC it took
538 // appr. 27 seconds to get the medians for an array of [1000,1000] using
539 // a halfBoxSize of [50,50].
540 // </example>
541 // <br>The fillEdge argument determines how the edge is filled where
542 // no full boxes can be made. true means it is set to zero; false means
543 // that the edge is removed, thus the output array is smaller than the
544 // input array.
545 // <note> This brute-force method of determining the medians outperforms
546 // all kinds of smart implementations. For a vector it is about as fast
547 // as the casacore class MedianSlider, for a 2D array
548 // it is much, much faster.
549 // </note>
550 template <typename T, typename FuncType>
552  const IPosition& halfBoxSize,
553  const FuncType& funcObj,
554  bool fillEdge=true);
555 
556 
557 } //# NAMESPACE CASACORE - END
558 
559 #include "MaskArrMath.tcc"
560 
561 #endif
size_t nelements() const
The number of elements of this masked array.
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:480
MaskedMadfmFunc(bool sorted=false, bool takeEvenMean=true)
Definition: MaskArrMath.h:499
float operator()(const MaskedArray< float > &arr) const
Definition: MaskArrMath.h:501
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:464
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:468
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:490
MaskedMedianFunc(bool sorted=false, bool takeEvenMean=true)
Definition: MaskArrMath.h:488
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:460
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:456
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:484
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:476
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:452
T operator()(const MaskedArray< T > &arr) const
Definition: MaskArrMath.h:472
this file contains all the compiler specific defines
Definition: mainpage.dox:28
LatticeExprNode mean(const LatticeExprNode &expr)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode sum(const LatticeExprNode &expr)
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
LatticeExprNode stddev(const LatticeExprNode &expr)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
MaskedArray< T > boxedArrayMath(const MaskedArray< T > &array, const IPosition &boxSize, const FuncType &funcObj)
Apply the given ArrayMath reduction function objects to each box in the array.
LatticeExprNode operator-(const LatticeExprNode &expr)
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1929
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode variance(const LatticeExprNode &expr)
T product(const TableVector< T > &tv)
Definition: TabVecMath.h:385
LatticeExprNode avdev(const LatticeExprNode &expr)
Array< T > slidingArrayMath(const MaskedArray< T > &array, const IPosition &halfBoxSize, const FuncType &funcObj, bool fillEdge=true)
Apply for each element in the array the given ArrayMath reduction function object to the box around t...
TableExprNode marray(const TableExprNode &array, const TableExprNode &mask)
Form a masked array.
Definition: ExprNode.h:1935
LatticeExprNode median(const LatticeExprNode &expr)
LatticeExprNode real(const LatticeExprNode &expr)
LatticeExprNode imag(const LatticeExprNode &expr)
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1680
MaskedArray< T > fmod(const MaskedArray< T > &left, const MaskedArray< T > &right)
MaskedArray< T > max(const MaskedArray< T > &left, const MaskedArray< T > &right)
MaskedArray< T > fmod(const T &left, const MaskedArray< T > &right)
MaskedArray< T > max(const MaskedArray< T > &left, const T &right)
T product(const MaskedArray< T > &a)
Product of every element of the MaskedArray where the Mask is true.
T median(const MaskedArray< T > &a, bool sorted, bool takeEvenMean)
MaskedArray< T > min(const MaskedArray< T > &left, const MaskedArray< T > &right)
T max(const MaskedArray< T > &left)
The maximum element of the array.
T mean(const MaskedArray< T > &a)
The mean of "a" is the sum of all elements of "a" divided by the number of elements of "a".
void min(const MaskedArray< T > &result, const Array< T > &left, const Array< T > &right)
"result" contains the minimum of "left" and "right" at each position.
MaskedArray< T > max(const T &left, const MaskedArray< T > &right)
MaskedArray< T > max(const Array< T > &left, const MaskedArray< T > &right)
MaskedArray< T > imag(const MaskedArray< std::complex< T >> &carray)
Extracts the imaginary part of a complex array into an array of floats.
Definition: MaskArrMath.h:252
T madfm(const MaskedArray< T > &a, bool sorted=false)
The median absolute deviation from the median.
Definition: MaskArrMath.h:434
MaskedArray< T > fmod(const Array< T > &left, const MaskedArray< T > &right)
MaskedArray< T > fmod(const MaskedArray< T > &left, const Array< T > &right)
MaskedArray< T > min(const Array< T > &left, const MaskedArray< T > &right)
MaskedArray< T > min(const MaskedArray< T > &left, const T &right)
T median(const MaskedArray< T > &a, bool sorted=false)
The median of "a" is a(n/2).
Definition: MaskArrMath.h:425
MaskedArray< T > atan2(const Array< T > &left, const MaskedArray< T > &right)
T variance(const MaskedArray< T > &a, T mean)
Rather than using a computed mean, use the supplied value.
MaskedArray< T > pow(const MaskedArray< T > &left, const MaskedArray< U > &right)
MaskedArray< T > atan2(const MaskedArray< T > &left, const Array< T > &right)
Transcendental functions requiring two arguments applied on an element-by-element basis.
MaskedArray< T > operator+(const MaskedArray< T > &a)
Unary arithmetic operation.
MaskedArray< T > sin(const MaskedArray< T > &left)
Transcendental function applied to the array on an element-by-element basis.
MaskedArray< T > fmod(const MaskedArray< T > &left, const T &right)
T min(const MaskedArray< T > &left)
The "min" and "max" functions require that the type "T" have comparison operators.
MaskedArray< T > min(const T &left, const MaskedArray< T > &right)
void max(const MaskedArray< T > &result, const Array< T > &left, const Array< T > &right)
"result" contains the maximum of "left" and "right" at each position.
MaskedArray< T > real(const MaskedArray< std::complex< T >> &carray)
Extracts the real part of a complex array into an array of floats.
Definition: MaskArrMath.h:246
T avdev(const MaskedArray< T > &a)
The average deviation of "a" is the sum of abs(a(i) - mean(a))/N.
T sumsquares(const MaskedArray< T > &a)
Sum of the squares of every element of the MaskedArray where the Mask is true.
MaskedArray< T > atan2(const MaskedArray< T > &left, const MaskedArray< T > &right)
T pvariance(const MaskedArray< T > &a, T mean, size_t ddof=0)
T variance(const MaskedArray< T > &a)
The variance of "a" is the sum of (a(i) - mean(a))**2/(a.nelements() - ddof).
MaskedArray< T > max(const MaskedArray< T > &left, const Array< T > &right)
Return an array that contains the maximum of "left" and "right" at each position.
T rms(const MaskedArray< T > &a)
The root-mean-square of "a" is the sqrt of sum(a*a)/N.
void minMax(T &minVal, T &maxVal, IPosition &minPos, IPosition &maxPos, const MaskedArray< T > &marray)
Find the minimum and maximum values of a MaskedArray.
T avdev(const MaskedArray< T > &a, T mean)
The average deviation of "a" is the sum of abs(a(i) - mean(a))/N.
void minMax(T &minVal, T &maxVal, const MaskedArray< T > &marray)
T stddev(const MaskedArray< T > &a)
The standard deviation of "a" is the square root of its variance.
MaskedArray< T > cube(const MaskedArray< T > &val)
Returns a MaskedArray where every element is cubed.
MaskedArray< T > pow(const MaskedArray< T > &left, const double &right)
T madfm(const MaskedArray< T > &a, bool sorted, bool takeEvenMean)
MaskedArray< T > min(const MaskedArray< T > &left, const Array< T > &right)
Return an array that contains the minimum of "left" and "right" at each position.
MaskedArray< T > pow(const Array< T > &left, const MaskedArray< U > &right)
MaskedArray< T > atan2(const T &left, const MaskedArray< T > &right)
T pstddev(const MaskedArray< T > &a, T mean, size_t ddof=0)
void indgen(MaskedArray< T > &a, T start, T inc)
Fills all elements of "array" where the mask is true with a sequence starting with "start" and increm...
MaskedArray< T > square(const MaskedArray< T > &val)
Returns a MaskedArray where every element is squared.
void indgen(MaskedArray< T > &a, T start)
Fills all elements of "array" where the mask is true with a sequence starting with "start" and increm...
MaskedArray< T > atan2(const MaskedArray< T > &left, const T &right)
MaskedArray< T > pow(const MaskedArray< T > &left, const Array< U > &right)
void indgen(MaskedArray< T > &a)
Fills all elements of "array" where the mask is true with a sequence starting with 0 and incremented ...