LCOV - code coverage report
Current view: top level - synthesis/ImagerObjects - SynthesisNormalizerMixin.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 44 0.0 %
Date: 2024-10-04 16:51:10 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /* -*- mode: c++ -*- */
       2             : //# SynthesisNormalizerMixin.h: Mixin for using SynthesisNormalizer class in
       3             : //#                             parallel imaging framework (ParallelImagerMixin)
       4             : //# Copyright (C) 2016
       5             : //# Associated Universities, Inc. Washington DC, USA.
       6             : //#
       7             : //# This library is free software; you can redistribute it and/or modify it
       8             : //# under the terms of the GNU Library General Public License as published by
       9             : //# the Free Software Foundation; either version 2 of the License, or (at your
      10             : //# option) any later version.
      11             : //#
      12             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      13             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      15             : //# License for more details.
      16             : //#
      17             : //# You should have received a copy of the GNU Library General Public License
      18             : //# along with this library; if not, write to the Free Software Foundation,
      19             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      20             : //#
      21             : //# Correspondence concerning AIPS++ should be addressed as follows:
      22             : //#        Internet email: casa-feedback@nrao.edu.
      23             : //#        Postal address: AIPS++ Project Office
      24             : //#                        National Radio Astronomy Observatory
      25             : //#                        520 Edgemont Road
      26             : //#                        Charlottesville, VA 22903-2475 USA
      27             : //#
      28             : #ifndef SYNTHESIS_NORMALIZER_MIXIN_H_
      29             : #define SYNTHESIS_NORMALIZER_MIXIN_H_
      30             : 
      31             : #include <synthesis/ImagerObjects/MPIGlue.h>
      32             : #include <synthesis/ImagerObjects/SynthesisNormalizer.h>
      33             : #include <casacore/casa/OS/File.h>
      34             : #include <casacore/casa/OS/Directory.h>
      35             : #include <casacore/casa/OS/RegularFile.h>
      36             : #include <memory>
      37             : #include <algorithm>
      38             : #include <vector>
      39             : 
      40             : namespace casa {
      41             : 
      42             : /**
      43             :  * Simple mixin class to put SynthesisNormalizer into ParallelImagerMixin
      44             :  * framework.
      45             :  */
      46             : template<class T>
      47             : class SynthesisNormalizerMixin
      48             :         : public T {
      49             : 
      50             : private:
      51             :         std::vector< std::shared_ptr<SynthesisNormalizer> > normalizers;
      52             : 
      53             : protected:
      54             :         void
      55           0 :         setup_normalizer(MPI_Comm comm, std::vector<casacore::Record> &norm_pars) {
      56             :                 // Create all normalizer components on rank 0 of comm. TODO: Could we
      57             :                 // distribute normalizers in a round-robin fashion across processes in
      58             :                 // comm?
      59             : 
      60           0 :                 teardown_normalizer();
      61           0 :                 if (T::effective_rank(comm) == 0)
      62           0 :                         for (auto pars : norm_pars) {
      63           0 :                                 SynthesisNormalizer *sn = new SynthesisNormalizer();
      64           0 :                                 sn->setupNormalizer(pars);
      65           0 :                                 normalizers.push_back(std::shared_ptr<SynthesisNormalizer>(sn));
      66             :                                 // FIXME: check whether we're to remove any files or directories
      67             :                                 // in addition to those provided in "partimagenames", i.e, those
      68             :                                 // with file name extensions
      69             :                                 //
      70             :                                 // To ensure restarts work correctly, remove existing files.
      71           0 :                                 if (pars.isDefined("partimagenames")) {
      72           0 :                                         const std::vector<casacore::String> &part_names =
      73           0 :                                                 pars.asArrayString("partimagenames").tovector();
      74           0 :                                         for (size_t p = 0; p < part_names.size(); ++p) {
      75           0 :                                                 casacore::File f(part_names[p]);
      76           0 :                                                 if (f.isDirectory(false))
      77           0 :                                                         casacore::Directory(f).removeRecursive();
      78             :                                                 else
      79           0 :                                                         casacore::RegularFile(f).remove();
      80             :                                         }
      81           0 :                                 }
      82             :                         }
      83           0 :         };
      84             : 
      85             :         void
      86           0 :         teardown_normalizer() {
      87           0 :                 normalizers.clear();
      88           0 :         };
      89             : 
      90             : public:
      91             :         void
      92           0 :         normalize_psf() {
      93           0 :                 for (auto sn : normalizers) {
      94           0 :                         sn->gatherImages(/*dopsf*/true, /*doresidual*/false,
      95             :                                          /*density*/false);
      96           0 :                         sn->dividePSFByWeight();
      97             :                 }
      98           0 :         };
      99             : 
     100             :         void
     101           0 :         normalize_model() {
     102           0 :                 for (auto sn : normalizers) {
     103           0 :                         sn->divideModelByWeight();
     104           0 :                         sn->scatterModel();
     105             :                 }
     106           0 :         };
     107             : 
     108             :         void
     109           0 :         normalize_residual() {
     110           0 :                 for (auto sn : normalizers) {
     111           0 :                         sn->gatherImages(/*dopsf*/false, /*doresidual*/true,
     112             :                                          /*density*/false);
     113           0 :                         sn->divideResidualByWeight();
     114             :                 }
     115           0 :         };
     116             : 
     117             :         void
     118           0 :         denormalize_model() {
     119           0 :                 for (auto sn : normalizers)
     120           0 :                         sn->multiplyModelByWeight();
     121           0 :         };
     122             : 
     123             :         void
     124           0 :         reduce_weight_density() {
     125           0 :                 for (auto sn : normalizers) {
     126           0 :                         sn->gatherImages(/*dopsf*/false, /*doresidual*/false,
     127             :                                          /*density*/true);
     128           0 :                         sn->scatterWeightDensity();
     129             :                 }
     130           0 :         };
     131             : };
     132             : 
     133             : } // namespace casa
     134             : 
     135             : #endif // SYNTHESIS_NORMALIZER_MIXIN_H_

Generated by: LCOV version 1.16