HOPS
HOPS class reference
MHO_PolarizationProductRelabeler.hh
Go to the documentation of this file.
1 #ifndef MHO_PolarizationProductRelabeler_HH__
2 #define MHO_PolarizationProductRelabeler_HH__
3 
4 #include <map>
5 #include <stack>
6 #include <string>
7 
8 #include "MHO_Message.hh"
9 
11 #include "MHO_TableContainer.hh"
12 #include "MHO_UnaryOperator.hh"
13 
14 namespace hops
15 {
16 
28 template< typename XArrayType > class MHO_PolarizationProductRelabeler: public MHO_UnaryOperator< XArrayType >
29 {
30  public:
32  {
33  fRemStationKey = "remote_station";
34  fRefStationKey = "reference_station";
35  fRemStationMk4IDKey = "remote_station_mk4id";
36  fRefStationMk4IDKey = "reference_station_mk4id";
37  fPol1 = "";
38  fPol2 = "";
39  fValid = false;
40  };
41 
43 
44  void SetPolarizationSwapPair(std::string pol1, std::string pol2)
45  {
46  //set the polarization labels to swap, all instances of pol1 will be replaced by pol2
47  //and all instances of pol2 will be replaced with pol1
48  if(pol1.size() == 1 && pol2.size() == 1)
49  {
50  fPol1 = pol1;
51  fPol2 = pol2;
52  fValid = true;
53  }
54  else
55  {
56  fValid = false;
57  msg_error("calibration",
58  "MHO_PolarizationProductRelabeler, only single character polarization labels are supported, ignoring."
59  << eom);
60  }
61  }
62 
71  void SetStationIdentifier(const std::string& id) { fStationIdentities = {id}; }
72 
73  void SetStationIdentifiers(const std::vector< std::string >& ids) { fStationIdentities = ids; }
74 
75  std::string GetStationIdentifier() const
76  {
77  return fStationIdentities.empty() ? std::string("") : fStationIdentities[0];
78  }
79 
80  protected:
88  virtual bool ExecuteInPlace(XArrayType* in) override
89  {
90  if(in != nullptr)
91  {
92  //need to use the user provided frequency <-> channel label map
93  auto pprod_axis_ptr = &(std::get< POLPROD_AXIS >(*in));
94  std::size_t npprods = pprod_axis_ptr->GetSize();
95 
96  for(std::size_t st_idx = 0; st_idx < 2; st_idx++)
97  {
98  if(IsApplicable(st_idx, in))
99  {
100  for(std::size_t i = 0; i < npprods; i++)
101  {
102  //swap any instances of pol1 <-> pol2
103  std::string pprod = pprod_axis_ptr->at(i);
104  if(pprod[st_idx] == fPol1[0])
105  {
106  pprod[st_idx] = fPol2[0];
107  }
108  else if(pprod[st_idx] == fPol2[0])
109  {
110  pprod[st_idx] = fPol1[0];
111  }
112  pprod_axis_ptr->at(i) = pprod;
113  }
114  }
115  }
116  }
117  return false;
118  }
119 
120  private:
121  //keys for tag retrieval
122  std::string fStationKey;
123  std::string fRemStationKey;
124  std::string fRefStationKey;
125  std::string fRemStationMk4IDKey;
126  std::string fRefStationMk4IDKey;
127 
128  //data
129  std::vector< std::string > fStationIdentities;
130  std::string fPol1;
131  std::string fPol2;
132  bool fValid;
133 
134  //determines if to apply the pol relabelling, for the station (ref or rem)
135  bool IsApplicable(std::size_t st_idx, const XArrayType* in)
136  {
137  std::string mk4id_key;
138  std::string station_code_key;
139 
140  if(st_idx == 0)
141  {
142  mk4id_key = fRefStationMk4IDKey;
143  station_code_key = fRefStationKey;
144  }
145  else
146  {
147  mk4id_key = fRemStationMk4IDKey;
148  station_code_key = fRemStationKey;
149  }
150 
151  std::string mk4id_val, code_val;
152  in->Retrieve(mk4id_key, mk4id_val);
153  in->Retrieve(station_code_key, code_val);
154 
155  for(const auto& id : fStationIdentities)
156  {
157  if(id.size() > 2)
158  {
159  msg_error("calibration",
160  "station identity: " << id << " is not a recognizable mark4 or 2-character code" << eom);
161  continue;
162  }
163  if(id.size() == 1 && (id == mk4id_val || id == "?"))
164  {
165  return true;
166  }
167  if(id.size() == 2 && (id == code_val || id == "??"))
168  {
169  return true;
170  }
171  }
172  return false;
173  }
174 };
175 
176 } // namespace hops
177 
178 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_PolarizationProductRelabeler.
Definition: MHO_PolarizationProductRelabeler.hh:29
MHO_PolarizationProductRelabeler()
Definition: MHO_PolarizationProductRelabeler.hh:31
virtual ~MHO_PolarizationProductRelabeler()
Definition: MHO_PolarizationProductRelabeler.hh:42
void SetPolarizationSwapPair(std::string pol1, std::string pol2)
Definition: MHO_PolarizationProductRelabeler.hh:44
virtual bool ExecuteInPlace(XArrayType *in) override
Function ExecuteInPlace - attaches channel labels based on sky frequency or user specified map.
Definition: MHO_PolarizationProductRelabeler.hh:88
std::string GetStationIdentifier() const
Definition: MHO_PolarizationProductRelabeler.hh:75
void SetStationIdentifier(const std::string &id)
Setter for station identifier.
Definition: MHO_PolarizationProductRelabeler.hh:71
void SetStationIdentifiers(const std::vector< std::string > &ids)
Definition: MHO_PolarizationProductRelabeler.hh:73
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_AdhocFlagging.hh:18