Line data Source code
1 : /**
2 : Bojan Nikolic <b.nikolic@mrao.cam.ac.uk>, <bojan@bnikolic.co.uk>
3 : Initial version January 2010.
4 : Maintained by ESO since 2013.
5 :
6 : This file is part of LibAIR and is licensed under GNU Public
7 : License Version 2
8 :
9 : \file arraygains.hpp
10 : Renamed arraygains.h 2023
11 :
12 :
13 : Structure to hold gains derived from WVR data
14 : */
15 : #ifndef _LIBAIR_APPS_ARRAYGAINS_HPP__
16 : #define _LIBAIR_APPS_ARRAYGAINS_HPP__
17 :
18 : #include <vector>
19 : #include <set>
20 :
21 : #include <casacore/casa/Arrays/Matrix.h>
22 :
23 : namespace LibAIR2 {
24 :
25 : // Forward
26 : class InterpArrayData;
27 : class dTdLCoeffsBase;
28 :
29 : /** Gains calculated for an array (taking into account flags)
30 : */
31 : class ArrayGains
32 : {
33 :
34 : public:
35 :
36 : /// At the moment anticipate only storing the non-dispersive path
37 : /// for each antenna. The two dimensions are time and antenna
38 : /// number
39 : typedef casacore::Matrix<double> path_t;
40 :
41 : private:
42 :
43 : /// The time stamps of each data row
44 : std::vector<double> time;
45 : /// Elevation of each data row
46 : std::vector<double> el;
47 : std::vector<size_t> state, field, source;
48 : /// The gains
49 : path_t path;
50 :
51 : public:
52 :
53 : // ----------------------- Public data -------------
54 :
55 : /// Number of antennas in the array
56 : const size_t nAnt;
57 :
58 : // ----------------------- Construction/Destruction -------------
59 :
60 : /**
61 : \param time Time points at which the gains have been
62 : calculated
63 :
64 : \param nAnt number of antennas in the array
65 : */
66 : ArrayGains(const std::vector<double> &time,
67 : const std::vector<double> &el,
68 : const std::vector<size_t> &state,
69 : const std::vector<size_t> &field,
70 : const std::vector<size_t> &source,
71 : size_t nAnt);
72 :
73 : // ----------------------- Public interface ---------------------
74 :
75 : /** Calculate the gains.
76 :
77 : This assumes the same coeffients are applicable to all time
78 : points and only calculates the non-dispersive path for each
79 : antenna
80 : */
81 : void calc(const InterpArrayData &wvrdata,
82 : const std::vector<double> &coeffs);
83 :
84 : /** \brief Calculate the gains using the second order approximation
85 :
86 : \param coeffs The first order differentials
87 : \param c2 The second order differntials
88 : \param TRef The reference sky brightness temperatures
89 : */
90 : void calc(const InterpArrayData &wvrdata,
91 : const std::vector<double> &coeffs,
92 : const std::vector<double> &c2,
93 : const std::vector<double> &TRef);
94 :
95 : /** Calculate the gains.
96 :
97 : */
98 : void calc(const InterpArrayData &wvrdata,
99 : const std::vector<double> &coeffs,
100 : const std::vector<double> &weights
101 : );
102 :
103 : /** Calculate the gains
104 :
105 : Uses the time and antenna variable coefficients from the coeff
106 : object.
107 : */
108 : void calc(const InterpArrayData &wvrdata,
109 : const dTdLCoeffsBase &coeffs);
110 :
111 : /** \brief Calculate the gains by linearly interpolating another
112 : array
113 : */
114 : void calcLinI(const ArrayGains &o);
115 :
116 : /** \brief Scale the all paths by a give factor
117 : */
118 : void scale(double s);
119 :
120 :
121 0 : const std::vector<double> &g_time(void) const
122 : {
123 0 : return time;
124 : }
125 :
126 : const std::vector<size_t> &g_state(void) const
127 : {
128 : return state;
129 : }
130 :
131 0 : const std::vector<size_t> &g_field(void) const
132 : {
133 0 : return field;
134 : }
135 :
136 : const std::vector<size_t> &g_source(void) const
137 : {
138 : return source;
139 : }
140 :
141 0 : const path_t &g_path(void) const
142 : {
143 0 : return path;
144 : }
145 :
146 : /** \brief Return the difference in path between antennas i and j
147 : at time *index* timei
148 :
149 : \returns The path difference in m
150 : */
151 : double deltaPath(size_t timei,
152 : size_t i,
153 : size_t j) const;
154 :
155 : /** \brief Convenience accessor for getting absolute path on
156 : antenna i at time index timei
157 : */
158 : double absPath(size_t timei,
159 : size_t i) const;
160 :
161 : /** \brief The greatest path RMS on a baseline
162 : */
163 : double greatestRMSBl(const std::vector<std::pair<double, double> > &tmask) const;
164 :
165 : /** \brief Path RMS for each antenna*/
166 : void pathRMSAnt(const std::vector<std::pair<double, double> > &tmask,
167 : std::vector<double> &res) const;
168 :
169 : void pathRMSAnt(std::vector<double> &res) const;
170 :
171 : /** \brief Compute discrepancy in path for two set of paths
172 : */
173 : void pathDiscAnt(const ArrayGains &other,
174 : std::vector<double> &res) const;
175 :
176 : /** \brief Compute discrepancy in path for two set of paths
177 : */
178 : void pathDiscAnt(const ArrayGains &other,
179 : const std::vector<std::pair<double, double> > &tmask,
180 : std::vector<double> &res) const;
181 :
182 : /** Set path for these sources to zero
183 : */
184 : void blankSources(std::set<size_t> &flagsrc);
185 :
186 : /** Set path for these times to zero
187 : */
188 : void blankTimes(std::vector<double> &blanktimes);
189 :
190 : };
191 :
192 : /** Invert the coefficients and reweight so that they can applied
193 : directly to flluctuations
194 :
195 : Any coefficient with value zero is ignored and not used in the
196 : correction.
197 :
198 : This version reweights the four channels to equal contribution,
199 : without considering the thermal noise performance at all.
200 : */
201 : void reweight(const std::vector<double> &coeffs,
202 : std::vector<double> &res);
203 :
204 :
205 : /** Invert and reweight coefficeints
206 :
207 : \see reweight
208 :
209 : \param coeffs The first order coefficients, dT/dL
210 :
211 : \param c2 The second order coefficients d2T/dL2
212 :
213 : \param res The output reweighted first order coefficients
214 :
215 : \param res2 The output reweighted second oorder coefficients
216 :
217 :
218 : This version weighs down the channels based on their thermal
219 : noise performance. Note that the output is in units dL/dT, i.e.,
220 : the oposite of the input.
221 : */
222 : void reweight_thermal(const std::vector<double> &coeffs,
223 : std::vector<double> &res);
224 : void reweight_thermal(const std::vector<double> &coeffs,
225 : const std::vector<double> &c2,
226 : std::vector<double> &res,
227 : std::vector<double> &res2);
228 :
229 : /** \brief Expected per-antenna error due to thermal effects
230 : */
231 : double thermal_error(const std::vector<double> &coeffs);
232 :
233 :
234 : }
235 :
236 : #endif
|