casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisIterator.h
Go to the documentation of this file.
00001 //# VisIterator.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: VisIterator.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
00027 
00028 #ifndef MSVIS_VISITERATOR_H
00029 #define MSVIS_VISITERATOR_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Matrix.h>
00033 #include <casa/Arrays/Cube.h>
00034 #include <casa/Arrays/Slicer.h>
00035 #include <casa/Containers/Stack.h>
00036 #include <casa/Containers/OrderedMap.h>
00037 #include <ms/MeasurementSets/MeasurementSet.h>
00038 #include <measures/Measures/Stokes.h>
00039 #include <measures/Measures/MeasConvert.h>
00040 #include <casa/Quanta/MVDoppler.h>
00041 #include <measures/Measures/MCDoppler.h>
00042 #include <measures/Measures/MDoppler.h>
00043 #include <tables/Tables/ArrayColumn.h>
00044 #include <tables/Tables/ScalarColumn.h>
00045 #include <casa/BasicSL/String.h>
00046 #include <scimath/Mathematics/SquareMatrix.h>
00047 #include <scimath/Mathematics/RigidVector.h>
00048 
00049 #include <ms/MeasurementSets/MSDerivedValues.h>
00050 #include <synthesis/MSVis/StokesVector.h>
00051 #include <synthesis/MSVis/VisImagingWeight.h>
00052 #include <synthesis/MSVis/VisibilityIterator.h>
00053 #include <ms/MeasurementSets/MSIter.h>
00054 
00055 namespace casa { //# NAMESPACE CASA - BEGIN
00056 
00057 //# forward decl
00058 class VisBuffer;
00059 
00060 // <summary>
00061 // ROVisIterator iterates through one or more readonly MeasurementSets
00062 // </summary>
00063 
00064 // <use visibility=export>
00065 
00066 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00067 // </reviewed>
00068 
00069 // <prerequisite>
00070 //   <li> <linkto class="MSIter">MSIter</linkto>
00071 //   <li> <linkto class="MeasurementSet">MeasurementSet</linkto>
00072 //   <li> <linkto class="VisSet">VisSet</linkto>
00073 // </prerequisite>
00074 //
00075 // <etymology>
00076 // The ROVisIterator is a readonly iterator returning visibilities
00077 // </etymology>
00078 //
00079 // <synopsis>
00080 // ROVisIterator provides iteration with various sort orders
00081 // for one or more MSs. It has member functions to retrieve the fields
00082 // commonly needed in synthesis calibration and imaging.
00083 //
00084 // One should use <linkto class="VisBuffer">VisBuffer</linkto>
00085 // to access chunks of data.
00086 // </synopsis>
00087 //
00088 // <example>
00089 // <code>
00090 // //
00091 // </code>
00092 // </example>
00093 //
00094 // <motivation>
00095 // For imaging and calibration you need to access an MS in some consistent
00096 // order (by field, spectralwindow, time interval etc.). This class provides
00097 // that access.
00098 //
00099 // Unlike ROVisibilityIterator, this supports non-strided in-row selection
00100 // (e.g., of channels and correlations).
00101 // </motivation>
00102 //
00103 // <thrown>
00104 //    <li>
00105 //    <li>
00106 // </thrown>
00107 //
00108 // <todo asof="1997/05/30">
00109 //   <li> cleanup the currently dual interface for visibilities and flags
00110 //   <li> sort out what to do with weights when interpolating
00111 //   <li> Handle the multi-MS case like ROVisibilityIterator does.
00112 // </todo>
00113 
00114 class ROVisIteratorImpl;
00115 
00116 class ROVisIterator : public ROVisibilityIterator
00117 {
00118   public:
00119 
00120   // Default constructor - useful only to assign another iterator later
00121   ROVisIterator();
00122 
00123   // Construct from MS and a Block of MS column enums specifying the iteration
00124   // order, if none are specified, time iteration is implicit.  An optional
00125   // timeInterval can be given to iterate through chunks of time.  The default
00126   // interval of 0 groups all times together.  Every 'chunk' of data contains
00127   // all data within a certain time interval (in seconds) and with identical
00128   // values of the other iteration columns (e.g.  DATA_DESC_ID and FIELD_ID).
00129   // Using selectChannel(), a number of groups of channels can be requested.
00130   // At present the channel group iteration will always occur before the
00131   // interval iteration.
00132   ROVisIterator(const MeasurementSet& ms, 
00133                 const Block<Int>& sortColumns, 
00134                 Double timeInterval=0);
00135 
00136   ROVisIterator(const MeasurementSet & ms, const Block<Int>& sortColumns,
00137                 Double timeInterval, const ROVisibilityIterator::Factory & factory);
00138 
00139 
00140   // Copy construct. This calls the assignment operator.
00141   ROVisIterator(const ROVisIterator & other);
00142 
00143   // Destructor
00144   ~ROVisIterator();
00145 
00146   // Assignment. Any attached VisBuffers are lost in the assign.
00147   ROVisIterator & operator=(const ROVisIterator &other);
00148 
00149   // Members
00150   
00151   // Advance iterator through data
00152   ROVisIterator & operator++(int);
00153   ROVisIterator & operator++();
00154 
00155   // Return channel numbers in selected VisSet spectrum
00156   // (i.e. disregarding possible selection on the iterator, but
00157   //  including the selection set when creating the VisSet)
00158 
00159   Vector<Int>& chanIds(Vector<Int>& chanids) const;
00160   Vector<Int>& chanIds(Vector<Int>& chanids,Int spw) const;
00161 
00162   // Return selected correlation indices
00163   Vector<Int>& corrIds(Vector<Int>& corrids) const;
00164 
00165   // Return the correlation type (returns Stokes enums)
00166   Vector<Int>& corrType(Vector<Int>& corrTypes) const;
00167 
00168   // Set up new chan/corr selection via Vector<Slice>
00169   void selectChannel(const Vector<Vector<Slice> >& chansel);
00170   void selectCorrelation(const Vector<Vector<Slice> >& corrsel);
00171 
00172   // Set up/return channel averaging bounds 
00173   Vector<Matrix<Int> >& setChanAveBounds(Float factor, Vector<Matrix<Int> >& bounds);
00174 
00175   // Get selected spws and channel counts
00176   void allSelectedSpectralWindows (Vector<Int> & spws, Vector<Int> & nvischan);
00177   void lsrFrequency(const Int& spw, Vector<Double>& freq, Bool& convert, const  Bool ignoreconv=False);
00178 
00179   // The following throws an exception, because this isn't the
00180   // language of channel selection in VisIterator
00181   void getChannelSelection(Block< Vector<Int> >&,
00182                            Block< Vector<Int> >&,
00183                            Block< Vector<Int> >&,
00184                            Block< Vector<Int> >&,
00185                            Block< Vector<Int> >&) 
00186   { throw(AipsError("VisIterator::getChannelSelection: you can't do that!")); };
00187 
00188 
00189   // Return number of chans/corrs per spw/pol
00190   Int numberChan(Int spw) const;
00191   Int numberCorr(Int pol) const;
00192 
00193 protected:
00194 
00195   class Factory : public ROVisibilityIterator::Factory {
00196   public:
00197 
00198       Factory (ROVisIterator * vi) : vi_p (vi) {}
00199       VisibilityIteratorReadImpl *
00200       operator() (const asyncio::PrefetchColumns * prefetchColumns,
00201                   const Block<MeasurementSet>& mss,
00202                   const Block<Int>& sortColumns,
00203                   const Bool addDefaultSortCols,
00204                   Double timeInterval) const;
00205   private:
00206 
00207       ROVisIterator * vi_p;
00208 
00209   };
00210 
00211   void getDataColumn(DataColumn whichOne, const Vector<Vector<Slice> >& slices, Cube<Complex>& data) const;
00212   virtual ROVisIteratorImpl * getReadImpl () const;
00213 };
00214 
00215 // <summary>
00216 // VisIterator iterates through one or more writable MeasurementSets
00217 // </summary>
00218 
00219 // <use visibility=export>
00220 
00221 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00222 // </reviewed>
00223 
00224 // <prerequisite>
00225 //   <li> <linkto class="ROVisIterator">ROVisIterator</linkto>
00226 // </prerequisite>
00227 //
00228 // <etymology>
00229 // The VisIterator is a read/write iterator returning visibilities
00230 // </etymology>
00231 //
00232 // <synopsis>
00233 // VisIterator provides iteration with various sort orders
00234 // for one or more MSs. It has member functions to retrieve the fields
00235 // commonly needed in synthesis calibration and imaging. It is 
00236 // derived from the read-only iterator
00237 // <linkto class="ROVisIterator">ROVisIterator</linkto>.
00238 //
00239 // One should use <linkto class="VisBuffer">VisBuffer</linkto>
00240 // to access chunks of data.
00241 // </synopsis>
00242 //
00243 // <example>
00244 // <code>
00245 // //
00246 // </code>
00247 // </example>
00248 //
00249 // <motivation>
00250 // For imaging and calibration you need to access an MS in some consistent
00251 // order (by field, spectralwindow, time interval etc.). This class provides
00252 // that access.
00253 //
00254 // Unlike ROVisibilityIterator, this supports non-strided in-row selection
00255 // (e.g., of channels).
00256 // </motivation>
00257 //
00258 // #<thrown>
00259 //
00260 // #</thrown>
00261 //
00262 // <todo asof="1997/05/30">
00263 //   <li> cleanup the currently dual interface for visibilities and flags
00264 //   <li> sort out what to do with weights when interpolating
00265 //   <li> Handle the multi-MS case like VisibilityIterator does.
00266 // </todo>
00267 
00268 class VisIteratorImpl;
00269 
00270 class VisIterator : public ROVisIterator
00271 {
00272 public:
00273 
00274   // Constructors.
00275   // Note: The VisIterator is not initialized correctly by default, you
00276   // need to call origin() before using it to iterate.
00277   VisIterator();
00278   VisIterator(MeasurementSet & ms, const Block<Int>& sortColumns, 
00279               Double timeInterval=0);
00280 
00281   VisIterator(const VisIterator & MSI);
00282 
00283   // Destructor
00284   virtual ~VisIterator();
00285 
00286   VisIterator & operator=(const VisIterator &MSI);
00287 
00288   // Members
00289   
00290   // Advance iterator through data
00291   VisIterator & operator++(int);
00292   VisIterator & operator++();
00293 
00294   // Set/modify the flag row column; dimension Vector(nrow)
00295   void setFlagRow(const Vector<Bool>& rowflags);
00296 
00297   // Set/modify the flags in the data.
00298   // This sets the flags as found in the MS, Cube(npol,nchan,nrow),
00299   // where nrow is the number of rows in the current iteration (given by
00300   // nRow()).
00301   void setFlag(const Cube<Bool>& flag);
00302 
00303   // Set/modify the visibilities
00304   // This sets the data as found in the MS, Cube(npol,nchan,nrow).
00305   void setVis(const Cube<Complex>& vis, DataColumn whichOne);
00306 
00307   // Set the visibility and flags, and interpolate from velocities if needed
00308   void setVisAndFlag(const Cube<Complex>& vis, const Cube<Bool>& flag,
00309                      DataColumn whichOne);
00310 
00311   // Set/modify the weightMat
00312   void setWeightMat(const Matrix<Float>& wtmat);
00313 
00314   // Set/modify the weightSpectrum
00315   void setWeightSpectrum(const Cube<Float>& wtsp);
00316 
00317 protected:
00318 
00319   class Factory : public ROVisibilityIterator::Factory {
00320   public:
00321 
00322       Factory (VisIterator * vi) : vi_p (vi) {}
00323       VisibilityIteratorReadImpl *
00324       operator() (const asyncio::PrefetchColumns * prefetchColumns,
00325                   const Block<MeasurementSet>& mss,
00326                   const Block<Int>& sortColumns,
00327                   const Bool addDefaultSortCols,
00328                   Double timeInterval) const;
00329   private:
00330 
00331       VisIterator * vi_p;
00332 
00333   };
00334 
00335   virtual void attachColumns(const Table &t);
00336 
00337   // deals with Float or Complex observed data (DATA and FLOAT_DATA).
00338   void putDataColumn(DataColumn whichOne, const Vector<Vector<Slice> >& slices,
00339                      const Cube<Complex>& data);
00340   void putDataColumn(DataColumn whichOne, const Cube<Complex>& data);
00341 
00342   // column access functions
00343   virtual void putCol(ScalarColumn<Bool> &column, const Vector<Bool> &array);
00344 
00345   virtual void putCol(ArrayColumn<Bool> &column, const Array<Bool> &array);
00346   virtual void putCol(ArrayColumn<Float> &column, const Array<Float> &array);
00347   virtual void putCol(ArrayColumn<Complex> &column, const Array<Complex> &array);
00348 
00349   virtual void putCol(ArrayColumn<Bool> &column, const Slicer &slicer, const Array<Bool> &array);
00350   virtual void putCol(ArrayColumn<Float> &column, const Slicer &slicer, const Array<Float> &array);
00351   virtual void putCol(ArrayColumn<Complex> &column, const Slicer &slicer, const Array<Complex> &array);
00352 
00353   VisIteratorImpl * getImpl () const;
00354 };
00355 
00356 
00357 
00358 
00359 } //# NAMESPACE CASA - END
00360 
00361 #endif