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
85{
86public:
88
89 // construct from an MSSelector object
91
92 // Copy constructor
93 MSFlagger(const MSFlagger& other);
94
95 // Assignment
97
99
100 // Change or Set the MS this MSFlagger refers to.
102
103 // Fill an internal buffer with the data item requested, similar to getData
104 // except that the data is not returned, but kept around for further
105 // processing. Only a single DATA related quantity can be requested, the
106 // corresponding FLAG and FLAG_ROW columns are read automatically.
107 // Reorder the data to 4d with ifr and time axis if ifrAxis is True.
108 Bool fillDataBuffer(const String& item, Bool ifrAxis);
109
110 // Difference the data, subtracting the average over a window of
111 // specified width and taking the absolute value. Complex quantities are
112 // turned into the corresponding amplitude after differencing.
113 // If doMedian==True the median difference is returned for window>2.
114 // For a window width of one, the previous sample is
115 // subtracted, giving a derivative like quantity.
116 // Note that the subtraction is done on row-by-row basis for TIME
117 // differencing, it is up to you to select a single baseline (if
118 // you didn't use ifrAxis=True in fillDataBuffer).
119 // Available directions are: TIME, CHANNEL
120 // Returns statistics over the buffer: median for times and channels,
121 // average absolute deviation over times, channels and all pixels.
122 Record diffDataBuffer(const String& direction, Int window=1,
123 Bool doMedian = False);
124
125 // Return the contents of the internal data buffer, including the flags
126 // as a Record
128 { return buffer_p;}
129
130 // Clip the data buffer at a specified level by setting the corresponding
131 // flags in the buffer. The cliplevel is specified as a multiple of
132 // the average absolute deviations returned by diffDataBuffer.
133 // A value of zero or less will skip the corresponding clip operation.
134 // Clipping will be done repeatedly, recalculating the deviations, until
135 // no more points are clipped.
136 Bool clipDataBuffer(Float pixelLevel, Float timeLevel, Float channelLevel);
137
138 // Replace the flags in the buffer with those in the supplied record.
139 // This allows interactive flagging from glish to be written back to the
140 // buffer for subsequent operations. The record should contain a
141 // flag and flag_row field.
143
144 // Write the flags in the buffer back to the table
146
147 // Clear the internal data buffer, reclaiming memory
150
151 // Create the FLAG_HISTORY column and initialize it from the
152 // FLAG_ROW and FLAG columns. Returns False if FLAG_HISTORY already exists.
153 // The first flagging bit is filled with the flags as found in the MS,
154 // subsequent bits can be used for user generated flags.
156
157 // Apply the flags in the FLAG_HISTORY column to the FLAG and FLAG_ROW
158 // columns. Returns False if FLAG_HISTORY doesn't exist.
159 // The default argument will apply the currently active flag level
160 // (as specified by the FLAG_LEVEL column keyword).
161 // Sets the current level to the flag level restored.
163
164 // Save the current flags to the FLAG_HISTORY. Save to the currently
165 // active level or (newLevel=True) the next highest level (if available).
166 // Will reset the current level to the level saved to.
167 Bool saveFlags(Bool newLevel);
168
169 // Return the current flaglevel (value of FLAG_LEVEL keyword)
171
172protected:
173 // fill the FLAG_HISTORY column from the FLAG and FLAG_ROW column
174 void fillFlagHist(Int nHis, Int numCorr, Int numChan, Table& tab);
175
176 // find the HypercubeId column for a tiled column (if any)
177 Bool findHypercubeId(String& hyperCubeId, const String& column,
178 const Table& tab);
179
180 // copy the flags to the flag history
181 void saveToFlagHist(Int level, Table& tab);
182
183 // copy the flag history back to the flags
184 void applyFlagHist(Int level, Table& tab);
185
186 // get buffer statistics - med=median, ad=average absolute deviation,
187 // T=Time, F=Frequency.
188 void getStats(Array<Float>& medTF, Array<Float>& adTF,
189 Array<Float>& medT, Array<Float>& medFmedT,
190 Array<Float>& adT, Array<Float>& medF,
191 Array<Float>& medTmedF, Array<Float>& adF,
192 const Array<Float>& diff, const Array<Bool>& flag,
193 const Array<Bool>& flagRow);
194
195 // add the statistics to a buffer
196 void addStats(Record& buf, const Array<Bool>& flag,
197 const Array<Bool> flagRow, const Array<Float>& data);
198
199 // reorder from 2d to 1d (removing ifr axis)
201
202 // collapse array "in" (with absolute differences)
203 // along specified axis by taking medians by profile taking into account
204 // the flags.
205 void diffMedian(Array<Float>& out, const Array<Float>& in,
206 Int axis, const Array<Bool>& flag);
207
208 // apply the row flags to the data flags and v.v.
209 void applyRowFlags(Array<Bool>& flag, Array<Bool>& flagRow);
210
211 // check if we are attached to an MSSelector
213
214private:
217};
218
219
220} //# NAMESPACE CASACORE - END
221
222#endif
223
224
225
226
227
228
229
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:215
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:148
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:127
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:223
this file contains all the compiler specific defines
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