DP3
AOFlaggerStep.h
Go to the documentation of this file.
1 // AOFlaggerStep.h: DPPP step class to flag data using rficonsole's
2 // functionality
3 //
4 // Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
9 
10 #ifndef DP3_STEPS_AOFLAGGERSTEP_H_
11 #define DP3_STEPS_AOFLAGGERSTEP_H_
12 
13 #include "InputStep.h"
14 
15 #include "base/DPBuffer.h"
16 #include "base/FlagCounter.h"
17 
18 #include <memory>
19 #include <mutex>
20 
21 #include <aoflagger.h>
22 
23 namespace dp3 {
24 
25 namespace common {
26 class ParameterSet;
27 }
28 
29 namespace steps {
30 
32 
55 
56 class AOFlaggerStep : public Step {
57  public:
60  AOFlaggerStep(const common::ParameterSet&, const std::string& prefix);
61 
62  ~AOFlaggerStep() override;
63 
64  common::Fields getRequiredFields() const override {
65  return kDataField | kFlagsField;
66  }
67 
68  common::Fields getProvidedFields() const override { return kFlagsField; }
69 
72  bool process(std::unique_ptr<base::DPBuffer> buffer) override;
73 
75  void finish() override;
76 
78  void addToMS(const std::string& msName) override;
79 
82  void updateInfo(const base::DPInfo&) override;
83 
85  void show(std::ostream&) const override;
86 
88  void showCounts(std::ostream&) const override;
89 
91  void showTimings(std::ostream&, double duration) const override;
92 
93  private:
96  void flag(unsigned int rightOverlap);
97 
99  static void formatBytes(std::ostream&, double);
100 
102  void flagBaseline(unsigned int leftOverlap, unsigned int windowSize,
103  unsigned int rightOverlap, unsigned int bl,
104  base::FlagCounter& counter, aoflagger::Strategy& strategy,
105  aoflagger::QualityStatistics& rfiStats);
106 
108  void addStats(aoflagger::QualityStatistics& rfiStats,
109  const aoflagger::ImageSet& values,
110  const aoflagger::FlagMask& rfiMask,
111  const aoflagger::FlagMask& origMask, int bl);
112 
113  std::string name_;
114  unsigned int buffer_index_;
115  unsigned int n_times_;
116  std::string strategy_name_;
117  unsigned int window_size_;
118  unsigned int overlap_;
119  double overlap_percentage_;
120  double memory_;
121  double memory_percentage_;
122  double memory_needed_;
123  bool flag_auto_correlations_;
124  bool collect_statistics_;
125  std::vector<std::unique_ptr<base::DPBuffer>> buffer_;
126  base::FlagCounter flag_counter_;
127  common::NSTimer total_timer_;
128  common::NSTimer quality_timer_;
129  common::NSTimer compute_timer_;
130  double move_time_;
131  double flag_time_;
132  double stats_time_;
133  std::vector<double> frequencies_;
134  aoflagger::AOFlagger aoflagger_;
135  std::mutex mutex_;
136  bool has_qstats_;
137  aoflagger::QualityStatistics qstats_;
138 };
139 
140 } // namespace steps
141 } // namespace dp3
142 
143 #endif
Buffer holding the data of a timeslot/band.
Class to keep counts of nr of flagged points.
Abstract base class for a Step generating input.
General info about DP3 data processing attributes like averaging.
Definition: DPInfo.h:35
Class to keep counts of nr of flagged points.
Definition: FlagCounter.h:35
Definition: Fields.h:16
Implements a map of Key-Value pairs.
Definition: ParameterSet.h:31
DPPP step class to flag using aoflagger's functionality.
Definition: AOFlaggerStep.h:56
void showTimings(std::ostream &, double duration) const override
Show the timings.
void finish() override
Finish the processing of this step and subsequent steps.
void addToMS(const std::string &msName) override
Write the statistics into the MS.
common::Fields getRequiredFields() const override
Get the fields required by the current step.
Definition: AOFlaggerStep.h:64
bool process(std::unique_ptr< base::DPBuffer > buffer) override
common::Fields getProvidedFields() const override
Definition: AOFlaggerStep.h:68
void showCounts(std::ostream &) const override
Show the flagger counts.
void show(std::ostream &) const override
Show the step parameters.
AOFlaggerStep(const common::ParameterSet &, const std::string &prefix)
void updateInfo(const base::DPInfo &) override
Abstract base class for a DP3 step.
Definition: Step.h:52
static constexpr dp3::common::Fields kDataField
Definition: Step.h:60
static constexpr dp3::common::Fields kFlagsField
Definition: Step.h:62
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53