casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Flagger.h
Go to the documentation of this file.
1 //# Flagger.h: this defines Flagger
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: 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 #ifndef FLAGGING_FLAGGER_H
28 #define FLAGGING_FLAGGER_H
29 
33 
35 #include <ms/MSSel/MSSelection.h>
39 #include <casa/Logging/LogIO.h>
40 #include <casa/Arrays/Vector.h>
41 #include <casa/Containers/Record.h>
42 #include <casa/Quanta/Quantum.h>
43 
44 namespace casa { //# NAMESPACE CASA - BEGIN
45 
46 class VisSet;
47 class RFChunkStats;
48 
49 // <summary>
50 // Flagger: high-performance automated flagging
51 // </summary>
52 
53 // <use visibility=global>
54 
55 // <reviewed reviewer="" date="" tests="" demos="">
56 // </reviewed>
57 
58 // <prerequisite>
59 // <li> implement/Flagger
60 // </prerequisite>
61 //
62 // <etymology>
63 // casacore::MSFlagger and plain flagger were already taken.
64 // </etymology>
65 //
66 // <synopsis>
67 // Flagger performs automated flagging operations on a measurement set.
68 // The class is constructed from an MS. After that, the run method may be used
69 // to run any number of flagging agents.
70 // </synopsis>
71 //
72 // <example>
73 // // construct casacore::MS and flagger
74 // casacore::MeasurementSet ms("test.MS2",casacore::Table::Update);
75 // Flagger flagger(ms);
76 // // build record of global flagging options
77 // casacore::Record opt(casacore::Record::Variable);
78 // // build record of flagging agents to be run
79 // casacore::Record selopt( flagger.defaultAgents().asRecord("select") );
80 // selopt.define(RF_POLICY,"RESET");
81 // selopt.define(RF_AUTOCORR,true);
82 // casacore::Record agents(casacore::Record::Variable);
83 // agents.defineRecord("select",selopt);
84 // // perform the flagging
85 // flagger.run(agents,opt);
86 // </example>
87 //
88 // <motivation>
89 // We need an automated flagging tool. Existing tools (casacore::MSFlagger and flagger.g)
90 // were too slow. Hence, Flagger was developed.
91 // </motivation>
92 //
93 // <todo asof="2001/04/16">
94 // <li> add this feature
95 // <li> fix this bug
96 // <li> start discussion of this possible extension
97 // </todo>
98 
99 
100 class Flagger : public FlaggerEnums
101 {
102 protected:
103 // creates an agent by name
104  std::shared_ptr<RFABase> createAgent ( const casacore::String &name,RFChunkStats &chunk,const casacore::RecordInterface &parms, bool &only_selector );
105 
106 // sets up record of agents and default parameters
108 
109 // print flagging reports from individual agents
110  void printAgentReports ( );
111 
112  void printSummaryReport ( RFChunkStats &chunk );
114 
117  std::vector<std::shared_ptr<RFABase> > acc;
118 
119  //new added
122  bool scan_looping; /* Is scan number part of visiter looping? */
128 
129 // casacore::Vector<casacore::Int> dataEnd_p;
130 // casacore::Vector<casacore::Int> dataStart_p, dataStep_p;
131 // casacore::Vector<casacore::Int> dataspectralwindowids_p;
132 // casacore::Vector<casacore::Int> spwidnchans_p;
138 
139  //
144 
146 
148 
149 public:
150 // default constructor
151  Flagger ();
152 // construct and attach to a measurement set
154 
155  ~Flagger ();
156 
157 // Change or set the casacore::MS this Flagger refers to.
158  bool attach( casacore::MeasurementSet &ms, casacore::Bool setupAgentDefaults=true );
159 
160  // Set the data selection parameters
161  casacore::Bool selectdata(casacore::Bool useoriginalms=false,
163  casacore::String baseline="", casacore::String uvrange="", casacore::String time="",
164  casacore::String correlation="", casacore::String intent="", casacore::String observation="");
165 
166  // Make a data selection
169  casacore::String correlation, casacore::String intent, casacore::String observation="");
170 
171  // Make a selection for manual flagging
173  casacore::Bool unflag,
174  casacore::String clipexpr,
176  casacore::String clipcolumn,
177  casacore::Bool outside,
178  casacore::Bool channel_average,
179  casacore::Double quackinterval=0.0,
180  casacore::String quackmode=casacore::String("beg"),
181  casacore::Bool quackincrement=casacore::Bool(false),
182  casacore::String opmode=casacore::String("flag"),
183  casacore::Double diameter = -1.0,
184  casacore::Double lowerlimit = -1.0,
185  casacore::Double upperlimit = 91.0);
186 
187  // Clean up all agents of type "select".
188  //casacore::Bool clearflagselections(casacore::Vector<casacore::Int> &recordlist,casacore::Vector<casacore::String> &agentlist);
191 
192  // Fill the selection record to attach to the list of agents
194 
195  // Set autoflag params
197 
198  // Get default autoflag params
200 
202 
203  // Detaches from the casacore::MS
204  void detach();
205 
207 
208  void summary ( const casacore::RecordInterface &agents );
209 
210  // flag version support.
215 
216 
217  // returns current MS
218  const casacore::MeasurementSet & measSet() const { return ms; }
219 
220 // number of antennas in MS
222  { return nant; };
223 
224 // number of IFRs in MS
226  { return nifr; };
227 
228 // number of feeds in MS
230  { return nfeed; };
231 
232 // number of feed correlations in MS
234  { return nfeedcorr; };
235 
236 // names of antennas
238  { return antnames; };
239 
240 // derives a flat IFR index from two antenna indices
242 
243 // vector version of above
245 
246 // derives antenna indices from a flat IFR index
247  void ifrToAnt ( casacore::uInt &ant1,casacore::uInt &ant2,casacore::uInt ifr ) const;
248 
249 // returns a record with all available agents and their default options
251  { return agent_defaults; }
252 
253 // returns a record of available options
254  static const casacore::RecordInterface & defaultOptions ();
255 
256 // returns the log sink
257  static casacore::LogIO & logSink () { return os; }
258 
259  /* Get rid of negative indices (meaning negation of antenna) in baselinelist */
260  static void reform_baselinelist(casacore::Matrix<casacore::Int> &baselinelist, unsigned nant);
261 
262  static int my_aipspp_sum(const casacore::Array<casacore::Bool> &a);
263 
264 private:
265 
266  Flagger( const Flagger & ) {};
267 
268  Flagger& operator=(const Flagger &) { return *this; };
269 
271 
272  // Sink used to store history
274 
275  // Hold the original ms
277 
278  // casacore::MS Selection
280  bool spw_selection; //non-trivial spw-selection
281 
282  // casacore::List of Agents
285 
286  // casacore::List of extra options
288 
289  // Debug Message flag
290  static const bool dbg;
291 
293  /* More initialization is required, if there exists a quacking agent */
294 };
295 
296 
297 } //# NAMESPACE CASA - END
298 
299 #endif
300 
casacore::uInt nifr
Definition: Flagger.h:140
casacore::Bool nullSelect_p
Definition: Flagger.h:124
casacore::uInt ifrNumber(casacore::Int ant1, casacore::Int ant2) const
derives a flat IFR index from two antenna indices
Flagger()
default constructor
casacore::Record * opts_p
casacore::List of extra options
Definition: Flagger.h:287
casacore::Bool setmanualflags(casacore::Bool autocorr, casacore::Bool unflag, casacore::String clipexpr, casacore::Vector< casacore::Double > cliprange, casacore::String clipcolumn, casacore::Bool outside, casacore::Bool channel_average, casacore::Double quackinterval=0.0, casacore::String quackmode=casacore::String("beg"), casacore::Bool quackincrement=casacore::Bool(false), casacore::String opmode=casacore::String("flag"), casacore::Double diameter=-1.0, casacore::Double lowerlimit=-1.0, casacore::Double upperlimit=91.0)
Make a selection for manual flagging.
int Int
Definition: aipstype.h:50
casacore::Vector< casacore::Double > spwfreqs
Definition: Flagger.h:143
casacore::Vector< casacore::Int > datafieldids_p
Definition: Flagger.h:134
const casacore::RecordInterface & defaultAgents() const
returns a record with all available agents and their default options
Definition: Flagger.h:250
casacore::Record agent_defaults
Definition: Flagger.h:145
virtual void reset()
Overrides PlotTool::reset().
casacore::Vector< casacore::String > correlations_p
casacore::Vector&lt;casacore::Int&gt; dataEnd_p; casacore::Vector&lt;casacore::Int&gt; dataStart_p, dataStep_p; casacore::Vector&lt;casacore::Int&gt; dataspectralwindowids_p; casacore::Vector&lt;casacore::Int&gt; spwidnchans_p;
Definition: Flagger.h:133
casacore::Bool selectdata_p
Definition: Flagger.h:126
casacore::LogSink logSink_p
Sink used to store history.
Definition: Flagger.h:273
casacore::Bool getFlagVersionList(casacore::Vector< casacore::String > &verlist)
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
bool spw_selection
Definition: Flagger.h:280
casacore::Bool setdata(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String baseline, casacore::String uvrange, casacore::String time, casacore::String correlation, casacore::String intent, casacore::String observation="")
Make a data selection.
ABSTRACT TOOL CLASSES A PlotTool is a higher level event handler for a PlotCanvas The idea is to take common tasks which may require multiple events and put them in one place PlotTools also provide additional functionality in that they can be active and blocking non blocking The PlotCanvas will only send events to active and will not send events to later tools or event handlers if the latest tool was blocking In this way a single tool can be used to handle ALL user interaction via the GUI at one time
Definition: PlotTool.h:43
casacore::Bool addAgent(casacore::RecordInterface &newAgent)
casacore::Bool saveFlagVersion(casacore::String versionname, casacore::String comment, casacore::String merge)
flag version support.
const casacore::Vector< casacore::String > & antNames() const
names of antennas
Definition: Flagger.h:237
ostream-like interface to creating log messages.
Definition: LogIO.h:167
A Measure: radial velocity.
casacore::uInt numFeedCorr() const
number of feed correlations in MS
Definition: Flagger.h:233
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
static const casacore::RecordInterface & defaultOptions()
returns a record of available options
static casacore::LogIO os
Definition: Flagger.h:147
casacore::Bool fillSelections(casacore::Record &rec)
Fill the selection record to attach to the list of agents.
casacore::Vector< casacore::Int > datadescids_p
Definition: Flagger.h:135
casacore::MeasurementSet * mssel_p
new added
Definition: Flagger.h:120
bool scan_looping
Definition: Flagger.h:122
void detach()
Detaches from the casacore::MS.
casacore::Vector< casacore::String > antnames
Definition: Flagger.h:142
void ifrToAnt(casacore::uInt &ant1, casacore::uInt &ant2, casacore::uInt ifr) const
derives antenna indices from a flat IFR index
VisSet * vs_p
Definition: Flagger.h:121
casacore::Record run(casacore::Bool trial, casacore::Bool reset)
casacore::uInt numFeed() const
number of feeds in MS
Definition: Flagger.h:229
std::shared_ptr< RFABase > createAgent(const casacore::String &name, RFChunkStats &chunk, const casacore::RecordInterface &parms, bool &only_selector)
creates an agent by name
casacore::Int agentCount_p
Definition: Flagger.h:284
casacore::MeasurementSet ms
Definition: Flagger.h:115
casacore::uInt nfeedcorr
Definition: Flagger.h:140
double Double
Definition: aipstype.h:55
casacore::MSSelection * msselection_p
casacore::MS Selection
Definition: Flagger.h:279
casacore::Vector< casacore::Int > ifr2ant1
Definition: Flagger.h:141
std::vector< std::shared_ptr< RFABase > > acc
Definition: Flagger.h:117
casacore::Vector< casacore::Int > ifr2ant2
Definition: Flagger.h:141
casacore::String dataMode_p
Definition: Flagger.h:127
const casacore::RecordInterface & setupAgentDefaults()
sets up record of agents and default parameters
casacore::Bool setautoflagparams(casacore::String algorithm, casacore::Record &parameters)
Set autoflag params.
void printSummaryReport(RFChunkStats &chunk)
casacore::Bool printflagselections()
MSSelection: Class to represent a selection on an MS.
Definition: MSSelection.h:118
Flagger: high-performance automated flagging.
Definition: Flagger.h:100
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
Flagger(const Flagger &)
Definition: Flagger.h:266
casacore::Bool setdata_p
Definition: Flagger.h:125
casacore::Bool clearflagselections(casacore::Int recordindex)
Clean up all agents of type &quot;select&quot;.
casacore::Bool selectdata(casacore::Bool useoriginalms=false, casacore::String field="", casacore::String spw="", casacore::String array="", casacore::String feed="", casacore::String scan="", casacore::String baseline="", casacore::String uvrange="", casacore::String time="", casacore::String correlation="", casacore::String intent="", casacore::String observation="")
Set the data selection parameters.
casacore::uInt numAnt() const
number of antennas in MS
Definition: Flagger.h:221
static void reform_baselinelist(casacore::Matrix< casacore::Int > &baselinelist, unsigned nant)
casacore::Record * agents_p
casacore::List of Agents
Definition: Flagger.h:283
A Table intended to hold astronomical data (a set of Measurements).
casacore::String msname_p
Definition: Flagger.h:123
FlaggerEnums: collection of enums for various flagger classes.
Definition: RFCommon.h:126
casacore::uInt nant
Definition: Flagger.h:140
casacore::uInt nfeed
Definition: Flagger.h:140
casacore::Bool restoreFlagVersion(casacore::Vector< casacore::String > versionname, casacore::String merge)
static const bool dbg
Debug Message flag.
Definition: Flagger.h:290
void printAgentReports()
print flagging reports from individual agents
static casacore::LogIO & logSink()
returns the log sink
Definition: Flagger.h:257
Flagger & operator=(const Flagger &)
Definition: Flagger.h:268
static int my_aipspp_sum(const casacore::Array< casacore::Bool > &a)
const casacore::MeasurementSet & measSet() const
returns current MS
Definition: Flagger.h:218
Distribute LogMessages to their destination(s)
Definition: LogSink.h:141
casacore::Record getautoflagparams(casacore::String algorithm)
Get default autoflag params.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Bool deleteFlagVersion(casacore::Vector< casacore::String > versionname)
RFChunkStats: vital information and flagging stats for a visibility chunk.
Definition: RFChunkStats.h:89
casacore::MeasurementSet * originalms_p
Hold the original ms.
Definition: Flagger.h:276
casacore::Vector< casacore::Int > ifrNumbers(casacore::Vector< casacore::Int > ant1, casacore::Vector< casacore::Int > ant2) const
vector version of above
bool attach(casacore::MeasurementSet &ms, casacore::Bool setupAgentDefaults=true)
Change or set the casacore::MS this Flagger refers to.
Abstract base class for Record classes.
Subchunk class Provides the ordered pair identifying the current subchunk The first component is the chunk(goes from 0 to nChunks-1 during the outer loop iteration).The second component is the subchunk number which is zero after VisibilityIterator
void summary(const casacore::RecordInterface &agents)
casacore::Bool selectDataChannel()
casacore::Bool quack_agent_exists
Definition: Flagger.h:292
casacore::uInt numIfr() const
number of IFRs in MS
Definition: Flagger.h:225
casacore::MeasurementSet originalms
Definition: Flagger.h:116
casacore::MRadialVelocity mDataStart_p
Definition: Flagger.h:136
unsigned int uInt
Definition: aipstype.h:51
casacore::MRadialVelocity mDataStep_p
Definition: Flagger.h:137
void printAgentRecord(casacore::String &, casacore::uInt, const casacore::RecordInterface &)