File: parallel_deconvolution.h

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (120 lines) | stat: -rw-r--r-- 3,927 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: LGPL-3.0-only

#ifndef RADLER_ALGORITHMS_PARALLEL_DECONVOLUTION_H_
#define RADLER_ALGORITHMS_PARALLEL_DECONVOLUTION_H_

#include <memory>
#include <mutex>
#include <vector>

#include <aocommon/image.h>
#include <aocommon/uvector.h>

#include "component_list.h"
#include "image_set.h"
#include "settings.h"
#include "algorithms/deconvolution_algorithm.h"
#include "logging/subimage_logset.h"
#include "utils/compressed_mask.h"

namespace radler::algorithms {

struct SubImage {
  size_t index;
  size_t x;
  size_t y;
  size_t width;
  size_t height;
  // Mask to be used during deconvoution (combines user mask with the
  // boundary mask)
  aocommon::UVector<bool> mask;
  // Selects the pixels inside this subimage
  aocommon::UVector<bool> boundary_mask;
  double peak;
  bool reached_major_threshold;
};

class ParallelDeconvolution {
 public:
  ParallelDeconvolution(const Settings& settings);

  ~ParallelDeconvolution();

  ParallelDeconvolution(const ParallelDeconvolution&) = delete;
  ParallelDeconvolution(ParallelDeconvolution&&) = delete;

  DeconvolutionAlgorithm& FirstAlgorithm() { return *algorithms_.front(); }
  const DeconvolutionAlgorithm& FirstAlgorithm() const {
    return *algorithms_.front();
  }

  ComponentList GetComponentList(const WorkTable& table) const;

  /**
   * @brief Same as @c FirstAlgorithm , except that for a multi-scale clean
   * the algorithm with the maximum number of scale counts is returned.
   */
  const DeconvolutionAlgorithm& MaxScaleCountAlgorithm() const;

  void SetAlgorithm(std::unique_ptr<DeconvolutionAlgorithm> algorithm);

  void SetRmsFactorImage(aocommon::Image&& image);

  void SetThreshold(double threshold);

  bool IsInitialized() const { return !algorithms_.empty(); }

  /**
   * Set the multiscale auto-masking mode. This method requires that the class
   * is initialized with the multiscale algorithm.
   */
  void SetAutoMaskMode(bool track_per_scale_masks, bool use_per_scale_masks);

  void SetCleanMask(const bool* mask);

  void SetSpectrallyForcedImages(std::vector<aocommon::Image>&& images);

  /** @param psf_images @see @ref ImageSet::LoadAndAveragePsfs. */
  void ExecuteMajorIteration(
      ImageSet& data_image, ImageSet& model_image,
      const std::vector<std::vector<aocommon::Image>>& psf_images,
      const std::vector<PsfOffset>& psf_offsets, bool& reached_major_threshold);

  void FreeDeconvolutionAlgorithms() {
    algorithms_.clear();
    mask_ = nullptr;
  }

 private:
  /** @param psf_images @see @ref ImageSet::LoadAndAveragePsfs. */
  void ExecuteParallelRun(
      ImageSet& data_image, ImageSet& model_image,
      const std::vector<std::vector<aocommon::Image>>& psf_images,
      const std::vector<PsfOffset>& psf_offsets, bool& reached_major_threshold);

  void ExecuteSingleThreadedRun(
      ImageSet& data_image, ImageSet& model_image,
      const std::vector<std::vector<aocommon::Image>>& psf_images,
      const std::vector<PsfOffset>& psf_offsets, bool& reached_major_threshold);

  /** @param psf_images @see @ref ImageSet::LoadAndAveragePsfs. */
  void RunSubImage(SubImage& sub_image, ImageSet& data_image,
                   const ImageSet& model_image, ImageSet& result_model,
                   const std::vector<aocommon::Image>& psf_images,
                   double major_iteration_threshold, bool find_peak_only,
                   std::mutex& mutex);

  std::vector<std::unique_ptr<DeconvolutionAlgorithm>> algorithms_;
  logging::SubImageLogSet logs_;
  // Radler::settings_ outlives ParallelDeconvolution::settings_
  const Settings& settings_;
  const bool* mask_;
  std::vector<aocommon::Image> spectrally_forced_images_;
  bool track_per_scale_masks_;
  bool use_per_scale_masks_;
  std::vector<utils::CompressedMask> scale_masks_;
  std::unique_ptr<class ComponentList> component_list_;
  aocommon::Image rms_image_;
};
}  // namespace radler::algorithms
#endif