casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageMSCleaner.h
Go to the documentation of this file.
00001 //# ImageMSCleaner.h: this defines Cleaner a class for doing convolution
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 //#
00027 //# $Id: $
00028 
00029 #ifndef SYNTHESIS_IMAGEMSCLEANER_H
00030 #define SYNTHESIS_IMAGEMSCLEANER_H
00031 
00032 //# Includes
00033 #include <synthesis/MeasurementEquations/MatrixCleaner.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 template <class T> class Matrix;
00039 template <class T> class ImageInterface;
00040 
00041 
00042 
00043 // <summary>A class interfacing images to MatrixCleaner </summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tLatticeCleaner">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //  <li> ImageInterface
00052 //  <li> MatrixCleaner
00053 // </prerequisite>
00054 //
00055 // <etymology>
00056 
00057 // The ImageCleaner class will use MSClean on Images.
00058 
00059 // </etymology>
00060 //
00061 // <synopsis>
00062 // This class will perform various types of Clean deconvolution
00063 // on Lattices.
00064 //
00065 // </synopsis>
00066 //
00067 // <example>
00068 // <srcblock>
00069 // </srcblock> 
00070 // </example>
00071 //
00072 // <motivation>
00073 // </motivation>
00074 //
00075 // <thrown>
00076 // <li> AipsError: if psf has more dimensions than the model. 
00077 // </thrown>
00078 //
00079 
00080 class ImageMSCleaner
00081 
00082 {
00083 
00084  public:
00085   //Default
00086   ImageMSCleaner();
00087   // Create a cleaner with a psf and dirty image
00088   ImageMSCleaner(ImageInterface<Float>& psf, ImageInterface<Float>& dirty);
00089   //assignmemnt constructor
00090   ImageMSCleaner(const ImageMSCleaner& other);
00091   //assignment operator
00092   ImageMSCleaner & operator=(const ImageMSCleaner & other);
00093 
00094   //The destructor
00095   ~ImageMSCleaner();
00096   
00097   // Update the dirty image only
00098   void update(ImageInterface<Float> & dirty);
00099   // Change the psf image 
00100   void setPsf(ImageInterface<Float> & psf);
00101 
00103   void setscales(const Int nscales, const Float scaleInc=1.0);
00104   // Set a specific set of scales
00105   void  setscales(const Vector<Float> & scales);
00106 
00107   // Set up control parameters
00108   // cleanType - type of the cleaning algorithm to use (HOGBOM, MULTISCALE)
00109   // niter - number of iterations
00110   // gain - loop gain used in cleaning (a fraction of the maximum 
00111   //        subtracted at every iteration)
00112   // aThreshold - absolute threshold to stop iterations
00113   // fThreshold - fractional threshold (i.e. given w.r.t. maximum residual)
00114   //              to stop iterations. This parameter is specified as
00115   //              Quantity so it can be given in per cents. 
00116   Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter,
00117                   const Float gain, const Quantity& aThreshold,
00118                   const Quantity& fThreshold);
00119   
00120   // This version of the method disables stopping on fractional threshold
00121   Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter,
00122                   const Float gain, const Quantity& threshold);
00123   
00124   // return how many iterations we did do
00125   Int iteration() const ;
00126   Int numberIterations() const ;
00127   
00128   // what iteration number to start on
00129   void startingIteration(const Int starting = 0);
00130 
00131   // Clean an image. 
00132   //return value gives you a hint of what's happening
00133   //  1 = converged
00134   //  0 = not converged but behaving normally
00135   // -1 = not converged and stopped on cleaning consecutive smallest scale
00136   // -2 = not converged and either large scale hit negative or diverging 
00137   // -3 = clean is diverging rather than converging 
00138   Int clean(ImageInterface<Float> & model, const String& algorithm, 
00139             const Int niter, const Float gain, const Quantity& threshold, 
00140             const Quantity& fthresh=Quantity(0.0, "%"),
00141             Bool doPlotProgress=False);
00142   // Set the mask
00143   // mask - input mask lattice
00144   // maskThreshold - if positive, the value is treated as a threshold value to determine
00145   // whether a pixel is good (mask value is greater than the threshold) or has to be 
00146   // masked (mask value is below the threshold). Negative threshold switches mask clipping
00147   // off. The mask value is used to weight the flux during cleaning. This mode is used
00148   // to implement cleaning based on the signal-to-noise as opposed to the standard cleaning
00149   // based on the flux. The default threshold value is 0.9, which ensures the behavior of the
00150   // code is exactly the same as before this parameter has been introduced.
00151   void setMask(ImageInterface<Float> & mask, const Float& maskThreshold = 0.9);
00152   // Tell the algorithm to NOT clean just the inner quarter
00153   // (This is useful when multiscale clean is being used
00154   // inside a major cycle for MF or WF algorithms)
00155   // if True, the full image deconvolution will be attempted
00156   void ignoreCenterBox(Bool ign) ;
00157   // Consider the case of a point source: 
00158   // the flux on all scales is the same, and the first scale will be chosen.
00159   // Now, consider the case of a point source with a *little* bit of extended structure:
00160   // thats right, the largest scale will be chosen.  In this case, we should provide some
00161   // bias towards the small scales, or against the large scales.  We do this in
00162   // an ad hoc manner, multiplying the maxima found at each scale by
00163   // 1.0 - itsSmallScaleBias * itsScaleSizes(scale)/itsScaleSizes(nScalesToClean-1);
00164   // Typical bias values range from 0.2 to 1.0.
00165   void setSmallScaleBias(const Float x=0.5);
00166    // During early iterations of a cycled MS Clean in mosaicing, it common
00167   // to come across an ocsilatory pattern going between positive and
00168   // negative in the large scale.  If this is set, we stop at the first
00169   // negative in the largest scale.
00170   void stopAtLargeScaleNegative() ;
00171   // Some algorithms require that the cycles be terminated when the image
00172   // is dominated by point sources; if we get nStopPointMode of the
00173   // smallest scale components in a row, we terminate the cycles
00174   void stopPointMode(Int nStopPointMode) ;
00175    // After completion of cycle, querry this to find out if we stopped because
00176   // of stopPointMode
00177   Bool queryStopPointMode() const ;
00178   // speedup() will speed the clean iteration by raising the
00179   // threshold.  This may be required if the threshold is
00180   // accidentally set too low (ie, lower than can be achieved
00181   // given errors in the approximate PSF).
00182   //
00183   // threshold(iteration) = threshold(0) 
00184   //                        * ( exp( (iteration - startingiteration)/Ndouble )/ 2.718 )
00185   // If speedup() is NOT invoked, no effect on threshold
00186   void speedup(const Float Ndouble);
00187 
00188   //Max residual after last clean
00189   Float maxResidual() {return maxResidual_p;};
00190 
00191  private:
00192   //Helper function to setup some param
00193   Bool setupMatCleaner(const String& alg, const Int niter, const Float gain, 
00194                        const Quantity& threshold, const Quantity& fthresh=Quantity(0.0, "%"));
00195   MatrixCleaner matClean_p;
00196   ImageInterface<Float>* psf_p;
00197   ImageInterface<Float>* dirty_p;
00198   ImageInterface<Float>* mask_p;
00199   Int nPsfChan_p;
00200   Int nImChan_p;
00201   Int nPsfPol_p;
00202   Int nImPol_p;
00203   Int chanAxis_p;
00204   Int polAxis_p;
00205   Int nMaskChan_p;
00206   Int nMaskPol_p;
00207   Vector<Float> scales_p;
00208   Float maskThresh_p;
00209   Float maxResidual_p;
00210 
00211 };
00212 
00213 } //# NAMESPACE CASA - END
00214 
00215 #endif