Line data Source code
1 : //# DelayRateFFT.h: Declaration of fringe-fitting aux class
2 : //# Copyright (C) 1996,1997,2000,2001,2002,2003,2011,2016
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be adressed as follows:
20 : //# Internet email: casa-feedback@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : //#
27 :
28 : namespace casa { //# NAMESPACE CASA - BEGIN
29 :
30 : class SDBListGridManager {
31 : public:
32 : casacore::Double fmin_, fmax_, df_;
33 : casacore::Double tmin_, tmax_, dt_;
34 : std::set< casacore::Int > spwins_;
35 : std::set< casacore::Double > times_;
36 : casacore::Int nt_;
37 : protected:
38 : SDBList& sdbs_;
39 : public:
40 0 : virtual void describe() { std::cerr << "I'm a SDBListGridManager superclass!" << endl; }
41 219 : casacore::Int nSPW() { return spwins_.size(); }
42 112487 : casacore::Int getTimeIndex(casacore::Double t) {
43 112487 : casacore::Int i = round( (t - tmin_)/dt_ );
44 112487 : if (i < 0) {
45 0 : cerr << "Index < 0! " << endl;
46 0 : cerr << "t " << t << " tmin_ " << tmin_ << " dt_ " << dt_ << endl;
47 : }
48 112487 : return i;
49 : }
50 219 : SDBListGridManager(SDBList& sdbs) : sdbs_(sdbs) {}
51 : };
52 :
53 : // A utility class that provides an API that allows clients to find
54 : // grid indices in time and frequency from a SBDList that can include
55 : // multiple spectral windows.
56 : class SDBListGridManagerCombo : public SDBListGridManager {
57 : public:
58 : casacore::Int nchan_;
59 : public:
60 : std::map< casacore::Int, casacore::Int > spwPMap_; // Maps MS spws to indices in our visibility arrays
61 : // You can't store references in a map.
62 : // C++ 11 has a reference_wrapper type, but for now:
63 : std::map< casacore::Int, casacore::Vector<casacore::Double> const * > pspwIdToFreqMap_;
64 : public:
65 : SDBListGridManagerCombo(SDBList& sdbs_);
66 0 : void describe() { std::cerr << "I'm a SDBListGridManagerCombo" << endl; }
67 : // pspw is the physical spw; the one the SolveDataBuffer returns from ::spectralWindow()
68 : // lspw is the logical spw; the one used as an index in the fringe fitter
69 0 : casacore::Int getLSPW(casacore::Int i) { return spwPMap_.find(i)->second; }
70 : casacore::Float getRefFreqFromLSPW(casacore::Int lspw);
71 : };
72 :
73 :
74 : class SDBListGridManagerConcat : public SDBListGridManager {
75 : public:
76 : casacore::Double fmin_, fmax_, df_;
77 : casacore::Int totalChans_ = 0, nSPWChan_;
78 : private:
79 : // You can't store references in a map.
80 : // C++ 11 has a reference_wrapper type, but for now:
81 : std::map< casacore::Int, casacore::Vector<casacore::Double> const * > spwIdToFreqMap_;
82 : public:
83 : SDBListGridManagerConcat(SDBList&);
84 112487 : casacore::Int bigFreqGridIndex(casacore::Double f) { return round( (f - fmin_)/df_ ); }
85 : casacore::Int swStartIndex(casacore::Int);
86 219 : casacore::Int nChannels() { return totalChans_; }
87 0 : void describe() { std::cerr << "I'm a SDBListGridManagerConcat" << endl; }
88 : void checkAllGridpoints();
89 : };
90 :
91 :
92 : // DelayRateFFT is responsible for the two-dimensional FFT of
93 : // visibility phases to find an estimate for deay. rate and phase
94 : // offset parameters during fringe-fitting.
95 : // The idiom used in KJones solvers is:
96 : // DelayFFT delfft1(vbga(ibuf), ptbw, refant());
97 : // delfft1.FFT();
98 : // delfft1.shift(f0[0]);
99 : // delfft1.searchPeak();
100 : // This class is designed to follow that API (without the shift).
101 :
102 : class DelayRateFFT {
103 : protected:
104 : casacore::Double dt_, f0_, df_;
105 : casacore::Int nt_;
106 : casacore::Int nChan_;
107 : casacore::Int refant_;
108 : // SBDListGridManager handles all the sizing and interpolating of
109 : // multiple spectral windows onto a single frequency grid.
110 : casacore::Array<casacore::Double>& delayWindow_;
111 : casacore::Array<casacore::Double>& rateWindow_;
112 : casacore::Array<casacore::Complex> Vall_;
113 : casacore::Array<casacore::Int> xcount_;
114 : casacore::Array<casacore::Float> sumw_;
115 : casacore::Array<casacore::Float> sumww_;
116 : casacore::Array<casacore::Float> peak_;
117 : casacore::Int nCorr_;
118 : casacore::Int nElem_;
119 : std::map< casacore::Int, std::set<casacore::Int> > activeAntennas_;
120 : std::set<casacore::Int> allActiveAntennas_;
121 : casacore::Matrix<casacore::Float> param_;
122 : casacore::Matrix<casacore::Bool> flag_;
123 : public:
124 : DelayRateFFT(SDBList& sdbs,
125 : casacore::Int refant,
126 : casacore::Array<casacore::Double>& delayWindow_,
127 : casacore::Array<casacore::Double>& rateWindow_
128 : );
129 219 : virtual ~DelayRateFFT() {};
130 : // Declaring makeAChild static seems to upset the package builder
131 : // Meanwhile *not* making it static means that calling it without an object
132 : // (which we do) is an error.
133 : static DelayRateFFT *makeAChild(int concat, SDBList& sdbs,
134 : casacore::Int refant,
135 : casacore::Array<casacore::Double>& delayWindow_,
136 : casacore::Array<casacore::Double>& rateWindow_);
137 7638 : const casacore::Matrix<casacore::Float>& param() { return param_; }
138 7312 : casacore::Int refant() const { return refant_; }
139 219 : const std::map<casacore::Int, std::set<casacore::Int> >& getActiveAntennas() const
140 219 : { return activeAntennas_; }
141 4204 : const std::set<casacore::Int>& getActiveAntennasCorrelation(casacore::Int icor) const
142 4204 : { return activeAntennas_.find(icor)->second; }
143 : void removeAntennasCorrelation(casacore::Int, std::set< casacore::Int >);
144 7200 : const casacore::Matrix<casacore::Bool>& flag() const { return flag_; }
145 : void printActive();
146 : casacore::Matrix<casacore::Float> delay() const;
147 : casacore::Matrix<casacore::Float> rate() const;
148 : // If I make these NULL then the class is abstract and I can't define a factory
149 : // method to generate subclass instances, so I define them (recklessly!) empty
150 : // instead
151 0 : virtual void FFT() {
152 0 : cerr << "DelayRateFFT::FFT()" << endl;
153 0 : }
154 0 : virtual void searchPeak() {
155 0 : cerr << "DelayRateFFT::searchPeak()" << endl;
156 0 : }
157 0 : virtual casacore::Float snr(casacore::Int icorr, casacore::Int ielem, casacore::Float delay,
158 : casacore::Float rate) {
159 0 : cerr << "DelayRateFFTConcat::snr"<< endl;
160 0 : return 0.0; }
161 : };
162 :
163 : class DelayRateFFTCombo : public DelayRateFFT {
164 : private:
165 : SDBListGridManagerCombo gm_;
166 : casacore::Int nspw_;
167 : casacore::Int nPadFactor_;
168 : casacore::Int nPadChan_;
169 : casacore::Int nPadT_;
170 : //
171 : public:
172 :
173 : DelayRateFFTCombo(SDBList& sdbs, casacore::Int refant,
174 : casacore::Array<casacore::Double>& delayWindow_,
175 : casacore::Array<casacore::Double>& rateWindow_
176 : );
177 : DelayRateFFTCombo(casacore::Array<casacore::Complex>& data,
178 : casacore::Float f0, casacore::Float df, casacore::Float dt, SDBList& s,
179 : casacore::Array<casacore::Double>& delayWindow_,
180 : casacore::Array<casacore::Double>& rateWindow_
181 : );
182 0 : ~DelayRateFFTCombo() {};
183 : void FFT() override;
184 : void searchPeak() override;
185 : casacore::Float snr(casacore::Int icorr, casacore::Int ielem, casacore::Float delay,
186 : casacore::Float rate) override;
187 : const casacore::Array<casacore::Complex>& Vall() const { return Vall_; }
188 : std::tuple<casacore::Double, casacore::Double, casacore::Double, casacore::Double>
189 : refineSearch(const casacore::Cube<casacore::Complex>&,
190 : const casacore::Vector<casacore::Float>&,
191 : casacore::Double, casacore::Double);
192 : }; // End of class DelayRateFFTCombo.
193 :
194 :
195 : // DelayRateFFTConcat is responsible for the two-dimensional FFT of
196 : // visibility phases to find an estimate for deay. rate and phase
197 : // offset parameters during fringe-fitting.
198 : class DelayRateFFTConcat : public DelayRateFFT {
199 : private:
200 : casacore::Int nPadFactor_;
201 : casacore::Int nPadT_;
202 : casacore::Int nPadChan_;
203 : casacore::Double df_all_;
204 : casacore::Array<casacore::Complex> Vpad_;
205 : SDBListGridManagerConcat gm_;
206 : public:
207 : DelayRateFFTConcat(SDBList& sdbs, casacore::Int refant,
208 : casacore::Array<casacore::Double>& delayWindow_,
209 : casacore::Array<casacore::Double>& rateWindow_);
210 : DelayRateFFTConcat(casacore::Array<casacore::Complex>& data, casacore::Int nPadFactor,
211 : casacore::Float f0, casacore::Float df, casacore::Float dt, SDBList& s,
212 : casacore::Array<casacore::Double>& delayWindow_,
213 : casacore::Array<casacore::Double>& rateWindow_);
214 438 : ~DelayRateFFTConcat() {};
215 : casacore::Double get_df_all() { return df_all_; }
216 : std::pair<casacore::Bool, casacore::Float> xinterp(casacore::Float alo, casacore::Float amax,
217 : casacore::Float ahi);
218 : const casacore::Array<casacore::Complex>& Vpad() const { return Vpad_; }
219 : void FFT() override;
220 : void searchPeak() override;
221 : casacore::Float snr(casacore::Int icorr, casacore::Int ielem, casacore::Float delay,
222 : casacore::Float rate) override;
223 :
224 :
225 : }; // End of class DelayRateFFTConcat.
226 :
227 :
228 :
229 :
230 : } //# NAMESPACE CASA - END
231 :
|