MosaicFT.h

Go to the documentation of this file.
00001 //# MosaicFT.h: Definition for MosaicFT
00002 //# Copyright (C) 2003-2016
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 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 General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU  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 adressed 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 //#
00027 //# $Id$
00028 
00029 #ifndef SYNTHESIS_TRANSFORM2_MOSAICFT_H
00030 #define SYNTHESIS_TRANSFORM2_MOSAICFT_H
00031 
00032 #include <synthesis/TransformMachines2/FTMachine.h>
00033 #include <synthesis/TransformMachines2/SkyJones.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <scimath/Mathematics/FFTServer.h>
00036 #include <msvis/MSVis/VisBuffer2.h>
00037 #include <images/Images/ImageInterface.h>
00038 #include <images/Images/ImageInterface.h>
00039 #include <casa/Containers/Block.h>
00040 #include <casa/Arrays/Array.h>
00041 #include <casa/Arrays/Vector.h>
00042 #include <casa/Utilities/CountedPtr.h>
00043 #include <scimath/Mathematics/ConvolveGridder.h>
00044 #include <lattices/Lattices/LatticeCache.h>
00045 #include <lattices/Lattices/ArrayLattice.h>
00046 #include <ms/MeasurementSets/MSColumns.h>
00047 #include <measures/Measures/Measure.h>
00048 #include <measures/Measures/MDirection.h>
00049 #include <measures/Measures/MPosition.h>
00050 #include <coordinates/Coordinates/DirectionCoordinate.h>
00051 
00052 namespace casa { //# NAMESPACE CASA - BEGIN
00053 
00054 // <summary>  An FTMachine for Gridded Fourier transforms </summary>
00055 
00056 // <use visibility=export>
00057 
00058 // <reviewed reviewer="" date="" tests="" demos="">
00059 
00060 // <prerequisite>
00061 //   <li> <linkto class=FTMachine>FTMachine</linkto> module
00062 //   <li> <linkto class=SkyEquation>SkyEquation</linkto> module
00063 //   <li> <linkto class=VisBuffer>VisBuffer</linkto> module
00064 // </prerequisite>
00065 //
00066 // <etymology>
00067 // FTMachine is a Machine for Fourier Transforms. MosaicFT does
00068 // Grid-based Fourier transforms.
00069 // </etymology>
00070 //
00071 // <synopsis> 
00072 // The <linkto class=SkyEquation>SkyEquation</linkto> needs to be able
00073 // to perform Fourier transforms on visibility data. MosaicFT
00074 // allows efficient Fourier Transform processing using a 
00075 // <linkto class=VisBuffer>VisBuffer</linkto> which encapsulates
00076 // a chunk of visibility (typically all baselines for one time)
00077 // together with all the information needed for processing
00078 // (e.g. UVW coordinates).
00079 //
00080 // Gridding and degridding in MosaicFT are performed using a
00081 // novel sort-less algorithm. In this approach, the gridded plane is
00082 // divided into small patches, a cache of which is maintained in memory
00083 // using a general-purpose <linkto class=LatticeCache>LatticeCache</linkto> class. As the (time-sorted)
00084 // visibility data move around slowly in the Fourier plane, patches are
00085 // swapped in and out as necessary. Thus, optimally, one would keep at
00086 // least one patch per baseline.  
00087 //
00088 // A grid cache is defined on construction. If the gridded uv plane is smaller
00089 // than this, it is kept entirely in memory and all gridding and
00090 // degridding is done entirely in memory. Otherwise a cache of tiles is
00091 // kept an paged in and out as necessary. Optimally the cache should be
00092 // big enough to hold all polarizations and frequencies for all
00093 // baselines. The paging rate will then be small. As the cache size is
00094 // reduced below this critical value, paging increases. The algorithm will
00095 // work for only one patch but it will be very slow!
00096 //
00097 // This scheme works well for arrays having a moderate number of
00098 // antennas since the saving in space goes as the ratio of
00099 // baselines to image size. For the ATCA, VLBA and WSRT, this ratio is
00100 // quite favorable. For the VLA, one requires images of greater than
00101 // about 200 pixels on a side to make it worthwhile.
00102 //
00103 // The FFT step is done plane by plane for images having less than
00104 // 1024 * 1024 pixels on each plane, and line by line otherwise.
00105 //
00106 // The gridding and degridding steps are implemented in Fortran
00107 // for speed. In gridding, the visibilities are added onto the
00108 // grid points in the neighborhood using a weighting function.
00109 // In degridding, the value is derived by a weight summ of the
00110 // same points, using the same weighting function.
00111 // </synopsis> 
00112 //
00113 // <example>
00114 // See the example for <linkto class=SkyModel>SkyModel</linkto>.
00115 // </example>
00116 //
00117 // <motivation>
00118 // Define an interface to allow efficient processing of chunks of 
00119 // visibility data
00120 // </motivation>
00121 //
00122 // <todo asof="97/10/01">
00123 // <ul> Deal with large VLA spectral line case 
00124 // </todo>
00125   class MosaicFT;
00126  
00127   class MPosition;
00128   class UVWMachine;
00129 
00130 namespace refim{
00131    class SimplePBConvFunc;
00132 
00133 class MosaicFT : public FTMachine {
00134 public:
00135 
00136   // Constructor: cachesize is the size of the cache in words
00137   // (e.g. a few million is a good number), tilesize is the
00138   // size of the tile used in gridding (cannot be less than
00139   // 12, 16 works in most cases). 
00140   // <group>
00141   MosaicFT(SkyJones* sj, MPosition mloc, String stokes,
00142             Long cachesize, Int tilesize=16, 
00143            Bool usezero=True, Bool useDoublePrec=False);
00144   // </group>
00145 
00146   // Construct from a Record containing the MosaicFT state
00147   MosaicFT(const RecordInterface& stateRec);
00148 
00149   // Copy constructor
00150   MosaicFT(const MosaicFT &other);
00151 
00152   // Assignment operator
00153   MosaicFT &operator=(const MosaicFT &other);
00154 
00155   ~MosaicFT();
00156 
00157   // Initialize transform to Visibility plane using the image
00158   // as a template. The image is loaded and Fourier transformed.
00159   void initializeToVis(ImageInterface<Complex>& image,
00160                        const vi::VisBuffer2& vb);
00161  
00162   // Finalize transform to Visibility plane: flushes the image
00163   // cache and shows statistics if it is being used.
00164   void finalizeToVis();
00165 
00166   // Initialize transform to Sky plane: initializes the image
00167   void initializeToSky(ImageInterface<Complex>& image,  Matrix<Float>& weight,
00168                        const vi::VisBuffer2& vb);
00170  
00171   // Finalize transform to Sky plane: flushes the image
00172   // cache and shows statistics if it is being used. DOES NOT
00173   // DO THE FINAL TRANSFORM!
00174   void finalizeToSky();
00175 
00176   // Get actual coherence from grid by degridding
00177   void get(vi::VisBuffer2& vb, Int row=-1);
00178 
00179 
00180   // Put coherence to grid by gridding.
00181   void put(const vi::VisBuffer2& vb, Int row=-1, Bool dopsf=False, 
00182            FTMachine::Type type=FTMachine::OBSERVED);
00183 
00184   // Make the entire image
00185   void makeImage(FTMachine::Type type,
00186                  vi::VisibilityIterator2& vs,
00187                  ImageInterface<Complex>& image,
00188                  Matrix<Float>& weight);
00189   
00190   // Get the final image: do the Fourier transform and
00191   // grid-correct, then optionally normalize by the summed weights
00192   ImageInterface<Complex>& getImage(Matrix<Float>&, Bool normalize=True);
00193   virtual void normalizeImage(Lattice<Complex>& /*skyImage*/,
00194                               const Matrix<Double>& /*sumOfWts*/,
00195                               Lattice<Float>& /*sensitivityImage*/,
00196                               Bool /*fftNorm*/)
00197   {throw(AipsError("MosaicFT::normalizeImage() called"));}
00198     
00199  
00200   // Get the final weights image
00201   void getWeightImage(ImageInterface<Float>&, Matrix<Float>&);
00202 
00203   // Get a flux (divide by this to get a flux density correct image) 
00204   // image if there is one
00205   virtual void getFluxImage(ImageInterface<Float>& image);
00206 
00207   // Save and restore the MosaicFT to and from a record
00208   Bool toRecord(String& error, RecordInterface& outRec, 
00209                 Bool withImage=False, const String diskimage="");
00210   Bool fromRecord(String& error, const RecordInterface& inRec);
00211   
00212   // Can this FTMachine be represented by Fourier convolutions?
00213   Bool isFourier() {return True;}
00214 
00215   // Return name of this machine
00216 
00217   virtual String name() const;
00218   virtual Bool useWeightImage(){return True;}; 
00219   
00220 
00221   // Copy convolution function etc to another FT machine
00222   // necessary if ft and ift are distinct but can share convfunctions
00223 
00224   void setConvFunc(CountedPtr<SimplePBConvFunc>& pbconvFunc);
00225   CountedPtr<SimplePBConvFunc>& getConvFunc();
00226 
00227   CountedPtr<TempImage<Float> >& getConvWeightImage();
00228 
00229   //reset weight image
00230   virtual void reset();
00231   virtual void setMiscInfo(const Int qualifier){(void)qualifier;};
00232   virtual void ComputeResiduals(vi::VisBuffer2&/*vb*/, Bool /*useCorrected*/) {};
00233 
00234 protected:        
00235 
00236   Int nint(Double val) {return Int(floor(val+0.5));};
00237 
00238   // Find the convolution function
00239   void findConvFunction(const ImageInterface<Complex>& image,
00240                         const vi::VisBuffer2& vb);
00241 
00242   void girarUVW(Matrix<Double>& uvw, Vector<Double>& dphase,
00243                 const vi::VisBuffer2& vb);
00244 
00245   void addBeamCoverage(ImageInterface<Complex>& image);
00246   void prepGridForDegrid();
00247 
00248   SkyJones* sj_p;
00249 
00250 
00251   // Get the appropriate data pointer
00252   Array<Complex>* getDataPointer(const IPosition&, Bool);
00253 
00254   void ok();
00255 
00256   void init();
00257 
00258   // Is this record on Grid? check both ends. This assumes that the
00259   // ends bracket the middle
00260   Bool recordOnGrid(const vi::VisBuffer2& vb, Int rownr) const;
00261 
00262 
00263   // Image cache
00264   LatticeCache<Complex> * imageCache;
00265 
00266   // Sizes
00267   Long cachesize;
00268   Int tilesize;
00269 
00270   // Gridder
00271   ConvolveGridder<Double, Complex>* gridder;
00272 
00273   // Is this tiled?
00274   Bool isTiled;
00275 
00276   // Array lattice
00277   CountedPtr<Lattice<Complex> > arrayLattice;
00278 
00279   // Lattice. For non-tiled gridding, this will point to arrayLattice,
00280   //  whereas for tiled gridding, this points to the image
00281   CountedPtr<Lattice<Complex> > lattice;
00282   CountedPtr<Lattice<Complex> > weightLattice;
00283 
00284   Float maxAbsData;
00285 
00286   // Useful IPositions
00287   IPosition centerLoc, offsetLoc;
00288 
00289   // Image Scaling and offset
00290   Vector<Double> uvScale, uvOffset;
00291 
00292   // Array for non-tiled gridding
00293   Array<Complex> griddedWeight;
00294   Array<DComplex> griddedWeight2;
00295   // Pointing columns
00296   MSPointingColumns* mspc;
00297 
00298   // Antenna columns
00299   MSAntennaColumns* msac;
00300 
00301   DirectionCoordinate directionCoord;
00302 
00303   MDirection::Convert* pointingToImage;
00304 
00305   Vector<Double> xyPos;
00306 
00307   MDirection worldPosMeas;
00308 
00309   Int priorCacheSize;
00310 
00311   // Grid/degrid zero spacing points?
00312   Bool usezero_p;
00313 
00314   Array<Complex> convFunc;
00315   Array<Complex> weightConvFunc_p;
00316   Int convSampling;
00317   Int convSize;
00318   Int convSupport;
00319   Vector<Int> convSupportPlanes_p;
00320   Vector<Int> convSizePlanes_p;
00321   Vector<Int> convRowMap_p;
00322   Vector<Int> convChanMap_p;
00323   Vector<Int> convPolMap_p;
00324 
00325   Int wConvSize;
00326 
00327   Int lastIndex_p;
00328 
00329   Int getIndex(const ROMSPointingColumns& mspc, const Double& time,
00330                const Double& interval);
00331 
00332   Bool getXYPos(const vi::VisBuffer2& vb, Int row);
00333 
00334   CountedPtr<TempImage<Float> >skyCoverage_p;
00335   TempImage<Complex>* convWeightImage_p;
00336   CountedPtr<SimplePBConvFunc> pbConvFunc_p;
00337   CountedPtr<UVWMachine> phaseShifter_p;
00338  //Later this 
00339   String machineName_p;
00340   Bool doneWeightImage_p;
00341   String stokes_p;
00342 
00343 
00344 };
00345 
00346 }// namespace refim ends
00347 
00348 } //# NAMESPACE CASA - END
00349 
00350 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1