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 
119  void SetApplyFlags(bool val) { fApplyFlags = val; }
120 
121  void SetExportAsMark4False() { fExportAsMark4 = false; }
122 
128  void SetFrequencyBands(std::vector< std::tuple< std::string, double, double > > fbands)
129  {
130  fFreqBands = fbands;
131  for(std::size_t i = 0; i < fFreqBands.size(); i++)
132  {
133  auto btup = fFreqBands[i];
134  fChanNameConstructor.AddBandLabel(std::get< 0 >(btup), std::get< 1 >(btup), std::get< 2 >(btup));
135  }
136  }
137 
143  void SetFreqGroups(std::vector< std::string > fgroups) { fFreqGroups = fgroups; }
144 
150  void SetOnlyBandwidth(double bw)
151  {
152  fOnlyBandwidth = bw;
153  fSelectByBandwidth = true;
154  }
155 
161  std::string get_correlation_vexdate() const { return fCorrDate; };
162 
163  private:
164  //the station 2-char to 1-char code map (user specified)
165  MHO_StationCodeMap* fStationCodeMap;
166 
168  //members for dealing with a single (current) scan of data /////////////
169  MHO_DiFXScanFileSet* fFileSet;
170 
171  bool CreateScanOutputDirectory();
172  void LoadInputFile();
173  //needed to locate the difxinput2json helper (installed alongside the HOPS binaries)
174  std::string LocateDiFXInput2JSON() const;
175  void CreateRootFileObject(std::string vexfile);
176 
177  //finalize the OVEX/root.json after visibilities have been processed: assigns
178  //chan_def.channel_name using the scan-wide global sky-freq grid and writes the
179  //ovex + root.json files. Split out of CreateRootFileObject so channel naming can
180  //see the union of actually-exported sky_freqs (only known after visibility records
181  //have been read and each baseline organized).
182  void FinalizeAndWriteRootFile();
183 
184  void ConvertVisibilityFileObjects();
185  void NormalizeVisibilities();
186  std::vector< long > MapAPsByTime(const visibility_store_type* vis, const visibility_store_type* ac) const;
187  std::vector< long > MapChannelsBySkyFreq(const visibility_store_type* vis, const visibility_store_type* ac,
188  const std::string& baseline, const std::string& station) const;
189  void ConvertStationFileObjects();
190 
191  //compute the union (deduped, sorted ascending) of sky_freqs across every channel
192  //that any baseline in fAllBaselineVisibilities will export. Each baseline must have
193  //been Organize()'d first so its fBaselineFreqs is populated.
194  std::vector< double > ComputeGlobalSkyFreqGrid(double tol = 0.001) const;
195 
196  void ExtractPCalData();
197  void ExtractStationCoords();
198  void CleanUp();
199 
200  std::string ConstructRootFileName(const std::string& output_dir, const std::string& root_code,
201  const std::string& src_name);
202 
203  std::string ConstructStaFileName(const std::string& output_dir, const std::string& root_code,
204  const std::string& station_code, const std::string& station_mk4id);
205 
206  //the DiFX input file structure
207  mho_json fInput;
208 
209  //the root code assigned to this scan
210  std::string fRootCode;
211  std::string fCorrDate; //the correlation data as a vex-formatted string
212 
213  //integer experiment number
214  int fExperNum;
215  bool fNormalize;
216  bool fExportAsMark4;
217  bool fApplyFlags;
218 
219  //place to cache the OVEX/ROOT file data
220  //this object only needs to be cached if we are exporting to mark4 types
221  mho_json fRootJSON;
222 
223  //the output directory for this scan
224  std::string fOutputDirectory;
225 
226  //cached so FinalizeAndWriteRootFile can emit the ovex/root.json after visibilities
227  //have been processed. Populated by CreateRootFileObject.
228  std::string fSrcName;
229  std::string fDiFXInputFilename;
230 
231  std::map< int, MHO_DiFXBaselineProcessor > fAllBaselineVisibilities;
232  MHO_DiFXPCalProcessor fPCalProcessor;
233 
234  std::map< std::string, multitone_pcal_type* > fStationCode2PCal;
235  std::map< std::string, station_coord_type* > fStationCode2Coords;
236 
237  //difx -> vex (2 char) station code map
238  //this is needed because DiFX arbitrarily converts all 2-character
239  //station codes to upper case
240  std::map< std::string, std::string > fDiFX2VexStationCodes;
241  std::map< std::string, std::string > fDiFX2VexStationNames;
242 
243  //generates the channel names (zoom bands not yet supported)
244  //TODO -- allow band <-> freq range to be set externally
245  MHO_DiFXChannelNameConstructor fChanNameConstructor;
246 
247  //builds station_coord_type entries from the DiFX .input json
248  MHO_DiFXStationCoordBuilder fStationCoordBuilder;
249 
250  //synthesizes $FREQ/$BBC/$IF for zoom-band stations
251  MHO_DiFXZoomBandRebuilder fZoomBandRebuilder;
252 
253  //in-place OVEX structural fix-ups (run inside CreateRootFileObject)
254  MHO_DiFXOvexPatcher fOvexPatcher;
255 
256  bool fPreserveDiFXScanNames;
257  bool fAttachDiFXInput;
258  bool fTryLocalDir; //forwarded as --localdir to the difxinput2json subprocess
259 
260  //frequency band labeling/selection
261  std::vector< std::tuple< std::string, double, double > > fFreqBands; //frequency band/group labels and ranges
262  std::vector< std::string > fFreqGroups; //limit output to matching frequency groups
263  bool fSelectByBandwidth;
264  double fOnlyBandwidth; //limit output to only channels of this bandwidth
265 };
266 
267 } // namespace hops
268 
269 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
Class MHO_DiFXChannelNameConstructor.
Definition: MHO_DiFXChannelNameConstructor.hh:30
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:20
takes care of all the wierd structural fix-ups that turn a freshly-parsed VEX json into the special O...
Definition: MHO_DiFXOvexPatcher.hh:36
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:128
void SetAttachDiFXInputTrue()
Setter for attach difx .input data true.
Definition: MHO_DiFXScanProcessor.hh:102
void SetExportAsMark4False()
Definition: MHO_DiFXScanProcessor.hh:121
void SetApplyFlags(bool val)
Enable/disable use of DiFX .flag file.
Definition: MHO_DiFXScanProcessor.hh:119
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:143
void SetStationCodes(MHO_StationCodeMap *code_map)
Setter for station codes.
Definition: MHO_DiFXScanProcessor.cc:58
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:161
virtual ~MHO_DiFXScanProcessor()
Definition: MHO_DiFXScanProcessor.cc:56
void SetPreserveDiFXScanNamesTrue()
Setter for preserve difx scan names true.
Definition: MHO_DiFXScanProcessor.hh:92
MHO_DiFXScanProcessor()
Definition: MHO_DiFXScanProcessor.cc:40
void SetOnlyBandwidth(double bw)
Setter for allowed channel bandwidth - channels with other bandwidths will be discarded.
Definition: MHO_DiFXScanProcessor.hh:150
void ProcessScan(MHO_DiFXScanFileSet &fileSet)
Processes a DiFX scan file set by loading input files, creating output directories,...
Definition: MHO_DiFXScanProcessor.cc:63
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
Class MHO_TableContainer.
Definition: MHO_TableContainer.hh:36
Definition: difx2mark4.h:111
int baseline
Definition: fourfit3.c:62
Definition: MHO_AdhocFlagging.hh:18