casacore
Loading...
Searching...
No Matches
MedianSlider.h
Go to the documentation of this file.
1//# MedianSlider.h: Optimized sliding-median computator
2//# Copyright (C) 2000,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@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#ifndef SCIMATH_MEDIANSLIDER_H
27#define SCIMATH_MEDIANSLIDER_H
28
29//#! Includes go here
30
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/Vector.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37
38// <summary>
39// Class to compute sliding median
40// </summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
45// </reviewed>
46
47// <synopsis>
48// MedianSlider is a class for efficient computing of sliding medians.
49// </synopsis>
50//
51// <example>
52// </example>
53//
54// <motivation>
55// Flagging Agents make extended use of sliding medians.
56// </motivation>
57//
58// <todo asof="yyyy/mm/dd">
59// <li> think about a 2D sliding median
60// </todo>
61
63{
64public:
65
68 MedianSlider ( const MedianSlider &other );
71
72 void cleanup ();
73
74// Adds a datum to the slider. Once the window is full, newer values will
75// push out older values. Returns the new median value.
76// If flag is set to true, adds a "flagged" datum, one which takes
77// up space in the window but is skipped during median computations.
78 Float add ( Float d,Bool flag=False );
79// Adds a flagged datum
80 Float add () { return add(0,True); }
81// Adds N flagged datums
82 Float next ( uInt n=1 );
83// Adds several datums at once (with corresponding flags)
84 Float add ( const Vector<Float> &d,const Vector<Bool> &flag );
85// Adds several non-flagged datums at once
86 Float add ( const Vector<Float> &d );
87
88// Returns the number of values currently in the window. This is less
89// than the window width initially.
90// Int size ();
91
92// Returns the number of non-flagged values in window
93 Int nval ();
94
95// Returns the current median value
96 Float median ();
97
98// Returns a previous value (from n steps ago) from the sliding window
99 Float prevVal ( uInt n,Bool &flag );
100
101// Returns value from midpoint (center) of window, possibly with flag
102 Float midpoint ( Bool &flag );
104 { Bool dum; return midpoint(dum); }
105
106// Returns the difference between the current median and the value
107// at window center. Optionally, also returns flag of median center
108 Float diff ( Bool &flag ) { return midpoint(flag) - median(); }
110 { Bool dum; return diff(dum); }
111
112// returns total memory usage (in bytes) for a given halfwin size
113 static size_t objsize ( int halfwin )
114 { return sizeof(MedianSlider)+(sizeof(Float)+sizeof(uInt)+sizeof(Bool))*(halfwin*2+1); }
115
116// For testing purposes only: verifies current value of median.
117// Throws an exception if it fails.
119
120private:
121
127
128};
129
130
132{
133 return nind;
134}
135
137{
138 if( !nind )
139 return 0;
140 return nind%2 ? buf[ index[nind/2] ]
141 : ( buf[ index[nind/2-1] ] + buf[ index[nind/2] ] )/2;
142// return nind%2 ? buf[ index[nind/2] ]
143// : buf[ index[nind/2-1] ];
144}
145
147{
148 return prevVal(halfwin+1,flag);
149}
150
151
152
153} //# NAMESPACE CASACORE - END
154
155#endif
Float add()
Adds a flagged datum.
Float next(uInt n=1)
Adds N flagged datums.
Float add(Float d, Bool flag=False)
Adds a datum to the slider.
Float median()
Returns the current median value
MedianSlider(const MedianSlider &other)
Bool assure()
For testing purposes only: verifies current value of median.
Float add(const Vector< Float > &d, const Vector< Bool > &flag)
Adds several datums at once (with corresponding flags)
Int nval()
Returns the number of values currently in the window.
Float prevVal(uInt n, Bool &flag)
Returns a previous value (from n steps ago) from the sliding window.
Float diff(Bool &flag)
Returns the difference between the current median and the value at window center.
static size_t objsize(int halfwin)
returns total memory usage (in bytes) for a given halfwin size
Float add(const Vector< Float > &d)
Adds several non-flagged datums at once.
MedianSlider(int halfwin)
MedianSlider & operator=(const MedianSlider &other)
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41