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