Line data Source code
1 : //# ExtendFlagger.h:
2 : //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003-2008
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 receied 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 : //#
28 : //# ----------------------------------------------------------------------------
29 : //# Change Log
30 : //# ----------------------------------------------------------------------------
31 : //# Date Name Comments
32 :
33 :
34 : #ifndef EXTENDFLAGGER_H
35 : #define EXTENDFLAGGER_H
36 :
37 : //# Includes
38 :
39 : #include <casacore/casa/aips.h>
40 : #include <iostream>
41 : #include <casacore/casa/OS/Timer.h>
42 :
43 : #include <casacore/casa/Arrays/Vector.h>
44 : #include <casacore/casa/Arrays/Array.h>
45 : #include <casacore/casa/Arrays/Matrix.h>
46 : #include <casacore/casa/Arrays/Slicer.h>
47 :
48 : #include <casacore/tables/Tables/Table.h>
49 : #include <casacore/tables/Tables/ArrayColumn.h>
50 : #include <casacore/tables/Tables/ScalarColumn.h>
51 : #include <casacore/tables/Tables/TableColumn.h>
52 :
53 : #include <casacore/tables/TaQL/ExprNode.h>
54 : #include <casacore/tables/TaQL/RecordGram.h>
55 :
56 : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
57 : #include <flagging/Flagging/Flagger.h>
58 :
59 :
60 : namespace casa { //# NAMESPACE CASA - BEGIN
61 :
62 : // <summary>
63 : // class for flaging and extend flagging
64 : // </summary>
65 :
66 : // <use visibility=export>
67 :
68 : // <reviewed reviewer="" date="" tests="">
69 : // </reviewed>
70 :
71 : // <prerequisite>
72 : //#! Classes or concepts you should understand before using this class.
73 : // </prerequisite>
74 :
75 : // <etymology>
76 : //
77 : //
78 : //There will be an "extendflag" T/F parameter and a number of
79 : //subparameters. This so that individual extensions can be better
80 : //controlled.
81 : //
82 : //extendflag = T
83 : // extendcorr = '' # ''=default,'all' (future: 'half')
84 : // extendchan = '' # ''=default,'all'
85 : // extendspw = '' # ''=default,'all'
86 : // extendant = '' # ''=default,'all'
87 : // extendtime = '' # ''=default,'all' (future: 'scan','field')
88 : //
89 : //In all cases the '' and 'all' options are the ones to implement first.
90 : //Next, if time allows, implement the ones in parentheses. More
91 : //esoteric ones are given below and would be after these (and probably
92 : //need more thought).
93 : //
94 : //NOTE: the extendchan and extendcorr are "in-row" selection (they
95 : //extend the flags to quantities in the same visibility that is plotted
96 : //and selected on), while the others are in different rows. The in-row
97 : //ones will be implemented first (CAS-714), the rest later (CAS-715).
98 : //
99 : //Note that these extensions are combined at the end, thus if you choose
100 : //'all' for all of these I think you will flag the entire dataset if you
101 : //flag any point! So be it. Also, averaging effectively extends the
102 : //flags to everything included in the average.
103 : //
104 : //Individually:
105 : //
106 : //extendcorr
107 : // '' flag only current point(s) correlations
108 : // 'all' extend flag to all correlations,
109 : // example: if RR selected then flag RR,RL,LR,LL
110 : //
111 : // Future options:
112 : // 'half' extend flag to all correlations with current one
113 : // example: if RR selected then flag RR,RL,LR (not LL)
114 : // NOTE: if RL selected then this rule would nominally
115 : // flag RR,RL,LL but not LR, should probably default to
116 : // 'all' in this case?
117 : //
118 : // Possible other options:
119 : // <correlation> take standard correlation selection string
120 : // example: extendcorr='RL,LR'
121 : //
122 : //extendchan
123 : // '' flag only current selected channels
124 : // 'all' extend flag to all channels
125 : //
126 : // NOTE: the spw that these apply to is given by extendspw (default is
127 : // current)
128 : //
129 : // Possible other options:
130 : // <chan> take standard channel selection/range string (the part after :
131 : // in spw string)
132 : // example: extendchan='0~4,59~63'
133 : //
134 : //extendspw
135 : // '' flag channel(s) only in current spw
136 : // 'all' extend flag to all spw (of current shape if extendchan not 'all')
137 : //
138 : // NOTE: if extendchan='' and extendspw='all', then only spw of the same
139 : //shape as the current spw will have the specified channel
140 : //flagged. This is so flagging on "narrow-band" spw will not
141 : //flag "wide-band" spw by mistake.
142 : // example: if CH 0 of spw with 64 chans is selected, then CH 0 in
143 : // all spw of 64 chans will flagged by extension
144 : //
145 : // Possible other options:
146 : // <spw> take standard spw selection/range string (the part before : in
147 : // spw string)
148 : // example: extendspw='0,3~6'
149 : //extendant
150 : // '' flag only current point(s) baseline
151 : // 'all' flag all baselines (fitting other selection/extension)
152 : // BEWARE - this option could delete excessive amounts of data
153 : // NOTE: if the user has chosen iteration='antenna' then 'all'
154 : // should flag only baselines to the current iteration of antenna.
155 : // Likewise if iteration='baseline', extendant='all' should flag
156 : // only the current baseline (in this case will act like '').
157 : // Otherwise the user would not be iterating.
158 : //
159 : // Possible other options:
160 : // 'ant1' extend flag to all baselines with the current point(s) ANT1
161 : // 'ant2' extend flag to all baselines with the current point(s) ANT2
162 : // <antenna> take standard antenna selection string
163 : // example: extendant='EA11,1&3'
164 : //
165 : //extendtime
166 : // '' flag only current point(s) integration (or average)
167 : // 'all' flag all integs matching rest of selection in entire dataset -
168 : // BEWARE - this could delete excessive amounts of data
169 : // NOTE: if iteration='field' is chosen, then 'all' will flag only
170 : // integrations in the current field iteration (not all fields)
171 : //
172 : // Future options:
173 : // 'scan' flag all integs in current scan
174 : // 'field' if xaxis='time' then flag all fields that would fall in box
175 : // drawn
176 : // example: would flag target source between plotted calibrators
177 : //
178 : // Possible other options:
179 : // <timerange> take a standard timerange string
180 : // example: extendtime='25:00:00~27:30:00'
181 : //
182 : //
183 : //Note that if the suggested future extend strings using selection
184 : //syntax (e.g.extendchan='10~20') is implemented, the extensions could
185 : //be to data disjoint from what is actually displayed.
186 : //
187 : //GUI Developments:
188 : //
189 : //Eventually, we will want to have an icon on the GUI that will bring up
190 : //a menu to change these during flagging. This is particularly useful
191 : //for the in-row selections (extendchan and extendcorr).
192 : //
193 : // </etymology>
194 :
195 : // <synopsis>
196 : //
197 : // </synopsis>
198 :
199 : // <example>
200 : // <srcblock>
201 : // ExtendFlagger eflg;
202 : // eflg.attach(ms);
203 : // eflg.setdata();
204 : // eflg.setmanualflags();
205 : // eflg.run()
206 : // </srcblock>
207 : // </example>
208 :
209 : // <motivation>
210 : // It has long been on the users wish list to do extended flagging
211 : // </motivation>
212 :
213 : // <thrown>
214 : // <li>
215 : // <li>
216 : // </thrown>
217 :
218 : // <todo asof="$DATE:$">
219 : //
220 : // </todo>
221 :
222 : class FlagIDS {
223 : public:
224 0 : FlagIDS() {
225 0 : bl = "";
226 0 : field = 0;
227 0 : time = "";
228 0 : spw = "";
229 0 : corr = "";
230 0 : chan = "";
231 0 : }
232 :
233 : casacore::String bl;
234 : casacore::uInt field;
235 : casacore::String time;
236 : casacore::String spw;
237 : casacore::String corr;
238 : casacore::String chan;
239 :
240 0 : FlagIDS &operator=(const FlagIDS &other) {
241 0 : bl = other.bl;
242 0 : field = other.field;
243 0 : time = other.time;
244 0 : spw = other.spw;
245 0 : corr = other.corr;
246 0 : chan = other.chan;
247 0 : return *this;
248 : }
249 :
250 : static int compareID (const void* val1, const void* val2);
251 :
252 0 : void show() {
253 : std::cout
254 0 : << " time=" << time
255 0 : << " bl=" << bl
256 0 : << " field=" << field
257 0 : << " spw=" << spw
258 0 : << " corr=" << corr
259 0 : << " chan=" << chan
260 0 : << std::endl;
261 0 : }
262 : };
263 :
264 : class FlagID {
265 : public:
266 : FlagID() {
267 : rowNum = 0;
268 : //casacore::uInt npts;
269 : ant1 = 0;
270 : ant2 = 0;
271 : field = 0;
272 : time = "";
273 : spw = 0;
274 : corr = "";
275 : chan = "";
276 : polid = 0;
277 : }
278 :
279 : casacore::uInt rowNum;
280 : //casacore::uInt npts;
281 : casacore::uInt ant1;
282 : casacore::uInt ant2;
283 : casacore::uInt field;
284 : casacore::String time;
285 : casacore::uInt spw;
286 : casacore::String corr;
287 : casacore::String chan;
288 : casacore::uInt polid;
289 :
290 : FlagID &operator=(const FlagID &other) {
291 : rowNum = other.rowNum;
292 : //casacore::uInt npts;
293 : ant1 = other.ant1;
294 : ant2 = other.ant2;
295 : field = other.field;
296 : time = other.time;
297 : spw = other.spw;
298 : corr = other.corr;
299 : chan = other.chan;
300 : polid = other.polid;
301 : return *this;
302 : }
303 :
304 : static int compare (const void* val1, const void* val2);
305 :
306 : void show() {
307 : std::cout << "rowNum=" << rowNum
308 : //casacore::uInt npts;
309 : << " ant1=" << ant1
310 : << " ant2=" << ant2
311 : << " field=" << field
312 : << " time=" << time
313 : << " spw=" << spw
314 : << " corr=" << corr
315 : << " chan=" << chan
316 : << " polid=" << polid
317 : << std::endl;
318 : }
319 : };
320 :
321 : class ExtendFlagger
322 : {
323 : public:
324 : // Constructor
325 : ExtendFlagger();
326 : ExtendFlagger(casacore::MeasurementSet& ms, const casacore::String& exchan,
327 : const casacore::String& excorr, const casacore::String& exant,
328 : const casacore::String& exspw, const casacore::String& time,
329 : const casacore::Vector<casacore::Vector<casacore::String> >& corrs, const casacore::Vector<casacore::Int>& chans);
330 :
331 : // Destructor
332 : virtual ~ExtendFlagger();
333 :
334 : // Operator=
335 : // Equate by reference.
336 : ExtendFlagger& operator=(const ExtendFlagger&){return *this;}
337 :
338 : casacore::Bool attach(casacore::MeasurementSet &ms);
339 : void detach();
340 :
341 : casacore::Bool initdata(const casacore::String& field = "", const casacore::String& spw = "",
342 : const casacore::String& array = "", const casacore::String& feed = "",
343 : const casacore::String& scan = "", const casacore::String& baseline = "",
344 : const casacore::String& uvrange = "", const casacore::String& time = "",
345 : const casacore::String& correlation = "", const casacore::String& intent = "");
346 :
347 : casacore::Bool setdata();
348 :
349 : casacore::Bool selectdata(casacore::Bool useoriginalms = true);
350 :
351 : casacore::Bool setmanualflags(casacore::Bool unflag = false,
352 : casacore::Bool autocorr = false);
353 :
354 : casacore::Bool run(casacore::Bool trial = false, casacore::Bool reset = false);
355 :
356 : casacore::Bool extend(const casacore::Vector<FlagID>& flagids);
357 : casacore::Bool extend2(const casacore::Vector<FlagID>& flagids);
358 :
359 : void setField(const casacore::String& field);
360 : void setSpw(const casacore::String& spw);
361 : void setArray(const casacore::String& array);
362 : void setFeed(const casacore::String& feed);
363 : void setScan(const casacore::String& scan);
364 : void setBaseline(const casacore::String& baseline);
365 : void setUvrange(const casacore::String& uvrange);
366 : void setTime(const casacore::String& time);
367 : void setCorrelation(const casacore::String& correlation);
368 : void setIntent(const casacore::String& intent);
369 : void setUnflag(casacore::Bool unflg);
370 :
371 : void setExtendChan(const casacore::String& exchan);
372 : void setExtendCorr(const casacore::String& excorr);
373 : void setExtendSpw(const casacore::String& exspw);
374 : void setExtendTime(const casacore::String& extime);
375 : void setExtendAnt(const casacore::String& exant);
376 : void setExtend(const casacore::String& exchan, const casacore::String& excorr,
377 : const casacore::String& exspw, const casacore::String& exant,
378 : const casacore::String& extime,
379 : const casacore::Vector<casacore::Vector<casacore::String> >& corrs, const casacore::Vector<casacore::Int>& chans);
380 : void setAbleCorr(const casacore::Vector<casacore::Vector<casacore::String> >& corrName);
381 : void setChanNum(const casacore::Vector<casacore::Int>& chanNum);
382 : casacore::String halfExtendCorr(const casacore::String& corr, const casacore::uInt polid = 0);
383 : casacore::String ableSpw(const casacore::Int spw);
384 : void show();
385 : private:
386 :
387 : Flagger flagger;
388 : // casacore::Bool useoriginalms;
389 :
390 : casacore::String field;
391 : casacore::String spw;
392 : casacore::String array;
393 : casacore::String feed;
394 : casacore::String scan;
395 : casacore::String baseline;
396 : casacore::String uvrange;
397 : casacore::String time;
398 : casacore::String correlation;
399 : casacore::String intent;
400 :
401 : casacore::String clipexpr;
402 : casacore::Vector<casacore::Double> cliprange;
403 : casacore::String clipcolumn;
404 : casacore::Bool outside;
405 : casacore::Bool channelavg;
406 : casacore::Double quackinterval;
407 : casacore::String opmode;
408 :
409 : casacore::Bool unflag;
410 :
411 : casacore::String extendChan;
412 : casacore::String extendCorr;
413 : casacore::String extendSpw;
414 : casacore::String extendAnt;
415 : casacore::String extendTime;
416 :
417 : casacore::Vector<casacore::Vector<casacore::String> > ableCorr;
418 : casacore::Vector<casacore::Int> chanNum;
419 :
420 : };
421 :
422 : } //# NAMESPACE CASA - END
423 :
424 : //#ifndef AIPS_NO_TEMPLATE_SRC
425 : //#include <flagging/Flagging/ExtendFlagger.cc>
426 : //#endif //# AIPS_NO_TEMPLATE_SRC
427 : #endif
428 :
|