DP3
GainCalAlgorithm.h
Go to the documentation of this file.
1 // GainCalAlgorithm.h: Perform algorithm for gain calibration
2 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 
8 
9 #ifndef DPPP_GAINCALALGORITHM_H
10 #define DPPP_GAINCALALGORITHM_H
11 
12 #include <casacore/casa/Arrays/Cube.h>
13 #include <casacore/casa/Arrays/ArrayMath.h>
14 
15 #include <aocommon/recursivefor.h>
16 
17 namespace dp3 {
18 
19 namespace base {
21 
23  public:
24  enum Status { CONVERGED = 1, NOTCONVERGED = 2, STALLED = 3, FAILED = 4 };
25 
27 
29  GainCalAlgorithm(unsigned int solInt, unsigned int nChan, Mode mode,
30  bool scalar, double tolerance, unsigned int maxAntennas,
31  bool detectStalling, unsigned int debugLevel);
32 
34  void resetVis();
35 
40  void init(bool initSolutions);
41 
44  Status doStep(unsigned int iter, aocommon::RecursiveFor& recursive_for);
45 
49  casacore::Matrix<std::complex<double>> getSolution(bool setNaNs);
50 
51  double getWeight() { return _totalWeight; }
52 
54  void incrementWeight(float weight);
55 
57  casacore::Array<std::complex<double>>& getVis() { return _vis; }
58 
60  casacore::Array<std::complex<double>>& getMVis() { return _mvis; }
61 
62  casacore::Vector<bool>& getStationFlagged() { return _stationFlagged; }
63 
65  unsigned int numCorrelations() { return _savedNCr; }
66 
68  unsigned int nCr() { return _nCr; }
69 
72 
73  private:
75  Status relax(unsigned int iter);
76  static bool isFinite(const std::complex<double>& val) {
77  return std::isfinite(val.real()) && std::isfinite(val.imag());
78  }
79 
80  void doStep_polarized();
81  void doStep_unpolarized(aocommon::RecursiveFor& recursive_for);
82 
83  double getAverageUnflaggedSolution();
84 
85  unsigned int _savedNCr;
86  casacore::Vector<bool>
87  _stationFlagged;
88  casacore::Array<std::complex<double>> _vis;
89  casacore::Array<std::complex<double>> _mvis;
90  casacore::Matrix<std::complex<double>>
91  _g;
92  casacore::Matrix<std::complex<double>> _gx;
93  casacore::Matrix<std::complex<double>>
94  _gxx;
95  casacore::Matrix<std::complex<double>> _gold;
96  casacore::Matrix<std::complex<double>>
97  _h;
98  casacore::Matrix<std::complex<double>> _z;
99 
100  unsigned int _nSt;
101  unsigned int _nUn;
102  unsigned int _nCr;
103  unsigned int _nSp;
104  unsigned int _badIters;
105  unsigned int
106  _veryBadIters;
107  unsigned int _solInt;
108  unsigned int _nChan;
109  Mode _mode;
110  bool _scalar;
111  double _tolerance;
112  double _totalWeight;
113  bool _detectStalling;
114  unsigned int _debugLevel;
115 
116  double _dg, _dgx;
117  std::vector<double> _dgs;
118 };
119 
120 } // namespace base
121 } // namespace dp3
122 
123 #endif
DPPP step class to apply a calibration correction to the data.
Definition: GainCalAlgorithm.h:22
double getWeight()
Definition: GainCalAlgorithm.h:51
casacore::Array< std::complex< double > > & getVis()
Returns a reference to the visibility matrix.
Definition: GainCalAlgorithm.h:57
casacore::Matrix< std::complex< double > > getSolution(bool setNaNs)
void clearStationFlagged()
Clear antFlagged.
GainCalAlgorithm(unsigned int solInt, unsigned int nChan, Mode mode, bool scalar, double tolerance, unsigned int maxAntennas, bool detectStalling, unsigned int debugLevel)
mode can be "diagonal", "fulljones", "phaseonly", "scalarphase"
void incrementWeight(float weight)
Increments the weight (only relevant for TEC-fitting)
unsigned int nCr()
Number of correlations (1 or 4)
Definition: GainCalAlgorithm.h:68
casacore::Vector< bool > & getStationFlagged()
Definition: GainCalAlgorithm.h:62
casacore::Array< std::complex< double > > & getMVis()
Returns a reference to the model visibility matrix.
Definition: GainCalAlgorithm.h:60
Status
Definition: GainCalAlgorithm.h:24
@ FAILED
Definition: GainCalAlgorithm.h:24
@ CONVERGED
Definition: GainCalAlgorithm.h:24
@ NOTCONVERGED
Definition: GainCalAlgorithm.h:24
@ STALLED
Definition: GainCalAlgorithm.h:24
unsigned int numCorrelations()
Number of correlations in the solution (1,2 or 4)
Definition: GainCalAlgorithm.h:65
Mode
Definition: GainCalAlgorithm.h:26
@ FULLJONES
Definition: GainCalAlgorithm.h:26
@ AMPLITUDEONLY
Definition: GainCalAlgorithm.h:26
@ DEFAULT
Definition: GainCalAlgorithm.h:26
@ PHASEONLY
Definition: GainCalAlgorithm.h:26
void resetVis()
Sets visibility matrices to zero.
void init(bool initSolutions)
Status doStep(unsigned int iter, aocommon::RecursiveFor &recursive_for)
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53