MultiTermMatrixCleaner.h

Go to the documentation of this file.
00001 //# MultiTermMatrixCleaner.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 //# $Id: MultiTermMatrixCleaner Urvashi R.V.  2010-12-04 <rurvashi@aoc.nrao.edu$
00027 
00028 #ifndef SYNTHESIS_MULTITERMLATTICECLEANER_H
00029 #define SYNTHESIS_MULTITERMLATTICECLEANER_H
00030 
00031 #include <scimath/Mathematics/FFTServer.h>
00032 #include <synthesis/MeasurementEquations/MatrixCleaner.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 class MultiTermMatrixCleaner : public MatrixCleaner
00037 {
00038 public:
00039   // Create a cleaner 
00040   MultiTermMatrixCleaner();
00041 
00042   // The copy constructor uses reference semantics
00043   //  MultiTermMatrixCleaner(const MultiTermMatrixCleaner & other);
00044 
00045   // The assignment operator also uses reference semantics
00046   //  MultiTermMatrixCleaner & operator=(const MultiTermMatrixCleaner & other); 
00047 
00048   // The destructor resizes arrays to empty before destruction.
00049   ~MultiTermMatrixCleaner();
00050 
00051   // Input : number of Taylor terms
00052   //         Reshapes PtrBlocks to hold the correct number of PSFs and Residual images
00053   Bool setntaylorterms(const int & nterms);
00054   
00055   // Input : scales
00056   Bool setscales(const Vector<Float> & scales);
00057 
00058   // Initialize all the memory being used.
00059   Bool initialise(Int nx,Int ny);
00060 
00061   // Calculate Hessian elements and check for invertibility
00062   // Does not have to be called externally, but can be. Either way, it executes only once.
00063   Int computeHessianPeak();
00064 
00065   // Input : psfs and dirty images
00066   Bool setpsf(int order, Matrix<Float> & psf);
00067   
00068   // Input : psfs and dirty images
00069   Bool setresidual(int order, Matrix<Float> & dirty);
00070  
00071   // Input : model images
00072   Bool setmodel(int order, Matrix<Float> & model);
00073 
00074   // Input : mask
00075   Bool setmask(Matrix<Float> & mask);
00076  
00077   // Run the minor cycle
00078   Int mtclean(Int maxniter, Float stopfraction, Float inputgain, Float userthreshold);
00079 
00080   // Output : Model images
00081   Bool getmodel(int order, Matrix<Float> & model);
00082   
00083   // Output : psfs and dirty images
00084   Bool getresidual(int order, Matrix<Float> & residual);
00085   
00086   // Compute principal solution - in-place on the residual images in vecDirty. 
00087   Bool computeprincipalsolution();
00088  
00089   // Output : Hessian matrix
00090   Bool getinvhessian(Matrix<Double> & invhessian);
00091 
00092   // Output : Peak residual computed from matR_p (residual convolved with PSF).
00093   Float getpeakresidual(){return rmaxval_p;}
00094 
00095 
00096 private:
00097   LogIO os;
00098 
00099   using MatrixCleaner::itsCleanType;
00100   using MatrixCleaner::itsMaxNiter;
00101   using MatrixCleaner::itsGain;
00102   using MatrixCleaner::itsThreshold;
00103   using MatrixCleaner::itsMask;
00104   using MatrixCleaner::itsPositionPeakPsf;
00105   //  using MatrixCleaner::itsScaleMasks;
00106   //  using MatrixCleaner::itsScaleXfrs;
00107   //  using MatrixCleaner::itsNscales;
00108   //  using MatrixCleaner::itsScalesValid;
00109   using MatrixCleaner::itsMaskThreshold;
00110 
00111   using MatrixCleaner::findMaxAbs;
00112   using MatrixCleaner::findMaxAbsMask;
00113   using MatrixCleaner::makeScale;
00114   //  using MatrixCleaner::addTo;
00115   using MatrixCleaner::makeBoxesSameSize;
00116   using MatrixCleaner::validatePsf;
00117   //using MatrixCleaner::makeScaleMasks;
00118 
00119   Int ntaylor_p; // Number of terms in the Taylor expansion to use.
00120   Int psfntaylor_p; // Number of terms in the Taylor expansion for PSF.
00121   Int nscales_p; // Number of scales to use for the multiscale part.
00122   Int nx_p;
00123   Int ny_p;
00124   Int totalIters_p; // Total number of minor-cycle iterations
00125   Float globalmaxval_p;
00126   Int maxscaleindex_p;
00127   IPosition globalmaxpos_p;
00128   Int itercount_p; // Number of minor cycle iterations
00129   Int maxniter_p;
00130   Float stopfraction_p;
00131   Float inputgain_p;
00132   Float userthreshold_p;
00133   Float prev_max_p;
00134   Float min_max_p;
00135   Float rmaxval_p;
00136 
00137   IPosition psfsupport_p;
00138   IPosition psfpeak_p;
00139   IPosition blc_p, trc_p, blcPsf_p, trcPsf_p;
00140 
00141   Vector<Float> scaleSizes_p; // Vector of scale sizes in pixels.
00142   Vector<Float> scaleBias_p; // Vector of scale biases !!
00143   Vector<Float> totalScaleFlux_p; // Vector of total scale fluxes.
00144   Vector<Float> totalTaylorFlux_p; // Vector of total flux in each taylor term.
00145   Vector<Float> maxScaleVal_p; // Vector for peaks at each scale size
00146   Vector<IPosition> maxScalePos_p; // Vector of peak positions at each scale size.
00147 
00148   IPosition gip;
00149   Int nx,ny;
00150   Bool donePSF_p,donePSP_p,doneCONV_p;
00151  
00152   Matrix<Complex> dirtyFT_p;
00153   Block<Matrix<Float> > vecScaleMasks_p;
00154   
00155   Matrix<Complex> cWork_p;
00156   Block<Matrix<Float> > vecWork_p;
00157   
00158   // h(s) [nx,ny,nscales]
00159   Block<Matrix<Float> > vecScales_p; 
00160   Block<Matrix<Complex> > vecScalesFT_p; 
00161   
00162   // B_k  [nx,ny,ntaylor]
00163   // Block<Matrix<Float> > vecPsf_p; 
00164   Block<Matrix<Complex> > vecPsfFT_p; 
00165   
00166   // I_D : Residual/Dirty Images [nx,ny,ntaylor]
00167   Block<Matrix<Float> > vecDirty_p; 
00168  
00169   // I_M : Model Images [nx,ny,ntaylor]
00170   Block<Matrix<Float> > vecModel_p; 
00171   //  Block <Matrix<Float> > vecScaleModel_p;
00172  
00173   // A_{smn} = B_{sm} * B{sn} [nx,ny,ntaylor,ntaylor,nscales,nscales]
00174   // A_{s1s2mn} = B_{s1m} * B{s2n} [nx,ny,ntaylor,ntaylor,nscales,nscales]
00175   Block<Matrix<Float> > cubeA_p; 
00176 
00177   // R_{sk} = I_D * B_{sk} [nx,ny,ntaylor,nscales]
00178   Block<Matrix<Float> > matR_p; 
00179   
00180   // a_{sk} = Solution vectors. [nx,ny,ntaylor,nscales]
00181   Block<Matrix<Float> > matCoeffs_p; 
00182 
00183   // Memory to be allocated per Matrix
00184   Double memoryMB_p;
00185   
00186   // Solve [A][Coeffs] = [I_D * B]
00187   // Shape of A : [ntaylor,ntaylor]
00188   Block<Matrix<Double> > matA_p;    // 2D matrix to be inverted.
00189   Block<Matrix<Double> > invMatA_p; // Inverse of matA_p;
00190 
00191   // FFTserver
00192   FFTServer<Float,Complex> fftcomplex;
00193 
00194   // Initial setup functions  
00195   Int verifyScaleSizes();
00196   Int allocateMemory();
00197   Int setupScaleFunctions();
00198 
00199   // Setup per major cycle
00200   Int setupUserMask();
00201   Int computeFluxLimit(Float &fluxlimit, Float threshold);
00202   Int computeRHS();
00203 
00204   // Solver functions : minor-cycle iterations. Need to be efficient.
00205   Int solveMatrixEqn(Int ntaylor,Int scale, IPosition blc, IPosition trc);
00206   Int chooseComponent(Int ntaylor,Int scale, Int criterion, IPosition blc, IPosition trc);
00207   Int updateModelAndRHS(Float loopgain);
00208   Int updateRHS(Int ntaylor, Int scale, Float loopgain,Vector<Float> coeffs, IPosition blc, IPosition trc, IPosition blcPsf, IPosition trcPsf);
00209   Int checkConvergence(Int updatetype, Float &fluxlimit, Float &loopgain); 
00210   Bool buildImagePatches();
00211 
00212   // Helper functions
00213   Int writeMatrixToDisk(String imagename, Matrix<Float> &themat);
00214   Int IND2(Int taylor,Int scale);
00215   Int IND4(Int taylor1, Int taylor2, Int scale1, Int scale2);
00216   
00217   Bool adbg;
00218 };
00219 
00220 } //# NAMESPACE CASA - END
00221 
00222 #endif
00223 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1