casa
$Rev:20696$
|
00001 //# FlagCalTableHandler.h: This file contains the interface definition of the FlagCalTableHandler class. 00002 //# 00003 //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/) 00004 //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved. 00005 //# Copyright (C) European Southern Observatory, 2011, All rights reserved. 00006 //# 00007 //# This library is free software; you can redistribute it and/or 00008 //# modify it under the terms of the GNU Lesser General Public 00009 //# License as published by the Free software Foundation; either 00010 //# version 2.1 of the License, or (at your option) any later version. 00011 //# 00012 //# This library is distributed in the hope that it will be useful, 00013 //# but WITHOUT ANY WARRANTY, without even the implied warranty of 00014 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 //# Lesser General Public License for more details. 00016 //# 00017 //# You should have received a copy of the GNU Lesser General Public 00018 //# License along with this library; if not, write to the Free Software 00019 //# Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00020 //# MA 02111-1307 USA 00021 //# $Id: $ 00022 00023 #ifndef FlagCalTableHandler_H_ 00024 #define FlagCalTableHandler_H_ 00025 00026 #include <flagging/Flagging/FlagDataHandler.h> 00027 #include <ms/MeasurementSets/MSSelectionTools.h> 00028 #include <synthesis/CalTables/NewCalTable.h> 00029 #include <synthesis/CalTables/CTInterface.h> 00030 #include <synthesis/CalTables/CTIter.h> 00031 #include <synthesis/CalTables/CalBuffer.h> 00032 00033 namespace casa { //# NAMESPACE CASA - BEGIN 00034 00035 class DummyBufferImpl: public vi::VisBuffer2 00036 { 00037 public: 00038 DummyBufferImpl() {} 00039 ~DummyBufferImpl() {} 00040 00041 virtual void copy (const VisBuffer2 & other, Bool fetchIfNeeded) {} 00042 virtual void copyComponents (const VisBuffer2 & other, 00043 const VisBufferComponents2 & components, 00044 Bool fetchIfNeeded = True) {} 00045 virtual void copyCoordinateInfo(const VisBuffer2 * other, Bool includeDirections, 00046 Bool fetchIfNeeded = True) {} 00047 00048 virtual void setShape (Int nCorrelations, Int nChannels, Int nRows, Bool) {} 00049 virtual const vi::VisibilityIterator2 * getVi () const {return NULL;} 00050 00051 virtual Bool isAttached () const {return True;} 00052 virtual Bool isFillable () const {return True;} 00053 00054 virtual void writeChangesBack () {} 00055 virtual void dirtyComponentsAdd (const VisBufferComponents2 & additionalDirtyComponents) {} 00056 virtual void dirtyComponentsAdd (VisBufferComponent2 component) {} 00057 virtual void dirtyComponentsClear () {} 00058 virtual VisBufferComponents2 dirtyComponentsGet () const { VisBufferComponents2 dummy; return dummy;} 00059 virtual void dirtyComponentsSet (const VisBufferComponents2 & dirtyComponents) {} 00060 virtual void dirtyComponentsSet (VisBufferComponent2 component) {} 00061 00062 virtual const Matrix<Float> & imagingWeight() const {Matrix<Float> dummy; return dummy;} 00063 00064 virtual Double getFrequency (Int rowInBuffer, Int frequencyIndex, 00065 Int frame = FrameNotSpecified) const {Double dummy; return dummy;} 00066 virtual const Vector<Double> & getFrequencies (Int rowInBuffer, 00067 Int frame = FrameNotSpecified) const {Vector<Double> dummy; return dummy;} 00068 virtual Int getChannelNumber (Int rowInBuffer, Int frequencyIndex) const {Int dummy; return dummy;} 00069 virtual const Vector<Int> & getChannelNumbers (Int rowInBuffer) const {Vector<Int> dummy; return dummy;} 00070 00071 virtual void normalize() {} 00072 00073 virtual void resetWeightsUsingSigma () {} 00074 00075 virtual Bool isNewArrayId () const {Bool dummy; return dummy;} 00076 virtual Bool isNewFieldId () const {Bool dummy; return dummy;} 00077 virtual Bool isNewMs() const {Bool dummy; return dummy;} 00078 virtual Bool isNewSpectralWindow () const {Bool dummy; return dummy;} 00079 virtual Bool isWritable () const {Bool dummy; return dummy;} 00080 virtual Int msId() const {Int dummy; return dummy;} 00081 virtual String msName (Bool stripPath = False) const {String dummy; return dummy;} 00082 virtual vi::Subchunk getSubchunk () const {vi::Subchunk dummy; return dummy;} 00083 00084 virtual const Vector<Int> & antenna1 () const {Vector<Int> dummy; return dummy;} 00085 virtual void setAntenna1 (const Vector<Int> & value) {} 00086 virtual const Vector<Int> & antenna2 () const {Vector<Int> dummy; return dummy;} 00087 virtual void setAntenna2 (const Vector<Int> & value) {} 00088 virtual const Vector<Int>& arrayId () const {Vector<Int> dummy; return dummy;} 00089 virtual void setArrayId (const Vector<Int>&) {} 00090 virtual Int dataDescriptionId () const {Int dummy; return dummy;} 00091 virtual void setDataDescriptionId (Int value) {} 00092 virtual void setDataDescriptionIds(const casa::Vector<int>&){} 00093 virtual const Vector<MDirection> & direction1 () const {Vector<MDirection> dummy; return dummy;} 00094 virtual const Vector<MDirection> & direction2 () const {Vector<MDirection> dummy; return dummy;} 00095 virtual const Vector<Double> & exposure () const {Vector<Double> dummy; return dummy;} 00096 virtual void setExposure (const Vector<Double> & value) {} 00097 virtual const Vector<Int> & feed1 () const {Vector<Int> dummy; return dummy;} 00098 virtual void setFeed1 (const Vector<Int> & value) {} 00099 virtual const Vector<Int> & feed2 () const {Vector<Int> dummy; return dummy;} 00100 virtual void setFeed2 (const Vector<Int> & value) {} 00101 virtual const Vector<Int>& fieldId () const {Vector<Int> dummy; return dummy;} 00102 virtual void setFieldId (const Vector<Int>&) {} 00103 virtual const Matrix<Bool> & flag () const {Matrix<Bool> dummy; return dummy;} 00104 virtual void setFlag (const Matrix<Bool>& value) {} 00105 virtual const Array<Bool> & flagCategory () const {Array<Bool> dummy; return dummy;} 00106 virtual void setFlagCategory (const Array<Bool>& value) {} 00107 virtual const Cube<Bool> & flagCube () const {Cube<Bool> dummy; return dummy;} 00108 virtual void setFlagCube (const Cube<Bool>& value) {} 00109 virtual const Vector<Bool> & flagRow () const {Vector<Bool> dummy; return dummy;} 00110 virtual void setFlagRow (const Vector<Bool>& value) {} 00111 virtual const Vector<Int> & observationId () const {Vector<Int> dummy; return dummy;} 00112 virtual void setObservationId (const Vector<Int> & value) {} 00113 virtual const Vector<Int> & processorId () const {Vector<Int> dummy; return dummy;} 00114 virtual void setProcessorId (const Vector<Int> & value) {} 00115 virtual const Vector<Int> & scan () const {Vector<Int> dummy; return dummy;} 00116 virtual void setScan (const Vector<Int> & value) {} 00117 virtual const Matrix<Float> & sigma () const {Matrix<Float> dummy; return dummy;} 00118 virtual void setSigma (const Matrix<Float> & value) {} 00119 virtual const Matrix<Float> & sigmaMat () const {Matrix<Float> dummy; return dummy;} 00120 virtual const Vector<Int> & stateId () const {Vector<Int> dummy; return dummy;} 00121 virtual void setStateId (const Vector<Int> & value) {} 00122 virtual const Vector<Double> & time () const {Vector<Double> dummy; return dummy;} 00123 virtual void setTime (const Vector<Double> & value) {} 00124 virtual const Vector<Double> & timeCentroid () const {Vector<Double> dummy; return dummy;} 00125 virtual void setTimeCentroid (const Vector<Double> & value) {} 00126 virtual const Vector<Double> & timeInterval () const {Vector<Double> dummy; return dummy;} 00127 virtual void setTimeInterval (const Vector<Double> & value) {} 00128 virtual const Matrix<Double> & uvw () const {Matrix<Double> dummy; return dummy;} 00129 virtual void setUvw (const Matrix<Double> & value) {} 00130 virtual const Matrix<Float> & weight () const {Matrix<Float> dummy; return dummy;} 00131 virtual void setWeight (const Matrix<Float>& value) {} 00132 virtual const Matrix<Float> & weightMat () const {Matrix<Float> dummy; return dummy;} 00133 virtual void setWeightMat (const Matrix<Float>& value) {} 00134 virtual const Cube<Float> & weightSpectrum () const {Cube<Float> dummy; return dummy;} 00135 virtual void setWeightSpectrum (const Cube<Float>& value) {} 00136 00137 virtual const Cube<Complex> & visCube () const {Cube<Complex> dummy; return dummy;} 00138 virtual void setVisCube(const Complex & c) {} 00139 virtual void setVisCube (const Cube<Complex> &){} 00140 virtual const Matrix<CStokesVector> & vis () const {Matrix<CStokesVector> dummy; return dummy;} 00141 virtual void setVis (Matrix<CStokesVector> &) {} 00142 virtual const Cube<Complex> & visCubeCorrected () const {Cube<Complex> dummy; return dummy;} 00143 virtual void setVisCubeCorrected (const Cube<Complex> &) {} 00144 virtual const Matrix<CStokesVector> & visCorrected () const {Matrix<CStokesVector> dummy; return dummy;} 00145 virtual void setVisCorrected (const Matrix<CStokesVector> &) {} 00146 virtual const Cube<Float> & visCubeFloat () const {Cube<Float> dummy; return dummy;} 00147 virtual void setVisCubeFloat (const Cube<Float> &) {} 00148 virtual const Cube<Complex> & visCubeModel () const {Cube<Complex> dummy; return dummy;} 00149 virtual void setVisCubeModel(const Complex & c) {} 00150 virtual void setVisCubeModel(const Cube<Complex>& vis) {} 00151 virtual void setVisCubeModel(const Vector<Float>& stokes) {} 00152 virtual const Matrix<CStokesVector> & visModel () const {Matrix<CStokesVector> dummy; return dummy;} 00153 virtual void setVisModel (Matrix<CStokesVector> &) {} 00154 00155 virtual MDirection azel0 (Double time) const {MDirection dummy; return dummy;} 00156 virtual Vector<MDirection> & azel(Double time) const {Vector<MDirection> dummy; return dummy;} 00157 virtual const Vector<SquareMatrix<Complex, 2> > & cjones () const {Vector<SquareMatrix<Complex, 2> > dummy; return dummy;} 00158 virtual const Vector<Int> & correlationTypes () const {Vector<Int> dummy; return dummy;} 00159 virtual Vector<Float> & feedPa(Double time) const {Vector<Float> dummy; return dummy;} 00160 virtual const Vector<Float> & feedPa1 () const {Vector<Float> dummy; return dummy;} 00161 virtual const Vector<Float> & feedPa2 () const {Vector<Float> dummy; return dummy;} 00162 virtual Double hourang(Double time) const {Double dummy; return dummy;} 00163 virtual Int nAntennas () const {Int dummy; return dummy;} 00164 virtual Int nChannels () const {Int dummy; return dummy;} 00165 virtual Int nCorrelations () const {Int dummy; return dummy;} 00166 virtual Int nRows () const {Int dummy; return dummy;} 00167 virtual Float parang0(Double time) const {Float dummy; return dummy;} 00168 virtual Vector<Float> & parang(Double time) const {Vector<Float> dummy; return dummy;} 00169 virtual const MDirection& phaseCenter () const {MDirection dummy; return dummy;} 00170 virtual Int polarizationFrame () const {Int dummy; return dummy;} 00171 virtual Int polarizationId () const {Int dummy; return dummy;} 00172 virtual const Vector<uInt> & rowIds () const {Vector<uInt> dummy; return dummy;} 00173 virtual Int spectralWindow () const {Int dummy; return dummy;} 00174 virtual const Vector<Int> & spectralWindows () const {Vector<Int> dummy; return dummy;} 00175 virtual void setSpectralWindows (const Vector<Int> & /*spectralWindows*/) {} 00176 00177 virtual void setFillable (Bool isFillable) {} 00178 virtual const Vector<Int> & dataDescriptionIds () const {Vector<Int> dummy; return dummy;} 00179 virtual Vector<Int> getCorrelationNumbers () const {Vector<Int> dummy; return dummy;} 00180 virtual void validateShapes () const {} 00181 00182 protected: 00183 00184 virtual void configureNewSubchunk (Int msId, const String & msName, Bool isNewMs, 00185 Bool isNewArrayId, Bool isNewFieldId, 00186 Bool isNewSpectralWindow, const vi::Subchunk & subchunk, 00187 Int nRows, Int nChannels, Int nCorrelations, 00188 const Vector<Int> & correlations) {} 00189 virtual void invalidate() {} 00190 virtual Bool isRekeyable () const {Bool dummy; return dummy;} 00191 virtual void setRekeyable (Bool isRekeable) {} 00192 00193 }; 00194 00195 00196 class CTCache 00197 { 00198 00199 public: 00200 CTCache(CTIter *calIter); 00201 ~CTCache(); 00202 00203 Int arrayId(); 00204 Int fieldId(); 00205 Int spectralWindow(); 00206 Vector<Int>& scan(); 00207 Vector<Double>& time(); 00208 Vector<Int>& antenna1(); 00209 Vector<Int>& antenna2(); 00210 Cube<Bool>& flagCube(); 00211 Vector<Int>& getChannelNumbers(Int rowInBuffer); 00212 Vector<Double>& getFrequencies(Int rowInBuffer,Int frame = vi::VisBuffer2::FrameNotSpecified); 00213 Int nRowChunk(); 00214 Int nRows(); 00215 Int nChannels(); 00216 Int nCorrelations(); 00217 00218 Cube<Complex>& visCube(); 00219 Cube<Complex>& visCubeCorrected(); 00220 Cube<Complex>& visCubeModel(); 00221 00222 // Convenient public methods for compatibility with MS-like interface 00223 Vector<Int>& observationId(); 00224 Vector<Int>& correlationTypes(); 00225 00226 // Methods for efficient synchronization with CTIter 00227 void invalidate(); 00228 00229 private: 00230 00231 CTIter *calIter_p; 00232 Int field0_p; 00233 Int spw0_p; 00234 Vector<Int> field_p; 00235 Vector<Int> spw_p; 00236 Vector<Int> scan_p; 00237 Vector<Double> time_p; 00238 Vector<Int> antenna1_p; 00239 Vector<Int> antenna2_p; 00240 Cube<Bool> flagCube_p; 00241 Vector<Int> channel_p; 00242 Vector<Double> frequency_p; 00243 Cube<Complex> cparam_p; // This is an actual Cube<Complex> 00244 Cube<Complex> fparam_p; // This is in reality a Cube<Float> 00245 Cube<Complex> snr_p; // This is in reality a Cube<Float> 00246 Int nRowChunk_p; 00247 Int nRow_p; 00248 Int nChannel_p; 00249 Int nCorr_p; 00250 00251 // Convenient members for compatibility with MS-like interface 00252 Vector<Int> observationId_p; 00253 Vector<Int> corrType_p; 00254 00255 // Members for efficient synchronization with CTIter 00256 Bool CTfieldIdOK_p; 00257 Bool CTspectralWindowOK_p; 00258 Bool CTscanOK_p; 00259 Bool CTtimeOK_p; 00260 Bool CTantenna1OK_p; 00261 Bool CTantenna2OK_p; 00262 Bool CTflagCubeOk_p; 00263 Bool CTobservationIdOK_p; 00264 Bool CTcorrTypeOK_p; 00265 Bool CTchannelOK_p; 00266 Bool CTfrequencyOK_p; 00267 Bool CTVisCubeOK_p; 00268 Bool CTcorrectedVisCubeOK_p; 00269 Bool CTmodelVisCubeOK_p; 00270 Bool CTnRowChunkOK_p; 00271 Bool CTnRowOK_p; 00272 Bool CTnChannelOK_p; 00273 Bool CTnCorrOK_p; 00274 00275 // Convenience methods and members to by-pass const methods issues 00276 Int& fillSpectralWindow(); 00277 Int& fillFieldId(); 00278 Int& fillnRowChunk(); 00279 00280 }; 00281 00282 00283 class CTBuffer: public DummyBufferImpl 00284 { 00285 00286 public: 00287 00288 CTBuffer(CTIter *ctIter) {ctCache_p = new CTCache(ctIter);invalidate();} 00289 ~CTBuffer() {} 00290 00291 const Vector<Int> & arrayId() const {arrayId_p.assign (Vector<Int> (time().nelements(), ctCache_p->arrayId())); return arrayId_p;} 00292 const Vector<Int> & fieldId() const {fieldId_p.assign (Vector<Int> (time().nelements(), ctCache_p->fieldId())); return fieldId_p;} 00293 Int spectralWindow() const {return ctCache_p->spectralWindow();} 00294 const Vector<Int>& scan() const {return ctCache_p->scan();} 00295 const Vector<Double>& time() const {return ctCache_p->time();} 00296 const Vector<Int>& antenna1() const {return ctCache_p->antenna1();} 00297 const Vector<Int>& antenna2() const {return ctCache_p->antenna2();} 00298 const Cube<Bool>& flagCube() const {return ctCache_p->flagCube();} 00299 const Vector<Int>& getChannelNumbers(Int rowInBuffer) const {return ctCache_p->getChannelNumbers(rowInBuffer);} 00300 const Vector<Double>& getFrequencies(Int rowInBuffer,Int frame = vi::VisBuffer2::FrameNotSpecified) const {return ctCache_p->getFrequencies(rowInBuffer);} 00301 Int nRows() const {return ctCache_p->nRows();} 00302 Int nChannels() const {return ctCache_p->nChannels();} 00303 Int nCorrelations() const {return ctCache_p->nCorrelations();} 00304 const Vector<Int> & spectralWindows () const { 00305 spectralWindows_p.assign (Vector<Int> (time().nelements(), ctCache_p->spectralWindow())); return spectralWindows_p;} 00306 00307 00308 const Cube<Complex>& visCube() const {return ctCache_p->visCube();} 00309 const Cube<Complex>& visCubeCorrected() const {return ctCache_p->visCubeCorrected();} 00310 const Cube<Complex>& visCubeModel() const {return ctCache_p->visCubeModel();} 00311 00312 // Convenient public methods for compatibility with MS-like interface 00313 const Vector<Int>& observationId() const {return ctCache_p->observationId();} 00314 const Vector<Int>& correlationTypes() const {return ctCache_p->correlationTypes();} 00315 00316 // Methods for efficient synchronization with CTIter 00317 void invalidate() {ctCache_p->invalidate();} 00318 00319 Vector<bool>& flagRowRef() {throw AipsError ("Not implemented " , __FILE__, __LINE__);} 00320 Cube<bool>& flagCubeRef() {throw AipsError ("Not implemented " , __FILE__, __LINE__);} 00321 Cube<complex<float> >& visCubeRef() {throw AipsError ("Not implemented " , __FILE__, __LINE__);} 00322 Cube<complex<float> >& visCubeCorrectedRef() {throw AipsError ("Not implemented " , __FILE__, __LINE__);} 00323 Cube<complex<float> >& visCubeModelRef() {throw AipsError ("Not implemented " , __FILE__, __LINE__);} 00324 Cube<float >& weightSpectrumRef() {throw AipsError ("Not implemented " , __FILE__, __LINE__);} 00325 00326 00327 private: 00328 00329 mutable Vector<Int> arrayId_p; 00330 mutable Vector<Int> fieldId_p; 00331 mutable Vector<Int> spectralWindows_p; 00332 CTIter *calIter_p; 00333 CTCache *ctCache_p; 00334 00335 }; 00336 00337 // Flag Data Handler class definition 00338 class FlagCalTableHandler: public FlagDataHandler 00339 { 00340 00341 public: 00342 00343 // Default constructor 00344 // NOTE: Time interval 0 groups all time steps together in one chunk. 00345 FlagCalTableHandler(string msname, uShort iterationApproach = SUB_INTEGRATION, Double timeInterval = 0); 00346 00347 // Default destructor 00348 ~FlagCalTableHandler(); 00349 00350 // Open CalTable 00351 bool open(); 00352 00353 // Close CalTable 00354 bool close(); 00355 00356 // Generate selected CalTable 00357 bool selectData(); 00358 00359 // Parse MSSelection expression 00360 bool parseExpression(MSSelection &parser); 00361 00362 // Generate CalIter 00363 bool generateIterator(); 00364 00365 // Move to next chunk 00366 bool nextChunk(); 00367 00368 // Move to next buffer 00369 bool nextBuffer(); 00370 00371 // Write flag cube into MS 00372 bool flushFlags(); 00373 00374 // Provide table name (for flag version) 00375 String getTableName(); 00376 00377 // Check if a given column is available in the cal table 00378 bool checkIfColumnExists(String column); 00379 00380 // Signal true when a progress summary has to be printed 00381 bool summarySignal(); 00382 00383 private: 00384 00385 // Mapping functions 00386 void generateScanStartStopMap(); 00387 00388 // Convenient private methods for compatibility with MS-like interface 00389 Block<String> getSortColumns(Block<Int> intCols); 00390 00391 // CatTable selection objects 00392 NewCalTable *selectedCalTable_p; 00393 NewCalTable *originalCalTable_p; 00394 CTInterface *calTableInterface_p; 00395 00396 // Calibration Table iterator and buffer 00397 CTIter *calIter_p; 00398 CTBuffer *calBuffer_p; 00399 00400 }; 00401 00402 } //# NAMESPACE CASA - END 00403 00404 #endif /* FlagCalTableHandler_H_ */