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