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:
82 
90  virtual bool InitializeInPlace(visibility_type* ) override
91  {
92  if(fPCData != nullptr){return true;}
93  return false;
94  };
95 
104  virtual bool InitializeOutOfPlace(const visibility_type* , visibility_type* ) override
105  {
106  if(fPCData != nullptr){return true;}
107  return false;
108  };
109 
117  virtual bool ExecuteInPlace(visibility_type* in) override;
126  virtual bool ExecuteOutOfPlace(const visibility_type* in, visibility_type* out) override;
127 
128  //temporal interpolation of tone phasors
134  void InterpolatePCData(double pcal_minus_visib_toffset);
135 
136  private:
137 
140 
141 #ifdef HOPS_USE_FFTW3
143 #else
145 #endif
146 
150  void InitializeFFTEngine();
151  FFT_ENGINE_TYPE fFFTEngine;
152 
159  bool IsApplicable(const visibility_type* in);
160 
169  bool PolMatch(std::size_t station_idx, std::string& pc_pol, std::string& polprod);
178  void DetermineChannelToneIndexes(double lower_freq, double upper_freq, std::size_t& lower_idx, std::size_t& upper_idx);
179 
180  //applies the station's phase-cal data for the polarization 'pc_pol' to the appropriate pol-product
181  void ApplyPCData(std::size_t pc_pol, std::size_t vis_pp, visibility_type* in);
182 
183  //fit a mean pcal offset and delay from this set of tones
184  void FitPCData(std::size_t ntones, double chan_center_freq, double sampler_delay, double* phase_spline,
185  std::string net_sideband);
186 
187  //constants
188  std::complex< double > fImagUnit;
189  double fDegToRad;
190  double fNanoSecToSecond;
191  double fMHzToHz;
192  double fPi;
193 
194  //selection
195  std::string fStationCode;
196  std::string fMk4ID;
197  std::size_t fStationIndex; //0 is reference, 1 is remote, unknown = 2
198 
199  //the multi-tone pcal data
200  std::size_t fPCPeriod;
201  multitone_pcal_type* fPCData;
202 
203  //the data weights
204  weight_type* fWeights;
205 
206  //workspace for delay fit
207  std::size_t fWorkspaceSize;
208  pcal_type fPCWorkspace;
209 
210  //keys for tag retrieval
211  std::string fStationKey;
212  std::string fRemStationKey;
213  std::string fRefStationKey;
214  std::string fRemStationMk4IDKey;
215  std::string fRefStationMk4IDKey;
216  std::string fChannelLabelKey;
217  std::string fSidebandLabelKey;
218  std::string fBandwidthKey;
219  std::string fSkyFreqKey;
220  std::string fLowerSideband;
221  std::string fUpperSideband;
222 
223  //need for pc_tonemask
224  std::string fPCToneMaskChannelsKey;
225  std::string fPCToneMaskBitmasksKey;
226  bool fHavePCToneMask;
227  std::string fPCToneMaskChannels;
228  std::vector< int > fPCToneMaskBitmasks;
229 
230  //needed if there have been time cuts to the visibilities, to trim to the appropriate range
231  MHO_PhaseCalibrationTrim fPCalTrimmer;
232 
233  //controls if pc delays are applied (no -- if there are no sampler delays)
234  bool fApplyPCDelay;
235 
236  //minor helper function to make sure all strings are compared as upper-case only
237  void make_upper(std::string& s)
238  {
239  for(char& c : s)
240  {
241  c = toupper(c);
242  };
243  }
244 };
245 
246 } // namespace hops
247 
248 #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:74
virtual bool ExecuteOutOfPlace(const visibility_type *in, visibility_type *out) override
Copies input visibility data and executes in-place correction.
Definition: MHO_MultitonePhaseCorrection.cc:215
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:90
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:64
virtual ~MHO_MultitonePhaseCorrection()
Definition: MHO_MultitonePhaseCorrection.cc:60
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:104
Class MHO_PhaseCalibrationTrim.
Definition: MHO_PhaseCalibrationTrim.hh:34
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_ChannelLabeler.hh:17