casa
$Rev:20696$
|
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 private: 00093 LogIO os; 00094 00095 using MatrixCleaner::itsCleanType; 00096 using MatrixCleaner::itsMaxNiter; 00097 using MatrixCleaner::itsGain; 00098 using MatrixCleaner::itsThreshold; 00099 using MatrixCleaner::itsMask; 00100 using MatrixCleaner::itsPositionPeakPsf; 00101 // using MatrixCleaner::itsScaleMasks; 00102 // using MatrixCleaner::itsScaleXfrs; 00103 // using MatrixCleaner::itsNscales; 00104 // using MatrixCleaner::itsScalesValid; 00105 using MatrixCleaner::itsMaskThreshold; 00106 00107 using MatrixCleaner::findMaxAbs; 00108 using MatrixCleaner::findMaxAbsMask; 00109 using MatrixCleaner::makeScale; 00110 // using MatrixCleaner::addTo; 00111 using MatrixCleaner::makeBoxesSameSize; 00112 using MatrixCleaner::validatePsf; 00113 //using MatrixCleaner::makeScaleMasks; 00114 00115 Int ntaylor_p; // Number of terms in the Taylor expansion to use. 00116 Int psfntaylor_p; // Number of terms in the Taylor expansion for PSF. 00117 Int nscales_p; // Number of scales to use for the multiscale part. 00118 Int nx_p; 00119 Int ny_p; 00120 Int totalIters_p; // Total number of minor-cycle iterations 00121 Float globalmaxval_p; 00122 Int maxscaleindex_p; 00123 IPosition globalmaxpos_p; 00124 Int itercount_p; // Number of minor cycle iterations 00125 Int maxniter_p; 00126 Float stopfraction_p; 00127 Float inputgain_p; 00128 Float userthreshold_p; 00129 Float prev_max_p; 00130 Float min_max_p; 00131 00132 IPosition psfsupport_p; 00133 IPosition psfpeak_p; 00134 IPosition blc_p, trc_p, blcPsf_p, trcPsf_p; 00135 00136 Vector<Float> scaleSizes_p; // Vector of scale sizes in pixels. 00137 Vector<Float> scaleBias_p; // Vector of scale biases !! 00138 Vector<Float> totalScaleFlux_p; // Vector of total scale fluxes. 00139 Vector<Float> totalTaylorFlux_p; // Vector of total flux in each taylor term. 00140 Vector<Float> maxScaleVal_p; // Vector for peaks at each scale size 00141 Vector<IPosition> maxScalePos_p; // Vector of peak positions at each scale size. 00142 00143 IPosition gip; 00144 Int nx,ny; 00145 Bool donePSF_p,donePSP_p,doneCONV_p; 00146 00147 Matrix<Complex> dirtyFT_p; 00148 Block<Matrix<Float> > vecScaleMasks_p; 00149 00150 Matrix<Complex> cWork_p; 00151 Block<Matrix<Float> > vecWork_p; 00152 00153 // h(s) [nx,ny,nscales] 00154 Block<Matrix<Float> > vecScales_p; 00155 Block<Matrix<Complex> > vecScalesFT_p; 00156 00157 // B_k [nx,ny,ntaylor] 00158 // Block<Matrix<Float> > vecPsf_p; 00159 Block<Matrix<Complex> > vecPsfFT_p; 00160 00161 // I_D : Residual/Dirty Images [nx,ny,ntaylor] 00162 Block<Matrix<Float> > vecDirty_p; 00163 00164 // I_M : Model Images [nx,ny,ntaylor] 00165 Block<Matrix<Float> > vecModel_p; 00166 // Block <Matrix<Float> > vecScaleModel_p; 00167 00168 // A_{smn} = B_{sm} * B{sn} [nx,ny,ntaylor,ntaylor,nscales,nscales] 00169 // A_{s1s2mn} = B_{s1m} * B{s2n} [nx,ny,ntaylor,ntaylor,nscales,nscales] 00170 Block<Matrix<Float> > cubeA_p; 00171 00172 // R_{sk} = I_D * B_{sk} [nx,ny,ntaylor,nscales] 00173 Block<Matrix<Float> > matR_p; 00174 00175 // a_{sk} = Solution vectors. [nx,ny,ntaylor,nscales] 00176 Block<Matrix<Float> > matCoeffs_p; 00177 00178 // Memory to be allocated per Matrix 00179 Double memoryMB_p; 00180 00181 // Solve [A][Coeffs] = [I_D * B] 00182 // Shape of A : [ntaylor,ntaylor] 00183 Block<Matrix<Double> > matA_p; // 2D matrix to be inverted. 00184 Block<Matrix<Double> > invMatA_p; // Inverse of matA_p; 00185 00186 // FFTserver 00187 FFTServer<Float,Complex> fftcomplex; 00188 00189 // Initial setup functions 00190 Int verifyScaleSizes(); 00191 Int allocateMemory(); 00192 Int setupScaleFunctions(); 00193 00194 // Setup per major cycle 00195 Int setupUserMask(); 00196 Int computeFluxLimit(Float &fluxlimit, Float threshold); 00197 Int computeRHS(); 00198 00199 // Solver functions : minor-cycle iterations. Need to be efficient. 00200 Int solveMatrixEqn(Int ntaylor,Int scale, IPosition blc, IPosition trc); 00201 Int chooseComponent(Int ntaylor,Int scale, Int criterion, IPosition blc, IPosition trc); 00202 Int updateModelAndRHS(Float loopgain); 00203 Int updateRHS(Int ntaylor, Int scale, Float loopgain,Vector<Float> coeffs, IPosition blc, IPosition trc, IPosition blcPsf, IPosition trcPsf); 00204 Int checkConvergence(Int updatetype, Float &fluxlimit, Float &loopgain); 00205 Bool buildImagePatches(); 00206 00207 // Helper functions 00208 Int writeMatrixToDisk(String imagename, Matrix<Float> &themat); 00209 Int IND2(Int taylor,Int scale); 00210 Int IND4(Int taylor1, Int taylor2, Int scale1, Int scale2); 00211 00212 Bool adbg; 00213 }; 00214 00215 } //# NAMESPACE CASA - END 00216 00217 #endif 00218