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 
19 #include "MHO_DiFXOvexPatcher.hh"
20 #include "MHO_DiFXPCalProcessor.hh"
21 #include "MHO_DiFXScanFileSet.hh"
27 #include "MHO_JSONHeaderWrapper.hh"
28 #include "MHO_StationCodeMap.hh"
29 
30 #include "MHO_DiFXTimeUtilities.hh"
31 
32 namespace hops
33 {
34 
47 {
48  public:
50  virtual ~MHO_DiFXScanProcessor();
51 
57  void SetRootCode(std::string rcode) { fRootCode = rcode; }
58 
64  void SetExperimentNumber(int num) { fExperNum = num; }
65 
71  void SetStationCodes(MHO_StationCodeMap* code_map);
77  void ProcessScan(MHO_DiFXScanFileSet& fileSet);
78 
82  void SetNormalizeFalse() { fNormalize = false; }
83 
87  void SetNormalizeTrue() { fNormalize = true; }
88 
92  void SetPreserveDiFXScanNamesTrue() { fPreserveDiFXScanNames = true; }
93 
97  void SetPreserveDiFXScanNamesFalse() { fPreserveDiFXScanNames = false; };
98 
102  void SetAttachDiFXInputTrue() { fAttachDiFXInput = true; }
103 
107  void SetAttachDiFXInputFalse() { fAttachDiFXInput = false; }
108 
112  void SetTryLocalDirectory(bool val) { fTryLocalDir = val; }
113 
114  void SetExportAsMark4True() { fExportAsMark4 = true; }
115 
116  void SetExportAsMark4False() { fExportAsMark4 = false; }
117 
123  void SetFrequencyBands(std::vector< std::tuple< std::string, double, double > > fbands)
124  {
125  fFreqBands = fbands;
126  for(std::size_t i = 0; i < fFreqBands.size(); i++)
127  {
128  auto btup = fFreqBands[i];
129  fChanNameConstructor.AddBandLabel(std::get< 0 >(btup), std::get< 1 >(btup), std::get< 2 >(btup));
130  }
131  }
132 
138  void SetFreqGroups(std::vector< std::string > fgroups) { fFreqGroups = fgroups; }
139 
145  void SetOnlyBandwidth(double bw)
146  {
147  fOnlyBandwidth = bw;
148  fSelectByBandwidth = true;
149  }
150 
156  std::string get_correlation_vexdate() const { return fCorrDate; };
157 
158  private:
159  //the station 2-char to 1-char code map (user specified)
160  MHO_StationCodeMap* fStationCodeMap;
161 
163  //members for dealing with a single (current) scan of data /////////////
164  MHO_DiFXScanFileSet* fFileSet;
165 
166  bool CreateScanOutputDirectory();
167  void LoadInputFile();
168  //needed to locate the difxinput2json helper (installed alongside the HOPS binaries)
169  std::string LocateDiFXInput2JSON() const;
170  void CreateRootFileObject(std::string vexfile);
171 
172  //finalize the OVEX/root.json after visibilities have been processed: assigns
173  //chan_def.channel_name using the scan-wide global sky-freq grid and writes the
174  //ovex + root.json files. Split out of CreateRootFileObject so channel naming can
175  //see the union of actually-exported sky_freqs (only known after visibility records
176  //have been read and each baseline organized).
177  void FinalizeAndWriteRootFile();
178 
179  void ConvertVisibilityFileObjects();
180  void NormalizeVisibilities();
181  void ConvertStationFileObjects();
182 
183  //compute the union (deduped, sorted ascending) of sky_freqs across every channel
184  //that any baseline in fAllBaselineVisibilities will export. Each baseline must have
185  //been Organize()'d first so its fBaselineFreqs is populated.
186  std::vector< double > ComputeGlobalSkyFreqGrid(double tol = 0.001) const;
187 
188  void ExtractPCalData();
189  void ExtractStationCoords();
190  void CleanUp();
191 
192  std::string ConstructRootFileName(const std::string& output_dir, const std::string& root_code,
193  const std::string& src_name);
194 
195  std::string ConstructStaFileName(const std::string& output_dir, const std::string& root_code,
196  const std::string& station_code, const std::string& station_mk4id);
197 
198  //the DiFX input file structure
199  mho_json fInput;
200 
201  //the root code assigned to this scan
202  std::string fRootCode;
203  std::string fCorrDate; //the correlation data as a vex-formatted string
204 
205  //integer experiment number
206  int fExperNum;
207  bool fNormalize;
208  bool fExportAsMark4;
209 
210  //place to cache the OVEX/ROOT file data
211  //this object only needs to be cached if we are exporting to mark4 types
212  mho_json fRootJSON;
213 
214  //the output directory for this scan
215  std::string fOutputDirectory;
216 
217  //cached so FinalizeAndWriteRootFile can emit the ovex/root.json after visibilities
218  //have been processed. Populated by CreateRootFileObject.
219  std::string fSrcName;
220  std::string fDiFXInputFilename;
221 
222  std::map< int, MHO_DiFXBaselineProcessor > fAllBaselineVisibilities;
223  MHO_DiFXPCalProcessor fPCalProcessor;
224 
225  std::map< std::string, multitone_pcal_type* > fStationCode2PCal;
226  std::map< std::string, station_coord_type* > fStationCode2Coords;
227 
228  //difx -> vex (2 char) station code map
229  //this is needed because DiFX arbitrarily converts all 2-character
230  //station codes to upper case
231  std::map< std::string, std::string > fDiFX2VexStationCodes;
232  std::map< std::string, std::string > fDiFX2VexStationNames;
233 
234  //generates the channel names (zoom bands not yet supported)
235  //TODO -- allow band <-> freq range to be set externally
236  MHO_DiFXChannelNameConstructor fChanNameConstructor;
237 
238  //builds station_coord_type entries from the DiFX .input json
239  MHO_DiFXStationCoordBuilder fStationCoordBuilder;
240 
241  //synthesizes $FREQ/$BBC/$IF for zoom-band stations
242  MHO_DiFXZoomBandRebuilder fZoomBandRebuilder;
243 
244  //in-place OVEX structural fix-ups (run inside CreateRootFileObject)
245  MHO_DiFXOvexPatcher fOvexPatcher;
246 
247  bool fPreserveDiFXScanNames;
248  bool fAttachDiFXInput;
249  bool fTryLocalDir; //forwarded as --localdir to the difxinput2json subprocess
250 
251  //frequency band labeling/selection
252  std::vector< std::tuple< std::string, double, double > > fFreqBands; //frequency band/group labels and ranges
253  std::vector< std::string > fFreqGroups; //limit output to matching frequency groups
254  bool fSelectByBandwidth;
255  double fOnlyBandwidth; //limit output to only channels of this bandwidth
256 };
257 
258 } // namespace hops
259 
260 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
Class MHO_DiFXChannelNameConstructor.
Definition: MHO_DiFXChannelNameConstructor.hh:29
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:19
takes care of all the wierd structural fix-ups that turn a freshly-parsed VEX json into the special O...
Definition: MHO_DiFXOvexPatcher.hh:37
Class MHO_DiFXPCalProcessor.
Definition: MHO_DiFXPCalProcessor.hh:28
Class MHO_DiFXScanFileSet.
Definition: MHO_DiFXScanFileSet.hh:23
Class MHO_DiFXScanProcessor.
Definition: MHO_DiFXScanProcessor.hh:47
void SetExportAsMark4True()
Definition: MHO_DiFXScanProcessor.hh:114
void SetFrequencyBands(std::vector< std::tuple< std::string, double, double > > fbands)
Setter for frequency bands (name, limits)
Definition: MHO_DiFXScanProcessor.hh:123
void SetAttachDiFXInputTrue()
Setter for attach difx .input data true.
Definition: MHO_DiFXScanProcessor.hh:102
void SetExportAsMark4False()
Definition: MHO_DiFXScanProcessor.hh:116
void SetNormalizeFalse()
Setter for normalize false - Do NOT apply mk4 style visibility normalization.
Definition: MHO_DiFXScanProcessor.hh:82
void SetRootCode(std::string rcode)
Setter for root code.
Definition: MHO_DiFXScanProcessor.hh:57
void SetFreqGroups(std::vector< std::string > fgroups)
Setter for (allowed) freq groups/bands.
Definition: MHO_DiFXScanProcessor.hh:138
void SetStationCodes(MHO_StationCodeMap *code_map)
Setter for station codes.
Definition: MHO_DiFXScanProcessor.cc:55
void SetNormalizeTrue()
Setter for normalize true - apply mk4 style visibility normalization.
Definition: MHO_DiFXScanProcessor.hh:87
void SetAttachDiFXInputFalse()
Setter for attach difx .input data false.
Definition: MHO_DiFXScanProcessor.hh:107
void SetTryLocalDirectory(bool val)
Enable/disable the difxio –localdir option, forwarded to difxinput2json.
Definition: MHO_DiFXScanProcessor.hh:112
std::string get_correlation_vexdate() const
Retrieves the correlation date as a string.
Definition: MHO_DiFXScanProcessor.hh:156
virtual ~MHO_DiFXScanProcessor()
Definition: MHO_DiFXScanProcessor.cc:53
void SetPreserveDiFXScanNamesTrue()
Setter for preserve difx scan names true.
Definition: MHO_DiFXScanProcessor.hh:92
MHO_DiFXScanProcessor()
Definition: MHO_DiFXScanProcessor.cc:38
void SetOnlyBandwidth(double bw)
Setter for allowed channel bandwidth - channels with other bandwidths will be discarded.
Definition: MHO_DiFXScanProcessor.hh:145
void ProcessScan(MHO_DiFXScanFileSet &fileSet)
Processes a DiFX scan file set by loading input files, creating output directories,...
Definition: MHO_DiFXScanProcessor.cc:60
void SetPreserveDiFXScanNamesFalse()
Setter for preserve difx scan names false.
Definition: MHO_DiFXScanProcessor.hh:97
void SetExperimentNumber(int num)
Setter for experiment number.
Definition: MHO_DiFXScanProcessor.hh:64
Responsible for building the per-station station_coord_type spline data (delay, az,...
Definition: MHO_DiFXStationCoordBuilder.hh:30
Creates new $FREQ/$BBC/$IF VEX sections for stations that DiFX correlated via zoom bands (zoomFreqId/...
Definition: MHO_DiFXZoomBandRebuilder.hh:33
Class MHO_StationCodeMap Handles the mapping of two character and one character station representatio...
Definition: MHO_StationCodeMap.hh:27
Definition: difx2mark4.h:111
Definition: MHO_AdhocFlagging.hh:18