MultiTermFTNew.h

Go to the documentation of this file.
00001 //# NewMultiTermFT.h: Definition for NewMultiTermFT
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_TRANSFORM2_MULTITERMFTNEW_H
00030 #define SYNTHESIS_TRANSFORM2_MULTITERMFTNEW_H
00031 
00032 #include <synthesis/TransformMachines2/FTMachine.h>
00033 #include <casa/Arrays/Matrix.h>
00034 #include <scimath/Mathematics/FFTServer.h>
00035 #include <msvis/MSVis/VisBuffer2.h>
00036 #include <images/Images/ImageInterface.h>
00037 #include <images/Images/ImageInterface.h>
00038 #include <casa/Containers/Block.h>
00039 #include <casa/Arrays/Array.h>
00040 #include <casa/Arrays/Vector.h>
00041 #include <casa/Arrays/Matrix.h>
00042 #include <scimath/Mathematics/ConvolveGridder.h>
00043 #include <lattices/Lattices/LatticeCache.h>
00044 #include <lattices/Lattices/ArrayLattice.h>
00045 //#include <synthesis/MeasurementComponents/SynthesisPeek.h>
00046 #include <casa/OS/Timer.h>
00047 
00048 namespace casa { //# NAMESPACE CASA - BEGIN
00049 
00050 class UVWMachine;
00051 namespace vi{
00052                           class VisibilityIterator2;
00053                         }
00054 
00055 namespace refim { //# namespace refactor imaginging
00056 class MultiTermFTNew : public FTMachine {
00057 public:
00058 
00059   // Construct using an existing FT-Machine 
00060   MultiTermFTNew(CountedPtr<FTMachine>& subftm, Int nterms=1, Bool forward=False);
00061 
00062   // Construct from a Record containing the MultiTermFTNew state
00063   MultiTermFTNew(const RecordInterface& stateRec);
00064 
00065   // Copy constructor. 
00066   // This first calls the default "=" operator, and then instantiates objects for member pointers.
00067   MultiTermFTNew(const MultiTermFTNew &other);
00068 
00069   // Assignment operator --- leave it as the default
00070   MultiTermFTNew &operator=(const MultiTermFTNew &other);
00071 
00072   // Destructor
00073   ~MultiTermFTNew();
00074 
00075   // Called at the start of de-gridding : subftm->initializeToVis()
00076   // Note : Pre-de-gridding model-image divisions by PBs will go here.
00077 
00078   void initializeToVis(ImageInterface<Complex>& /*image*/,
00079                          const vi::VisBuffer2& /*vb*/){throw(AipsError("not implemented"));};
00080    // Vectorized InitializeToVis
00081   //  void initializeToVis(Block<CountedPtr<ImageInterface<Complex> > > & compImageVec,PtrBlock<SubImage<Float> *> & modelImageVec, PtrBlock<SubImage<Float> *>& weightImageVec, PtrBlock<SubImage<Float> *>& fluxScaleVec, Block<Matrix<Float> >& weightsVec, const VisBuffer& vb);
00082 
00083   virtual void initializeToVisNew(const vi::VisBuffer2& vb,
00084                                              CountedPtr<SIImageStore> imstore);
00085 
00086   // Called at the end of de-gridding : subftm->finalizeToVis()
00087   void finalizeToVis();
00088 
00089   // Called at the start of gridding : subftm->initializeToSky()
00090   void initializeToSky(ImageInterface<Complex>& /*image*/,
00091                          Matrix<Float>& /*weight*/, const vi::VisBuffer2& /*vb*/){throw(AipsError("not implemented"));};
00092   //  void initializeToSky(Block<CountedPtr<ImageInterface<Complex> > > & compImageVec, Block<Matrix<Float> >& weightsVec, const VisBuffer& vb, const Bool dopsf);
00093 
00094   virtual void initializeToSkyNew(const Bool dopsf,
00095                                   const vi::VisBuffer2& vb,
00096                                   CountedPtr<SIImageStore> imstore);
00097 
00098 
00099   // Called at the end of gridding : subftm->finalizeToSky()
00100   void finalizeToSky(){throw(AipsError("MultiTermFTNew::finalizeToSky() called without arguments!"));};
00101 
00102   //void finalizeToSky(Block<CountedPtr<ImageInterface<Complex> > > & compImageVec, PtrBlock<SubImage<Float> *> & resImageVec, PtrBlock<SubImage<Float> *>& weightImageVec, PtrBlock<SubImage<Float> *>& fluxScaleVec, Bool dopsf, Block<Matrix<Float> >& weightsVec, const VisBuffer& vb);
00103 
00104   virtual void finalizeToSkyNew(Bool dopsf, 
00105                                            const vi::VisBuffer2& vb,
00106                                            CountedPtr<SIImageStore> imstore  );
00107 
00108   //  void normalizeToSky(ImageInterface<Complex>& compImage, ImageInterface<Float>& resImage, ImageInterface<Float>& weightImage, Bool dopsf, Matrix<Float>& weights)
00109   // {throw(AipsError("MultiTermFTNew::normalizeToSky should not get called !"));};
00110 
00111 
00112   // Do the degridding via subftm->get() and modify model-visibilities by Taylor-weights
00113   void get(vi::VisBuffer2& vb, Int row=-1);
00114   // Modify imaging weights with Taylor-weights and do gridding via subftm->put()
00115   void put(vi::VisBuffer2& vb, Int row=-1, Bool dopsf=False,
00116            refim::FTMachine::Type type=refim::FTMachine::OBSERVED);
00117   // Have a const version for compatibility with other FTMs.. Throw an exception if called.
00118   void put(const vi::VisBuffer2& /*vb*/, Int /*row=-1*/, Bool /*dopsf=False*/,
00119            refim::FTMachine::Type /*type=FTMachine::OBSERVED*/)
00120   {throw(AipsError("Internal error: called MultiTermFTNew::put(const VB2)"));};
00121   // Calculate residual visibilities if possible.
00122   // The purpose is to allow rGridFT to make this multi-threaded
00123   virtual void ComputeResiduals(vi::VisBuffer2& vb, Bool useCorrected);
00124 
00125   // Make an image : subftm->makeImage()
00126   void makeImage(refim::FTMachine::Type type,
00127                  vi::VisibilityIterator2& vs,
00128                  ImageInterface<Complex>& image,
00129                  Matrix<Float>& weight);
00130 
00131   // Get the final image: do the Fourier transform grid-correct, then 
00132   // optionally normalize by the summed weights
00133   // Note : Post-gridding residual-image divisions by PBs will go here.
00134   //           For now, it just calls subftm->getImage()
00135   //  ImageInterface<Complex>& getImage(Matrix<Float>& weights, Bool normalize=True)
00136   //{return getImage(weights,normalize,0);};
00137   //ImageInterface<Complex>& getImage(Matrix<Float>& weights, Bool normalize=True, 
00138   //                                                         const Int taylorindex=0);
00139   ImageInterface<Complex>& getImage(Matrix<Float>& /*weights*/, Bool /*normalize*/=True)
00140   {throw(AipsError("MultiTermFTNew::getImage() should not be called"));}
00141  
00142   virtual Bool useWeightImage()
00143   {AlwaysAssert(subftms_p.nelements()>0,AipsError); return subftms_p[0]->useWeightImage(); };
00144 
00145   void getWeightImage(ImageInterface<Float>& weightImage, Matrix<Float>& weights)
00146   {AlwaysAssert(subftms_p.nelements()>0,AipsError); 
00147     subftms_p[0]->getWeightImage(weightImage, weights);}
00148   //  {throw(AipsError("MultiTermFTNew::getWeightImage() should not be called"));}
00149 
00150   // Save and restore the MultiTermFTNew to and from a record
00151   virtual Bool toRecord(String& error, RecordInterface& outRec, Bool withImage=False,
00152                         const String diskimage="");
00153   virtual Bool fromRecord(String& error, const RecordInterface& inRec);
00154 
00155   // Various small inline functions
00156   virtual Bool isFourier() {return True;}
00157   virtual void setNoPadding(Bool nopad){subftms_p[0]->setNoPadding(nopad);};
00158   virtual String name()const {return machineName_p;};
00159   virtual void setMiscInfo(const Int qualifier){(void)qualifier;};
00160 
00161   void printFTTypes()
00162   {
00163     cout << "** Number of FTs : " << subftms_p.nelements() << " -- " ;
00164     for(uInt tix=0; tix<(subftms_p).nelements(); tix++)
00165       cout << tix << " : " << (subftms_p[tix])->name() << "   " ;
00166     cout << endl;
00167   };
00168 
00169   FTMachine* cloneFTM();
00170   virtual void setDryRun(Bool val) 
00171   {
00172     isDryRun=val;
00173     //cerr << "MTFTMN: " << isDryRun << endl;
00174     for (uInt i=0;i<subftms_p.nelements();i++)
00175       subftms_p[i]->setDryRun(val);
00176   };
00177   virtual Bool isUsingCFCache() {Bool v=False; if (subftms_p.nelements() > 0) v=subftms_p[0]->isUsingCFCache(); return v;};
00178 
00179 protected:
00180   // have to call the initmaps of subftm
00181   virtual void initMaps(const vi::VisBuffer2& vb);
00182   // Instantiate a new sub FTM
00183   CountedPtr<FTMachine> getNewFTM(const CountedPtr<FTMachine>& ftm);
00184 
00185   // Multiply Imaging weights by Taylor-function weights - during "put"
00186   Bool modifyVisWeights(vi::VisBuffer2& vb, uInt thisterm);
00187   // Multiply model visibilities by Taylor-function weights - during "get"
00188   Bool modifyModelVis(vi::VisBuffer2 &vb, uInt thisterm);
00189   // Restore vb.imagingweights to the original
00190   void restoreImagingWeights(vi::VisBuffer2 &vb);
00191 
00192   // Helper function to write ImageInterfaces to disk
00193   Bool storeAsImg(String fileName, ImageInterface<Float> & theImg);
00194 
00195 
00196   Cube<Complex> modviscube_p;
00197 
00199   uInt nterms_p, psfnterms_p;
00200   Double reffreq_p;
00201   Matrix<Float> imweights_p;
00202   String machineName_p;
00203 
00204   //  Bool donePSF_p;
00205 
00206   Block< CountedPtr<FTMachine> > subftms_p;
00207 
00208 };
00209 
00210 } //end namespace refim
00211 } //# NAMESPACE CASA - END
00212 
00213 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1