casacore
Loading...
Searching...
No Matches
MSFlagger.h
Go to the documentation of this file.
1// # MSFlagger.h: this defines MSFlagger, which implement flagging/editing
2// # Copyright (C) 1997,1998,1999,2000
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 MS_MSFLAGGER_H
27#define MS_MSFLAGGER_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/casa/Containers/Record.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35class MSSelector;
36class Table;
37class String;
38
39// <summary>
40// MSFlagger specifies selections on a MeasurementSet
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> MeasurementSet
50// <li> SomeOtherClass
51// <li> some concept
52// </prerequisite>
53//
54// <etymology>
55// MSFlagger is a class that sets flags in an MS
56// </etymology>
57//
58// <synopsis>
59// This class is used to change the flag and flag_history columns in
60// a MeasurementSet. It provides functions for automated flagging based on
61// clipping the data that is too far from the median value.
62// The ms DO uses this class to allow flagging from glish or a GUI.
63//
64// <example> <srcblock>
65// MSFlagger msFlagger(myMS);
66// </srcblock></example>
67// </synopsis>
68//
69// <motivation>
70// Flagging/editing of data is a central requirement in data processing, this
71// class provides some simple flagging algorithms and the code
72// that modifies & creates flag columns in the MS.
73// </motivation>
74//
75// <thrown>
76// <li>
77// <li>
78// </thrown>
79//
80// <todo asof="yyyy/mm/dd">
81// <li> add this feature
82// </todo>
83
84class MSFlagger {
85 public:
87
88 // construct from an MSSelector object
90
91 // Copy constructor
92 MSFlagger(const MSFlagger& other);
93
94 // Assignment
96
98
99 // Change or Set the MS this MSFlagger refers to.
101
102 // Fill an internal buffer with the data item requested, similar to getData
103 // except that the data is not returned, but kept around for further
104 // processing. Only a single DATA related quantity can be requested, the
105 // corresponding FLAG and FLAG_ROW columns are read automatically.
106 // Reorder the data to 4d with ifr and time axis if ifrAxis is True.
107 Bool fillDataBuffer(const String& item, Bool ifrAxis);
108
109 // Difference the data, subtracting the average over a window of
110 // specified width and taking the absolute value. Complex quantities are
111 // turned into the corresponding amplitude after differencing.
112 // If doMedian==True the median difference is returned for window>2.
113 // For a window width of one, the previous sample is
114 // subtracted, giving a derivative like quantity.
115 // Note that the subtraction is done on row-by-row basis for TIME
116 // differencing, it is up to you to select a single baseline (if
117 // you didn't use ifrAxis=True in fillDataBuffer).
118 // Available directions are: TIME, CHANNEL
119 // Returns statistics over the buffer: median for times and channels,
120 // average absolute deviation over times, channels and all pixels.
121 Record diffDataBuffer(const String& direction, Int window = 1, Bool doMedian = False);
122
123 // Return the contents of the internal data buffer, including the flags
124 // as a Record
126
127 // Clip the data buffer at a specified level by setting the corresponding
128 // flags in the buffer. The cliplevel is specified as a multiple of
129 // the average absolute deviations returned by diffDataBuffer.
130 // A value of zero or less will skip the corresponding clip operation.
131 // Clipping will be done repeatedly, recalculating the deviations, until
132 // no more points are clipped.
133 Bool clipDataBuffer(Float pixelLevel, Float timeLevel, Float channelLevel);
134
135 // Replace the flags in the buffer with those in the supplied record.
136 // This allows interactive flagging from glish to be written back to the
137 // buffer for subsequent operations. The record should contain a
138 // flag and flag_row field.
140
141 // Write the flags in the buffer back to the table
143
144 // Clear the internal data buffer, reclaiming memory
146 buffer_p = Record();
147 return True;
148 }
149
150 // Create the FLAG_HISTORY column and initialize it from the
151 // FLAG_ROW and FLAG columns. Returns False if FLAG_HISTORY already exists.
152 // The first flagging bit is filled with the flags as found in the MS,
153 // subsequent bits can be used for user generated flags.
155
156 // Apply the flags in the FLAG_HISTORY column to the FLAG and FLAG_ROW
157 // columns. Returns False if FLAG_HISTORY doesn't exist.
158 // The default argument will apply the currently active flag level
159 // (as specified by the FLAG_LEVEL column keyword).
160 // Sets the current level to the flag level restored.
161 Bool restoreFlags(Int level = -1);
162
163 // Save the current flags to the FLAG_HISTORY. Save to the currently
164 // active level or (newLevel=True) the next highest level (if available).
165 // Will reset the current level to the level saved to.
166 Bool saveFlags(Bool newLevel);
167
168 // Return the current flaglevel (value of FLAG_LEVEL keyword)
170
171 protected:
172 // fill the FLAG_HISTORY column from the FLAG and FLAG_ROW column
173 void fillFlagHist(Int nHis, Int numCorr, Int numChan, Table& tab);
174
175 // find the HypercubeId column for a tiled column (if any)
176 Bool findHypercubeId(String& hyperCubeId, const String& column, const Table& tab);
177
178 // copy the flags to the flag history
179 void saveToFlagHist(Int level, Table& tab);
180
181 // copy the flag history back to the flags
182 void applyFlagHist(Int level, Table& tab);
183
184 // get buffer statistics - med=median, ad=average absolute deviation,
185 // T=Time, F=Frequency.
186 void getStats(Array<Float>& medTF, Array<Float>& adTF, Array<Float>& medT, Array<Float>& medFmedT,
187 Array<Float>& adT, Array<Float>& medF, Array<Float>& medTmedF, Array<Float>& adF,
188 const Array<Float>& diff, const Array<Bool>& flag, const Array<Bool>& flagRow);
189
190 // add the statistics to a buffer
191 void addStats(Record& buf, const Array<Bool>& flag, const Array<Bool> flagRow,
192 const Array<Float>& data);
193
194 // reorder from 2d to 1d (removing ifr axis)
196
197 // collapse array "in" (with absolute differences)
198 // along specified axis by taking medians by profile taking into account
199 // the flags.
200 void diffMedian(Array<Float>& out, const Array<Float>& in, Int axis, const Array<Bool>& flag);
201
202 // apply the row flags to the data flags and v.v.
203 void applyRowFlags(Array<Bool>& flag, Array<Bool>& flagRow);
204
205 // check if we are attached to an MSSelector
207
208 private:
211};
212
213} // namespace casacore
214
215#endif
void setMSSelector(MSSelector &msSel)
Change or Set the MS this MSFlagger refers to.
Bool fillDataBuffer(const String &item, Bool ifrAxis)
Fill an internal buffer with the data item requested, similar to getData except that the data is not ...
Bool saveFlags(Bool newLevel)
Save the current flags to the FLAG_HISTORY.
Bool restoreFlags(Int level=-1)
Apply the flags in the FLAG_HISTORY column to the FLAG and FLAG_ROW columns.
MSSelector * msSel_p
Definition MSFlagger.h:209
Bool writeDataBufferFlags()
Write the flags in the buffer back to the table.
void diffMedian(Array< Float > &out, const Array< Float > &in, Int axis, const Array< Bool > &flag)
collapse array "in" (with absolute differences) along specified axis by taking medians by profile tak...
MSFlagger & operator=(const MSFlagger &other)
Assignment.
Bool findHypercubeId(String &hyperCubeId, const String &column, const Table &tab)
find the HypercubeId column for a tiled column (if any)
void applyRowFlags(Array< Bool > &flag, Array< Bool > &flagRow)
apply the row flags to the data flags and v.v.
Bool createFlagHistory(Int nHis=2)
Create the FLAG_HISTORY column and initialize it from the FLAG_ROW and FLAG columns.
void addStats(Record &buf, const Array< Bool > &flag, const Array< Bool > flagRow, const Array< Float > &data)
add the statistics to a buffer
void fillFlagHist(Int nHis, Int numCorr, Int numChan, Table &tab)
fill the FLAG_HISTORY column from the FLAG and FLAG_ROW column
Bool check()
check if we are attached to an MSSelector
void saveToFlagHist(Int level, Table &tab)
copy the flags to the flag history
MSFlagger(const MSFlagger &other)
Copy constructor.
MSFlagger(MSSelector &msSel)
construct from an MSSelector object
Bool clearDataBuffer()
Clear the internal data buffer, reclaiming memory.
Definition MSFlagger.h:145
void applyFlagHist(Int level, Table &tab)
copy the flag history back to the flags
Record diffDataBuffer(const String &direction, Int window=1, Bool doMedian=False)
Difference the data, subtracting the average over a window of specified width and taking the absolute...
void getStats(Array< Float > &medTF, Array< Float > &adTF, Array< Float > &medT, Array< Float > &medFmedT, Array< Float > &adT, Array< Float > &medF, Array< Float > &medTmedF, Array< Float > &adF, const Array< Float > &diff, const Array< Bool > &flag, const Array< Bool > &flagRow)
get buffer statistics - med=median, ad=average absolute deviation, T=Time, F=Frequency.
Int flagLevel()
Return the current flaglevel (value of FLAG_LEVEL keyword).
void reorderFlagRow(Array< Bool > &flagRow)
reorder from 2d to 1d (removing ifr axis)
Record getDataBuffer()
Return the contents of the internal data buffer, including the flags as a Record.
Definition MSFlagger.h:125
Bool clipDataBuffer(Float pixelLevel, Float timeLevel, Float channelLevel)
Clip the data buffer at a specified level by setting the corresponding flags in the buffer.
Bool setDataBufferFlags(const Record &flags)
Replace the flags in the buffer with those in the supplied record.
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
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