DP3
OneApplyCal.h
Go to the documentation of this file.
1 // OneApplyCal.h: DP3 step class to apply a calibration correction to the data
2 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 
8 
9 #ifndef DP3_STEPS_ONEAPPLYCAL_H_
10 #define DP3_STEPS_ONEAPPLYCAL_H_
11 
12 #include <mutex>
13 
14 #include <casacore/casa/Arrays/Cube.h>
15 #include <casacore/casa/Arrays/ArrayMath.h>
16 #include <schaapcommon/h5parm/h5parm.h>
17 #include <schaapcommon/h5parm/jonesparameters.h>
18 
19 #include "Step.h"
20 #include "base/DPBuffer.h"
21 #include "base/FlagCounter.h"
22 #include "common/Timer.h"
23 #include "parmdb/ParmFacade.h"
24 #include "parmdb/ParmSet.h"
25 #include "parmdb/Parm.h"
26 
27 namespace dp3 {
28 namespace steps {
30 
33 
34 class OneApplyCal : public Step {
35  public:
38  OneApplyCal(const common::ParameterSet&, const std::string& prefix,
39  const std::string& defaultPrefix, bool substep = false,
40  std::string predictDirection = "");
41 
42  ~OneApplyCal() override;
43 
44  common::Fields getRequiredFields() const override {
46  }
47 
48  common::Fields getProvidedFields() const override {
50  if (itsUpdateWeights) fields |= kWeightsField;
51  return fields;
52  }
53 
57  bool process(std::unique_ptr<base::DPBuffer> buffer) override;
58 
60  void finish() override;
61 
63  void updateInfo(const base::DPInfo&) override;
64 
66  void show(std::ostream&) const override;
67 
69  void showTimings(std::ostream&, double duration) const override;
70 
71  bool invert() { return itsInvert; }
72 
73  private:
76  void updateParmsParmDB(const double bufStartTime);
77 
80  void updateParmsH5(const double bufStartTime, hsize_t direction_index,
81  const std::string& direction_name,
82  const std::vector<double>& times);
83 
85  void showCounts(std::ostream&) const override;
86 
87  void initDataArrays();
88 
90  unsigned int nPol(schaapcommon::h5parm::SolTab& solution_table);
91 
92  // Check the number of polarizations in the parmdb
93  unsigned int nPol(const std::string& parmName);
94 
95  std::vector<double> CalculateBufferTimes(double buffer_start_time,
96  bool use_end);
97 
99  void MakeSolutionTables(schaapcommon::h5parm::H5Parm& h5parm);
100 
101  std::string getDirectionPatch(const std::string& direction_name);
102 
103  void CorrectionLoop(dp3::base::DPBuffer& buffer,
104  const std::string& direction_name);
105 
106  void CheckParmDB();
107 
108  std::string itsName;
109  std::string itsParmDBName;
110  // itsParmDBOnDisk specifies the existence of a parmdb on disk. If this is
111  // false, it means the solutions are instead stored in the DPBuffer, which can
112  // be fetched with DPBuffer::GetSolutions.
113  bool itsParmDBOnDisk;
114  bool itsUseH5Parm;
115  std::string itsSolSetName;
116  std::shared_ptr<parmdb::ParmFacade> itsParmDB;
117  std::string specified_correction_;
118  size_t n_polarizations_in_sol_tab_ = 0;
119  schaapcommon::h5parm::JonesParameters::MissingAntennaBehavior
120  itsMissingAntennaBehavior;
121  schaapcommon::h5parm::GainType itsCorrectType;
122  bool itsInvert;
123  schaapcommon::h5parm::JonesParameters::InterpolationType itsInterpolationType;
124  unsigned int itsTimeSlotsPerParmUpdate;
125  bool itsUpdateWeights;
126  bool itsUseModelData;
127 
128  unsigned int itsCount;
129 
131  std::vector<casacore::String> itsParmExprs;
132 
136  std::map<std::string, std::unique_ptr<schaapcommon::h5parm::JonesParameters>>
137  itsJonesParametersPerDirection;
138 
139  unsigned int itsTimeStep;
140  unsigned int itsNCorr;
141  double itsLastTime;
142  base::FlagCounter itsFlagCounter;
143  bool itsUseAP;
144  hsize_t itsDirection;
145  common::NSTimer itsTimer;
146  std::vector<std::string> solution_table_names_;
147 
148  // This variable keeps the H5 contents in memory, reading
149  // the H5 file only once in the constructor. These solutions
150  // are used in the constructor, process(..) and methods
151  // called from process(..).
152  std::vector<schaapcommon::h5parm::SolTab> solution_tables_;
153 
154  static std::mutex theirHDF5Mutex;
155 };
156 
157 } // namespace steps
158 } // namespace dp3
159 
160 #endif
Buffer holding the data of a timeslot/band.
Class to keep counts of nr of flagged points.
Set of parameters to be used.
Class giving access to a parameter.
Class to hold code for virtual base class for Flaggers in DP3.
Buffer holding the data of a timeslot/band.
Definition: DPBuffer.h:92
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
DP3 step class to apply a calibration correction to the data.
Definition: OneApplyCal.h:34
void finish() override
Finish the processing of this step and subsequent steps.
common::Fields getRequiredFields() const override
Get the fields required by the current step.
Definition: OneApplyCal.h:44
OneApplyCal(const common::ParameterSet &, const std::string &prefix, const std::string &defaultPrefix, bool substep=false, std::string predictDirection="")
void showTimings(std::ostream &, double duration) const override
Show the timings.
bool invert()
Definition: OneApplyCal.h:71
common::Fields getProvidedFields() const override
Definition: OneApplyCal.h:48
void updateInfo(const base::DPInfo &) override
Update the general info.
bool process(std::unique_ptr< base::DPBuffer > buffer) override
void show(std::ostream &) const override
Show the step parameters.
Abstract base class for a DP3 step.
Definition: Step.h:52
static constexpr dp3::common::Fields kWeightsField
Definition: Step.h:64
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