casa
$Rev:20696$
|
00001 //# ExtendFlagger.h: 00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003-2008 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have receied a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 //# 00028 //# ---------------------------------------------------------------------------- 00029 //# Change Log 00030 //# ---------------------------------------------------------------------------- 00031 //# Date Name Comments 00032 00033 00034 #ifndef EXTENDFLAGGER_H 00035 #define EXTENDFLAGGER_H 00036 00037 //# Includes 00038 00039 #include <casa/aips.h> 00040 #include <casa/iostream.h> 00041 #include <casa/OS/Timer.h> 00042 00043 #include <casa/Arrays/Vector.h> 00044 #include <casa/Arrays/Array.h> 00045 #include <casa/Arrays/Matrix.h> 00046 #include <casa/Arrays/Slicer.h> 00047 00048 #include <tables/Tables/Table.h> 00049 #include <tables/Tables/ArrayColumn.h> 00050 #include <tables/Tables/ScalarColumn.h> 00051 #include <tables/Tables/TableColumn.h> 00052 00053 #include <tables/Tables/ExprNode.h> 00054 #include <tables/Tables/RecordGram.h> 00055 00056 #include <ms/MeasurementSets/MeasurementSet.h> 00057 #include <flagging/Flagging/Flagger.h> 00058 00059 00060 namespace casa { //# NAMESPACE CASA - BEGIN 00061 00062 // <summary> 00063 // class for flaging and extend flagging 00064 // </summary> 00065 00066 // <use visibility=export> 00067 00068 // <reviewed reviewer="" date="" tests=""> 00069 // </reviewed> 00070 00071 // <prerequisite> 00072 //#! Classes or concepts you should understand before using this class. 00073 // </prerequisite> 00074 00075 // <etymology> 00076 // 00077 // 00078 //There will be an "extendflag" T/F parameter and a number of 00079 //subparameters. This so that individual extensions can be better 00080 //controlled. 00081 // 00082 //extendflag = T 00083 // extendcorr = '' # ''=default,'all' (future: 'half') 00084 // extendchan = '' # ''=default,'all' 00085 // extendspw = '' # ''=default,'all' 00086 // extendant = '' # ''=default,'all' 00087 // extendtime = '' # ''=default,'all' (future: 'scan','field') 00088 // 00089 //In all cases the '' and 'all' options are the ones to implement first. 00090 //Next, if time allows, implement the ones in parentheses. More 00091 //esoteric ones are given below and would be after these (and probably 00092 //need more thought). 00093 // 00094 //NOTE: the extendchan and extendcorr are "in-row" selection (they 00095 //extend the flags to quantities in the same visibility that is plotted 00096 //and selected on), while the others are in different rows. The in-row 00097 //ones will be implemented first (CAS-714), the rest later (CAS-715). 00098 // 00099 //Note that these extensions are combined at the end, thus if you choose 00100 //'all' for all of these I think you will flag the entire dataset if you 00101 //flag any point! So be it. Also, averaging effectively extends the 00102 //flags to everything included in the average. 00103 // 00104 //Individually: 00105 // 00106 //extendcorr 00107 // '' flag only current point(s) correlations 00108 // 'all' extend flag to all correlations, 00109 // example: if RR selected then flag RR,RL,LR,LL 00110 // 00111 // Future options: 00112 // 'half' extend flag to all correlations with current one 00113 // example: if RR selected then flag RR,RL,LR (not LL) 00114 // NOTE: if RL selected then this rule would nominally 00115 // flag RR,RL,LL but not LR, should probably default to 00116 // 'all' in this case? 00117 // 00118 // Possible other options: 00119 // <correlation> take standard correlation selection string 00120 // example: extendcorr='RL,LR' 00121 // 00122 //extendchan 00123 // '' flag only current selected channels 00124 // 'all' extend flag to all channels 00125 // 00126 // NOTE: the spw that these apply to is given by extendspw (default is 00127 // current) 00128 // 00129 // Possible other options: 00130 // <chan> take standard channel selection/range string (the part after : 00131 // in spw string) 00132 // example: extendchan='0~4,59~63' 00133 // 00134 //extendspw 00135 // '' flag channel(s) only in current spw 00136 // 'all' extend flag to all spw (of current shape if extendchan not 'all') 00137 // 00138 // NOTE: if extendchan='' and extendspw='all', then only spw of the same 00139 //shape as the current spw will have the specified channel 00140 //flagged. This is so flagging on "narrow-band" spw will not 00141 //flag "wide-band" spw by mistake. 00142 // example: if CH 0 of spw with 64 chans is selected, then CH 0 in 00143 // all spw of 64 chans will flagged by extension 00144 // 00145 // Possible other options: 00146 // <spw> take standard spw selection/range string (the part before : in 00147 // spw string) 00148 // example: extendspw='0,3~6' 00149 //extendant 00150 // '' flag only current point(s) baseline 00151 // 'all' flag all baselines (fitting other selection/extension) 00152 // BEWARE - this option could delete excessive amounts of data 00153 // NOTE: if the user has chosen iteration='antenna' then 'all' 00154 // should flag only baselines to the current iteration of antenna. 00155 // Likewise if iteration='baseline', extendant='all' should flag 00156 // only the current baseline (in this case will act like ''). 00157 // Otherwise the user would not be iterating. 00158 // 00159 // Possible other options: 00160 // 'ant1' extend flag to all baselines with the current point(s) ANT1 00161 // 'ant2' extend flag to all baselines with the current point(s) ANT2 00162 // <antenna> take standard antenna selection string 00163 // example: extendant='EA11,1&3' 00164 // 00165 //extendtime 00166 // '' flag only current point(s) integration (or average) 00167 // 'all' flag all integs matching rest of selection in entire dataset - 00168 // BEWARE - this could delete excessive amounts of data 00169 // NOTE: if iteration='field' is chosen, then 'all' will flag only 00170 // integrations in the current field iteration (not all fields) 00171 // 00172 // Future options: 00173 // 'scan' flag all integs in current scan 00174 // 'field' if xaxis='time' then flag all fields that would fall in box 00175 // drawn 00176 // example: would flag target source between plotted calibrators 00177 // 00178 // Possible other options: 00179 // <timerange> take a standard timerange string 00180 // example: extendtime='25:00:00~27:30:00' 00181 // 00182 // 00183 //Note that if the suggested future extend strings using selection 00184 //syntax (e.g.extendchan='10~20') is implemented, the extensions could 00185 //be to data disjoint from what is actually displayed. 00186 // 00187 //GUI Developments: 00188 // 00189 //Eventually, we will want to have an icon on the GUI that will bring up 00190 //a menu to change these during flagging. This is particularly useful 00191 //for the in-row selections (extendchan and extendcorr). 00192 // 00193 // </etymology> 00194 00195 // <synopsis> 00196 // 00197 // </synopsis> 00198 00199 // <example> 00200 // <srcblock> 00201 // ExtendFlagger eflg; 00202 // eflg.attach(ms); 00203 // eflg.setdata(); 00204 // eflg.setmanualflags(); 00205 // eflg.run() 00206 // </srcblock> 00207 // </example> 00208 00209 // <motivation> 00210 // It has long been on the users wish list to do extended flagging 00211 // </motivation> 00212 00213 // <thrown> 00214 // <li> 00215 // <li> 00216 // </thrown> 00217 00218 // <todo asof="$DATE:$"> 00219 // 00220 // </todo> 00221 00222 class FlagIDS { 00223 public: 00224 FlagIDS() { 00225 bl = ""; 00226 field = 0; 00227 time = ""; 00228 spw = ""; 00229 corr = ""; 00230 chan = ""; 00231 } 00232 00233 String bl; 00234 uInt field; 00235 String time; 00236 String spw; 00237 String corr; 00238 String chan; 00239 00240 FlagIDS &operator=(const FlagIDS &other) { 00241 bl = other.bl; 00242 field = other.field; 00243 time = other.time; 00244 spw = other.spw; 00245 corr = other.corr; 00246 chan = other.chan; 00247 return *this; 00248 } 00249 00250 static int compareID (const void* val1, const void* val2); 00251 00252 void show() { 00253 cout 00254 << " time=" << time 00255 << " bl=" << bl 00256 << " field=" << field 00257 << " spw=" << spw 00258 << " corr=" << corr 00259 << " chan=" << chan 00260 << endl; 00261 } 00262 }; 00263 00264 class FlagID { 00265 public: 00266 FlagID() { 00267 rowNum = 0; 00268 //uInt npts; 00269 ant1 = 0; 00270 ant2 = 0; 00271 field = 0; 00272 time = ""; 00273 spw = 0; 00274 corr = ""; 00275 chan = ""; 00276 polid = 0; 00277 } 00278 00279 uInt rowNum; 00280 //uInt npts; 00281 uInt ant1; 00282 uInt ant2; 00283 uInt field; 00284 String time; 00285 uInt spw; 00286 String corr; 00287 String chan; 00288 uInt polid; 00289 00290 FlagID &operator=(const FlagID &other) { 00291 rowNum = other.rowNum; 00292 //uInt npts; 00293 ant1 = other.ant1; 00294 ant2 = other.ant2; 00295 field = other.field; 00296 time = other.time; 00297 spw = other.spw; 00298 corr = other.corr; 00299 chan = other.chan; 00300 polid = other.polid; 00301 return *this; 00302 } 00303 00304 static int compare (const void* val1, const void* val2); 00305 00306 void show() { 00307 cout << "rowNum=" << rowNum 00308 //uInt npts; 00309 << " ant1=" << ant1 00310 << " ant2=" << ant2 00311 << " field=" << field 00312 << " time=" << time 00313 << " spw=" << spw 00314 << " corr=" << corr 00315 << " chan=" << chan 00316 << " polid=" << polid 00317 << endl; 00318 } 00319 }; 00320 00321 class ExtendFlagger 00322 { 00323 public: 00324 // Constructor 00325 ExtendFlagger(); 00326 ExtendFlagger(MeasurementSet& ms, const String& exchan, 00327 const String& excorr, const String& exant, 00328 const String& exspw, const String& time, 00329 const Vector<Vector<String> >& corrs, const Vector<Int>& chans); 00330 00331 // Destructor 00332 virtual ~ExtendFlagger(); 00333 00334 // Operator= 00335 // Equate by reference. 00336 ExtendFlagger& operator=(const ExtendFlagger&){return *this;} 00337 00338 Bool attach(MeasurementSet &ms); 00339 void detach(); 00340 00341 Bool initdata(const String& field = "", const String& spw = "", 00342 const String& array = "", const String& feed = "", 00343 const String& scan = "", const String& baseline = "", 00344 const String& uvrange = "", const String& time = "", 00345 const String& correlation = "", const String& intent = ""); 00346 00347 Bool setdata(); 00348 00349 Bool selectdata(Bool useoriginalms = True); 00350 00351 Bool setmanualflags(Bool unflag = False, 00352 Bool autocorr = False); 00353 00354 Bool run(Bool trial = False, Bool reset = False); 00355 00356 Bool extend(const Vector<FlagID>& flagids); 00357 Bool extend2(const Vector<FlagID>& flagids); 00358 00359 void setField(const String& field); 00360 void setSpw(const String& spw); 00361 void setArray(const String& array); 00362 void setFeed(const String& feed); 00363 void setScan(const String& scan); 00364 void setBaseline(const String& baseline); 00365 void setUvrange(const String& uvrange); 00366 void setTime(const String& time); 00367 void setCorrelation(const String& correlation); 00368 void setIntent(const String& intent); 00369 void setUnflag(Bool unflg); 00370 00371 void setExtendChan(const String& exchan); 00372 void setExtendCorr(const String& excorr); 00373 void setExtendSpw(const String& exspw); 00374 void setExtendTime(const String& extime); 00375 void setExtendAnt(const String& exant); 00376 void setExtend(const String& exchan, const String& excorr, 00377 const String& exspw, const String& exant, 00378 const String& extime, 00379 const Vector<Vector<String> >& corrs, const Vector<Int>& chans); 00380 void setAbleCorr(const Vector<Vector<String> >& corrName); 00381 void setChanNum(const Vector<Int>& chanNum); 00382 String halfExtendCorr(const String& corr, const uInt polid = 0); 00383 String ableSpw(const Int spw); 00384 void show(); 00385 private: 00386 00387 Flagger flagger; 00388 Bool useoriginalms; 00389 00390 String field; 00391 String spw; 00392 String array; 00393 String feed; 00394 String scan; 00395 String baseline; 00396 String uvrange; 00397 String time; 00398 String correlation; 00399 String intent; 00400 00401 String clipexpr; 00402 Vector<Double> cliprange; 00403 String clipcolumn; 00404 Bool outside; 00405 Bool channelavg; 00406 Double quackinterval; 00407 String opmode; 00408 00409 Bool unflag; 00410 00411 String extendChan; 00412 String extendCorr; 00413 String extendSpw; 00414 String extendAnt; 00415 String extendTime; 00416 00417 Vector<Vector<String> > ableCorr; 00418 Vector<Int> chanNum; 00419 00420 }; 00421 00422 } //# NAMESPACE CASA - END 00423 00424 //#ifndef AIPS_NO_TEMPLATE_SRC 00425 //#include <flagging/Flagging/ExtendFlagger.cc> 00426 //#endif //# AIPS_NO_TEMPLATE_SRC 00427 #endif 00428