MosaicFT.h

Go to the documentation of this file.
00001 //# MosaicFT.h: Definition for MosaicFT
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2002
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 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_MOSAICFT_H
00030 #define SYNTHESIS_MOSAICFT_H
00031 
00032 #include <synthesis/TransformMachines/FTMachine.h>
00033 #include <synthesis/TransformMachines/SkyJones.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <scimath/Mathematics/FFTServer.h>
00036 #include <msvis/MSVis/VisBuffer.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   class SimplePBConvFunc;
00127   class MPosition;
00128   class UVWMachine;
00129 
00130 
00131 class MosaicFT : public FTMachine {
00132 public:
00133 
00134   // Constructor: cachesize is the size of the cache in words
00135   // (e.g. a few million is a good number), tilesize is the
00136   // size of the tile used in gridding (cannot be less than
00137   // 12, 16 works in most cases). 
00138   // <group>
00139   MosaicFT(SkyJones* sj, MPosition mloc, String stokes,
00140             Long cachesize, Int tilesize=16, 
00141            Bool usezero=True, Bool useDoublePrec=False);
00142   // </group>
00143 
00144   // Construct from a Record containing the MosaicFT state
00145   MosaicFT(const RecordInterface& stateRec);
00146 
00147   // Copy constructor
00148   MosaicFT(const MosaicFT &other);
00149 
00150   // Assignment operator
00151   MosaicFT &operator=(const MosaicFT &other);
00152 
00153   ~MosaicFT();
00154 
00155   // Initialize transform to Visibility plane using the image
00156   // as a template. The image is loaded and Fourier transformed.
00157   void initializeToVis(ImageInterface<Complex>& image,
00158                        const VisBuffer& vb);
00159  
00160   // Finalize transform to Visibility plane: flushes the image
00161   // cache and shows statistics if it is being used.
00162   void finalizeToVis();
00163 
00164   // Initialize transform to Sky plane: initializes the image
00165   void initializeToSky(ImageInterface<Complex>& image,  Matrix<Float>& weight,
00166                        const VisBuffer& vb);
00168  
00169   // Finalize transform to Sky plane: flushes the image
00170   // cache and shows statistics if it is being used. DOES NOT
00171   // DO THE FINAL TRANSFORM!
00172   void finalizeToSky();
00173 
00174   // Get actual coherence from grid by degridding
00175   void get(VisBuffer& vb, Int row=-1);
00176 
00177 
00178   // Put coherence to grid by gridding.
00179   void put(const VisBuffer& vb, Int row=-1, Bool dopsf=False, 
00180            FTMachine::Type type=FTMachine::OBSERVED);
00181 
00182   // Make the entire image
00183   void makeImage(FTMachine::Type type,
00184                  VisSet& vs,
00185                  ImageInterface<Complex>& image,
00186                  Matrix<Float>& weight);
00187   
00188   // Get the final image: do the Fourier transform and
00189   // grid-correct, then optionally normalize by the summed weights
00190   ImageInterface<Complex>& getImage(Matrix<Float>&, Bool normalize=True);
00191   virtual void normalizeImage(Lattice<Complex>& /*skyImage*/,
00192                               const Matrix<Double>& /*sumOfWts*/,
00193                               Lattice<Float>& /*sensitivityImage*/,
00194                               Bool /*fftNorm*/)
00195   {throw(AipsError("MosaicFT::normalizeImage() called"));}
00196     
00197  
00198   // Get the final weights image
00199   void getWeightImage(ImageInterface<Float>&, Matrix<Float>&);
00200 
00201   // Get a flux (divide by this to get a flux density correct image) 
00202   // image if there is one
00203   virtual void getFluxImage(ImageInterface<Float>& image);
00204 
00205   // Save and restore the MosaicFT to and from a record
00206   Bool toRecord(String& error, RecordInterface& outRec, 
00207                 Bool withImage=False, const String diskimage="");
00208   Bool fromRecord(String& error, const RecordInterface& inRec);
00209   
00210   // Can this FTMachine be represented by Fourier convolutions?
00211   Bool isFourier() {return True;}
00212 
00213   // Return name of this machine
00214 
00215   virtual String name() const;
00216   virtual Bool useWeightImage(){return True;}; 
00217   
00218 
00219   // Copy convolution function etc to another FT machine
00220   // necessary if ft and ift are distinct but can share convfunctions
00221 
00222   void setConvFunc(CountedPtr<SimplePBConvFunc>& pbconvFunc);
00223   CountedPtr<SimplePBConvFunc>& getConvFunc();
00224 
00225   CountedPtr<TempImage<Float> >& getConvWeightImage();
00226 
00227   //reset weight image
00228   virtual void reset();
00229   virtual void setMiscInfo(const Int qualifier){(void)qualifier;};
00230   virtual void ComputeResiduals(VisBuffer&/*vb*/, Bool /*useCorrected*/) {};
00231 
00232 protected:        
00233 
00234   Int nint(Double val) {return Int(floor(val+0.5));};
00235 
00236   // Find the convolution function
00237   void findConvFunction(const ImageInterface<Complex>& image,
00238                         const VisBuffer& vb);
00239 
00240   void girarUVW(Matrix<Double>& uvw, Vector<Double>& dphase,
00241                 const VisBuffer& vb);
00242 
00243   void addBeamCoverage(ImageInterface<Complex>& image);
00244   void prepGridForDegrid();
00245 
00246   SkyJones* sj_p;
00247 
00248 
00249   // Get the appropriate data pointer
00250   Array<Complex>* getDataPointer(const IPosition&, Bool);
00251 
00252   void ok();
00253 
00254   void init();
00255 
00256   // Is this record on Grid? check both ends. This assumes that the
00257   // ends bracket the middle
00258   Bool recordOnGrid(const VisBuffer& vb, Int rownr) const;
00259 
00260 
00261   // Image cache
00262   LatticeCache<Complex> * imageCache;
00263 
00264   // Sizes
00265   Long cachesize;
00266   Int tilesize;
00267 
00268   // Gridder
00269   ConvolveGridder<Double, Complex>* gridder;
00270 
00271   // Is this tiled?
00272   Bool isTiled;
00273 
00274   // Array lattice
00275   CountedPtr<Lattice<Complex> > arrayLattice;
00276 
00277   // Lattice. For non-tiled gridding, this will point to arrayLattice,
00278   //  whereas for tiled gridding, this points to the image
00279   CountedPtr<Lattice<Complex> > lattice;
00280   CountedPtr<Lattice<Complex> > weightLattice;
00281 
00282   Float maxAbsData;
00283 
00284   // Useful IPositions
00285   IPosition centerLoc, offsetLoc;
00286 
00287   // Image Scaling and offset
00288   Vector<Double> uvScale, uvOffset;
00289 
00290   // Array for non-tiled gridding
00291   Array<Complex> griddedWeight;
00292   Array<DComplex> griddedWeight2;
00293   // Pointing columns
00294   MSPointingColumns* mspc;
00295 
00296   // Antenna columns
00297   MSAntennaColumns* msac;
00298 
00299   DirectionCoordinate directionCoord;
00300 
00301   MDirection::Convert* pointingToImage;
00302 
00303   Vector<Double> xyPos;
00304 
00305   MDirection worldPosMeas;
00306 
00307   Int priorCacheSize;
00308 
00309   // Grid/degrid zero spacing points?
00310   Bool usezero_p;
00311 
00312   Array<Complex> convFunc;
00313   Array<Complex> weightConvFunc_p;
00314   Int convSampling;
00315   Int convSize;
00316   Int convSupport;
00317   Vector<Int> convSupportPlanes_p;
00318   Vector<Int> convSizePlanes_p;
00319   Vector<Int> convRowMap_p;
00320   Vector<Int> convChanMap_p;
00321   Vector<Int> convPolMap_p;
00322 
00323   Int wConvSize;
00324 
00325   Int lastIndex_p;
00326 
00327   Int getIndex(const ROMSPointingColumns& mspc, const Double& time,
00328                const Double& interval);
00329 
00330   Bool getXYPos(const VisBuffer& vb, Int row);
00331 
00332   CountedPtr<TempImage<Float> >skyCoverage_p;
00333   TempImage<Complex>* convWeightImage_p;
00334   CountedPtr<SimplePBConvFunc> pbConvFunc_p;
00335   CountedPtr<UVWMachine> phaseShifter_p;
00336  //Later this 
00337   String machineName_p;
00338   Bool doneWeightImage_p;
00339   String stokes_p;
00340 
00341 
00342 };
00343 
00344 } //# NAMESPACE CASA - END
00345 
00346 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1