SynthesisNormalizerMixin.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00057
00058
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
00067
00068
00069
00070
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(true, false,
00095 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(false, true,
00112 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(false, false,
00127 true);
00128 sn->scatterWeightDensity();
00129 }
00130 };
00131 };
00132
00133 }
00134
00135 #endif // SYNTHESIS_NORMALIZER_MIXIN_H_