MultiTermLatticeCleaner.h

Go to the documentation of this file.
00001 //# MultiTermLatticeCleaner.h: Minor Cycle for MSMFS deconvolution
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 //# Urvashi Rau <rurvashi@aoc.nrao.edu>
00027 //#
00028 //# $Id: HostInfoDarwin.h 21521 2014-12-10 08:06:42Z gervandiepen $
00029 
00030 #ifndef LATTICES_MULTITERMLATTICECLEANER_H
00031 #define LATTICES_MULTITERMLATTICECLEANER_H
00032 
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/lattices/LatticeMath/LatticeCleaner.h>
00035 #include <casacore/lattices/Lattices/LatticeIterator.h>
00036 #include <casacore/lattices/LEL/LatticeExpr.h>
00037 #include <casacore/lattices/LEL/LatticeExprNode.h>
00038 
00039 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00040 
00041 template<class T> class MultiTermLatticeCleaner : public LatticeCleaner<T>
00042 {
00043 public:
00044   // Create a cleaner for a specific dirty image and PSF
00045   MultiTermLatticeCleaner();
00046 
00047   // The copy constructor uses reference semantics
00048   MultiTermLatticeCleaner(const MultiTermLatticeCleaner<T> & other);
00049 
00050   // The assignment operator also uses reference semantics
00051   MultiTermLatticeCleaner<T> & operator=(const MultiTermLatticeCleaner<T> & other); 
00052 
00053   // The destructor does nothing special.
00054   ~MultiTermLatticeCleaner();
00055 
00056   // Input : number of Taylor terms
00057   //         Reshapes PtrBlocks to hold the correct number of PSFs and Residual images
00058   Bool setntaylorterms(const int & nterms);
00059   
00060   // Input : scales
00061   Bool setscales(const Vector<Float> & scales);
00062 
00063   // Initialize all the memory being used.
00064   Bool initialise(Int nx,Int ny);
00065 
00066   // Set control parameters.
00067   Bool setcontrol(CleanEnums::CleanType cleanType,const Int niter,const Float gain,const Quantity& aThreshold,const Bool choose);
00068   //# This function is defined in the base class LatticeCleaner, but was not
00069   //# defined in the new MultiTermLatticeCleaner.
00070   //# I (GvD) have added it for the time being.
00071   Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter,
00072                   const Float gain, const Quantity& aThreshold,
00073                   const Quantity& /*fThreshold*/,
00074                   const Bool choose=True)
00075     { return setcontrol (cleanType, niter, gain, aThreshold, choose); }
00076 
00077   // Input : psfs and dirty images
00078   Bool setpsf(int order, Lattice<T> & psf);
00079   
00080   // Input : psfs and dirty images
00081   Bool setresidual(int order, Lattice<T> & dirty);
00082  
00083   // Input : model images
00084   Bool setmodel(int order, Lattice<T> & model);
00085  
00086   // Input : mask
00087   Bool setmask(Lattice<T> & mask);
00088  
00089   // Run the minor cycle
00090   Int mtclean(LatticeCleanProgress* progress=0);
00091 
00092   // Output : Model images
00093   Bool getmodel(int order, Lattice<T> & model);
00094   
00095   // Ouput : psfs and dirty images
00096   Bool getresidual(int order, Lattice<T> & residual);
00097  
00098   // Output : Hessian matrix
00099   Bool getinvhessian(Matrix<Double> & invhessian);
00100 
00101 private:
00102   LogIO os;
00103 
00104   using LatticeCleaner<T>::itsCleanType;
00105   using LatticeCleaner<T>::itsMaxNiter;
00106   using LatticeCleaner<T>::itsGain;
00107   using LatticeCleaner<T>::itsThreshold;
00108   using LatticeCleaner<T>::itsMask;
00109   using LatticeCleaner<T>::itsPositionPeakPsf;
00110 
00111   using LatticeCleaner<T>::findMaxAbsLattice;
00112   using LatticeCleaner<T>::findMaxAbsMaskLattice;
00113   using LatticeCleaner<T>::makeScale;
00114   using LatticeCleaner<T>::addTo;
00115   using LatticeCleaner<T>::makeBoxesSameSize;
00116   using LatticeCleaner<T>::validatePsf;
00117 
00118   Int ntaylor_p; // Number of terms in the Taylor expansion to use.
00119   Int psfntaylor_p; // Number of terms in the Taylor expansion for PSF.
00120   Int nscales_p; // Number of scales to use for the multiscale part.
00121   Int nx_p;
00122   Int ny_p;
00123   Int totalIters_p;
00124   
00125   // Image mask
00126   TempLattice<Float>* dirty_p;
00127   TempLattice<Complex>* dirtyFT_p;
00128   TempLattice<Float>* mask_p;
00129   TempLattice<Float>* fftmask_p;
00130   
00131   Vector<Float> scaleSizes_p; // Vector of scale sizes in pixels.
00132   Vector<Float> scaleBias_p; // Vector of scale biases !!
00133   Vector<Float> totalScaleFlux_p; // Vector of total scale fluxes.
00134   Vector<Float> totalTaylorFlux_p; // Vector of total flux in each taylor term.
00135   Float weightScaleFactor_p;
00136   Float maxPsf_p;
00137 
00138   IPosition gip,imshape;
00139   Int nx,ny,npol_p,nchan;
00140   Bool donePSF_p,donePSP_p,doneCONV_p;
00141  
00142   // h(s) [nx,ny,nscales]
00143   PtrBlock<TempLattice<Float>* > vecScales_p; 
00144   PtrBlock<TempLattice<Complex>* > vecScalesFT_p; 
00145   
00146   // B_k  [nx,ny,ntaylor]
00147   PtrBlock<TempLattice<Float>* > vecPsf_p; 
00148   PtrBlock<TempLattice<Complex>* > vecPsfFT_p; 
00149   
00150   // I_D : Residual/Dirty Images [nx,ny,ntaylor]
00151   PtrBlock<TempLattice<Float>* > vecDirty_p; 
00152  
00153   // I_M : Model Images [nx,ny,ntaylor]
00154   PtrBlock<TempLattice<Float>* > vecModel_p; 
00155  
00156   // A_{smn} = B_{sm} * B{sn} [nx,ny,ntaylor,ntaylor,nscales,nscales]
00157   // A_{s1s2mn} = B_{s1m} * B{s2n} [nx,ny,ntaylor,ntaylor,nscales,nscales]
00158   PtrBlock<TempLattice<Float>* > cubeA_p; 
00159   PtrBlock<LatticeIterator<Float>* > itercubeA_p;
00160   
00161   // R_{sk} = I_D * B_{sk} [nx,ny,ntaylor,nscales]
00162   PtrBlock<TempLattice<Float>* > matR_p; 
00163   PtrBlock<LatticeIterator<Float>* > itermatR_p;
00164   
00165   // a_{sk} = Solution vectors. [nx,ny,ntaylor,nscales]
00166   PtrBlock<TempLattice<Float>* > matCoeffs_p; 
00167   PtrBlock<LatticeIterator<Float>* > itermatCoeffs_p;
00168 
00169   // Memory to be allocated per TempLattice
00170   Double memoryMB_p;
00171   
00172   // Solve [A][Coeffs] = [I_D * B]
00173   // Shape of A : [ntaylor,ntaylor]
00174   PtrBlock<Matrix<Double>*> matA_p;    // 2D matrix to be inverted.
00175   PtrBlock<Matrix<Double>*> invMatA_p; // Inverse of matA_p;
00176 
00177   // Scratch Lattices and iterators.
00178   TempLattice<Complex>* cWork_p;
00179   TempLattice<Float>* tWork_p;
00180   LatticeIterator<Float>* itertWork_p;
00181   
00182   LatticeExprNode len_p;
00183 
00184   Float lambda_p;
00185   
00186   Int numberOfTempLattices(Int nscales,Int ntaylor);
00187   Int manageMemory(Bool allocate);
00188   
00189   Bool findMaxAbsLattice(const TempLattice<Float>& masklat,const Lattice<Float>& lattice,Float& maxAbs,IPosition& posMaxAbs, Bool flip=False);
00190   Int addTo(Lattice<Float>& to, const Lattice<Float>& add, Float multiplier);
00191 
00192   Int setupFFTMask();
00193   Int setupUserMask();
00194   Int setupBlobs();
00195   Int computeFluxLimit(Float &fluxlimit, Float threshold);
00196   Int computeMatrixA();
00197   Int computeRHS();
00198   Int solveMatrixEqn(Int scale);
00199   Int computePenaltyFunction(Int scale, Float &loopgain, Bool choosespec);
00200   Int updateSolution(IPosition globalmaxpos, Int maxscaleindex, Float loopgain);
00201   Int checkConvergence(Bool choosespec, Float thresh, Float fluxlimit); 
00202   
00203   Int IND2(Int taylor,Int scale);
00204   Int IND4(Int taylor1, Int taylor2, Int scale1, Int scale2);
00205   
00206   Bool adbg;
00207 };
00208 
00209 } //# NAMESPACE CASACORE - END
00210 
00211 #ifndef CASACORE_NO_AUTO_TEMPLATES
00212 #include <casacore/lattices/LatticeMath/MultiTermLatticeCleaner.tcc>
00213 #endif //# CASACORE_NO_AUTO_TEMPLATES
00214 #endif
00215 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1