HOPS
HOPS class reference
MHO_DiFXScanProcessor.hh
Go to the documentation of this file.
1 #ifndef MHO_DiFXScanProcessor_HH__
2 #define MHO_DiFXScanProcessor_HH__
3 
4 #include <algorithm>
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <vector>
9 
10 #include "MHO_Message.hh"
11 
13 
16 #include "MHO_ClassIdentityMap.hh"
17 
20 #include "MHO_DiFXPCalProcessor.hh"
21 #include "MHO_DiFXScanFileSet.hh"
25 #include "MHO_JSONHeaderWrapper.hh"
26 #include "MHO_StationCodeMap.hh"
27 
28 #include "MHO_DiFXTimeUtilities.hh"
29 
30 namespace hops
31 {
32 
45 {
46  public:
48  virtual ~MHO_DiFXScanProcessor();
49 
55  void SetRootCode(std::string rcode) { fRootCode = rcode; }
56 
62  void SetExperimentNumber(int num) { fExperNum = num; }
63 
69  void SetStationCodes(MHO_StationCodeMap* code_map);
75  void ProcessScan(MHO_DiFXScanFileSet& fileSet);
76 
80  void SetNormalizeFalse() { fNormalize = false; }
81 
85  void SetNormalizeTrue() { fNormalize = true; }
86 
90  void SetPreserveDiFXScanNamesTrue() { fPreserveDiFXScanNames = true; }
91 
95  void SetPreserveDiFXScanNamesFalse() { fPreserveDiFXScanNames = false; };
96 
100  void SetAttachDiFXInputTrue() {fAttachDiFXInput = true; }
101 
105  void SetAttachDiFXInputFalse() {fAttachDiFXInput = false; }
106 
107  void SetExportAsMark4True(){fExportAsMark4 = true;}
108  void SetExportAsMark4False(){fExportAsMark4 = false;}
109 
115  void SetFrequencyBands(std::vector< std::tuple< std::string, double, double > > fbands)
116  {
117  fFreqBands = fbands;
118  for(std::size_t i = 0; i < fFreqBands.size(); i++)
119  {
120  auto btup = fFreqBands[i];
121  fChanNameConstructor.AddBandLabel(std::get< 0 >(btup), std::get< 1 >(btup), std::get< 2 >(btup));
122  }
123  }
124 
130  void SetFreqGroups(std::vector< std::string > fgroups) { fFreqGroups = fgroups; }
131 
137  void SetOnlyBandwidth(double bw)
138  {
139  fOnlyBandwidth = bw;
140  fSelectByBandwidth = true;
141  }
142 
143  //use json representation of vex-scan information to return epoch string of frt
150  std::string get_fourfit_reftime_for_scan(mho_json scan_obj);
151 
152  // //given a mjd date and number of seconds, compute the vex string representation
153  // static std::string get_vexdate_from_mjd_sec(double mjd, double sec);
154 
160  std::string get_correlation_vexdate() const { return fCorrDate; };
161 
162  private:
170  void apply_delay_model_clock_correction(const mho_json& ant, const mho_json& ant_poly, station_coord_type* st_coord);
171 
181  int local_getDifxAntennaShiftedClock(const mho_json& da, double dt, int outputClockSize, double* clockOut);
182 
193  void calculateZerothOrderParallacticAngle(station_coord_type* st_coord, double X, double Y, double Z, double src_dec,
194  double dt);
195 
196  //the station 2-char to 1-char code map (user specified)
197  MHO_StationCodeMap* fStationCodeMap;
198 
200  //members for dealing with a single (current) scan of data /////////////
201  MHO_DiFXScanFileSet* fFileSet;
202 
203  bool CreateScanOutputDirectory();
204  void LoadInputFile();
205  void CreateRootFileObject(std::string vexfile);
206  void ConvertVisibilityFileObjects();
207  void NormalizeVisibilities();
208  void ConvertStationFileObjects();
209 
210  void ExtractPCalData();
211  void ExtractStationCoords();
212  void CleanUp();
213 
214  std::string ConstructRootFileName(const std::string& output_dir, const std::string& root_code,
215  const std::string& src_name);
216 
217  std::string ConstructStaFileName(const std::string& output_dir, const std::string& root_code,
218  const std::string& station_code, const std::string& station_mk4id);
219 
220  void PatchOvexStructures(mho_json& vex_root, std::string mode_name);
221 
222  //the DiFX input file structure
223  mho_json fInput;
224 
225  //the root code assigned to this scan
226  std::string fRootCode;
227  std::string fCorrDate; //the correlation data as a vex-formatted string
228 
229  //integer experiment number
230  int fExperNum;
231  bool fNormalize;
232  bool fExportAsMark4;
233 
234  //place to cache the OVEX/ROOT file data
235  //this object only needs to be cached if we are exporting to mark4 types
236  mho_json fRootJSON;
237 
238  //the output directory for this scan
239  std::string fOutputDirectory;
240 
241  std::map< int, MHO_DiFXBaselineProcessor > fAllBaselineVisibilities;
242  MHO_DiFXPCalProcessor fPCalProcessor;
243 
244  std::map< std::string, multitone_pcal_type* > fStationCode2PCal;
245  std::map< std::string, station_coord_type* > fStationCode2Coords;
246 
247  //difx -> vex (2 char) station code map
248  //this is needed because DiFX arbitrarily converts all 2-character
249  //station codes to upper case
250  std::map< std::string, std::string > fDiFX2VexStationCodes;
251  std::map< std::string, std::string > fDiFX2VexStationNames;
252 
253  //generates the channel names (zoom bands not yet supported)
254  //TODO -- allow band <-> freq range to be set externally
255  MHO_DiFXChannelNameConstructor fChanNameConstructor;
256 
257  bool fPreserveDiFXScanNames;
258  bool fAttachDiFXInput;
259 
260  double MICROSEC_TO_SEC; //needed to match difx2mark4 convention
261 
262  //frequency band labelling/selection
263  std::vector< std::tuple< std::string, double, double > > fFreqBands; //frequency band/group labels and ranges
264  std::vector< std::string > fFreqGroups; //limit output to matching frequency groups
265  bool fSelectByBandwidth;
266  double fOnlyBandwidth; //limit output to only channels of this bandwidth
267 };
268 
269 } // namespace hops
270 
271 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
Class MHO_DiFXChannelNameConstructor.
Definition: MHO_DiFXChannelNameConstructor.hh:28
void AddBandLabel(std::string band_label, double freq_low, double freq_high)
Adds a frequency range for a specific band label.
Definition: MHO_DiFXChannelNameConstructor.cc:17
Class MHO_DiFXPCalProcessor.
Definition: MHO_DiFXPCalProcessor.hh:28
Class MHO_DiFXScanFileSet.
Definition: MHO_DiFXScanFileSet.hh:23
Class MHO_DiFXScanProcessor.
Definition: MHO_DiFXScanProcessor.hh:45
void SetExportAsMark4True()
Definition: MHO_DiFXScanProcessor.hh:107
std::string get_fourfit_reftime_for_scan(mho_json scan_obj)
Calculates and returns the fourfit reference time epoch string for a given scan object.
Definition: MHO_DiFXScanProcessor.cc:723
void SetFrequencyBands(std::vector< std::tuple< std::string, double, double > > fbands)
Setter for frequency bands (name, limits)
Definition: MHO_DiFXScanProcessor.hh:115
void SetAttachDiFXInputTrue()
Setter for attach difx .input data true.
Definition: MHO_DiFXScanProcessor.hh:100
void SetExportAsMark4False()
Definition: MHO_DiFXScanProcessor.hh:108
void SetNormalizeFalse()
Setter for normalize false - Do NOT apply mk4 style visibility normalization.
Definition: MHO_DiFXScanProcessor.hh:80
void SetRootCode(std::string rcode)
Setter for root code.
Definition: MHO_DiFXScanProcessor.hh:55
void SetFreqGroups(std::vector< std::string > fgroups)
Setter for (allowed) freq groups/bands.
Definition: MHO_DiFXScanProcessor.hh:130
void SetStationCodes(MHO_StationCodeMap *code_map)
Setter for station codes.
Definition: MHO_DiFXScanProcessor.cc:48
void SetNormalizeTrue()
Setter for normalize true - apply mk4 style visibility normalization.
Definition: MHO_DiFXScanProcessor.hh:85
void SetAttachDiFXInputFalse()
Setter for attach difx .input data false.
Definition: MHO_DiFXScanProcessor.hh:105
std::string get_correlation_vexdate() const
Retrieves the correlation date as a string.
Definition: MHO_DiFXScanProcessor.hh:160
virtual ~MHO_DiFXScanProcessor()
Definition: MHO_DiFXScanProcessor.cc:46
void SetPreserveDiFXScanNamesTrue()
Setter for preserve difx scan names true.
Definition: MHO_DiFXScanProcessor.hh:90
MHO_DiFXScanProcessor()
Definition: MHO_DiFXScanProcessor.cc:31
void SetOnlyBandwidth(double bw)
Setter for allowed channel bandwidth - channels with other bandwidths will be discarded.
Definition: MHO_DiFXScanProcessor.hh:137
void ProcessScan(MHO_DiFXScanFileSet &fileSet)
Processes a DiFX scan file set by loading input files, creating output directories,...
Definition: MHO_DiFXScanProcessor.cc:53
void SetPreserveDiFXScanNamesFalse()
Setter for preserve difx scan names false.
Definition: MHO_DiFXScanProcessor.hh:95
void SetExperimentNumber(int num)
Setter for experiment number.
Definition: MHO_DiFXScanProcessor.hh:62
Class MHO_StationCodeMap Handles the mapping of two character and one character station representatio...
Definition: MHO_StationCodeMap.hh:27
Class MHO_TableContainer.
Definition: MHO_TableContainer.hh:36
Definition: difx2mark4.h:111
Definition: MHO_ChannelLabeler.hh:17