Deconvolver.h

Go to the documentation of this file.
00001 //# Deconvolver: defines classes for deconvolver.
00002 //# Copyright (C) 1996-2007
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: DOdeconvolver.h,v 19.7 2005/03/18 01:43:31 kgolap Exp $
00028 
00029 #ifndef SYNTHESIS_DECONVOLVER_H
00030 #define SYNTHESIS_DECONVOLVER_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/IPosition.h>
00034 #include <casa/Quanta/Quantum.h>
00035 #include <measures/Measures/MDirection.h>
00036 #include <measures/Measures/MPosition.h>
00037 #include <measures/Measures/MRadialVelocity.h>
00038 #include <lattices/LatticeMath/LatticeCleaner.h>
00039 #include <scimath/Mathematics/GaussianBeam.h>
00040 
00041 #include <synthesis/MeasurementEquations/MultiTermMatrixCleaner.h>
00042 
00043 #include <casa/namespace.h>
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 template<class T> class Lattice;
00046 template<class T> class PagedImage;
00047 template<class T> class TempImage;
00048 template<class T> class ImageInterface;
00049 template<class T> class LatticeConvolver;
00050 template<class T> class ResidualEquation;
00051 template<class T> class SubImage;
00052 
00053 
00054 class File;
00055 class CEMemModel;
00056 class ClarkCleanLatModel;
00057 class LatConvEquation;
00058 class ImageMSCleaner;
00059 class ImageNACleaner;
00060 // <summary> A simple deconvolver operating on images (no SkyEquation) </summary>
00061 
00062 // <use visibility=export>
00063 
00064 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00065 // </reviewed>
00066 
00067 // <prerequisite>
00068 //   <li> <linkto class="SkyEquation">SkyEquation</linkto>
00069 //   <li> <linkto class="SkyModel">SkyModel</linkto>
00070 // </prerequisite>
00071 //
00072 // <etymology>
00073 // Undo convolution or at least try to do it !
00074 // </etymology>
00075 //
00076 // <synopsis>
00077 // This class is a container that allows many SkyComponents to be grouped
00078 // together and manipulated as a group. In this respect this class is identical
00079 // to the <linkto class="ComponentList">ComponentList</linkto> class. The user
00080 // is encouraged to read the synopsis of that class for a general description
00081 // of the capabilities of this class.
00082 //
00083 // This class is differs from the ComponentList class in the following ways:
00084 // <ul>
00085 // <li> All components are indexed starting at one. This means the first
00086 //      component in this class is obtained by <src>component(1)</src> rather
00087 //      than <src>component(0)</src> in the ComponentList class.
00088 // <li> Copies of the components, rather than references, are returned to the
00089 //      user. This means that this class needs a replace function whereas
00090 //      ComponentList does not.
00091 // <li> Components that have been removed from the list are stored in a
00092 //      temporary place. In the ComponentList class once they are deleted they
00093 //      are gone.
00094 // <li> This class is derived from ApplicationObject and follows the AIPS++
00095 //      conventions for "distributed objects". Hence the fuunctions in this
00096 //      class can be made accessible from glish. 
00097 // <li> This class can generate simulated components and add them to the list.
00098 // </ul>
00099 //
00100 // There is a one-to-one correspondence between the functions in the glish
00101 // componentlist object (see the AIPS++ User Reference manual) and functions in
00102 // this class. This is make simplify the porting from glish to C++ of a glish
00103 // script using the componentlist distributed object.
00104 // </synopsis>
00105 //
00106 // <example>
00107 // These examples are coded in the tDOcomponentlist.h file.
00108 // <h4>Example 1:</h4>
00109 // In this example a ComponentList object is created and used to calculate the
00110 // ...
00111 // <srcblock>
00112 // </srcblock>
00113 // </example>
00114 //
00115 // <motivation> 
00116 // This class was written to make the componentlist classes usable from glish
00117 // </motivation>
00118 //
00119 // <thrown>
00120 // <li> AipsError - If an internal inconsistancy is detected, when compiled in 
00121 // debug mode only.
00122 // </thrown>
00123 //
00124 // <todo asof="1998/05/22">
00125 //   <li> Nothing I hope. But I expect users will disagree.
00126 // </todo>
00127 
00128 class Deconvolver 
00129 {
00130 public:
00131   // "deconvolver" ctor
00132   Deconvolver();
00133   
00134   Deconvolver(const String& dirty, const String& psf);
00135   
00136   Deconvolver(const Deconvolver &other);
00137   Deconvolver &operator=(const Deconvolver &other);
00138   ~Deconvolver();
00139 
00140   // Open the given dirty image and psf
00141   // If warn is true,  print warnings about there being
00142   // no psf if one is not supplied.
00143   Bool open(const String& dirty, const String& psf, Bool warn=True);
00144 
00145   // After some cleaning, the dirty image is replaced with the
00146   // residual image in the deconvolver tool.  reopen reinstates
00147   // that dirty image; cannot be invoked before open has been
00148   // invoked
00149   Bool reopen();
00150   
00151   // Flush the ms to disk and detach from the ms file. All function
00152   // calls after this will be a no-op.
00153   Bool close();
00154   
00155   String dirtyname() const;
00156   String psfname() const;
00157 
00158   // Output a summary of the state of the object
00159   Bool summary() const;
00160   
00161   // Return the state of the object as a string
00162   String state() const;
00163   
00164   // Return the image shape
00165   IPosition imageshape() const;
00166 
00167   // Restore
00168   Bool restore(const String& model,
00169                const String& image, GaussianBeam& mbeam);
00170 
00171   // Residual
00172   Bool residual(const String& model, 
00173                const String& image);
00174 
00175   // Smooth
00176   Bool smooth(const String& model, 
00177               const String& image,
00178               GaussianBeam& mbeam,
00179               Bool normalizeVolume);
00180 
00181   // Clean algorithm
00182   //maxResidual and iterationsDone are return values
00183   Bool clean(const String& algorithm,
00184              const Int niter, const Float gain, const Quantity& threshold, 
00185              const Bool displayProgress,
00186              const String& model, const String& mask, Float& maxResidual, 
00187              Int& iterationsDone );
00188   Bool naclean(const Int niter,
00189                         const Float gain, const Quantity& threshold, 
00190                const String& model, const String& mask, const Int masksupp, const Int memoryType, const Float numSigma, Float& maxResidual, Int& iterationsDone) ;
00191 
00192   //Clark Clean but image, psf, mask has to be 4-axes in the canonical casa order.
00193   //Useful for cleaning dirty images made in CASA
00194   //if mask is larger than a quarter of the image it will do a full image clean ...unlike the one below
00195   Bool clarkclean(const Int niter, 
00196                   const Float gain, const Quantity& threshold, 
00197                   const String& model, const String& maskName,
00198                   Float& maxresid, Int& iterused,
00199                   Float cycleFactor=1.5);
00200 
00201   // Clark Clean algorithm
00202   Bool clarkclean(const Int niter, 
00203                   const Float gain, const Quantity& threshold, 
00204                   const Bool displayProgress, 
00205                   const String& model, const String& mask,
00206                   const Int histBins, 
00207                   const Vector<Int>& psfPatchSize, const Float maxExtPsf,
00208                   const Float speedUp, Int maxNumPix,
00209                   const Int maxNumMajorCycles,
00210                   const Int maxNumMinorIterations);
00211   
00212   
00213   // MEM algorithm    add other inputs as required
00214   Bool mem(const String& algorithm,
00215            const Int niter, const Quantity& sigma, 
00216            const Quantity& targetFlux, 
00217            Bool constrainTargetFlux, 
00218            Bool displayprogress, 
00219            const String& model, 
00220            const String& prior = "",
00221            const String& mask = "",
00222            const Bool imagePlane = False);
00223   
00224   // make a prior image
00225   Bool makeprior(const String& prior,
00226                  const String& templateImage,
00227                  const Quantity& lowClipfrom, 
00228                  const Quantity& lowClipto, 
00229                  const Quantity& highClipfrom, 
00230                  const Quantity& highClipto, 
00231                  const Vector<Int>& blc,
00232                  const Vector<Int>& trc);
00233   
00234   // Set up scales: based on scaleMethod = "nscales" or "uservector",
00235   // we will create the scale sizes in pixels via a power law or
00236   // use the user specified scale sizes.
00237   Bool setscales(const String& scaleMethod, const Int nscales, 
00238                  const Vector<Float>& userScaleSizes);
00239   
00240   // NNLS algorithm
00241   Bool nnls(const String& algorithm, const Int niter, const Float tolerance,
00242             const String& model, 
00243             const String& fluxMask, const String& dataMask);
00244 
00245   // Fourier transform the model and componentlist
00246   Bool ft(const String& model, const String& transform);
00247 
00248   // Make an empty image
00249   Bool make(const String& model);
00250 
00251   // Make an empty image with just one Stokes pixel (ie, for a mask)
00252   Bool make1(const String& imagename);
00253 
00254   // Make an empty image modeled after templateImage
00255   Bool make(const String& model, ImageInterface<Float>& templateImage);
00256 
00257   // Make a Box Mask
00258   Bool boxmask(const String& boxmask,
00259                const Vector<Int> blc,
00260                const Vector<Int> trc,
00261                const Quantity& fillValue=1.0,
00262                const Quantity& externalValue=0.0);
00263 
00264   //make a mask image from regions
00265   Bool regionmask(const String& maskimage, Record* imageRegRec, 
00266                   Matrix<Quantity>& blctrcs, const Float& value=1.0);
00267 
00268   // Clip an image below some Stokes I threshold
00269   Bool clipimage(const String& clippedImage, const String& inputImage,
00270                  const Quantity& threshold);
00271 
00272   // Fit the psf
00273   Bool fitpsf(const String& psf, GaussianBeam& beam);
00274 
00275   // Convolve one image with another
00276   Bool convolve(const String& convolvedmodel, 
00277                 const String& model);
00278 
00279   // Make a Gaussian -- you might want to use it for convolution, etc
00280   Bool makegaussian(const String& gaussianimage, GaussianBeam& mbeam, Bool normalizeVolume);
00281 
00282   // ------------------  Multi-Term Deconvolver functions - START ----------------------
00283   // Initialize the Multi-Term Matrix Cleaners and compute Hessian elements.
00284   Bool mtopen(const Int nTaylor,
00285               const Vector<Float>& userScaleSizes,
00286               const Vector<String>& psfs);
00287 
00288   // Do component-finding iterations
00289   Bool mtclean(const Vector<String>& residuals,
00290                const Vector<String>& models,
00291                const Int niter,
00292                const Float gain, 
00293                const Quantity& threshold, 
00294                const Bool displayProgress,
00295                const String& mask, 
00296                Float& maxResidual, Int& iterationsDone);
00297 
00298   // Restore the output images
00299   Bool mtrestore(const Vector<String>& models,
00300                  const Vector<String>& residuals,
00301                  const Vector<String>& images,
00302                  GaussianBeam& mbeam);
00303 
00304   // Calculate alpha and beta from restored images.
00305   Bool mtcalcpowerlaw(const Vector<String>& images,
00306                       const Vector<String>& residuals,
00307                       const String& alphaname,
00308                       const String& betaname,
00309                       const Quantity& threshold,
00310                       const Bool calcerror);
00311 
00312 
00313   // ------------------  Multi-Term Deconvolver functions - END ----------------------
00314 
00315 
00316 private:
00317   
00318   // Cut the inner quarter out of an image
00319   SubImage<Float>* innerQuarter(PagedImage<Float>& in);
00320 
00321   // Return full image as a SubImage
00322   SubImage<Float>* allQuarters(PagedImage<Float>& in);
00323 
00324   // Clone an image
00325   Bool clone(const String& imageName, const String& newImageName);
00326   
00327 
00328   //find which axes are the spectral and pol one
00329   void findAxes();
00330 
00331   //check mask
00332 
00333   void checkMask(ImageInterface<Float>& maskimage, Int& xbeg, Int& xend, 
00334                  Int& ybeg, Int& yend);
00335 
00336 
00337   // setup lattice cleaner
00338   Bool setupLatCleaner(const String& algorithm,
00339                        const Int niter, const Float gain, const Quantity& threshold, 
00340                        const Bool displayProgress);
00341 
00342   // Embed a mask into an image. A convenience function.
00343   Bool createMask(LatticeExpr<Bool> &lemask, ImageInterface<Float> &outimage);
00344   //Put a unit peak gaussian at centre
00345   Bool putGaussian(ImageInterface<Float>& im, const GaussianBeam& beam);
00346   PagedImage<Float>* dirty_p;
00347   PagedImage<Float>* psf_p;
00348 
00349   LatticeConvolver<Float>* convolver_p;
00350   ResidualEquation<Lattice<Float> >* residEqn_p;
00351   LatConvEquation* latConvEqn_p;
00352   CountedPtr <ImageMSCleaner> cleaner_p;
00353   std::shared_ptr <ImageNACleaner> naCleaner_p;
00354 
00355   Bool scalesValid_p;
00356 
00357   Int nx_p, ny_p, npol_p, nchan_p;
00358   Int chanAxis_p, polAxis_p;
00359   String mode_p;
00360   GaussianBeam beam_p;
00361 //  Quantity bmaj_p, bmin_p, bpa_p;
00362   Bool beamValid_p;
00363   String dirtyName_p;
00364   String psfName_p;
00365   Bool fullPlane_p;
00366 
00367   Vector<Float> itsTotalFluxScale;
00368   Float itsTotalFlux;
00369   Vector<Float> scaleSizes_p;
00370 
00371   // Multi-Term private variables
00372   Int mt_nterms_p;
00373   MultiTermMatrixCleaner mt_cleaner_p;
00374   Bool mt_valid_p;
00375 
00376   // Set the defaults
00377   void defaults();
00378 
00379   Bool removeTable(const String& tablename);
00380   
00381   // Prints an error message if the deconvolver DO is detached and returns True.
00382   Bool detached() const;
00383 
00384   String imageName() const;
00385 
00386   Bool valid() const;
00387 
00388 };
00389 
00390 } //# NAMESPACE CASA - END
00391 
00392 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1