Line data Source code
1 : //# RFADiffBase.h: this defines RFADiffBase and RFADiffMapbase 2 : //# Copyright (C) 2000,2001,2002 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_RFADIFFBASE_H 28 : #define FLAGGING_RFADIFFBASE_H 29 : 30 : #include <flagging/Flagging/RFAFlagCubeBase.h> 31 : #include <flagging/Flagging/RFDataMapper.h> 32 : #include <flagging/Flagging/RFFloatLattice.h> 33 : #include <flagging/Flagging/RFRowClipper.h> 34 : #include <casacore/scimath/Mathematics/MedianSlider.h> 35 : #include <casacore/casa/Arrays/LogiVector.h> 36 : #include <casacore/casa/Containers/RecordInterface.h> 37 : 38 : 39 : namespace casa { //# NAMESPACE CASA - BEGIN 40 : 41 : // min number of deviations for which average is considered valid 42 : const int RFA_MIN_NAD = 20; 43 : // significant change in accumulated average 44 : const casacore::Float RFA_AAD_CHANGE = 0.05; 45 : 46 : // <summary> 47 : // RFADiffBase: abstract class for deviation-based flagging 48 : // </summary> 49 : 50 : // <use visibility=local> 51 : 52 : // <reviewed reviewer="" date="" tests="" demos=""> 53 : // </reviewed> 54 : 55 : // <prerequisite> 56 : // <li> RFCubeLattice 57 : // <li> RFRowClipper 58 : // </prerequisite> 59 : // 60 : // <etymology> 61 : // Diff = Deviation. Well, almost... 62 : // </etymology> 63 : // 64 : // <synopsis> 65 : // Several flagging algorithms flag by analyzing the deviation w/respect 66 : // to something at each point. RFADiffBase provides common functions for 67 : // these classes. It will maintain a lattice of deviations, compute the 68 : // noise level estimates, and flag points. It will also flag rows with 69 : // excessive noise level (using RFRowClipper). Derived classes are 70 : // responsible for computing the deviation. 71 : // </synopsis> 72 : // 73 : // <todo asof="2001/04/16"> 74 : // <li> add this feature 75 : // <li> fix this bug 76 : // <li> start discussion of this possible extension 77 : // </todo> 78 : 79 : class RFADiffBase : public RFAFlagCubeBase 80 : { 81 : public: 82 : RFADiffBase ( RFChunkStats &ch,const casacore::RecordInterface &parm ); 83 : virtual ~RFADiffBase (); 84 : 85 : virtual casacore::uInt estimateMemoryUse (); 86 : virtual casacore::Bool newChunk ( casacore::Int &maxmem ); 87 : virtual void endChunk (); 88 : virtual void startData (bool verbose); 89 : virtual void startDry (bool verbose); 90 : virtual IterMode iterTime (casacore::uInt it); 91 : virtual IterMode iterDry (casacore::uInt it); 92 : virtual IterMode endData (); 93 : virtual IterMode endDry (); 94 : 95 : virtual casacore::String getDesc (); 96 : static const casacore::RecordInterface & getDefaults (); 97 : 98 : protected: 99 : static casacore::Bool dummy_Bool; 100 : 101 : // prepares for a pass over one data row 102 : void startDataRow (casacore::uInt ifr); 103 : // updates the diff lattice with a value, and performs clipping 104 : casacore::Float setDiff (casacore::uInt ich,casacore::uInt ifr,casacore::Float d,casacore::Bool &flagged = dummy_Bool ); 105 : // ends pass over single data row 106 : void endDataRow (casacore::uInt ifr); 107 : 108 : // updates noise estimates (sih0), returns the max change 109 : casacore::Float updateSigma (); 110 : 111 : // computes a correlations mask. Called once for each chunk (since correlations 112 : // can change from chunk to chunk) 113 : virtual RFlagWord newCorrMask () =0; 114 : 115 : casacore::Double clip_level; // clipping level, in AADs 116 : casacore::Double row_clip_level; // clipping level for rows (based on noise estimates), <0 for disable 117 : casacore::Bool disable_row_clip; // flag: row clipping _disabled_ globally 118 : casacore::Bool clipping_rows; // flag: row clipping active for this chunk 119 : 120 : RFFloatLattice diff; // (Nchan,Nifr,Nt) cube of deviations 121 : FlagCubeIterator * pflagiter; // flag iterator used by setDiff() 122 : RFRowClipper rowclipper; 123 : 124 : casacore::Vector<casacore::Float> diffrow; // one row of deviations, for noise computations 125 : int idiffrow; 126 : 127 : casacore::Matrix<casacore::Float> sig; // current noise estimate for (it,ifr) 128 : casacore::Matrix<casacore::Float> sig0; // reference estimate (boxcar average from previous pass) 129 : casacore::LogicalVector sigupdated; 130 : }; 131 : 132 : // <summary> 133 : // Abstract base class for deviation-based flagging with a data mapper. 134 : // </summary> 135 : 136 : // <use visibility=local> 137 : 138 : // <reviewed reviewer="" date="" tests="" demos=""> 139 : // </reviewed> 140 : 141 : // <prerequisite> 142 : // <li> RFDataMapper 143 : // </prerequisite> 144 : // 145 : // <synopsis> 146 : // This is another abstract class on top of DiffBase. It is also inherited from 147 : // RFDataMapper, so it includes functions for mapping visibilities to a single 148 : // casacore::Float value. 149 : // </synopsis> 150 : // 151 : // <todo asof="2001/04/16"> 152 : // <li> add this feature 153 : // <li> fix this bug 154 : // <li> start discussion of this possible extension 155 : // </todo> 156 : 157 : class RFADiffMapBase : public RFADiffBase, protected RFDataMapper 158 : { 159 : public: 160 : RFADiffMapBase ( RFChunkStats &ch,const casacore::RecordInterface &parm ); 161 : virtual ~RFADiffMapBase (); 162 : 163 : virtual IterMode iterTime (casacore::uInt it); 164 : 165 : virtual casacore::String getDesc (); 166 : 167 : // returns a casacore::Record of all available parameters and their default values 168 : static const casacore::RecordInterface & getDefaults (); 169 : 170 : protected: 171 0 : virtual RFlagWord newCorrMask () 172 0 : { return RFDataMapper::corrMask(chunk.visIter()); } 173 : 174 0 : void setupMapper () 175 0 : { RFDataMapper::setVisBuffer(chunk.visBuf()); } 176 : }; 177 : 178 : } //# NAMESPACE CASA - END 179 : 180 : #endif