DP3
BdaSolverBuffer.h
Go to the documentation of this file.
1 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #ifndef DDECAL_BDA_SOLVER_BUFFER_H
5 #define DDECAL_BDA_SOLVER_BUFFER_H
6 
7 #include <cmath>
8 #include <complex>
9 #include <memory>
10 #include <vector>
11 
12 #include <aocommon/queue.h>
13 
14 #include "base/BdaBuffer.h"
15 
16 namespace dp3 {
17 namespace ddecal {
18 
20  public:
26  struct IntervalRow {
27  double time;
28  std::size_t baseline_nr;
29  std::size_t n_channels;
30  std::size_t n_correlations;
31  const std::complex<float>* unweighted_data;
32  const std::complex<float>* weighted_data;
33  const bool* flags;
34  const float* weights;
35  std::vector<std::complex<float>*> unweighted_model_data;
36  std::vector<const std::complex<float>*> weighted_model_data;
37  };
38 
45  BdaSolverBuffer(double start, double interval, size_t n_baselines)
46  : data_(),
47  time_start_(start),
48  time_interval_(interval),
49  current_interval_(0),
50  last_complete_interval_per_baseline_(n_baselines, -1),
51  data_rows_() {
52  assert(interval > 0.0);
53  // Ensure that the current solution interval is valid.
54  data_rows_.PushBack(std::vector<IntervalRow>());
55  }
56 
69  void AppendAndWeight(std::unique_ptr<base::BdaBuffer> buffer,
70  const std::vector<std::string>& direction_names,
71  bool keep_unweighted_model_data);
72 
77  void Clear();
78 
84  bool IntervalIsComplete() const {
85  return *std::min_element(last_complete_interval_per_baseline_.begin(),
86  last_complete_interval_per_baseline_.end()) >= 0;
87  }
88 
95 
101  size_t BufferCount() const { return data_.Size(); }
102 
108  const std::vector<IntervalRow>& GetIntervalRows() const {
109  return data_rows_[0];
110  }
111 
115  int GetCurrentInterval() const { return current_interval_; }
116 
131  const std::vector<std::vector<std::complex<double>>>& solutions,
132  const std::vector<double>& channel_block_start_frequencies,
133  size_t n_polarizations, const std::vector<int>& antenna1,
134  const std::vector<int>& antenna2,
135  const std::vector<std::vector<double>>& channel_frequencies);
136 
144  std::vector<std::unique_ptr<base::BdaBuffer>> GetDone() {
145  std::vector<std::unique_ptr<base::BdaBuffer>> result;
146  result.swap(done_);
147  return result;
148  }
149 
154  double CurrentIntervalStart() const {
155  return time_start_ + current_interval_ * time_interval_;
156  }
157 
164  double IntervalDuration() const { return time_interval_; }
165 
166  private:
171  int RelativeIndex(double time_center) const {
172  return int(std::floor((time_center - time_start_) / time_interval_)) -
173  current_interval_;
174  }
175 
188  struct InputData {
189  std::unique_ptr<base::BdaBuffer> unweighted;
190  std::unique_ptr<base::BdaBuffer> weighted;
191  };
192 
194  aocommon::Queue<InputData> data_;
195 
197  std::vector<std::unique_ptr<base::BdaBuffer>> done_;
198 
200  const double time_start_;
201  const double time_interval_;
202  int current_interval_;
203 
207  std::vector<int> last_complete_interval_per_baseline_;
208 
213  aocommon::Queue<std::vector<IntervalRow>> data_rows_;
214 };
215 
216 } // namespace ddecal
217 } // namespace dp3
218 
219 #endif // DDECAL_BDA_SOLVER_BUFFER_H
Buffer holding baseline-dependently averaged (BDA) data.
Definition: BdaSolverBuffer.h:19
void ApplySolutions(const std::vector< std::vector< std::complex< double >>> &solutions, const std::vector< double > &channel_block_start_frequencies, size_t n_polarizations, const std::vector< int > &antenna1, const std::vector< int > &antenna2, const std::vector< std::vector< double >> &channel_frequencies)
const std::vector< IntervalRow > & GetIntervalRows() const
Definition: BdaSolverBuffer.h:108
double CurrentIntervalStart() const
Definition: BdaSolverBuffer.h:154
bool IntervalIsComplete() const
Definition: BdaSolverBuffer.h:84
BdaSolverBuffer(double start, double interval, size_t n_baselines)
Definition: BdaSolverBuffer.h:45
int GetCurrentInterval() const
Definition: BdaSolverBuffer.h:115
size_t BufferCount() const
Definition: BdaSolverBuffer.h:101
void AppendAndWeight(std::unique_ptr< base::BdaBuffer > buffer, const std::vector< std::string > &direction_names, bool keep_unweighted_model_data)
double IntervalDuration() const
Definition: BdaSolverBuffer.h:164
std::vector< std::unique_ptr< base::BdaBuffer > > GetDone()
Definition: BdaSolverBuffer.h:144
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53
Definition: BdaSolverBuffer.h:26
std::vector< std::complex< float > * > unweighted_model_data
Definition: BdaSolverBuffer.h:35
const bool * flags
Definition: BdaSolverBuffer.h:33
const float * weights
Definition: BdaSolverBuffer.h:34
const std::complex< float > * weighted_data
Definition: BdaSolverBuffer.h:32
std::vector< const std::complex< float > * > weighted_model_data
Definition: BdaSolverBuffer.h:36
double time
Definition: BdaSolverBuffer.h:27
const std::complex< float > * unweighted_data
Definition: BdaSolverBuffer.h:31
std::size_t baseline_nr
Definition: BdaSolverBuffer.h:28
std::size_t n_correlations
Definition: BdaSolverBuffer.h:30
std::size_t n_channels
Definition: BdaSolverBuffer.h:29