DP3
Demixer.h
Go to the documentation of this file.
1 // Demixer.h: DP3 step class to subtract A-team sources
2 // Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 
5 #ifndef DP3_STEPS_DEMIXER_H_
6 #define DP3_STEPS_DEMIXER_H_
7 
8 #include <casacore/measures/Measures/MeasFrame.h>
9 
10 #include "Filter.h"
11 #include "ResultStep.h"
12 #include "MultiResultStep.h"
13 #include "PhaseShift.h"
14 
15 #include "base/Baseline.h"
16 #include "base/FlagCounter.h"
17 
18 #include "common/ParameterSet.h"
19 #include "common/Timer.h"
20 
21 #include "model/Patch.h"
22 
23 namespace dp3 {
24 namespace steps {
25 
36 
37 class Demixer : public Step {
38  public:
41  Demixer(const common::ParameterSet&, const std::string& prefix);
42 
46  bool process(std::unique_ptr<base::DPBuffer>) override;
47 
49 
51 
53  void finish() override;
54 
56  void updateInfo(const base::DPInfo&) override;
57 
59  void show(std::ostream&) const override;
60 
62  void showCounts(std::ostream&) const override;
63 
65  void showTimings(std::ostream&, double duration) const override;
66 
68  void addToMS(const std::string& msName) override;
69 
70  private:
73  void addFactors(std::unique_ptr<base::DPBuffer> newBuf);
74 
77  void makeFactors(const aocommon::xt::UTensor<std::complex<double>, 4>& bufIn,
78  aocommon::xt::UTensor<std::complex<double>, 5>& bufOut,
79  const base::DPBuffer::WeightsType& weightSums,
80  size_t nChanOut, size_t nChanAvg);
81 
83  void handleDemix();
84 
86  void deproject(aocommon::xt::UTensor<std::complex<double>, 5>& factors,
87  unsigned int resultIndex);
88 
90  void demix();
91 
93  void dumpSolutions();
94 
97  void mergeSubtractResult();
98 
99  std::string itsName;
100  base::DPBuffer itsBufTmp;
101  std::string itsSkyName;
102  std::string itsInstrumentName;
103  double itsDefaultGain;
104  size_t itsMaxIter;
105  base::BaselineSelection itsSelBL;
106  std::shared_ptr<Filter> itsFilter;
107  std::shared_ptr<ResultStep> itsFilterResult;
108  std::vector<std::shared_ptr<PhaseShift>> itsPhaseShifts;
109  bool itsMovingPhaseRef;
110  casacore::MeasFrame itsMeasFrame;
112  std::vector<std::shared_ptr<Step>> itsFirstSteps;
115  std::vector<std::shared_ptr<MultiResultStep>> itsAvgResults;
116  std::shared_ptr<Step> itsAvgStepSubtr;
117  std::shared_ptr<Filter> itsFilterSubtr;
119  std::shared_ptr<MultiResultStep> itsAvgResultFull;
120  std::shared_ptr<MultiResultStep> itsAvgResultSubtr;
122  bool itsIgnoreTarget;
124  std::string itsTargetSource;
125  std::vector<std::string> itsSubtrSources;
126  std::vector<std::string> itsModelSources;
127  std::vector<std::string> itsExtraSources;
128  std::vector<std::string> itsAllSources;
129  bool itsPropagateSolutions;
130  unsigned int itsNBl;
131  unsigned int itsNChanAvg;
132  unsigned int itsNChanAvgSubtr;
133  unsigned int itsNChanIn;
134  unsigned int itsNChanOut;
135  unsigned int itsNChanOutSubtr;
136  unsigned int itsNCorr;
137  unsigned int itsNDir;
138  unsigned int itsNModel;
139  unsigned int itsNStation;
140  unsigned int itsNTimeAvg;
141  unsigned int itsNTimeAvgSubtr;
142  unsigned int itsNTimeChunk;
143  unsigned int itsNTimeChunkSubtr;
144  unsigned int itsNTimeDemix;
145  unsigned int itsNTimeIn;
146  unsigned int itsNTimeOut;
147  unsigned int itsNTimeOutSubtr;
148  double itsFreqResolution;
149  double itsTimeResolution;
150  double itsTimeIntervalAvg;
151 
152  bool itsUseLBFGS;
154  unsigned int
155  itsLBFGShistory;
157  double itsLBFGSrobustdof;
159  std::vector<double>
160  itsRangeLBFGSsol;
161  //< (if given) as [low,high], to this range.
162 
167  aocommon::xt::UTensor<std::complex<double>, 4> itsFactorBuf;
174  std::vector<aocommon::xt::UTensor<std::complex<double>, 5>> itsFactors;
175 
180  aocommon::xt::UTensor<std::complex<double>, 4> itsFactorBufSubtr;
187  std::vector<aocommon::xt::UTensor<std::complex<double>, 5>> itsFactorsSubtr;
188 
189  std::vector<std::shared_ptr<model::Patch>> itsPatchList;
190  base::Direction itsPhaseRef;
191  std::vector<base::Baseline> itsBaselines;
192  std::vector<int> itsUVWSplitIndex;
193  std::vector<double> itsFreqDemix;
194  std::vector<double> itsFreqSubtr;
195  std::vector<double> itsUnknowns;
196  std::vector<double> itsPrevSolution;
197  unsigned int itsTimeIndex;
198  unsigned int itsNConverged;
199  base::FlagCounter itsFlagCounter;
200  // Store ratio of variance, before/after demixing
201  float itsVarianceRatio{0.0f};
202  unsigned int itsTotalDemixRuns{0};
203 
204  common::NSTimer itsTimer;
205  common::NSTimer itsTimerPhaseShift;
206  common::NSTimer itsTimerDemix;
207  common::NSTimer itsTimerSolve;
208  common::NSTimer itsTimerDump;
209 };
210 
211 } // namespace steps
212 } // namespace dp3
213 
214 #endif
Pair of stations that together form a baseline (interferometer).
DP3 step to filter out baselines and channels.
Class to keep counts of nr of flagged points.
Class containing a few static functions to parse a baseline selection string.
Definition: BaselineSelection.h:47
Buffer holding the data of a timeslot/band.
Definition: DPBuffer.h:92
xt::xtensor< float, 3 > WeightsType
Definition: DPBuffer.h:96
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 subtract A-team sources This class is a Step class to subtract the strong A-team so...
Definition: Demixer.h:37
void finish() override
Finish the processing of this step and subsequent steps.
common::Fields getProvidedFields() const override
void updateInfo(const base::DPInfo &) override
Update the general info.
void addToMS(const std::string &msName) override
We use addToMS() to update HISTORY table.
void show(std::ostream &) const override
Show the step parameters.
void showTimings(std::ostream &, double duration) const override
Show the timings.
Demixer(const common::ParameterSet &, const std::string &prefix)
common::Fields getRequiredFields() const override
Get the fields required by the current step.
bool process(std::unique_ptr< base::DPBuffer >) override
void showCounts(std::ostream &) const override
Show the counts.
Abstract base class for a DP3 step.
Definition: Step.h:52
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53
A direction on the celestial sphere.
Definition: Direction.h:15