Line data Source code
1 : //# AccorJones.cc: Implementation of AccorJones
2 : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2011,2017
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 addressed 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 : #include <synthesis/MeasurementComponents/AccorJones.h>
28 :
29 : #include <msvis/MSVis/VisBuffer.h>
30 : #include <msvis/MSVis/VisBuffAccumulator.h>
31 : #include <synthesis/MeasurementEquations/VisEquation.h>
32 : #include <synthesis/MeasurementComponents/SolveDataBuffer.h>
33 :
34 : #include <casacore/casa/Arrays/ArrayMath.h>
35 : #include <casacore/casa/Arrays/MatrixMath.h>
36 : #include <casacore/casa/BasicSL/String.h>
37 : #include <casacore/casa/Utilities/Assert.h>
38 : #include <casacore/casa/Exceptions/Error.h>
39 : #include <casacore/casa/System/Aipsrc.h>
40 :
41 : #include <sstream>
42 :
43 :
44 :
45 : using namespace casacore;
46 : namespace casa { //# NAMESPACE CASA - BEGIN
47 :
48 : // **********************************************************
49 : // AccorJones Implementations
50 : //
51 :
52 0 : AccorJones::AccorJones(VisSet& vs) :
53 : VisCal(vs), // virtual base
54 : VisMueller(vs), // virtual base
55 0 : SolvableVisJones(vs) // immediate parent
56 : {
57 0 : if (prtlev()>2) cout << "Accor::Accor(vs)" << endl;
58 0 : }
59 :
60 0 : AccorJones::AccorJones(String msname,Int MSnAnt,Int MSnSpw) :
61 : VisCal(msname,MSnAnt,MSnSpw), // virtual base
62 : VisMueller(msname,MSnAnt,MSnSpw), // virtual base
63 0 : SolvableVisJones(msname,MSnAnt,MSnSpw) // immediate parent
64 : {
65 0 : if (prtlev()>2) cout << "Accor::Accor(msname,MSnAnt,MSnSpw)" << endl;
66 0 : }
67 :
68 35 : AccorJones::AccorJones(const MSMetaInfoForCal& msmc) :
69 : VisCal(msmc), // virtual base
70 : VisMueller(msmc), // virtual base
71 35 : SolvableVisJones(msmc) // immediate parent
72 : {
73 35 : if (prtlev()>2) cout << "Accor::Accor(msmc)" << endl;
74 35 : }
75 :
76 0 : AccorJones::AccorJones(const Int& nAnt) :
77 : VisCal(nAnt),
78 : VisMueller(nAnt),
79 0 : SolvableVisJones(nAnt)
80 : {
81 0 : if (prtlev()>2) cout << "Accor::Accor(nAnt)" << endl;
82 0 : }
83 :
84 70 : AccorJones::~AccorJones() {
85 35 : if (prtlev()>2) cout << "Accor::~Accor()" << endl;
86 70 : }
87 :
88 0 : void AccorJones::selfSolveOne(VisBuffGroupAcc&) {
89 :
90 : // NB: Use "AccorJones::selfSolveOne(SDBList& sdbs)" instead!
91 0 : throw(AipsError("VisBuffGroupAcc is invalid for AccorJones"));
92 : }
93 :
94 273 : void AccorJones::selfSolveOne(SDBList& sdbs) {
95 :
96 : // Use just the first SDB in the SDBList, for now
97 273 : SolveDataBuffer& sdb(sdbs(0));
98 :
99 : // Make a guess at antenna-based G
100 : // Correlation membership-dependencexm
101 : // assumes corrs in canonical order
102 : // nCorr = 1: use icorr=0
103 : // nCorr = 2: use icorr=[0,1]
104 : // nCorr = 4: use icorr=[0,3]
105 :
106 273 : Int nCorr(2);
107 273 : Int nDataCorr(sdb.nCorrelations());
108 273 : Vector<Int> corridx(nCorr,0);
109 273 : if (nDataCorr==2) {
110 265 : corridx(0)=0;
111 265 : corridx(1)=1;
112 : }
113 8 : else if (nDataCorr==4) {
114 8 : corridx(0)=0;
115 8 : corridx(1)=3;
116 : }
117 :
118 273 : Int guesschan(sdb.nChannels()-1);
119 :
120 : // cout << "guesschan = " << guesschan << endl;
121 : // cout << "nCorr = " << nCorr << endl;
122 : // cout << "corridx = " << corridx << endl;
123 :
124 : // Find out which ants are available
125 273 : Int nRow=sdb.nRows();
126 273 : Vector<Bool> rowok(nRow,False);
127 2935 : for (Int irow=0;irow<nRow;++irow) {
128 :
129 2662 : const Int& a1(sdb.antenna1()(irow));
130 2662 : const Int& a2(sdb.antenna2()(irow));
131 :
132 : // Is this row ok?
133 5324 : rowok(irow)= (!sdb.flagRow()(irow) &&
134 2662 : a1==a2);
135 : }
136 :
137 273 : const Cube<Complex>& V(sdb.visCubeCorrected());
138 273 : Float amp(0.0);
139 273 : solveCPar()=Complex(1.0);
140 273 : solveParOK()=False;
141 2935 : for (Int irow=0;irow<nRow;++irow) {
142 :
143 2662 : if (rowok(irow)) {
144 2662 : const Int& a1=sdb.antenna1()(irow);
145 2662 : const Int& a2=sdb.antenna2()(irow);
146 :
147 2662 : if (a1 == a2) {
148 :
149 7986 : for (Int icorr=0;icorr<nCorr;icorr++) {
150 5324 : const Complex& Vi(V(corridx(icorr),guesschan,irow));
151 5324 : amp=abs(Vi);
152 5324 : if (amp>0.0f) {
153 5324 : solveCPar()(icorr,0,a1) = sqrt(amp);
154 5324 : solveParOK()(icorr,0,a1) = True;
155 : }
156 : }
157 : }
158 : } // rowok
159 : } // irow
160 :
161 : // For scalar data, set "other" pol soln to zero
162 273 : if (nDataCorr == 1)
163 0 : solveCPar()(IPosition(3,1,0,0),IPosition(3,1,0,nAnt()-1))=Complex(0.0);
164 273 : }
165 :
166 : // Fill the trivial DJ matrix elements
167 0 : void AccorJones::initTrivDJ() {
168 :
169 0 : if (prtlev()>4) cout << " Accor::initTrivDJ" << endl;
170 :
171 : // Must be trivial
172 0 : AlwaysAssert((trivialDJ()),AipsError);
173 :
174 : // 1 0 0 0
175 : // 0 0 & 0 1
176 : //
177 0 : if (diffJElem().nelements()==0) {
178 0 : diffJElem().resize(IPosition(4,2,2,1,1));
179 0 : diffJElem()=0.0;
180 0 : diffJElem()(IPosition(4,0,0,0,0))=Complex(1.0);
181 0 : diffJElem()(IPosition(4,1,1,0,0))=Complex(1.0);
182 : }
183 :
184 0 : }
185 :
186 273 : void AccorJones::keepNCT() {
187 3074 : for (Int elem=0;elem<nElem();++elem) {
188 2801 : ct_->addRow(1);
189 :
190 2801 : CTMainColumns ncmc(*ct_);
191 :
192 : // We are adding to the most-recently added row
193 2801 : Int row=ct_->nrow()-1;
194 :
195 : // Meta-info
196 2801 : ncmc.time().put(row,refTime());
197 2801 : ncmc.fieldId().put(row,currField());
198 2801 : ncmc.spwId().put(row,currSpw());
199 2801 : ncmc.scanNo().put(row,currScan());
200 2801 : ncmc.obsId().put(row,currObs());
201 2801 : ncmc.interval().put(row,0.0);
202 2801 : ncmc.antenna1().put(row,elem);
203 2801 : ncmc.antenna2().put(row,-1);
204 :
205 : // Params
206 2801 : ncmc.cparam().put(row,solveAllCPar().xyPlane(elem));
207 :
208 : // Stats
209 2801 : ncmc.paramerr().put(row,solveAllParErr().xyPlane(elem));
210 2801 : ncmc.snr().put(row,solveAllParErr().xyPlane(elem));
211 2801 : ncmc.flag().put(row,!solveAllParOK().xyPlane(elem));
212 2801 : }
213 :
214 : // This spw now has some solutions in it
215 273 : spwOK_(currSpw())=True;
216 273 : }
217 :
218 : } //# NAMESPACE CASA - END
|