MatrixNACleaner.h

Go to the documentation of this file.
00001 //# MatrixNACleaner.h: this defines Cleaner a class for doing 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 General Public License as published by
00007 //# the Free Software Foundation; either version 3 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 //#
00027 
00028 
00029 #ifndef SYNTHESIS_MATRIXNACLEANER_H
00030 #define SYNTHESIS_MATRIXNACLEANER_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Quanta/Quantum.h>
00035 #include <casa/Arrays/IPosition.h>
00036 #include <casa/Arrays/Vector.h>
00037 #include <casa/Containers/Block.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 template <class T> class Matrix;
00043 
00044 // <summary>A simple deconvolver that masks by memory of previous peaks</summary>
00045 // <synopsis> Evolution of a simple cleaner 
00046 // 
00047 // </synopsis>
00048 
00049 // <summary>A class for doing multi-dimensional cleaning</summary>
00050 
00051 // <use visibility=export>
00052 
00053 // <reviewed reviewer="" date="yyyy/mm/dd" tests="Mulouktanee">
00054 // </reviewed>
00055 
00056 // <prerequisite>
00057 //  <li> The mathematical concept of deconvolution
00058 // </prerequisite>
00059 //
00060 // <etymology>
00061 
00062 // The MatrixNACleaner Uses the matrix class and cleaner is for deconvolver by CLEAN
00063 // NA stands for Non Amnesiac...i.e remember where past peaks were to search in these region preferentially ...i.e no need to mask 
00064 
00065 // </etymology>
00066 //
00067 // <synopsis>
00068 // This class will perform various types of Clean deconvolution
00069 // on Lattices.
00070 //
00071 // </synopsis>
00072 //
00073 // <example>
00074 // <srcblock>
00075 // </srcblock> 
00076 // </example>
00077 //
00078 // <motivation>
00079 // </motivation>
00080 //
00081 // <thrown>
00082 // <li> AipsError: if psf has more dimensions than the model. 
00083 // </thrown>
00084 //
00085 // <todo asof="yyyy/mm/dd">
00086 // </todo>
00087 
00088 class MatrixNACleaner
00089 {
00090 public:
00091 
00092   // Create a cleaner : default constructor
00093   MatrixNACleaner();
00094 
00095   // Create a cleaner for a specific dirty image and PSF
00096   MatrixNACleaner(const Matrix<Float> & psf, const Matrix<Float> & dirty, const Int memtype=2, const Float numSigma=5.0);
00097 
00098   // The copy constructor uses reference semantics
00099   MatrixNACleaner(const MatrixNACleaner& other);
00100 
00101   // The assignment operator also uses reference semantics
00102   MatrixNACleaner & operator=(const MatrixNACleaner & other); 
00103 
00104   // The destructor does nothing special.
00105   ~MatrixNACleaner();
00106  
00107   
00108   
00109   //Set the dirty image without calculating convolutions..
00110   //can be done by calling  makeDirtyScales or setscales if one want to redo the 
00111   //psfscales too.
00112   void setDirty(const Matrix<Float>& dirty);
00113   
00114   
00115 
00116   //change the psf
00117   //don't forget to redo the setscales or run makePsfScales, 
00118   //followed by makeDirtyScales 
00119   void setPsf(const Matrix<Float>& psf);
00120  
00121  
00122  
00123   // niter - number of iterations
00124   // gain - loop gain used in cleaning (a fraction of the maximum 
00125   //        subtracted at every iteration)
00126   // aThreshold - absolute threshold to stop iterations
00127  
00128   void setcontrol(const Int niter,
00129                   const Float gain, const Quantity& aThresho, const Int masksupport=3 , const Int memType=2, const Float numsigma=5.0);
00130 
00131  
00132 
00133   // return how many iterations we did do
00134   Int iteration() const { return itsIteration; }
00135  
00136 
00137  
00138  //Total flux accumulated so far
00139   Float totalFlux() const {return itsTotalFlux;}
00140 
00141 
00142   // Clean an image.
00143  
00144   Int clean(Matrix<Float> & model);
00145 
00146   // Set the mask
00147   // mask - input mask lattice
00148   
00149   void setMask(Matrix<Float> & mask);
00150  
00151 
00152   void setPixFlag(const Matrix<Bool>& bitpix);
00153 
00154   // remove the mask;
00155   // useful when keeping object and sending a new dirty image to clean 
00156   // one can set another mask then 
00157   void unsetMask();
00158 
00159   void getMask(Matrix<Float>& mask);
00160 
00161   
00162 
00163   // Look at what WE think the residuals look like
00164   Matrix<Float>  getResidual() { return *itsResidual; }
00165 
00166   // Method to return threshold
00167   Float threshold() const;
00168 
00169   
00170   Float maxResidual() {return itsMaximumResidual;};
00171   // Helper function to optimize adding
00172   //static void addTo(Matrix<Float>& to, const Matrix<Float> & add);
00173 
00174 protected:
00175   // Make sure that the peak of the Psf is within the image
00176   Bool validatePsf(const Matrix<Float> & psf);
00177 
00178  
00179   // Find the Peak of the lattice, applying a mask
00180   Bool findMaxAbsMask(const Matrix<Float>& lattice,  Matrix<Float>& mask,
00181                       Float& maxAbs, IPosition& posMax, const Int support=5);
00182 
00183   // Helper function to reduce the box sizes until the have the same   
00184   // size keeping the centers intact  
00185   static void makeBoxesSameSize(IPosition& blc1, IPosition& trc1,                               
00186      IPosition &blc2, IPosition& trc2);
00187 
00188 
00189   Float itsGain;
00190   Int itsMaxNiter;      // maximum possible number of iterations
00191   Quantum<Double> itsThreshold;
00192   
00193 
00194 private:
00195 
00196   //# The following functions are used in various places in the code and are
00197   //# documented in the .cc file. Static functions are used when the functions
00198   //# do not modify the object state. They ensure that implicit assumptions
00199   //# about the current state and implicit side-effects are not possible
00200   //# because all information must be supplied in the input arguments
00201 
00202   std::shared_ptr<Matrix<Float> > itsMask;
00203   std::shared_ptr<Matrix<Float> > itsDirty;
00204   std::shared_ptr<Matrix<Float> > itsPsf;
00205   std::shared_ptr<Matrix<Float> >itsResidual;
00206   std::shared_ptr<Matrix<Bool> > itsBitPix;
00207 
00208   Float amnesiac(const Float& val);
00209   Float weak(const Float& v);
00210   Float medium(const Float& v);
00211   Float strong(const Float& v);
00212 
00213   Float itsMaximumResidual;
00214   Int itsIteration;     // what iteration did we get to?
00215   Int itsStartingIter;  // what iteration did we get to?
00216   Float itsTotalFlux;
00217   Int itsSupport;
00218   IPosition psfShape_p;
00219   IPosition itsPositionPeakPsf;
00220   Float itsRms;
00221   Int typeOfMemory_p;  //0 nomemory, 1 weak, 2 medium, 3 strong
00222   Float numSigma_p;
00223   std::function<Float(const Float&)> f_p;
00224 };
00225 
00226 } //# NAMESPACE CASA - END
00227 
00228 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1