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