DP3
MsReader.h
Go to the documentation of this file.
1 // Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
7 
8 #ifndef DP3_STEPS_MSREADER_H_
9 #define DP3_STEPS_MSREADER_H_
10 
11 #include <casacore/casa/Arrays/Slicer.h>
12 #include <casacore/ms/MeasurementSets/MeasurementSet.h>
13 #include <casacore/tables/Tables/TableIter.h>
14 
15 #include "base/DPBuffer.h"
16 
17 #include "InputStep.h"
18 
19 #include "base/UVWCalculator.h"
20 #include "base/FlagCounter.h"
21 
22 namespace dp3 {
23 namespace steps {
25 
100 
101 class MsReader : public InputStep {
102  public:
106  MsReader(const casacore::MeasurementSet& ms,
107  const common::ParameterSet& parset, const std::string& prefix,
108  bool allow_missing_data = false);
109 
112  bool process(std::unique_ptr<base::DPBuffer> buffer) override;
113 
115  void finish() override;
116 
118  void updateInfo(const base::DPInfo&) override {}
119 
122  void addToMS(const std::string&) override{};
123 
125  void show(std::ostream&) const override;
126 
128  void showCounts(std::ostream&) const override;
129 
131  void showTimings(std::ostream&, double duration) const override;
132 
134  void getUVW(const casacore::RefRows& rowNrs, double time, base::DPBuffer&);
135 
137  const casacore::Table& table() const override { return ms_; }
138 
140  std::string msName() const override;
141 
143  const std::string& BaselineSelection() const { return baseline_selection_; }
144 
146  bool MissingData() const { return missing_data_; }
147 
149  const std::vector<std::string>& ExtraDataColumnNames() const {
150  return extra_data_column_names_;
151  }
152 
153  bool AutoWeight() const { return auto_weight_; }
154 
156  static void FlagInfinityNan(base::DPBuffer& buffer,
157  base::FlagCounter& flagCounter);
158 
161  static std::pair<unsigned int, unsigned int> ParseChannelSelection(
162  const std::string& start_channel_string,
163  const std::string& n_channels_string, unsigned int n_channels);
164 
165  private:
167  void SelectBaselines();
168 
172  void InitializeColumns(bool allow_missing_data,
173  const std::string& data_column_name,
174  const std::string& flag_column_name,
175  const std::string& weight_column_name);
176 
184  void InitializeIterator(bool force_auto_weight);
185 
189  void ReadAntennas(const casacore::Table& table);
190 
194  void ReadArrayInformation();
195 
200  void ParseTimeSelection(const common::ParameterSet& parset,
201  const std::string& prefix);
202 
205  void SkipFirstTimes(double& first_time, double interval);
206 
208  void InitializeChannels(int spectralWindow);
209 
212  void ReadChannelProperties(int spectralWindow);
213 
215  void ReadPolarizations(int spectralWindow);
216 
218  void AutoWeight(base::DPBuffer& buf);
219 
222  void GetWeights(const casacore::RefRows& rowNrs, base::DPBuffer&);
223 
224  casacore::MeasurementSet ms_;
225  casacore::Table selection_ms_;
226  casacore::TableIterator ms_iterator_;
227  std::vector<std::string> extra_data_column_names_;
228  std::string start_channel_expression_{"0"};
229  std::string n_channels_expression_{"0"};
230  std::string baseline_selection_{};
231  bool sort_{false};
232  bool auto_weight_{false};
233  bool has_weight_spectrum_{false};
234  bool use_flags_{true};
235  bool use_all_channels_{false};
236  bool missing_data_{false};
240  double time_tolerance_{1.0e-2};
242  double time_correction_{0.0};
243  double next_time_{0.0};
244  double previous_time_{0.0};
245  unsigned int n_read_{0};
246  unsigned int n_inserted_{0};
247  casacore::Slicer column_slicer_;
248  casacore::Slicer array_slicer_;
249  std::unique_ptr<base::UVWCalculator> uvw_calculator_;
250  base::FlagCounter flag_counter_;
251  common::NSTimer timer_;
252 };
253 
254 } // namespace steps
255 } // namespace dp3
256 
257 #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.
Class to calculate UVW coordinates Note: this code is used by LOFAR and APERTIF software.
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
Implements a map of Key-Value pairs.
Definition: ParameterSet.h:31
Abstract base class for a Step generating input.
Definition: InputStep.h:37
DP3 step reading from an MS.
Definition: MsReader.h:101
void show(std::ostream &) const override
Show the step parameters.
static std::pair< unsigned int, unsigned int > ParseChannelSelection(const std::string &start_channel_string, const std::string &n_channels_string, unsigned int n_channels)
MsReader(const casacore::MeasurementSet &ms, const common::ParameterSet &parset, const std::string &prefix, bool allow_missing_data=false)
const casacore::Table & table() const override
Get the main MS table.
Definition: MsReader.h:137
void updateInfo(const base::DPInfo &) override
Do nothing, since MsReader sets its info in the constructor.
Definition: MsReader.h:118
bool AutoWeight() const
Definition: MsReader.h:153
void getUVW(const casacore::RefRows &rowNrs, double time, base::DPBuffer &)
Read the UVW at the given row numbers into the buffer.
void addToMS(const std::string &) override
Definition: MsReader.h:122
const std::string & BaselineSelection() const
Get the baseline selection.
Definition: MsReader.h:143
void showCounts(std::ostream &) const override
If needed, show the flag counts.
bool MissingData() const
Is the data column missing?
Definition: MsReader.h:146
void finish() override
Finish the processing of this step and subsequent steps.
std::string msName() const override
Get the name of the MS.
const std::vector< std::string > & ExtraDataColumnNames() const
Get the names of the extra data columns that are also read.
Definition: MsReader.h:149
void showTimings(std::ostream &, double duration) const override
Show the timings.
bool process(std::unique_ptr< base::DPBuffer > buffer) override
static void FlagInfinityNan(base::DPBuffer &buffer, base::FlagCounter &flagCounter)
Flags infinite and Not-a-Number values.
BaseTimer< std::chrono::steady_clock > NSTimer
Definition: Timer.h:129
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53