SynthesisNormalizerMixin.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00002 //# SynthesisNormalizerMixin.h: Mixin for using SynthesisNormalizer class in
00003 //#                             parallel imaging framework (ParallelImagerMixin)
00004 //# Copyright (C) 2016
00005 //# Associated Universities, Inc. Washington DC, USA.
00006 //#
00007 //# This library is free software; you can redistribute it and/or modify it
00008 //# under the terms of the GNU Library General Public License as published by
00009 //# the Free Software Foundation; either version 2 of the License, or (at your
00010 //# option) any later version.
00011 //#
00012 //# This library is distributed in the hope that it will be useful, but WITHOUT
00013 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015 //# License for more details.
00016 //#
00017 //# You should have received a copy of the GNU Library General Public License
00018 //# along with this library; if not, write to the Free Software Foundation,
00019 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00020 //#
00021 //# Correspondence concerning AIPS++ should be addressed as follows:
00022 //#        Internet email: aips2-request@nrao.edu.
00023 //#        Postal address: AIPS++ Project Office
00024 //#                        National Radio Astronomy Observatory
00025 //#                        520 Edgemont Road
00026 //#                        Charlottesville, VA 22903-2475 USA
00027 //#
00028 #ifndef SYNTHESIS_NORMALIZER_MIXIN_H_
00029 #define SYNTHESIS_NORMALIZER_MIXIN_H_
00030 
00031 #include <synthesis/ImagerObjects/MPIGlue.h>
00032 #include <synthesis/ImagerObjects/SynthesisNormalizer.h>
00033 #include <casa/OS/File.h>
00034 #include <casa/OS/Directory.h>
00035 #include <casa/OS/RegularFile.h>
00036 #include <memory>
00037 #include <algorithm>
00038 #include <vector>
00039 
00040 namespace casa {
00041 
00046 template<class T>
00047 class SynthesisNormalizerMixin
00048         : public T {
00049 
00050 private:
00051         std::vector< std::shared_ptr<SynthesisNormalizer> > normalizers;
00052 
00053 protected:
00054         void
00055         setup_normalizer(MPI_Comm comm, std::vector<Record> &norm_pars) {
00056                 // Create all normalizer components on rank 0 of comm. TODO: Could we
00057                 // distribute normalizers in a round-robin fashion across processes in
00058                 // comm?
00059 
00060                 teardown_normalizer();
00061                 if (T::effective_rank(comm) == 0)
00062                         for (auto pars : norm_pars) {
00063                                 SynthesisNormalizer *sn = new SynthesisNormalizer();
00064                                 sn->setupNormalizer(pars);
00065                                 normalizers.push_back(std::shared_ptr<SynthesisNormalizer>(sn));
00066                                 // FIXME: check whether we're to remove any files or directories
00067                                 // in addition to those provided in "partimagenames", i.e, those
00068                                 // with file name extensions
00069                                 //
00070                                 // To ensure restarts work correctly, remove existing files.
00071                                 if (pars.isDefined("partimagenames")) {
00072                                         const std::vector<String> &part_names =
00073                                                 pars.asArrayString("partimagenames").tovector();
00074                                         for (size_t p = 0; p < part_names.size(); ++p) {
00075                                                 File f(part_names[p]);
00076                                                 if (f.isDirectory(false))
00077                                                         Directory(f).removeRecursive();
00078                                                 else
00079                                                         RegularFile(f).remove();
00080                                         }
00081                                 }
00082                         }
00083         };
00084 
00085         void
00086         teardown_normalizer() {
00087                 normalizers.clear();
00088         };
00089 
00090 public:
00091         void
00092         normalize_psf() {
00093                 for (auto sn : normalizers) {
00094                         sn->gatherImages(/*dopsf*/true, /*doresidual*/false,
00095                                          /*density*/false);
00096                         sn->dividePSFByWeight();
00097                 }
00098         };
00099 
00100         void
00101         normalize_model() {
00102                 for (auto sn : normalizers) {
00103                         sn->divideModelByWeight();
00104                         sn->scatterModel();
00105                 }
00106         };
00107 
00108         void
00109         normalize_residual() {
00110                 for (auto sn : normalizers) {
00111                         sn->gatherImages(/*dopsf*/false, /*doresidual*/true,
00112                                          /*density*/false);
00113                         sn->divideResidualByWeight();
00114                 }
00115         };
00116 
00117         void
00118         denormalize_model() {
00119                 for (auto sn : normalizers)
00120                         sn->multiplyModelByWeight();
00121         };
00122 
00123         void
00124         reduce_weight_density() {
00125                 for (auto sn : normalizers) {
00126                         sn->gatherImages(/*dopsf*/false, /*doresidual*/false,
00127                                          /*density*/true);
00128                         sn->scatterWeightDensity();
00129                 }
00130         };
00131 };
00132 
00133 } // namespace casa
00134 
00135 #endif // SYNTHESIS_NORMALIZER_MIXIN_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1