HOPS
HOPS class reference
MHO_MultitonePhaseCorrection.hh
Go to the documentation of this file.
1 #ifndef MHO_MultitonePhaseCorrection_HH__
2 #define MHO_MultitonePhaseCorrection_HH__
3 
4 #include <cctype>
5 #include <cmath>
6 #include <complex>
7 #include <map>
8 #include <vector>
9 
10 #include "MHO_Constants.hh"
11 #include "MHO_Message.hh"
12 
14 #include "MHO_TableContainer.hh"
15 #include "MHO_UnaryOperator.hh"
16 
17 #ifdef HOPS_USE_FFTW3
19 #else
21 #endif
22 
24 
25 namespace hops
26 {
27 
39 class MHO_MultitonePhaseCorrection: public MHO_UnaryOperator< visibility_type >
40 {
41  public:
44 
50  void SetStation(std::string station) { fStationCode = station; }; //2-char station code
51 
57  void SetStationMk4ID(std::string station_id) { fMk4ID = station_id; } //1-char mk4id
58 
64  void SetPCPeriod(std::size_t pc_period) { fPCPeriod = pc_period; }
65 
72 
73  //pass in the data weights (to be applied to the pcal phasors as well?)
79  void SetWeights(weight_type* w) { fWeights = w; }
80 
81  protected:
89  virtual bool InitializeInPlace(visibility_type* ) override
90  {
91  if(fPCData != nullptr)
92  {
93  return true;
94  }
95  return false;
96  };
97 
106  virtual bool InitializeOutOfPlace(const visibility_type* , visibility_type* ) override
107  {
108  if(fPCData != nullptr)
109  {
110  return true;
111  }
112  return false;
113  };
114 
122  virtual bool ExecuteInPlace(visibility_type* in) override;
123 
124  //temporal interpolation of tone phasors
130  void InterpolatePCData(double pcal_minus_visib_toffset);
131 
132  private:
135 
136 #ifdef HOPS_USE_FFTW3
138 #else
140 #endif
141 
145  void InitializeFFTEngine();
146  FFT_ENGINE_TYPE fFFTEngine;
147 
154  bool IsApplicable(const visibility_type* in);
155 
164  bool PolMatch(std::size_t station_idx, std::string& pc_pol, std::string& polprod);
173  void DetermineChannelToneIndexes(double lower_freq, double upper_freq, std::size_t& lower_idx, std::size_t& upper_idx);
174 
175  //applies the station's phase-cal data for the polarization 'pc_pol' to the appropriate pol-product
176  void ApplyPCData(std::size_t pc_pol, std::size_t vis_pp, visibility_type* in);
177 
178  //fit a mean pcal offset and delay from this set of tones
179  void FitPCData(std::size_t ntones, double chan_center_freq, double sampler_delay, double* phase_spline,
180  std::string net_sideband);
181 
182  //constants
183  std::complex< double > fImagUnit;
184  double fDegToRad;
185  double fNanoSecToSecond;
186  double fMHzToHz;
187  double fPi;
188 
189  //selection
190  std::string fStationCode;
191  std::string fMk4ID;
192  std::size_t fStationIndex; //0 is reference, 1 is remote, unknown = 2
193 
194  //the multi-tone pcal data
195  std::size_t fPCPeriod;
196  multitone_pcal_type* fPCData;
197 
198  //the data weights
199  weight_type* fWeights;
200 
201  //workspace for delay fit
202  std::size_t fWorkspaceSize;
203  pcal_type fPCWorkspace;
204 
205  //keys for tag retrieval
206  std::string fStationKey;
207  std::string fRemStationKey;
208  std::string fRefStationKey;
209  std::string fRemStationMk4IDKey;
210  std::string fRefStationMk4IDKey;
211  std::string fChannelLabelKey;
212  std::string fSidebandLabelKey;
213  std::string fBandwidthKey;
214  std::string fSkyFreqKey;
215  std::string fLowerSideband;
216  std::string fUpperSideband;
217 
218  //need for pc_tonemask
219  std::string fPCToneMaskChannelsKey;
220  std::string fPCToneMaskBitmasksKey;
221  bool fHavePCToneMask;
222  std::string fPCToneMaskChannels;
223  std::vector< int > fPCToneMaskBitmasks;
224 
225  //needed if there have been time cuts to the visibilities, to trim to the appropriate range
226  MHO_PhaseCalibrationTrim fPCalTrimmer;
227 
228  //controls if pc delays are applied (no -- if there are no sampler delays)
229  bool fApplyPCDelay;
230 
231  //minor helper function to make sure all strings are compared as upper-case only
232  void make_upper(std::string& s)
233  {
234  for(char& c : s)
235  {
236  c = toupper(c);
237  };
238  }
239 };
240 
241 } // namespace hops
242 
243 #endif
Class MHO_AxisPack.
Definition: MHO_AxisPack.hh:22
Class MHO_MultidimensionalFastFourierTransformFFTW.
Definition: MHO_MultidimensionalFastFourierTransformFFTW.hh:37
Class MHO_MultitonePhaseCorrection.
Definition: MHO_MultitonePhaseCorrection.hh:40
void InterpolatePCData(double pcal_minus_visib_toffset)
Temporally interpolates phase calibration (Pcal) tone phasors.
Definition: MHO_MultitonePhaseCorrection.cc:71
void SetPCPeriod(std::size_t pc_period)
Setter for phase cal averaging period.
Definition: MHO_MultitonePhaseCorrection.hh:64
virtual bool InitializeInPlace(visibility_type *) override
Initializes visibility_type object in-place and checks if fPCData is nullptr.
Definition: MHO_MultitonePhaseCorrection.hh:89
MHO_MultitonePhaseCorrection()
Definition: MHO_MultitonePhaseCorrection.cc:24
virtual bool ExecuteInPlace(visibility_type *in) override
Applies multi-tone phase calibration to visibility data in-place.
Definition: MHO_MultitonePhaseCorrection.cc:141
void SetMultitonePCData(multitone_pcal_type *pcal)
Setter for multitone pcdata.
Definition: MHO_MultitonePhaseCorrection.cc:61
virtual ~MHO_MultitonePhaseCorrection()
Definition: MHO_MultitonePhaseCorrection.cc:59
void SetStationMk4ID(std::string station_id)
Setter for station mk4id.
Definition: MHO_MultitonePhaseCorrection.hh:57
void SetWeights(weight_type *w)
Setter for weights.
Definition: MHO_MultitonePhaseCorrection.hh:79
void SetStation(std::string station)
Setter for station code.
Definition: MHO_MultitonePhaseCorrection.hh:50
virtual bool InitializeOutOfPlace(const visibility_type *, visibility_type *) override
Initializes out-of-place visibility data (only if fPCData != nullptr).
Definition: MHO_MultitonePhaseCorrection.hh:106
Class MHO_PhaseCalibrationTrim.
Definition: MHO_PhaseCalibrationTrim.hh:34
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_AdhocFlagging.hh:18