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