LCOV - code coverage report
Current view: top level - synthesis/MeasurementEquations - CEMemProgress.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 131 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 6 0.0 %

          Line data    Source code
       1             : //# CEMemProgress.cc:  monitor progress in Mem
       2             : //# Copyright (C) 1997,1998,1999,2000,2001,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             : //# $Id$
      27             : 
      28             : 
      29             : //# Includes
      30             : #include <synthesis/MeasurementEquations/CEMemProgress.h>
      31             : #include <casacore/images/Images/TempImage.h>
      32             : #include <casacore/casa/System/PGPlotter.h>
      33             : #include <casacore/casa/BasicMath/Math.h>
      34             : 
      35             : #include <sstream>
      36             : 
      37             : 
      38             : using namespace casacore;
      39             : namespace casa { //# NAMESPACE CASA - BEGIN
      40             : 
      41           0 : CEMemProgress::CEMemProgress(PGPlotter* pgplotter)
      42           0 :   : itsPgplotter(pgplotter),
      43           0 :     itsCurrentIndex(0),
      44           0 :     itsCurrentTotalIterations(0),
      45           0 :     itsCurrentFluxScale(0.0),
      46           0 :     itsCurrentMaxResidualScale(0.0),
      47           0 :     itsCurrentSigmaScale(0.0),    
      48           0 :     itsCurrentNormGradScale(0.0),    
      49           0 :     itsCurrentEntropyScale(0.0)
      50             : {
      51           0 :   itsIterationNumbers.resize(100);
      52           0 :   itsMaxResiduals.resize(100);  
      53           0 :   itsTotalFluxes.resize(100);  
      54           0 :   itsSigmas.resize(100);
      55           0 :   itsNormGrads.resize(100);
      56           0 :   itsEntropies.resize(100);
      57             : 
      58             :   // to prevent trailing vector elements from being plotted
      59           0 :   itsIterationNumbers = 999999999;
      60           0 : }
      61             : 
      62           0 : CEMemProgress::~CEMemProgress()
      63             : {
      64             :   //  if(itsPgplotter) delete itsPgplotter; itsPgplotter=0;
      65           0 : }
      66             : 
      67             : // NOTE:  currently, we only display totalFlux, sigma, and maxResidual.
      68             : // normGrad and entropy are not displayed, but their vectors and scales
      69             : // are fully processed in case we want to diplay them in the future.
      70             : //
      71           0 :   void CEMemProgress::info(const Bool /*lastcall*/,
      72             :                          const Int iteration,
      73             :                          const Int numberIterations,
      74             :                            const Lattice<Float>& /*model*/,
      75             :                            const Lattice<Float>& /*resid*/,
      76             :                          const Float& maxResid,
      77             :                            const IPosition& /*posMaxResid*/,
      78             :                          const Float& totalFlux,
      79             :                          const Float& sigma,
      80             :                          const Float& normGrad,
      81             :                          const Float& entropy)
      82             : {
      83             : 
      84           0 :   LogIO os(LogOrigin("CEMemProgress", "info()", WHERE));
      85             : 
      86             : 
      87           0 :   if(itsCurrentIndex == 0) {
      88           0 :     if(itsPgplotter) {
      89             :       
      90           0 :       itsCurrentFluxScale = 2.0*(max(maxResid, totalFlux));
      91           0 :       itsCurrentMaxResidualScale = 1.1*maxResid;
      92           0 :       itsCurrentSigmaScale = 1.1*sigma;
      93           0 :       itsCurrentTotalIterations = numberIterations;
      94           0 :       itsCurrentEntropyScale = entropy;
      95           0 :       itsCurrentNormGradScale =  10.0*normGrad;
      96           0 :       basicSetUp(numberIterations);
      97             : 
      98             :     }
      99             :   }
     100             : 
     101           0 :   if (itsCurrentIndex >= itsTotalFluxes.nelements() ) {
     102           0 :     uInt nn = itsTotalFluxes.nelements();
     103             :     
     104           0 :     itsTotalFluxes.resize(2*nn+1, true);
     105           0 :     itsMaxResiduals.resize(2*nn+1, true);
     106           0 :     itsSigmas.resize(2*nn+1, true);
     107           0 :     itsNormGrads.resize(2*nn+1, true);
     108           0 :     itsEntropies.resize(2*nn+1, true);
     109             : 
     110             : 
     111           0 :     Vector<Float> inr(itsIterationNumbers);
     112           0 :     itsIterationNumbers.resize(2*nn+1);
     113             :     // to prevent trailing vector elements from being plotted
     114           0 :     itsIterationNumbers = 99999999;
     115           0 :     for (uInt i=0;i<nn;i++) {
     116           0 :       itsIterationNumbers(i) = inr(i);
     117             :     }
     118           0 :   }
     119             : 
     120           0 :   itsTotalFluxes(itsCurrentIndex) = totalFlux;
     121           0 :   itsMaxResiduals(itsCurrentIndex) = maxResid;
     122           0 :   itsIterationNumbers(itsCurrentIndex) = iteration + 1;
     123           0 :   itsSigmas(itsCurrentIndex) = sigma;
     124           0 :   itsNormGrads(itsCurrentIndex) = normGrad;
     125           0 :   itsEntropies(itsCurrentIndex) = entropy;
     126           0 :   itsCurrentIndex++;
     127             : 
     128           0 :   if(itsPgplotter) {
     129           0 :     Bool rePlot = false;
     130           0 :     if ( totalFlux > (0.9*itsCurrentFluxScale)) {
     131           0 :       rePlot = true;
     132           0 :       itsCurrentFluxScale *= 2.0;
     133             :     }
     134           0 :     if ( numberIterations > (Int)itsCurrentTotalIterations) {
     135           0 :       itsCurrentTotalIterations = numberIterations;
     136           0 :       rePlot = true;
     137             :     }
     138             :     // If we ever plot normGrad, we will need to test/rest its
     139             :     // Scale and rePlot
     140             : 
     141             : 
     142           0 :     if (rePlot) {      
     143           0 :       basicSetUp(true);      
     144             :     } else {
     145           0 :       plotOne(iteration+1, sigma, maxResid, totalFlux);
     146             :     }
     147             :   }  
     148           0 : };
     149             : 
     150             : 
     151             : 
     152           0 : void  CEMemProgress::basicSetUp(Bool doPlot)
     153             : {
     154             : 
     155           0 :   Float xMax = Float(itsCurrentTotalIterations)*1.15;
     156           0 :   Float xMin = -0.05*Float(itsCurrentTotalIterations);
     157             : 
     158           0 : if(itsPgplotter){
     159           0 :   itsPgplotter->sch(0.6);
     160           0 :   itsPgplotter->sci(1);
     161           0 :   itsPgplotter->page();
     162           0 :   itsPgplotter->svp(0.06, 0.94, 0.64, 0.92);
     163           0 :   itsPgplotter->swin(xMin, xMax, 0.0, itsCurrentSigmaScale);
     164           0 :   itsPgplotter->box("BCST", 0, 0, "BCNST", 0, 0);
     165           0 :   itsPgplotter->lab(" ", "sigma", "MEM Iteration Progress");
     166           0 :   itsPgplotter->iden();
     167             :   {
     168           0 :     itsPgplotter->sci(1);
     169           0 :     ostringstream oos;
     170           0 :     oos << "Sigma ";
     171           0 :     itsPgplotter->text(0.85*xMax,
     172           0 :                        (0.9*itsCurrentSigmaScale), oos);
     173           0 :   }
     174           0 :   if (doPlot) {
     175           0 :     itsPgplotter->pt(itsIterationNumbers, itsSigmas, 2);
     176             :   }
     177             : 
     178             : 
     179             :   // middle graph
     180           0 :   itsPgplotter->sci(1);
     181           0 :   itsPgplotter->svp(0.06, 0.94, 0.36, 0.64);
     182           0 :   itsPgplotter->swin(xMin, xMax, 0.0, itsCurrentMaxResidualScale);
     183           0 :   itsPgplotter->box("BCST", 0, 0, "BCNST", 0, 0);
     184           0 :   itsPgplotter->lab(" ", "Peak Resid (Jy)", " ");
     185             :   {
     186           0 :     ostringstream oos;
     187           0 :     oos << "MaxRes ";
     188           0 :     itsPgplotter->text(0.85*xMax,
     189           0 :                        (0.9*itsCurrentMaxResidualScale), oos);
     190           0 :   }
     191           0 :   if (doPlot) {
     192           0 :     itsPgplotter->pt(itsIterationNumbers, itsMaxResiduals, 2);
     193             :   }
     194             : 
     195             :   // lower graph
     196           0 :   itsPgplotter->sci(3);
     197           0 :   itsPgplotter->svp(0.06, 0.94, 0.09, 0.36);
     198           0 :   itsPgplotter->swin(xMin, xMax, 0.0, itsCurrentFluxScale);
     199           0 :   itsPgplotter->box("BCNST", 0, 0, "BCNST", 0, 0);
     200           0 :   itsPgplotter->lab("Number of iterations", "Total Flux", " ");
     201             :   {
     202           0 :     ostringstream oos;
     203           0 :     oos << "Total Flux ";
     204           0 :     itsPgplotter->text(0.85*xMax,
     205           0 :                        (0.9*itsCurrentFluxScale), oos);
     206           0 :   }
     207           0 :   if (doPlot) {
     208           0 :     itsPgplotter->pt(itsIterationNumbers, itsTotalFluxes, 2);
     209             :   }
     210             : }
     211             : 
     212             : 
     213           0 : };
     214             : 
     215             : 
     216           0 : void  CEMemProgress::plotOne(const Int iteration, 
     217             :                              const Float sigma, const Float resid, 
     218             :                              const Float flux)
     219             : {
     220             : 
     221           0 :   Float xMax = Float(itsCurrentTotalIterations)*1.15;
     222           0 :   Float xMin = -0.05*Float(itsCurrentTotalIterations);
     223             : 
     224           0 :   Vector<Float> x(1);
     225           0 :   Vector<Float> y(1);
     226           0 :   x(0) = iteration;
     227           0 : if(itsPgplotter){
     228             :   // top graph
     229           0 :   itsPgplotter->sch(0.6);
     230           0 :   itsPgplotter->sci(1);
     231           0 :   itsPgplotter->svp(0.06, 0.94, 0.64, 0.92);
     232           0 :   itsPgplotter->swin(xMin, xMax, 0.0, itsCurrentSigmaScale);
     233           0 :   y(0) = sigma;
     234           0 :   itsPgplotter->pt(x,y,2);
     235             : 
     236             :   // middle graph
     237           0 :   itsPgplotter->sci(1);
     238           0 :   itsPgplotter->svp(0.06, 0.94, 0.36, 0.64);
     239           0 :   itsPgplotter->swin(xMin, xMax, 0.0, itsCurrentMaxResidualScale);
     240           0 :   y(0) = resid;
     241           0 :   itsPgplotter->pt(x,y,2);
     242             : 
     243             :   // lower graph
     244           0 :   itsPgplotter->sci(3);
     245           0 :   itsPgplotter->svp(0.06, 0.94, 0.09, 0.36);
     246           0 :   itsPgplotter->swin(xMin, xMax, 0.0, itsCurrentFluxScale);
     247           0 :   y(0) = flux;
     248           0 :   itsPgplotter->pt(x,y,2);
     249             : }
     250           0 : };
     251             : 
     252             : 
     253             : 
     254             : } //# NAMESPACE CASA - END
     255             : 

Generated by: LCOV version 1.16