casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ViImplementation2.h
Go to the documentation of this file.
00001 //# VisibilityIterator.h: Step through the MeasurementEquation by visibility
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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 received 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: VisibilityIterator2.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
00027 
00028 #if ! defined (MSVIS_ViImplementation2_H_121115_0950)
00029 #define MSVIS_ViImplementation2_H_121115_0950
00030 
00031 #include <casa/aips.h>
00032 #include <casa/BasicSL.h>
00033 #include <synthesis/MSVis/VisBufferComponents2.h>
00034 #include <measures/Measures/MFrequency.h>
00035 
00036 #include <boost/noncopyable.hpp>
00037 #include <map>
00038 #include <vector>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 template <typename T> class Array;
00043 template <typename T> class Block;
00044 //class CStokesVector;
00045 template <typename T> class Cube;
00046 template <typename T> class Matrix;
00047 class MDirection;
00048 class MeasurementSet;
00049 class MEpoch;
00050 class MPosition;
00051 class MSDerivedValues;
00052 class RecordInterface;
00053 template <typename T, Int n> class RigidVector;
00054 class Slice;
00055 class String;
00056 template <typename T, Int n> class SquareMatrix;
00057 template <typename T> class Vector;
00058 class VisImagingWeight;
00059 
00060 namespace vi {
00061 
00062 class FrequencySelections;
00063 class Subchunk;
00064 class VisibilityIterator2;
00065 
00066 //# forward decl
00067 
00068 class VisBuffer2;
00069 
00070 class ChannelSelector;
00071 class ChannelSelectorCache;
00072 class SpectralWindowChannelsCache;
00073 class SpectralWindowChannels;
00074 class SubtableColumns;
00075 
00076 
00077 // <summary>
00078 // VisibilityIterator2 iterates through one or more readonly MeasurementSets
00079 // </summary>
00080 
00081 // <use visibility=export>
00082 
00083 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00084 // </reviewed>
00085 
00086 // <prerequisite>
00087 //   <li> <linkto class="MSIter">MSIter</linkto>
00088 //   <li> <linkto class="MeasurementSet">MeasurementSet</linkto>
00089 //   <li> <linkto class="VisSet">VisSet</linkto>
00090 // </prerequisite>
00091 //
00092 // <etymology>
00093 // The VisibilityIterator2 is a readonly iterator returning visibilities
00094 // </etymology>
00095 //
00096 // <synopsis>
00097 // VisibilityIterator2 provides iteration with various sort orders
00098 // for one or more MSs. It has member functions to retrieve the fields
00099 // commonly needed in synthesis calibration and imaging.
00100 //
00101 // One should use <linkto class="VisBuffer">VisBuffer</linkto>
00102 // to access chunks of data.
00103 // </synopsis>
00104 //
00105 // <example>
00106 // <code>
00107 // //
00108 // </code>
00109 // </example>
00110 //
00111 // <motivation>
00112 // For imaging and calibration you need to access an MS in some consistent
00113 // order (by field, spectralwindow, time interval etc.). This class provides
00114 // that access.
00115 // </motivation>
00116 //
00117 // <thrown>
00118 //    <li>
00119 //    <li>
00120 // </thrown>
00121 //
00122 // <todo asof="1997/05/30">
00123 //   <li> cleanup the currently dual interface for visibilities and flags
00124 //   <li> sort out what to do with weights when interpolating
00125 // </todo>
00126 
00127 class ViImplementation2 : private boost::noncopyable {
00128 
00129     friend class VisibilityIterator2;
00130 
00131 public:
00132 
00133     ViImplementation2 () {}
00134 
00135     // Destructor
00136 
00137     virtual ~ViImplementation2 () {}
00138 
00139     //   +==================================+
00140     //   |                                  |
00141     //   | Iteration Control and Monitoring |
00142     //   |                                  |
00143     //   +==================================+
00144 
00145 
00146     // Methods to control and monitor subchunk iteration
00147 
00148     virtual void origin () = 0;
00149     virtual Bool more () const = 0;
00150     virtual void next () = 0;
00151     virtual Subchunk getSubchunkId () const = 0;
00152 
00153     // Methods to control chunk iterator
00154 
00155     virtual void originChunks (Bool forceRewind = False) = 0;
00156     virtual Bool moreChunks () const = 0;
00157     virtual void nextChunk () = 0;
00158 
00159     virtual Bool isWritable () const = 0;
00160 
00161     // Return the time interval (in seconds) used for iteration.
00162     // This is not the same as the INTERVAL column.  Setting the
00163     // the interval requires calling origin chunks before performing
00164     // further iterator.
00165 
00166     virtual Double getInterval() const = 0;
00167     virtual void setInterval (Double timeInterval) = 0;
00168 
00169     // Select the channels to be returned.  Requires calling originChunks before
00170     // performing additional iteration.
00171 
00172     virtual void setFrequencySelections (const FrequencySelections & selection) = 0;
00173 
00174     // Set the 'blocking' size for returning data.
00175     // With the default (0) only a single integration is returned at a time, this
00176     // is what is currently required for the calibration software. With blocking
00177     // set, up to nRows can be returned in one go. The chunk
00178     // size determines the actual maximum.
00179 
00180     virtual void setRowBlocking (Int nRows = 0) = 0;
00181 
00182     virtual Bool existsColumn (VisBufferComponent2 id) const = 0;
00183 
00184     virtual const Block<Int>& getSortColumns() const = 0;
00185 
00186     virtual Bool isNewArrayId () const = 0;
00187     virtual Bool isNewFieldId () const = 0;
00188     virtual Bool isNewMs () const = 0;
00189     virtual Bool isNewSpectralWindow () const = 0;
00190 
00191     // Return the number of rows in the current iteration
00192 
00193     virtual Int nRows () const = 0;
00194 
00195     // Return the row ids as from the original root table. This is useful
00196     // to find correspondance between a given row in this iteration to the
00197     // original ms row
00198 
00199     virtual void getRowIds (Vector<uInt> & rowids) const = 0;
00200 
00201     virtual VisBuffer2 * getVisBuffer () = 0;
00202 
00203 
00204     //   +=========================+
00205     //   |                         |
00206     //   | Subchunk Data Accessors |
00207     //   |                         |
00208     //   +=========================+
00209 
00210     // Return antenna1
00211 
00212     virtual void antenna1 (Vector<Int> & ant1) const = 0;
00213 
00214     // Return antenna2
00215 
00216     virtual void antenna2 (Vector<Int> & ant2) const = 0;
00217 
00218     // Return the correlation type (returns Stokes enums)
00219 
00220     virtual void corrType (Vector<Int> & corrTypes) const = 0;
00221 
00222     // Return current DataDescription Id
00223 
00224     virtual Int dataDescriptionId () const = 0;
00225 
00226     virtual void dataDescriptionIds (Vector<Int> & ddis) const = 0;
00227 
00228     // Return actual time interval
00229 
00230     virtual void  exposure (Vector<Double> & expo) const = 0;
00231 
00232     // Return feed1
00233 
00234     virtual void feed1 (Vector<Int> & fd1) const = 0;
00235 
00236     // Return feed2
00237 
00238     virtual void feed2 (Vector<Int> & fd2) const = 0;
00239 
00240     // Return the current FieldId
00241 
00242     virtual void fieldIds (Vector<Int>&) const = 0;
00243 
00244     // Return the current ArrayId
00245 
00246     virtual void arrayIds (Vector<Int>&) const = 0;
00247 
00248     // Return the current Field Name
00249 
00250     virtual String fieldName () const = 0;
00251 
00252     // Return flag for each polarization, channel and row
00253 
00254     virtual void flag (Cube<Bool> & flags) const = 0;
00255 
00256     // Return flag for each channel & row
00257 
00258     virtual void flag (Matrix<Bool> & flags) const = 0;
00259 
00260     // Determine whether FLAG_CATEGORY is valid.
00261 
00262     virtual Bool flagCategoryExists () const = 0;
00263 
00264     // Return flags for each polarization, channel, category, and row.
00265 
00266     virtual void flagCategory (Array<Bool> & flagCategories) const = 0;
00267 
00268     // Return row flag
00269 
00270     virtual void flagRow (Vector<Bool> & rowflags) const = 0;
00271 
00272     // Return the OBSERVATION_IDs
00273 
00274     virtual void observationId (Vector<Int> & obsids) const = 0;
00275 
00276     // Return current Polarization Id
00277 
00278     virtual Int polarizationId () const = 0;
00279 
00280     // Return the PROCESSOR_IDs
00281 
00282     virtual void processorId (Vector<Int> & procids) const = 0;
00283 
00284     // Return scan number
00285 
00286     virtual void scan (Vector<Int> & scans) const = 0;
00287 
00288     // Return the current Source Name
00289 
00290     virtual String sourceName () const = 0;
00291 
00292     // Return the STATE_IDs
00293 
00294     virtual void stateId (Vector<Int> & stateids) const = 0;
00295 
00296 
00297     // Return feed configuration matrix for specified antenna
00298 
00299     virtual void jonesC (Vector<SquareMatrix<Complex, 2> > & cjones) const = 0;
00300 
00301     // Return frame for polarization (returns PolFrame enum)
00302 
00303     virtual Int polFrame () const = 0;
00304 
00305     // Return sigma
00306 
00307     virtual void sigma (Vector<Float> & sig) const = 0;
00308 
00309     // Return sigma matrix (pol-dep)
00310 
00311     virtual void sigmaMat (Matrix<Float> & sigmat) const = 0;
00312 
00313     // Return current SpectralWindow
00314 
00315     virtual Int spectralWindow () const = 0;
00316 
00317     virtual void spectralWindows (Vector<Int> & spws) const = 0;
00318 
00319     // Return MJD midpoint of interval.
00320 
00321     virtual void time (Vector<Double> & t) const = 0;
00322 
00323     // Return MJD centroid of interval.
00324 
00325     virtual void timeCentroid (Vector<Double> & t) const = 0;
00326 
00327     // Return nominal time interval
00328 
00329     virtual void timeInterval (Vector<Double> & ti) const = 0;
00330 
00331     // Return u,v and w (in meters)
00332 
00333     virtual void uvw (Matrix<Double> & uvwmat) const = 0;
00334 
00335     // Return the visibilities as found in the MS, Cube (npol,nchan,nrow).
00336 
00337     virtual void visibilityCorrected (Cube<Complex> & vis) const = 0;
00338     virtual void visibilityModel (Cube<Complex> & vis) const = 0;
00339     virtual void visibilityObserved (Cube<Complex> & vis) const = 0;
00340 
00341     // Return FLOAT_DATA as a Cube (npol, nchan, nrow) if found in the MS.
00342 
00343     virtual void floatData (Cube<Float> & fcube) const = 0;
00344 
00345     // Return the visibility 4-vector of polarizations for each channel.
00346     // If the MS doesn't contain all polarizations, it is assumed it
00347     // contains one or two parallel hand polarizations.
00348 
00349 //    virtual void visibilityCorrected (Matrix<CStokesVector> & vis) const = 0;
00350 //    virtual void visibilityModel (Matrix<CStokesVector> & vis) const = 0;
00351 //    virtual void visibilityObserved (Matrix<CStokesVector> & vis) const = 0;
00352 
00353     // Return the shape of the visibility Cube
00354 
00355     virtual IPosition visibilityShape () const = 0;
00356 
00357 
00358     // Return weight
00359 
00360     virtual void weight (Vector<Float> & wt) const = 0;
00361 
00362     // Returns the nPol_p x curNumRow_p weight matrix
00363 
00364     virtual void weightMat (Matrix<Float> & wtmat) const = 0;
00365 
00366     // Determine whether WEIGHT_SPECTRUM exists.
00367 
00368     virtual Bool weightSpectrumExists () const = 0;
00369 
00370     // Return weightspectrum (a weight for each channel)
00371 
00372     virtual void weightSpectrum (Cube<Float> & wtsp) const = 0;
00373 
00374     // Return the number of sub-intervals in the current chunk
00375 
00376     //   +------------------------+
00377     //   |                        |
00378     //   | Angular Data Providers |
00379     //   |                        |
00380     //   +------------------------+
00381 
00382     // True if all elements of the cube returned by getBeamOffsets are zero
00383 
00384     virtual Bool allBeamOffsetsZero () const = 0;
00385 
00386     // Return the antenna AZ/EL Vector (nant)
00387 
00388     virtual MDirection azel0 (Double time) const = 0;
00389     static void azel0Calculate (Double time, MSDerivedValues & msd,
00390                                 MDirection & azel0, const MEpoch & mEpoch0);
00391 
00392     virtual const Vector<MDirection> & azel (Double time) const = 0;
00393     static void azelCalculate (Double time, MSDerivedValues & msd, Vector<MDirection> & azel,
00394                                Int nAnt, const MEpoch & mEpoch0);
00395 
00396     // Return feed parallactic angles Vector (nant) (1 feed/ant)
00397 
00398     virtual const Vector<Float> & feed_pa (Double time) const = 0;
00399     static Vector<Float> feed_paCalculate (Double time, MSDerivedValues & msd,
00400                                            Int nAntennas, const MEpoch & mEpoch0,
00401                                            const Vector<Float> & receptor0Angle);
00402 
00403     // Return a cube containing pairs of coordinate offsets for each
00404     // receptor of each feed (values are in radians, coordinate system is fixed
00405     // with antenna and is the same one as used to define the BEAM_OFFSET
00406     // parameter in the feed table). The cube axes are receptor, antenna, feed.
00407 
00408     virtual const Cube<RigidVector<Double, 2> > & getBeamOffsets () const = 0;
00409 
00410     // Return the hour angle for the specified time
00411 
00412     virtual Double hourang (Double time) const = 0;
00413     static Double hourangCalculate (Double time, MSDerivedValues & msd, const MEpoch & mEpoch0);
00414 
00415     // Return nominal parallactic angle at specified time
00416     // (does not include feed position angle offset--see feed_pa)
00417     // A global value for all antennas (e.g., small array)
00418 
00419     virtual const Float & parang0 (Double time) const = 0;
00420     static Float parang0Calculate (Double time, MSDerivedValues & msd, const MEpoch & epoch0);
00421 
00422     // Per antenna:
00423 
00424     virtual const Vector<Float> & parang (Double time) const = 0;
00425     static Vector<Float> parangCalculate (Double time, MSDerivedValues & msd,
00426                                           int nAntennas, const MEpoch mEpoch0);
00427 
00428     // Return the current phase center as an MDirection
00429 
00430     virtual const MDirection & phaseCenter () const = 0;
00431 
00432     // Return receptor angles for all antennae and feeds
00433     // First axis of the cube is a receptor number,
00434     // 2nd is antennaId, 3rd is feedId
00435     // Note: the method is intended to provide an access to MSIter::receptorAngles
00436     // for VisBuffer in the multi-feed case. It may be worth to change the
00437     // interface of feed_pa to return the information for all feeds.
00438 
00439     virtual const Cube<Double> & receptorAngles () const = 0;
00440 
00441     //   +=========================+
00442     //   |                         |
00443     //   | Chunk and MS Level Data |
00444     //   |                         |
00445     //   +=========================+
00446 
00447     // return a string mount identifier for each antenna
00448 
00449     virtual const Vector<String> & antennaMounts () const = 0;
00450 
00451     virtual MEpoch getEpoch () const = 0;
00452 
00453     // Return imaging weight (a weight for each channel)
00454     //virtual Matrix<Float> & imagingWeight (Matrix<Float> & wt) const = 0;
00455 
00456     virtual const VisImagingWeight & getImagingWeightGenerator () const = 0;
00457 
00458     virtual MFrequency::Types getObservatoryFrequencyType () const = 0; //???
00459     virtual MPosition getObservatoryPosition () const = 0;
00460     virtual Vector<Float> getReceptor0Angle () = 0;
00461 
00462     virtual Int getReportingFrameOfReference () const = 0;
00463     virtual void setReportingFrameOfReference (Int frame) = 0;
00464 
00465     virtual Vector<Int> getCorrelations () const = 0;
00466     virtual Vector<Int> getChannels (Double time, Int frameOfReference) const = 0;
00467     virtual Vector<Double> getFrequencies (Double time, Int frameOfReference) const = 0;
00468 
00469 
00470     //reference to actual ms in interator
00471 
00472     virtual Int msId () const = 0; // zero-based index of current MS in set of MSs
00473     virtual const MeasurementSet & ms () const = 0;
00474     virtual Int getNMs () const = 0;
00475 
00476     // Call to use the slurp i/o method for all scalar columns. This
00477     // will set the BucketCache cache size to the full column length
00478     // and cause the full column to be cached in memory, if
00479     // any value of the column is used. In case of out-of-memory,
00480     // it will automatically fall-back on the smaller cache size.
00481     // Slurping the column is to be considered as a work-around for the
00482     // Table i/o code, which uses BucketCache and performs extremely bad
00483     // for random access. Slurping is useful when iterating non-sequentially
00484     // an MS or parts of an MS, it is not tested with multiple MSs.
00485 
00486     virtual void slurp () const = 0;
00487 
00488     // Access the current ROMSColumns object in MSIter
00489 
00490     virtual const vi::SubtableColumns & subtableColumns () const = 0;
00491 
00492     // get back the selected spectral windows and spectral channels for
00493     // current ms
00494 
00495     virtual const SpectralWindowChannels & getSpectralWindowChannels (Int msId, Int spectralWindowId) const = 0;
00496 
00497     //assign a VisImagingWeight object to this iterator
00498 
00499     virtual void useImagingWeight (const VisImagingWeight & imWgt) = 0;
00500 
00501     // Return number of antennasm spws, polids, ddids
00502 
00503     virtual Int nAntennas () const = 0;
00504     virtual Int nDataDescriptionIds () const = 0;
00505     virtual Int nPolarizations () const = 0;
00506     virtual Int nRowsInChunk () const = 0; // number rows in current chunk
00507     virtual Int nRowsViWillSweep () const = 0; // number of rows in all selected ms's
00508     virtual Int nSpectralWindows () const = 0;
00509 
00510     //   +-------------------+
00511     //   |                   |
00512     //   | Writeback Methods |
00513     //   |                   |
00514     //   +-------------------+
00515 
00516     // This method writes back any changed (dirty) components of the provided
00517     // VisBuffer and is the preferred method for writing data out.
00518 
00519     virtual void writeBackChanges (VisBuffer2 * vb) = 0;
00520 
00521     // Write/modify the flags in the data.
00522     // This will flag all channels in the original data that contributed to
00523     // the output channel in the case of channel averaging.
00524     // All polarizations have the same flag value.
00525     virtual void writeFlag (const Matrix<Bool> & flag) = 0;
00526 
00527     // Write/modify the flags in the data.
00528     // This writes the flags as found in the MS, Cube (npol,nchan,nrow),
00529     // where nrow is the number of rows in the current iteration (given by
00530     // nRow ()).
00531     virtual void writeFlag (const Cube<Bool> & flag) = 0;
00532 
00533     // Write/modify the flag row column = 0; dimension Vector (nrow)
00534     virtual void writeFlagRow (const Vector<Bool> & rowflags) = 0;
00535 
00536     virtual void writeFlagCategory(const Array<Bool>& fc) = 0;
00537 
00538     // Write/modify the visibilities.
00539     // This is possibly only for a 'reference' MS which has a new DATA column.
00540     // The first axis of the matrix should equal the selected number of channels
00541     // in the original MS.
00542     // If the MS does not contain all polarizations, only the parallel
00543     // hand polarizations are used.
00544 //    virtual void writeVisCorrected (const Matrix<CStokesVector> & visibilityStokes) = 0;
00545 //    virtual void writeVisModel (const Matrix<CStokesVector> & visibilityStokes) = 0;
00546 //    virtual void writeVisObserved (const Matrix<CStokesVector> & visibilityStokes) = 0;
00547 
00548     // Write/modify the visibilities
00549     // This writes the data as found in the MS, Cube (npol,nchan,nrow).
00550     virtual void writeVisCorrected (const Cube<Complex> & vis) = 0;
00551     virtual void writeVisModel (const Cube<Complex> & vis) = 0;
00552     virtual void writeVisObserved (const Cube<Complex> & vis) = 0;
00553 
00554     // Write/modify the weights
00555     virtual void writeWeight (const Matrix<Float> & wt) = 0;
00556 
00557     // Write/modify the weightMat
00558     //virtual void writeWeightMat (const Matrix<Float> & wtmat) = 0;
00559 
00560     // Write/modify the weightSpectrum
00561     virtual void writeWeightSpectrum (const Cube<Float> & wtsp) = 0;
00562 
00563     // Write/modify the Sigma
00564     virtual void writeSigma (const Matrix<Float> & sig) = 0;
00565 
00566     // Write/modify the ncorr x nrow SigmaMat.
00567     //virtual void writeSigmaMat (const Matrix<Float> & sigmat) = 0;
00568 
00569     // Write the information needed to generate on-the-fly model visibilities.
00570 
00571     virtual void writeModel(const RecordInterface& rec, Bool iscomponentlist=True,
00572                             Bool incremental=False) = 0;
00573 
00574 
00575 protected:
00576 
00577 };
00578 
00579 } // end namespace vi
00580 
00581 } //# NAMESPACE CASA - END
00582 
00583 #endif // ! defined (MSVIS_ViImplementation2_H_121115_0950)
00584 
00585