LCOV - code coverage report
Current view: top level - synthesis/MeasurementEquations - AspMatrixCleaner.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 5 5 100.0 %
Date: 2024-11-06 17:42:47 Functions: 4 4 100.0 %

          Line data    Source code
       1             : //# AspMatrixCleaner.h: Minor Cycle for Asp deconvolution
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //#
      27             : //# $Id: AspMatrixCleaner.h Genie H. 2020-04-06 <mhsieh@nrao.edu $
      28             : 
      29             : #ifndef SYNTHESIS_ASPMATRIXCLEANER_H
      30             : #define SYNTHESIS_ASPMATRIXCLEANER_H
      31             : 
      32             : //# Includes
      33             : #include <casacore/scimath/Mathematics/FFTServer.h>
      34             : #include <synthesis/MeasurementEquations/MatrixCleaner.h>
      35             : #include <deque>
      36             : #include <casacore/coordinates/Coordinates/CoordinateSystem.h>
      37             : #include <casacore/coordinates/Coordinates/SpectralCoordinate.h>
      38             : #include <casacore/casa/Utilities/CountedPtr.h>
      39             : 
      40             : namespace casa { //# NAMESPACE CASA - BEGIN
      41             : 
      42             : class AspMatrixCleaner : public MatrixCleaner
      43             : {
      44             : public:
      45             :   // Create a cleaner : default constructor
      46             :   AspMatrixCleaner();
      47             : 
      48             :   // The destructor does nothing special.
      49             :   ~AspMatrixCleaner();
      50             : 
      51             :   casacore::Bool setaspcontrol(const casacore::Int niter,
      52             :       const casacore::Float gain, const casacore::Quantity& aThreshold,
      53             :       const casacore::Quantity& fThreshold);
      54             : 
      55             : 
      56             :   // Clean an image.
      57             :   //return value gives you a hint of what's happening
      58             :   //  1 = converged
      59             :   //  0 = not converged but behaving normally
      60             :   // -1 = not converged and stopped on cleaning consecutive smallest scale
      61             :   // -2 = not converged and either large scale hit negative or diverging
      62             :   // -3 = clean is diverging rather than converging
      63             :   casacore::Int aspclean(casacore::Matrix<casacore::Float> & model, casacore::Bool doPlotProgress=false);
      64             : 
      65             :   // helper functions for ASP
      66             :   float getPsfGaussianWidth(casacore::ImageInterface<casacore::Float>& psf);
      67             :   void getLargestScaleSize(casacore::ImageInterface<casacore::Float>& psf);
      68             : 
      69             :   // Make an image of the specified scale by Gaussian
      70             :   void makeInitScaleImage(casacore::Matrix<casacore::Float>& iscale, const casacore::Float& scaleSize);
      71             :   void makeScaleImage(casacore::Matrix<casacore::Float>& iscale, const casacore::Float& scaleSize, const casacore::Float& amp, const casacore::IPosition& center);
      72             : 
      73             :   void setInitScales();
      74             :   void setInitScaleXfrs(const casacore::Float width);
      75             : 
      76             :   // calculate the convolutions of the psf with the initial scales
      77             :   void setInitScalePsfs();
      78             : 
      79          70 :   casacore::Bool setInitScaleMasks(const casacore::Array<casacore::Float> arrmask, const casacore::Float& maskThreshold = 0.99);
      80             : 
      81             :   void maxDirtyConvInitScales(float& strengthOptimum, int& optimumScale, casacore::IPosition& positionOptimum);
      82             : 
      83             :   // returns the active-set aspen for cleaning
      84             :   std::vector<casacore::Float> getActiveSetAspen();
      85             : 
      86             :   // Juat define the active-set aspen scales
      87             :   void defineAspScales(std::vector<casacore::Float>& scaleSizes);
      88             : 
      89             :   void switchedToHogbom(bool runlong= false);
      90             :   void setOrigDirty(const casacore::Matrix<casacore::Float>& dirty);
      91          35 :   void setFusedThreshold(const casacore::Float fusedThreshold = 0.0) { itsFusedThreshold = fusedThreshold; }
      92          35 :   void setUserLargestScale(const casacore::Int largestScale = -1) { itsUserLargestScale = float(largestScale); }
      93             : 
      94             :   // setter/getter
      95             :   float getterPsfWidth() { return itsPsfWidth; }
      96             :   bool getterSwitchedHogbom() { return itsSwitchedToHogbom; }
      97          35 :   casacore::Matrix<casacore::Float>  getterResidual() { return (*itsDirty); }
      98          35 :   float getterPeakResidual() { return itsPeakResidual; }
      99             : 
     100             :   void setBinSizeForSumFlux(const casacore::Int binSize = 4) { itsBinSizeForSumFlux = binSize ; } ;
     101             :   void getFluxByBins(const std::vector<casacore::Float>& scaleSizes,const std::vector<casacore::Float>& optimum, casacore::Int binSize, std::vector<casacore::Float>&  sumFluxByBins, std::vector<casacore::Float>&  rangeFluxByBins);
     102             : 
     103             : 
     104             : //protected:
     105             : private:
     106             : 
     107             :   using MatrixCleaner::findMaxAbs;
     108             :   using MatrixCleaner::findMaxAbsMask;
     109             :   using MatrixCleaner::itsGain;
     110             :   using MatrixCleaner::itsMaxNiter;
     111             :   using MatrixCleaner::itsThreshold;
     112             :   using MatrixCleaner::itsMask;
     113             :   using MatrixCleaner::itsScalesValid;
     114             :   using MatrixCleaner::itsNscales;
     115             :   using MatrixCleaner::itsMaskThreshold;
     116             :   using MatrixCleaner::itsDirty;
     117             :   using MatrixCleaner::itsXfr;
     118             :   using MatrixCleaner::itsScaleSizes;
     119             :   casacore::Block<casacore::Matrix<casacore::Float> > itsInitScales;
     120             :   casacore::Block<casacore::Matrix<casacore::Complex> > itsInitScaleXfrs;
     121             :   casacore::Block<casacore::Matrix<casacore::Float> > itsDirtyConvInitScales;
     122             :   casacore::Block<casacore::Matrix<casacore::Float> > itsInitScaleMasks;
     123             :   casacore::Block<casacore::Matrix<casacore::Float> > itsPsfConvInitScales;
     124             : 
     125             :   using MatrixCleaner::itsIteration;
     126             :   using MatrixCleaner::itsStartingIter;
     127             :   using MatrixCleaner::itsFracThreshold;
     128             :   using MatrixCleaner::itsMaximumResidual;
     129             :   using MatrixCleaner::itsStrengthOptimum;
     130             :   using MatrixCleaner::itsTotalFlux;
     131             :   using MatrixCleaner::index;
     132             : 
     133             :   using MatrixCleaner::destroyScales;
     134             :   casacore::Bool destroyAspScales();
     135             :   casacore::Bool destroyInitScales();
     136             :   using MatrixCleaner::destroyMasks;
     137             :   casacore::Bool destroyInitMasks();
     138             :   casacore::Float computeThreshold() const;
     139             : 
     140             :   using MatrixCleaner::itsIgnoreCenterBox;
     141             :   using MatrixCleaner::itsStopAtLargeScaleNegative;
     142             :   using MatrixCleaner::itsStopPointMode;
     143             :   using MatrixCleaner::itsDidStopPointMode;
     144             :   using MatrixCleaner::psfShape_p;
     145             :   using MatrixCleaner::noClean_p;
     146             : 
     147             :   // FFTServer
     148             :   casacore::FFTServer<casacore::Float,casacore::Complex> fft;
     149             : 
     150             :   // set to 0, 1*, 2*, 4*, and 8* width for initial scales in Asp
     151             :   std::vector<casacore::Float> itsInitScaleSizes;
     152             :   //std::vector<casacore::Float> itsAspScaleSizes; // No longer needed. permanent list for making model image
     153             :   //std::vector<casacore::Float> itsAspAmplitude;
     154             :   //std::vector<casacore::IPosition> itsAspCenter;
     155             :   casacore::Int itsNInitScales;
     156             :   std::deque<int> itsNumIterNoGoodAspen;
     157             :   float itsPsfWidth;
     158             :   bool itsUseZhang;
     159             :   bool itsSwitchedToHogbom;
     160             :   unsigned int itsNumHogbomIter;
     161             :   unsigned int itsNthHogbom;
     162             :   std::vector<casacore::Float> itsGoodAspActiveSet; // avtice-set of aspens (updated)
     163             :   std::vector<casacore::Float> itsGoodAspAmplitude; // amplitude of avtice-set of aspens (updated)
     164             :   std::vector<casacore::IPosition> itsGoodAspCenter; // center of aspens in active-set
     165             :   //std::vector<casacore::Float> itsPrevAspActiveSet; // No longer needed. avtice-set of aspens (before bfgs)
     166             :   //std::vector<casacore::Float> itsPrevAspAmplitude; // No longer needed. amplitude of avtice-set of aspens (before bfgs)
     167             :   casacore::Int itsOptimumScale;
     168             :   casacore::IPosition itsPositionOptimum;
     169             :   casacore::Float itsOptimumScaleSize;
     170             :   double itsUsedMemoryMB;
     171             :   float itsPeakResidual;
     172             :   float itsPrevPeakResidual;
     173             :   casacore::CountedPtr<casacore::Matrix<casacore::Float> > itsOrigDirty;
     174             : 
     175             :   const casacore::Int itsDefaultNorm = 1;
     176             :   casacore::Int itsNormMethod;
     177             :   casacore::Float itsFusedThreshold;
     178             :   casacore::Int itsBinSizeForSumFlux ;   // number of bins for histogram of the sum of Flux
     179             :   unsigned int itsNumNoChange; // number of times peakres rarely changes
     180             :   float itsLargestInitScale; // estimated largest initial scale
     181             :   float itsUserLargestScale; // user-specified largest initial scale
     182             :   casacore::IPosition blcDirty, trcDirty;
     183             : };
     184             : 
     185             : } //# NAMESPACE CASA - END
     186             : 
     187             : #endif

Generated by: LCOV version 1.16