casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AgentFlagger.h
Go to the documentation of this file.
1 //# AgentFlagger.h: this defines AgentFlagger
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 
30 #include <casa/Logging/LogIO.h>
31 #include <casa/Arrays/Vector.h>
32 #include <casa/Containers/Record.h>
33 
34 // This is needed for FlagAgentList, which should probably go into a separate header
36 
37 // To handle variant parameters
39 
40 namespace casa { //# NAMESPACE CASA - BEGIN
41 
42 class FlagAgentSummary;
43 class FlagDataHandler;
44 
45 #if ! defined(WITHOUT_DBUS)
46 class FlagAgentDisplay;
47 #endif
48 
49 // <summary>
50 // AgentFlagger: 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> <linkto class="FlagDataHandler:description">FlagDataHandler</linkto>
60 // <li> <linkto class="FlagMSHandlerr:description">FlagMSHandler</linkto>
61 // <li> <linkto class="FlagCalTableHandler:description">FlagCalTableHandler</linkto>
62 // </prerequisite>
63 //
64 // <etymology>
65 //
66 // </etymology>
67 //
68 // <synopsis>
69 // AgentFlagger performs automated flagging operations on a measurement set or calibration
70 // table. The class is constructed from an casacore::MS or cal table. After that, the run method may be used
71 // to run any number of flagging agents.
72 // </synopsis>
73 //
74 // <example>
75 // <srcblock>
76 // // The following is a typical way of using this class and its methods to perform flagging.
77 //
78 // // Open the casacore::MS or a calibration file and attach it to the tool. This will create an object of the
79 // // FlagDataHandler (fdh) type. The constructor of the fdh takes three arguments,
80 // // the casacore::MS or CAL table, the iteration approach to use and the time interval. Only the MS
81 // // is mandatory to use. By default it will use the FlagDataHandler::SUB_INTEGRATION iteration
82 // // approach and 0.0 seconds as the time interval.
83 //
84 // AgentFlagger *tf = new AgentFlagger();
85 // af->open('my.ms')
86 //
87 // // Select the data where to flag. If left blank, the whole casacore::MS will be selected. This step
88 // // will use the casacore::MS Selection class. There are two methods to perform the selection. One takes
89 // // a casacore::Record of the parameters, the other takes the individual parameters as arguments.
90 //
91 // // 1) First method:
92 // casacore::String spw = "0:1~10";
93 // casacore::String scan = "1";
94 // casacore::Record selection = casacore::Record();
95 // selection.define("spw", spw);
96 // selection.define("scan", scan);
97 // af->selectData(selection);
98 //
99 // // 2) Second method:
100 // af->selectData(spw=spw, scan=scan);
101 //
102 // // Now it is time to build a list of the agents that we want to run to process the data. This
103 // // step will create a list of all the agents that will be executed to flag/unflag the data.
104 // // This method can be called multiple times. Every call should contain the desired parameters of
105 // // the agent and optionally data selection parameters. When data selection parameters are present,
106 // // the agent will loop through only that portion of the data.
107 //
108 // // This method will check if the requested agent (mode) is known from the following list
109 // // (manual, clip, quack, shadow, elevation, tfcrop, rflag, extend, unflag, summary, and antint). If
110 // // empty or unknown, it will give a warning and return.
111 //
112 // // If any tfcrop, rflag or extend mode is present, this method will calculate the maximum value
113 // // of time interval (ntime) from these agents. The maximum value will be used for all agents in
114 // // the list.
115 //
116 // // A similar situation will happen with the combinescans parameter. If any of the combinescans is
117 // // true, it will be taken as true to all agents.
118 //
119 // // Async I/O will be activated if any of the modes clip, tfcrop or rflag is requested. Also for
120 // // these three modes, there will be a call to a function that will validate the requested
121 // // datacolumn parameter. It will detect if the input is an casacore::MS or a cal table and validate the
122 // // column. The default is the DATA column. If the input is a cal table, the function will
123 // // first check if FPARAM is available, then CPARAM. If none of them is available it will return
124 // // false and the agent will not be created.
125 //
126 // // Only for the tfcrop agent, if a correlation ALL is requested, this method will create one
127 // // agent for each available polarization in the MS. For example, if the casacore::MS contains polarizations
128 // // XX and YY and the parameter is correlation="ABS_ALL", then there will be two tfcrop agents,
129 // // one with correlation="ABS_XX" and the other with correlation="ABS_YY". The apply parameter
130 // // is set by default to true to apply the flags.
131 //
132 // casacore::Record agent_pars = casacore::Record();
133 // agent_pars.define("mode", "clip");
134 // agent_pars.define("clipzeros", true);
135 // agent_pars.define("apply", true);
136 // af->parseAgentParameters(agent_pars);
137 //
138 // casacore::Record agent_pars = casacore::Record();
139 // agent_pars.define("mode", "manual");
140 // agent_pars.define("autocorr", true);
141 // af->parseAgentParameters(agent_pars);
142 //
143 // casacore::Record agent_pars = casacore::Record();
144 // agent_pars.define("mode", "summary");
145 // agent_pars.define("basecnt", true);
146 // af->parseAgentParameters(agent_pars);
147 //
148 // // There are convenience functions to parse the agent's parameters, one specific for each agent.
149 // // The above calls can also be done using these functions instead.
150 //
151 // af->parseClipParameters(clipzeros=true, apply=true);
152 // af->parseManualParameters(autocorr=true);
153 // af->parseSummaryParameters(basecnt=true);
154 //
155 // // In either one of the cases, three agents will be created.
156 // //
157 // // NOTE: it is possible to add multiple summary agents to the list and gather a list of summary
158 // // reports when executing the tool.
159 //
160 // // We need to initialize the agents, which
161 // // will call the constructor of each one of them and set the parameters that were given in the previous
162 // // calls. Some basic checks will be performed at this stage for types and values of the parameters.
163 //
164 // // If any tfcrop, rflag, extend or display agent is in the list, the iteration approach will be
165 // // set to a different value depending on whether combinescans is true or not. When true, the
166 // // iteration approach will be set to FlagDataHandler::COMBINE_SCANS_MAP_ANTENNA_PAIRS_ONLY, otherwise
167 // // to FlagDataHandler::COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY.
168 //
169 // // This method will create agents and add them to a FlagAgentList. If for any reason, the call to
170 // // FlagAgentBase::create(fdh_p, agent_rec) fails, an error message will be displayed. Any agents previously
171 // // added to the FlagAgentList will remain there. A subsequent call to this method can be done to add
172 // // more agents to the same FlagAgentList.
173 //
174 // af->initAgents();
175 //
176 // // Before next step which will write the new flags, it is advisable to create a backup of
177 // // the current flags in the MS.
178 //
179 // af.saveflagversion(versionname='backup_before_manual_1',
180 // comment='Backup of flags before running manual',merge='replace')
181 //
182 // // The next step in the chain is to actually process the flags and write them or
183 // // not to the MS. The run method takes two parameters, writeflags and sequential.
184 // // The parameter writeflags controls whether to write the flags or not to the MS.
185 // // By default it is set to true. Setting writeflags to false is useful when one
186 // // wants to run the tool together with the display agent to see what is going to be
187 // // flagged before deciding to write or not to the MS. The sequential parameter
188 // // controls if the order of the agent's list needs to be preserved or not. If set to false,
189 // // the order will not be preserved and the framework may execute the agent's list in parallel.
190 // // By default sequential is set to true.
191 //
192 // // The run method gathers several reports, depending on which agents are run. The display and summary agents
193 // // produce reports that can be retrieved from calling the run method. The reports are returned via a Record
194 // // that may contain multiple reports at the same time.
195 
196 // casacore::Record myReports;
197 // myReports = af->run();
198 //
199 // // To destroy the tool, call a method to execute the destructor.
200 //
201 // af->done();
202 //
203 // </srcblock>
204 // </example>
205 //
206 // <motivation>
207 // To flag data using different algorithms.
208 // </motivation>
209 //
210 
211 
213 {
214 protected:
215 
217 
218  // variables used to initialize the FlagDataHandler
223 
224 
225  // members to parse to selectData
238 
239  // agent's members
245 
246  // true if there are apply and unapply parameters in the list
248 
249  // Display agent parameters
250 #if ! defined(WITHOUT_DBUS)
252 #endif
253 
254  // variables for initAgents
256  std::vector<casacore::Record> agents_config_list_p;
257  std::vector<casacore::Record> agents_config_list_copy_p;
259 
260 public:
261  // default constructor
262  AgentFlagger();
263 
264  // destructor
265  ~AgentFlagger();
266 
267  // reset everything
268  void done();
269 
270  // configure the tool, open the MS
271  bool open(casacore::String msname, casacore::Double ntime);
272 
273  // parse the data selection
274  bool selectData(casacore::Record selrec);
276  casacore::String antenna, casacore::String uvrange, casacore::String timerange,
277  casacore::String correlation, casacore::String intent, casacore::String observation="");
278 
279  // parse the parameters of the agent
280  bool parseAgentParameters(casacore::Record agent_params);
283 
284  // initialize the agents list
285  bool initAgents();
286 
287  // Run the tool and write the flags to the MS
288  casacore::Record run(casacore::Bool writeflags, casacore::Bool sequential=true);
289 
290  // Flag backup methods
291  bool printFlagSelections();
292  bool saveFlagVersion(casacore::String versionname, casacore::String comment, casacore::String merge);
296 
297  // Agent's specific parsing methods (for convenience only)
298  // Parse parameters for manual
300  casacore::String antenna, casacore::String uvrange, casacore::String timerange,casacore::String correlation,
301  casacore::String intent, casacore::String observation, casacore::Bool autocorr, casacore::Bool apply);
302 
303  // Parse parameters for clip
305  casacore::String antenna, casacore::String uvrange, casacore::String timerange,casacore::String correlation,
306  casacore::String intent, casacore::String observation, casacore::String datacolumn,
307  casacore::Vector<casacore::Double> clipminmax, casacore::Bool clipoutside, casacore::Bool channelavg, casac::variant chanbin, casacore::Bool timeavg,
309 
310  // Parse parameters for quack
312  casacore::String antenna, casacore::String uvrange, casacore::String timerange,casacore::String correlation,
313  casacore::String intent, casacore::String observation, casacore::String quackmode, casacore::Double quackinterval,
314  casacore::Bool quackincrement, casacore::Bool apply);
315 
316  // Parse parameters for elevation
318  casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation,
319  casacore::String intent, casacore::String observation, casacore::Double lowerlimit, casacore::Double upperlimit,
321 
322  // Parse parameters for tfcrop
324  casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation,
325  casacore::String intent, casacore::String observation, casacore::Double ntime, casacore::Bool combinescans,
326  casacore::String datacolumn, casacore::Double timecutoff, casacore::Double freqcutoff, casacore::String timefit,
327  casacore::String freqfit, casacore::Int maxnpieces, casacore::String flagdimension, casacore::String usewindowstats,
328  casacore::Int halfwin, casacore::Bool extendflags, casacore::Bool apply, casacore::Bool channelavg, casac::variant chanbin, casacore::Bool timeavg,
329  casacore::String timebin);
330 
331  // Parse parameters for the 'antint' mode (antenna integrations)
334  casacore::String scan, casacore::String antenna,
335  casacore::String uvrange, casacore::String timerange,
336  casacore::String correlation, casacore::String intent,
337  casacore::String observation,
338  casacore::String antint_ref_antenna,
339  casacore::Double minchanfrac,
341 
342  // Parse parameters for extend
344  casacore::String scan="", casacore::String antenna="", casacore::String uvrange="", casacore::String timerange="", casacore::String correlation="",
345  casacore::String intent="", casacore::String observation="", casacore::Double ntime=0.0, casacore::Bool combinescans=false,
346  casacore::Bool extendpols=true, casacore::Double growtime=50.0, casacore::Double growfreq=50.0, casacore::Bool growaround=false,
347  casacore::Bool flagneartime=false, casacore::Bool flagnearfreq=false, casacore::Bool apply=true);
348 
349  // Parse parameters for summary
351  casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation,
352  casacore::String intent, casacore::String observation, casacore::Bool spwchan, casacore::Bool spwcorr, casacore::Bool basecnt, casacore::Bool fieldcnt,
354 
355 private:
356 
358 
359  AgentFlagger& operator=(const AgentFlagger &) {return *this;};
360 
361  // Maximum between two numbers
363 
364  // Check if mode is valid against a list of known modes
365  bool isModeValid(casacore::String mode);
366 
368 
369  // Sink used to store history
371 
372  // Debug message flag
373  static const bool dbg;
374 
375  // Store the temporary maximum value
377 
378  // Helper members
381 
382  // casacore::Time average parameter in clip mode
384 
385 };
386 
387 
388 } //# NAMESPACE CASA - END
389 
390 #endif
391 
AgentFlagger(const AgentFlagger &)
Definition: AgentFlagger.h:357
AgentFlagger()
default constructor
casacore::uShort iterationApproach_p
Definition: AgentFlagger.h:220
bool restoreFlagVersion(casacore::Vector< casacore::String > versionname, casacore::String merge)
bool parseSummaryParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::Bool spwchan, casacore::Bool spwcorr, casacore::Bool basecnt, casacore::Bool fieldcnt, casacore::String name)
Parse parameters for summary.
int Int
Definition: aipstype.h:50
bool printFlagSelections()
Flag backup methods.
casacore::Bool isMS_p
Definition: AgentFlagger.h:222
casacore::Double timeInterval_p
Definition: AgentFlagger.h:221
bool saveFlagVersion(casacore::String versionname, casacore::String comment, casacore::String merge)
A top level class defining the data handling interface for the flagging module.
bool deleteFlagVersion(casacore::Vector< casacore::String > versionname)
void apply(const Jones &j1, VisVector &v, const Jones &j2)
Apply a pair of Jones to a VisVector:
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 parseAntIntParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::String antint_ref_antenna, casacore::Double minchanfrac, casacore::Bool verbose, casacore::Bool apply)
Parse parameters for the &#39;antint&#39; mode (antenna integrations)
bool parseClipParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::String datacolumn, casacore::Vector< casacore::Double > clipminmax, casacore::Bool clipoutside, casacore::Bool channelavg, casac::variant chanbin, casacore::Bool timeavg, casacore::String timebin, casacore::Bool clipzeros, casacore::Bool apply)
Parse parameters for clip.
bool initAgents()
initialize the agents list
AgentFlagger & operator=(const AgentFlagger &)
Definition: AgentFlagger.h:359
ostream-like interface to creating log messages.
Definition: LogIO.h:167
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
casacore::String array_p
Definition: AgentFlagger.h:234
casacore::String feed_p
Definition: AgentFlagger.h:233
FlagDataHandler * fdh_p
variables for initAgents
Definition: AgentFlagger.h:255
casacore::String mode_p
agent&#39;s members
Definition: AgentFlagger.h:240
casacore::String uvrange_p
Definition: AgentFlagger.h:235
std::vector< casacore::Record > agents_config_list_p
Definition: AgentFlagger.h:256
bool selectData(casacore::Record selrec)
parse the data selection
bool isExpressionPolarizationAll(casacore::String expression)
void getMax(casacore::Double value)
Maximum between two numbers.
bool open(casacore::String msname, casacore::Double ntime)
configure the tool, open the MS
casacore::Bool combinescans_p
Definition: AgentFlagger.h:243
casacore::Bool validateDataColumn(casacore::String datacol)
casa::FlagAgentDisplay * displayAgent_p
Display agent parameters.
Definition: AgentFlagger.h:251
casacore::Record run(casacore::Bool writeflags, casacore::Bool sequential=true)
Run the tool and write the flags to the MS.
bool getFlagVersionList(casacore::Vector< casacore::String > &verlist)
~AgentFlagger()
destructor
casacore::String antenna_p
Definition: AgentFlagger.h:229
casacore::Bool iterset_p
Definition: AgentFlagger.h:380
casacore::String scan_p
Definition: AgentFlagger.h:227
bool parseQuackParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::String quackmode, casacore::Double quackinterval, casacore::Bool quackincrement, casacore::Bool apply)
Parse parameters for quack.
casacore::String timerange_p
Definition: AgentFlagger.h:230
double Double
Definition: aipstype.h:55
bool isModeValid(casacore::String mode)
Check if mode is valid against a list of known modes.
bool parseTfcropParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::Double ntime, casacore::Bool combinescans, casacore::String datacolumn, casacore::Double timecutoff, casacore::Double freqcutoff, casacore::String timefit, casacore::String freqfit, casacore::Int maxnpieces, casacore::String flagdimension, casacore::String usewindowstats, casacore::Int halfwin, casacore::Bool extendflags, casacore::Bool apply, casacore::Bool channelavg, casac::variant chanbin, casacore::Bool timeavg, casacore::String timebin)
Parse parameters for tfcrop.
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
casacore::LogSink logSink_p
Sink used to store history.
Definition: AgentFlagger.h:370
casacore::String field_p
Definition: AgentFlagger.h:228
AgentFlagger: high-performance automated flagging.
Definition: AgentFlagger.h:212
bool parseAgentParameters(casacore::Record agent_params)
parse the parameters of the agent
FlagAgentSummary * summaryAgent_p
Definition: AgentFlagger.h:242
casacore::Double max_p
Store the temporary maximum value.
Definition: AgentFlagger.h:376
casacore::Record agentParams_p
Definition: AgentFlagger.h:241
void done()
reset everything
casacore::String spw_p
members to parse to selectData
Definition: AgentFlagger.h:226
casacore::String getExpressionFunction(casacore::String expression)
static const bool dbg
Debug message flag.
Definition: AgentFlagger.h:373
casacore::String intent_p
Definition: AgentFlagger.h:232
casacore::Bool extendflags_p
Definition: AgentFlagger.h:244
casacore::String observation_p
Definition: AgentFlagger.h:236
Distribute LogMessages to their destination(s)
Definition: LogSink.h:141
casacore::Record dataselection_p
Definition: AgentFlagger.h:237
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool parseManualParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::Bool autocorr, casacore::Bool apply)
Agent&#39;s specific parsing methods (for convenience only) Parse parameters for manual.
casacore::String msname_p
variables used to initialize the FlagDataHandler
Definition: AgentFlagger.h:219
casacore::Bool mixed_p
true if there are apply and unapply parameters in the list
Definition: AgentFlagger.h:247
bool parseExtendParameters(casacore::String field="", casacore::String spw="", casacore::String array="", casacore::String feed="", casacore::String scan="", casacore::String antenna="", casacore::String uvrange="", casacore::String timerange="", casacore::String correlation="", casacore::String intent="", casacore::String observation="", casacore::Double ntime=0.0, casacore::Bool combinescans=false, casacore::Bool extendpols=true, casacore::Double growtime=50.0, casacore::Double growfreq=50.0, casacore::Bool growaround=false, casacore::Bool flagneartime=false, casacore::Bool flagnearfreq=false, casacore::Bool apply=true)
Parse parameters for extend.
FlagAgentList agents_list_p
Definition: AgentFlagger.h:258
casacore::Bool timeAvg_p
casacore::Time average parameter in clip mode
Definition: AgentFlagger.h:383
casacore::Bool timeset_p
Helper members.
Definition: AgentFlagger.h:379
casacore::String correlation_p
Definition: AgentFlagger.h:231
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
bool parseElevationParameters(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan, casacore::String antenna, casacore::String uvrange, casacore::String timerange, casacore::String correlation, casacore::String intent, casacore::String observation, casacore::Double lowerlimit, casacore::Double upperlimit, casacore::Bool apply)
Parse parameters for elevation.
unsigned short uShort
Definition: aipstype.h:49
std::vector< casacore::Record > agents_config_list_copy_p
Definition: AgentFlagger.h:257
static casacore::LogIO os
Definition: AgentFlagger.h:216