DP3
RotationAndDiagonalConstraint.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 DP3_DDECAL_ROTATIONANDDIAGONAL_CONSTRAINT_H_
5 #define DP3_DDECAL_ROTATIONANDDIAGONAL_CONSTRAINT_H_
6 
7 #include "Constraint.h"
8 
9 #include "base/CalType.h"
10 
11 #include <vector>
12 #include <optional>
13 #include <ostream>
14 
15 namespace dp3 {
16 namespace ddecal {
17 
19  public:
21 
22  void Apply(SolutionSpan& solutions, double time) override;
23 
24  void Initialize(size_t n_antennas,
25  const std::vector<uint32_t>& solutions_per_direction,
26  const std::vector<double>& frequencies) override;
27 
28  void SetWeights(const std::vector<double>& weights) override;
29 
30  void SetDoRotationReference(bool do_rotation_reference);
31 
32  std::vector<ConstraintResult> GetResult() const override { return results_; }
33 
34  private:
35  void FitRotationAndDiagonal(
36  const std::complex<double>* data, double& angle,
37  std::array<std::complex<double>, 2>& diagonal) const;
38 
39  template <size_t PolCount>
40  void SetChannelWeights(std::vector<double>& values, size_t channel,
41  double new_value) const;
42 
43  std::vector<ConstraintResult> results_;
44  bool do_rotation_reference_;
45  base::CalType diagonal_solution_type_;
46 };
47 
53 void ConstrainDiagonal(std::array<std::complex<double>, 2>& diagonal,
54  base::CalType mode);
55 
56 std::vector<ConstraintResult> MakeDiagonalResults(
57  size_t n_antennas, size_t n_sub_solutions, size_t n_channels,
58  base::CalType diagonal_solution_type);
59 
60 inline void StoreDiagonal(ConstraintResult* results,
61  const std::array<std::complex<double>, 2>& diagonal,
62  size_t channel, size_t antenna, size_t subsolution,
63  size_t n_channels, size_t n_sub_solutions,
64  base::CalType diagonal_solution_type) {
65  // This is a bit more verbose than necessary, but using a single
66  // switch statement instead of multiple conditionals is probably
67  // most efficient.
68  using base::CalType;
69  const size_t index_part =
70  (antenna * n_sub_solutions + subsolution) * n_channels + channel;
71  switch (diagonal_solution_type) {
72  case CalType::kDiagonal:
73  results[0].vals[index_part * 2] = std::abs(diagonal[0]);
74  results[0].vals[index_part * 2 + 1] = std::abs(diagonal[1]);
75  results[1].vals[index_part * 2] = std::arg(diagonal[0]);
76  results[1].vals[index_part * 2 + 1] = std::arg(diagonal[1]);
77  break;
78  case CalType::kDiagonalAmplitude:
79  results[0].vals[index_part * 2] = std::abs(diagonal[0]);
80  results[0].vals[index_part * 2 + 1] = std::abs(diagonal[1]);
81  break;
82  case CalType::kDiagonalPhase:
83  results[0].vals[index_part * 2] = std::arg(diagonal[0]);
84  results[0].vals[index_part * 2 + 1] = std::arg(diagonal[1]);
85  break;
86  case CalType::kScalar:
87  results[0].vals[index_part] = std::abs(diagonal[0]);
88  results[1].vals[index_part] = std::arg(diagonal[0]);
89  break;
90  case CalType::kScalarAmplitude:
91  results[0].vals[index_part] = std::abs(diagonal[0]);
92  break;
93  case CalType::kScalarPhase:
94  results[0].vals[index_part] = std::arg(diagonal[0]);
95  break;
96  default:
97  assert(false);
98  }
99 }
100 
101 } // namespace ddecal
102 } // namespace dp3
103 
104 #endif
This class is the base class for classes that implement a constraint on calibration solutions....
Definition: Constraint.h:27
Definition: RotationAndDiagonalConstraint.h:18
void Initialize(size_t n_antennas, const std::vector< uint32_t > &solutions_per_direction, const std::vector< double > &frequencies) override
std::vector< ConstraintResult > GetResult() const override
Definition: RotationAndDiagonalConstraint.h:32
void SetDoRotationReference(bool do_rotation_reference)
void Apply(SolutionSpan &solutions, double time) override
RotationAndDiagonalConstraint(base::CalType diagonal_solution_type)
void SetWeights(const std::vector< double > &weights) override
CalType
Definition: CalType.h:11
aocommon::xt::Span< std::complex< double >, 4 > SolutionSpan
Definition: Solutions.h:20
void StoreDiagonal(ConstraintResult *results, const std::array< std::complex< double >, 2 > &diagonal, size_t channel, size_t antenna, size_t subsolution, size_t n_channels, size_t n_sub_solutions, base::CalType diagonal_solution_type)
Definition: RotationAndDiagonalConstraint.h:60
std::vector< ConstraintResult > MakeDiagonalResults(size_t n_antennas, size_t n_sub_solutions, size_t n_channels, base::CalType diagonal_solution_type)
void ConstrainDiagonal(std::array< std::complex< double >, 2 > &diagonal, base::CalType mode)
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53
Definition: ConstraintResult.h:18
std::vector< double > vals
Both vals and weights have the dimensions described in dims and axes.
Definition: ConstraintResult.h:20