LCOV - code coverage report
Current view: top level - synthesis/ImagerObjects - SDAlgorithmHogbomClean.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 68 77 88.3 %
Date: 2023-11-06 10:06:49 Functions: 8 8 100.0 %

          Line data    Source code
       1             : //# SDAlgorithmHogbomClean.cc: Implementation of SDAlgorithmHogbomClean classes
       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: aips2-request@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             : //# $Id$
      27             : 
      28             : #include <casacore/casa/Arrays/ArrayMath.h>
      29             : #include <casacore/casa/OS/HostInfo.h>
      30             : #include <synthesis/ImagerObjects/SDAlgorithmHogbomClean.h>
      31             : #include <components/ComponentModels/SkyComponent.h>
      32             : #include <components/ComponentModels/ComponentList.h>
      33             : #include <casacore/images/Images/TempImage.h>
      34             : #include <casacore/images/Images/SubImage.h>
      35             : #include <casacore/images/Regions/ImageRegion.h>
      36             : #include <casacore/casa/OS/File.h>
      37             : #include <casacore/lattices/LEL/LatticeExpr.h>
      38             : #include <casacore/lattices/Lattices/TiledLineStepper.h>
      39             : #include <casacore/lattices/Lattices/LatticeStepper.h>
      40             : #include <casacore/lattices/Lattices/LatticeIterator.h>
      41             : #include <synthesis/TransformMachines/StokesImageUtil.h>
      42             : #include <casacore/coordinates/Coordinates/StokesCoordinate.h>
      43             : #include <casacore/casa/Exceptions/Error.h>
      44             : #include <casacore/casa/BasicSL/String.h>
      45             : #include <casacore/casa/Utilities/Assert.h>
      46             : #include <casacore/casa/OS/Directory.h>
      47             : #include <casacore/tables/Tables/TableLock.h>
      48             : 
      49             : #include<synthesis/ImagerObjects/SIMinorCycleController.h>
      50             : 
      51             : #include <sstream>
      52             : 
      53             : #include <casacore/casa/Logging/LogMessage.h>
      54             : #include <casacore/casa/Logging/LogIO.h>
      55             : #include <casacore/casa/Logging/LogSink.h>
      56             : 
      57             : #include <casacore/casa/System/Choice.h>
      58             : #include <msvis/MSVis/StokesVector.h>
      59             : 
      60             : 
      61             : using namespace casacore;
      62             : namespace casa { //# NAMESPACE CASA - BEGIN
      63             : 
      64             : #define NEED_UNDERSCORES
      65             : #if defined(NEED_UNDERSCORES)
      66             : #define hclean hclean_
      67             : #endif
      68             : extern "C" {
      69             :   void hclean(Float*, Float*, Float*, int*, Float*, int*, int*, int*,
      70             :               int*, int*, int*, int*, int*, int*, int*, Float*, Float*,
      71             :               Float*, void *, void *);
      72             :    };
      73             : 
      74             : 
      75             : 
      76             :   ////////////////// Global functions ? 
      77        3367 : void REFHogbomCleanImageSkyModelstopnow (Int *yes) {
      78             : 
      79        3367 :   *yes=0;
      80        3367 :   return;
      81             : 
      82             :   /*
      83             :   Vector<String> choices(2);
      84             :   choices(0)="Continue";
      85             :   choices(1)="Stop Now";
      86             :   LogMessage message(LogOrigin("REFHogbomCleanImageSkyModel","solve"));
      87             :   LogSink logSink;
      88             :   *yes=0;
      89             :   return;
      90             :   String choice=Choice::choice("Clean iteration: do you want to continue or stop?", choices);
      91             :   if (choice==choices(0)) {
      92             :     *yes=0;
      93             :   }
      94             :   else {
      95             :     message.message("Stopping");
      96             :     logSink.post(message);
      97             :     *yes=1;
      98             :   }
      99             :   */
     100             : 
     101             : }
     102             : 
     103        5859 : void REFHogbomCleanImageSkyModelmsgput(Int *npol, Int* /*pol*/, Int* iter, Int* px, Int* py,
     104             :                                     Float* fMaxVal) {
     105       17577 :   LogIO os(LogOrigin("REFHogbomCleanImageSkyModel","solve"));
     106       11718 :    ostringstream o; 
     107             : //  LogSink logSink(LogMessage::NORMAL2);
     108             :   
     109        5859 :   if(*npol<0) {
     110           0 :     StokesVector maxVal(fMaxVal[0], fMaxVal[1], fMaxVal[2], fMaxVal[3]);
     111           0 :     if(*iter==0) {
     112             :       //      o<<stokes<<": Before iteration, peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     113           0 :       o<<"Before iteration, peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     114           0 :       os << LogIO::NORMAL1 << o.str() << LogIO::POST;
     115             :       //      message.message(o);
     116             :       //      logSink.post(message);
     117             :     }
     118           0 :     else if(*iter>-1) {
     119             :       //      o<<stokes<<": Iteration "<<*iter<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     120           0 :       o<<"Iteration "<<*iter<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     121           0 :       os << LogIO::NORMAL1 << o.str() << LogIO::POST;
     122             :       //      message.message(o);
     123             :       //      logSink.post(message);
     124             :     }
     125             :     else {
     126             :       //      o<<stokes<<": Final iteration "<<abs(*iter)<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     127           0 :       o<<"Final iteration "<<abs(*iter)<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     128           0 :       os << LogIO::NORMAL1 << o.str() << LogIO::POST;
     129             :       //      message.message(o);
     130             :       //      logSink.post(message);
     131             :     }
     132             :   }
     133             :   else {
     134        5859 :     Float maxVal(fMaxVal[0]);
     135        5859 :     if(*iter==0) {
     136             :       //      o<<stokes<<": Before iteration, peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     137        2492 :       o<<"Before iteration, peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     138        2492 :       os << LogIO::NORMAL1 << o.str() << LogIO::POST;
     139             :       //      message.message(o);
     140             :       //      logSink.post(message);
     141             :     }
     142        3367 :     else if(*iter>-1) {
     143             :       //      o<<stokes<<": Iteration "<<*iter<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     144         875 :       o<<"Iteration "<<*iter<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     145         875 :       os << LogIO::NORMAL1 << o.str() << LogIO::POST;
     146             :       //      message.message(o);
     147             :       //      logSink.post(message);
     148             :     }
     149             :     else {
     150             :       //      o<<stokes<<": Final iteration "<<abs(*iter)<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     151        2492 :       o<<"Final iteration "<<abs(*iter)<<" peak is "<<maxVal<<" at "<<*px-1<<","<<*py-1;
     152        2492 :       os << LogIO::NORMAL1 << o.str() << LogIO::POST;
     153             :       //      message.message(o);
     154             :       //      logSink.post(message);
     155             :     }
     156             :   }
     157             :   
     158        5859 : }
     159             : 
     160             : 
     161             : 
     162         790 :   SDAlgorithmHogbomClean::SDAlgorithmHogbomClean():
     163         790 :     SDAlgorithmBase()
     164             :     //    itsMatResidual(), itsMatModel(), itsMatPsf(),
     165             :     //    itsMaxPos( IPosition() ),
     166             :     //    itsPeakResidual(0.0),
     167             :     //    itsModelFlux(0.0),
     168             :     //    itsMatMask()
     169             :  {
     170         790 :    itsAlgorithmName=String("Hogbom");
     171         790 :  }
     172             : 
     173        1580 :   SDAlgorithmHogbomClean::~SDAlgorithmHogbomClean()
     174             :  {
     175             :    
     176        1580 :  }
     177             : 
     178             :   //  void SDAlgorithmHogbomClean::initializeDeconvolver( Float &peakresidual, Float &modelflux )
     179        2492 :   void SDAlgorithmHogbomClean::initializeDeconvolver()
     180             :   {
     181        4984 :     LogIO os( LogOrigin("SDAlgorithmHogbomClean","initializeDeconvolver",WHERE) );
     182             : 
     183        2492 :     itsImages->residual()->get( itsMatResidual, true );
     184        2492 :     itsImages->model()->get( itsMatModel, true );
     185        2492 :     itsImages->psf()->get( itsMatPsf, true );
     186        2492 :     itsImages->mask()->get( itsMatMask, true );
     187             : 
     188             :     //    cout << "initDecon : " << itsImages->residual()->shape() << " : " << itsMatResidual.shape() 
     189             :     //   << itsImages->model()->shape() << " : " << itsMatModel.shape() 
     190             :     //   << itsImages->psf()->shape() << " : " << itsMatPsf.shape() 
     191             :     //   << endl;
     192             : 
     193             :     /*
     194             :     findMaxAbs( itsMatResidual, itsPeakResidual, itsMaxPos );
     195             :     itsModelFlux = sum( itsMatModel );
     196             : 
     197             :     peakresidual = itsPeakResidual;
     198             :     modelflux = itsModelFlux;
     199             :     */
     200        2492 :   }
     201             : 
     202             : 
     203        2492 :   void SDAlgorithmHogbomClean::takeOneStep( Float loopgain, 
     204             :                                             Int cycleNiter, 
     205             :                                             Float cycleThreshold, 
     206             :                                             Float &peakresidual, 
     207             :                                             Float &modelflux, 
     208             :                                             Int &iterdone)
     209             :   {
     210             : 
     211             :     Bool delete_iti, delete_its, delete_itp, delete_itm;
     212             :     const Float *lpsf_data, *lmask_data;
     213             :     Float *limage_data, *limageStep_data;
     214             : 
     215        2492 :     limage_data = itsMatModel.getStorage( delete_iti );
     216        2492 :     limageStep_data = itsMatResidual.getStorage( delete_its );
     217        2492 :     lpsf_data = itsMatPsf.getStorage( delete_itp );
     218        2492 :     lmask_data = itsMatMask.getStorage( delete_itm );
     219             : 
     220        2492 :     Int niter= cycleNiter;
     221        2492 :     Float g = loopgain;
     222        2492 :     Float thres = cycleThreshold;
     223             : 
     224        2492 :     IPosition shp = itsMatPsf.shape();
     225             :     /*
     226             :     Int xbeg = shp[0]/4;
     227             :     Int xend = 3*shp[0]/4;
     228             :     Int ybeg = shp[1]/4;
     229             :     Int yend = 3*shp[1]/4;
     230             :     */
     231             :     
     232        2492 :     Int xbeg = 0;
     233        2492 :     Int xend = shp[0]-1;
     234        2492 :     Int ybeg = 0;
     235        2492 :     Int yend = shp[1]-1;
     236             :     
     237             : 
     238        2492 :     Int newNx = shp[0];
     239        2492 :     Int newNy = shp[1];
     240        2492 :     Int npol = 1;
     241             :     
     242             :     // Fortran indexes at 1
     243        2492 :     Int fxbeg=xbeg+1;
     244        2492 :     Int fxend=xend+1;
     245        2492 :     Int fybeg=ybeg+1;
     246        2492 :     Int fyend=yend+1;
     247             :     
     248        2492 :     Int domaskI = 1;
     249             :     
     250        2492 :     Int starting_iteration = 0;  
     251        2492 :     Int ending_iteration=0;         
     252        2492 :     Float cycleSpeedup = -1; // ie, ignore it
     253             :     
     254        2492 :     hclean(limage_data, limageStep_data,
     255             :            (Float*)lpsf_data, &domaskI, (Float*)lmask_data,
     256             :            &newNx, &newNy, &npol,
     257             :            &fxbeg, &fxend, &fybeg, &fyend, &niter,
     258             :            &starting_iteration, &ending_iteration,
     259             :            &g, &thres, &cycleSpeedup,
     260             :            (void*) &REFHogbomCleanImageSkyModelmsgput,
     261             :            (void*) &REFHogbomCleanImageSkyModelstopnow);
     262             :     
     263        2492 :     iterdone=ending_iteration;
     264             :     
     265        2492 :     itsMatModel.putStorage( limage_data, delete_iti );
     266        2492 :     itsMatResidual.putStorage( limageStep_data, delete_its );
     267        2492 :     itsMatPsf.freeStorage( lpsf_data, delete_itp );
     268        2492 :     itsMatMask.freeStorage( lmask_data, delete_itm );
     269             :     
     270             :     
     271             :     /////////////////
     272        2492 :     findMaxAbsMask( itsMatResidual, itsMatMask, itsPeakResidual, itsMaxPos );
     273        2492 :     peakresidual = itsPeakResidual;
     274             : 
     275        2492 :     modelflux = sum( itsMatModel ); // Performance hog ?
     276        2492 :   }         
     277             : 
     278        2492 :   void SDAlgorithmHogbomClean::finalizeDeconvolver()
     279             :   {
     280        2492 :     (itsImages->residual())->put( itsMatResidual );
     281        2492 :     (itsImages->model())->put( itsMatModel );
     282        2492 :   }
     283             : 
     284             : 
     285             : } //# NAMESPACE CASA - END
     286             : 

Generated by: LCOV version 1.16