Line data Source code
1 : //# GJonesMBuf.cc: Implementation of GJonesMBuf.h
2 : //# Copyright (C) 1996,1997,1998,2001,2002,2003
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 : //# $Id$
27 : //----------------------------------------------------------------------------
28 :
29 : #include <synthesis/CalTables/GJonesMBuf.h>
30 : #include <casacore/casa/Arrays/ArrayMath.h>
31 : #include <casacore/tables/Tables/RefRows.h>
32 :
33 : using namespace casacore;
34 : namespace casa { //# NAMESPACE CASA - BEGIN
35 :
36 : //----------------------------------------------------------------------------
37 :
38 0 : GJonesPolyMBuf::GJonesPolyMBuf() : GJonesMBuf()
39 : {
40 : // Null constructor
41 : // Output to private data:
42 : // GJonesMBuf GJonesMBuf GJones cal main buffer
43 : // polyType_p Vector<String> Polynomial type
44 : // polyMode_p Vector<String> Polynomial mode (e.g. A&P)
45 : // scaleFactor_p Vector<Complex> Polynomial scale factor
46 : // nPolyAmp_p Vector<Int> Polynomial degree (amplitude)
47 : // nPolyPhase_p Vector<Int> Polynomial degree (phase)
48 : // polyCoeffAmp_p Array<Double> Polynomial coeff. (amplitude)
49 : // polyCoeffPhase_p Array<Double> Polynomial coeff. (phase)
50 : // phaseUnits_p Vector<String> Phase units
51 : // polyTypeOK_p Bool Polynomial type cache ok
52 : // polyModeOK_p Bool Polynomial mode cache ok
53 : // scaleFactorOK_p Bool Scale factor cache ok
54 : // nPolyAmpOK_p Bool Poly. degree (amp) cache ok
55 : // nPolyPhaseOK_p Bool Poly. degree (phase) cache ok
56 : // polyCoeffAmpOK_p Bool Poly. coeff. (amp) cache ok
57 : // polyCoeffPhaseOK_p Bool Poly. coeff. (phase) cache ok
58 : // phaseUnitsOK_p Bool Phase units cache ok
59 : //
60 : // Invalidate cache
61 0 : invalidate();
62 0 : };
63 :
64 : //----------------------------------------------------------------------------
65 :
66 1 : GJonesPolyMBuf::GJonesPolyMBuf (const Vector<Int>& calIndices,
67 1 : const Block<Vector<Int> >& indexValues) :
68 1 : GJonesMBuf (calIndices, indexValues)
69 : {
70 : // Construct from a set of cal buffer indices and specified index values
71 : // Output to private data:
72 : // GJonesMBuf GJonesMBuf Parent class cal main table buffer
73 : //
74 : // Set the local non-index columns to default values
75 1 : fillAttributes (calIndices);
76 1 : };
77 :
78 : //----------------------------------------------------------------------------
79 :
80 0 : GJonesPolyMBuf::GJonesPolyMBuf (CalIterBase& calIter) : GJonesMBuf (calIter)
81 : {
82 : // Construct from a calibration table iterator
83 : // Input:
84 : // calIter CalIterBase& Calibration table iterator
85 : // Output to private data:
86 : // GJonesMBuf GJonesMBuf GJones cal main buffer
87 : // polyType_p Vector<String> Polynomial type
88 : // polyMode_p Vector<String> Polynomial mode (e.g. A&P)
89 : // scaleFactor_p Vector<Complex> Polynomial scale factor
90 : // nPolyAmp_p Vector<Int> Polynomial degree (amplitude)
91 : // nPolyPhase_p Vector<Int> Polynomial degree (phase)
92 : // polyCoeffAmp_p Array<Double> Polynomial coeff. (amplitude)
93 : // polyCoeffPhase_p Array<Double> Polynomial coeff. (phase)
94 : // phaseUnits_p Vector<String> Phase units
95 : // polyTypeOK_p Bool Polynomial type cache ok
96 : // polyModeOK_p Bool Polynomial mode cache ok
97 : // scaleFactorOK_p Bool Scale factor cache ok
98 : // nPolyAmpOK_p Bool Poly. degree (amp) cache ok
99 : // nPolyPhaseOK_p Bool Poly. degree (phase) cache ok
100 : // polyCoeffAmpOK_p Bool Poly. coeff. (amp) cache ok
101 : // polyCoeffPhaseOK_p Bool Poly. coeff. (phase) cache ok
102 : // phaseUnitsOK_p Bool Phase units cache ok
103 : //
104 : // Invalidate cache
105 0 : invalidate();
106 0 : };
107 :
108 : //----------------------------------------------------------------------------
109 :
110 0 : void GJonesPolyMBuf::invalidate()
111 : {
112 : // Invalidate the current cache
113 : // Output to private data:
114 : // polyTypeOK_p Bool Polynomial type cache ok
115 : // polyModeOK_p Bool Polynomial mode cache ok
116 : // scaleFactorOK_p Bool Scale factor cache ok
117 : // nPolyAmpOK_p Bool Poly. degree (amp) cache ok
118 : // nPolyPhaseOK_p Bool Poly. degree (phase) cache ok
119 : // polyCoeffAmpOK_p Bool Poly. coeff. (amp) cache ok
120 : // polyCoeffPhaseOK_p Bool Poly. coeff. (phase) cache ok
121 : // phaseUnitsOK_p Bool Phase units cache ok
122 : //
123 : // Invalidate parent class cache
124 0 : GJonesMBuf::invalidate();
125 :
126 : // Set all cache flags to false
127 0 : polyTypeOK_p = false;
128 0 : polyModeOK_p = false;
129 0 : scaleFactorOK_p = false;
130 0 : nPolyAmpOK_p = false;
131 0 : nPolyPhaseOK_p = false;
132 0 : polyCoeffAmpOK_p = false;
133 0 : polyCoeffPhaseOK_p = false;
134 0 : phaseUnitsOK_p = false;
135 0 : };
136 :
137 : //----------------------------------------------------------------------------
138 :
139 1 : Int GJonesPolyMBuf::append (CalTable& calTable)
140 : {
141 : // Append the current calibration buffer to a calibration table
142 : // Input:
143 : // calTable CalTable& Calibration table
144 : //
145 : // Extend the inherited parent class method
146 1 : Int nAdded = SolvableVisJonesMBuf::append(calTable);
147 :
148 : // Compute the row numbers already added by the parent class
149 1 : uInt endRow = calTable.nRowMain() - 1;
150 1 : uInt startRow = endRow - nAdded + 1;
151 :
152 : // Attach a calibration table columns accessor
153 1 : GJonesPolyMCol gjpMainCol(dynamic_cast<GJonesPolyTable&>(calTable));
154 :
155 : // Append the current cal buffer main columns
156 1 : RefRows refRows(startRow, endRow);
157 1 : gjpMainCol.polyType().putColumnCells(refRows, polyType());
158 1 : gjpMainCol.polyMode().putColumnCells(refRows, polyMode());
159 1 : gjpMainCol.scaleFactor().putColumnCells(refRows, scaleFactor());
160 1 : gjpMainCol.nPolyAmp().putColumnCells(refRows, nPolyAmp());
161 1 : gjpMainCol.nPolyPhase().putColumnCells(refRows, nPolyPhase());
162 1 : gjpMainCol.polyCoeffAmp().putColumnCells(refRows, polyCoeffAmp());
163 1 : gjpMainCol.polyCoeffPhase().putColumnCells(refRows, polyCoeffPhase());
164 1 : gjpMainCol.phaseUnits().putColumnCells(refRows, phaseUnits());
165 :
166 1 : return nAdded;
167 1 : };
168 :
169 : //----------------------------------------------------------------------------
170 :
171 23 : Int GJonesPolyMBuf::nRow()
172 : {
173 : // Return the maximum number of rows in the calibration buffer
174 : // Input from private data:
175 : // polyType_p Vector<String> Polynomial type
176 : // polyMode_p Vector<String> Polynomial mode (e.g. A&P)
177 : // scaleFactor_p Vector<Complex> Polynomial scale factor
178 : // nPolyAmp_p Vector<Int> Polynomial degree (amplitude)
179 : // nPolyPhase_p Vector<Int> Polynomial degree (phase)
180 : // polyCoeffAmp_p Array<Double> Polynomial coeff. (amplitude)
181 : // polyCoeffPhase_p Array<Double> Polynomial coeff. (phase)
182 : // phaseUnits_p Vector<String> Phase units
183 : // polyTypeOK_p Bool Polynomial type cache ok
184 : // polyModeOK_p Bool Polynomial mode cache ok
185 : // scaleFactorOK_p Bool Scale factor cache ok
186 : // nPolyAmpOK_p Bool Poly. degree (amp) cache ok
187 : // nPolyPhaseOK_p Bool Poly. degree (phase) cache ok
188 : // polyCoeffAmpOK_p Bool Poly. coeff. (amp) cache ok
189 : // polyCoeffPhaseOK_p Bool Poly. coeff. (phase) cache ok
190 : // phaseUnitsOK_p Bool Phase units cache ok
191 : // Output:
192 : // nRow Int Maximum number of rows
193 : //
194 : // Extend the inherited parent class method
195 23 : Int nRowParent = SolvableVisJonesMBuf::nRow();
196 :
197 : // Process each local column individually
198 23 : Vector<Int> colLength(9);
199 23 : Int n = 0;
200 23 : colLength(n++) = nRowParent;
201 23 : colLength(n++) = polyType().nelements();
202 23 : colLength(n++) = polyMode().nelements();
203 23 : colLength(n++) = scaleFactor().nelements();
204 23 : colLength(n++) = nPolyAmp().nelements();
205 23 : colLength(n++) = nPolyPhase().nelements();
206 45 : colLength(n++) = polyCoeffAmp().shape().nelements() > 0 ?
207 45 : polyCoeffAmp().shape().getLast(1)(0) : 0;
208 45 : colLength(n++) = polyCoeffPhase().shape().nelements() > 0 ?
209 45 : polyCoeffPhase().shape().getLast(1)(0) : 0;
210 23 : colLength(n++) = phaseUnits().nelements();
211 :
212 46 : return max(colLength);
213 23 : };
214 :
215 : //----------------------------------------------------------------------------
216 :
217 20 : Bool GJonesPolyMBuf::fillMatchingRows (const Vector<Int>& matchingRows,
218 : const String& sFreqGrpName,
219 : const String& sPolyType,
220 : const String& sPolyMode,
221 : const Complex& sScaleFactor,
222 : const Int& sNPolyAmp,
223 : const Int& sNPolyPhase,
224 : const Vector<Double>& sPolyCoeffAmp,
225 : const Vector<Double>& sPolyCoeffPhase,
226 : const String& sPhaseUnits,
227 : const MFrequency& sRefFreq,
228 : const Int& sRefAnt)
229 : {
230 : // Update the parametrized solution in each of a set of buffer rows
231 : // Input:
232 : // matchingRows const Vec<Int>& Buffer rows to update
233 : // sFreqGrpName const String& Freq. group name
234 : // sPolyType const String& Polynomial type
235 : // sPolyMode const String& Polynomial mode (e.g. A&P)
236 : // sScaleFactor const Complex& Polynomial scale factor
237 : // sNPolyAmp const Int& Poly. degree (amp)
238 : // sNPolyPhase const Int& Poly. degree (phase)
239 : // sPolyCoeffAmp const Vector<Double>& Poly. coeff. (amp)
240 : // sPolyCoeffPhase const Vector<Double>& Poly. coeff. (phase)
241 : // sPhaseUnits const String& Phase units
242 : // sRefFreq const MFrequency& Reference frequency
243 : // sRefAnt const Int & Reference antenna id.
244 : //
245 : // Initialization
246 20 : Bool retval = false;
247 20 : Int nMatch = matchingRows.nelements();
248 :
249 20 : if (nMatch > 0) {
250 20 : retval = true;
251 :
252 : // Resize the coefficient arrays
253 20 : IPosition ampCoeffShape = polyCoeffAmp().shape();
254 20 : if (sPolyMode.contains("AMP") && ampCoeffShape(3) != 2*sNPolyAmp) {
255 1 : ampCoeffShape(3) = 2*sNPolyAmp;
256 1 : polyCoeffAmp().resize(ampCoeffShape);
257 : };
258 20 : IPosition phaseCoeffShape = polyCoeffPhase().shape();
259 20 : if (sPolyMode.contains("PHAS") && phaseCoeffShape(3) != 2*sNPolyPhase) {
260 1 : IPosition phaseCoeffShape = polyCoeffPhase().shape();
261 1 : phaseCoeffShape(3) = 2*sNPolyPhase;
262 1 : polyCoeffPhase().resize(phaseCoeffShape);
263 1 : polyCoeffPhase() = 0;
264 1 : };
265 :
266 : // Update each matched row
267 40 : for (Int i=0; i < nMatch; i++) {
268 20 : uInt row = matchingRows(i);
269 20 : freqGrpName()(row) = sFreqGrpName;
270 20 : polyType()(row) = sPolyType;
271 :
272 : // Check if the polynomial mode needs to be updated
273 20 : String currMode = polyMode()(row);
274 40 : if ((currMode.contains("AMP") && sPolyMode.contains("PHAS")) ||
275 20 : (currMode.contains("PHAS") && sPolyMode.contains("AMP"))) {
276 0 : polyMode()(row) = "A&P";
277 : } else {
278 20 : polyMode()(row) = sPolyMode;
279 : };
280 :
281 20 : if (sPolyMode.contains("PHAS")) {
282 20 : Complex currFactor = scaleFactor()(row);
283 40 : scaleFactor()(row) =
284 40 : abs(currFactor) > 0 ? currFactor*sScaleFactor : sScaleFactor;
285 20 : nPolyPhase()(row) = sNPolyPhase;
286 :
287 : // Phase units
288 20 : phaseUnits()(row) = sPhaseUnits;
289 : };
290 :
291 20 : if (sPolyMode.contains("AMP")) {
292 20 : nPolyAmp()(row) = sNPolyAmp;
293 : };
294 :
295 : // Update all array elements
296 40 : for (Int recep=0; recep < ampCoeffShape(0); recep++) {
297 40 : for (Int spw=0; spw < ampCoeffShape(1); spw++) {
298 40 : for (Int chan=0; chan < ampCoeffShape(2); chan++) {
299 20 : IPosition ipos4(4, recep, spw, chan, row);
300 :
301 :
302 20 : if (sPolyMode.contains("PHAS")) {
303 : // Compute a phase scale factor if the reference
304 : // frequency has changed
305 20 : Double phaseScaleFactor = 0;
306 20 : Double refFreqHz = refFreqMeas()(ipos4).get("Hz").getValue();
307 20 : Double sRefFreqHz = sRefFreq.get("Hz").getValue();
308 20 : if (abs(refFreqHz) > 0 && abs(sRefFreqHz) > 0) {
309 0 : phaseScaleFactor = sRefFreqHz / refFreqHz;
310 : };
311 : // Reference frequency and antenna
312 20 : refFreqMeas()(ipos4) = sRefFreq;
313 20 : refAnt()(ipos4) = sRefAnt;
314 :
315 : // Phase polynomial coefficients
316 380 : for (Int coeff=0; coeff < 2*sNPolyPhase; coeff++) {
317 360 : IPosition ipos5(5, recep, spw, chan, coeff, row);
318 : // Multiply exisiting coefficients by the phase scale factor
319 360 : polyCoeffPhase()(ipos5) *= phaseScaleFactor;
320 360 : polyCoeffPhase()(ipos5) += sPolyCoeffPhase(coeff);
321 360 : };
322 : }
323 :
324 20 : if (sPolyMode.contains("AMP")) {
325 : // Amplitude polynomial coefficients
326 380 : for (Int coeff=0; coeff < 2*sNPolyAmp; coeff++) {
327 360 : IPosition ipos5(5, recep, spw, chan, coeff, row);
328 360 : polyCoeffAmp()(ipos5) = sPolyCoeffAmp(coeff);
329 360 : };
330 : };
331 :
332 20 : };
333 : };
334 : };
335 :
336 20 : };
337 20 : };
338 20 : return retval;
339 : };
340 :
341 : //----------------------------------------------------------------------------
342 :
343 46 : Vector<String>& GJonesPolyMBuf::polyType()
344 : {
345 : // POLY_TYPE data field accessor
346 : // Input from private data:
347 : // polyType_p Vector<String> Polynomial type
348 : // polyTypeOK_p Bool Polynomial type cache ok
349 : //
350 : // Fill local cache for this column if cache not valid
351 46 : if (connectedToIter()) {
352 0 : if (!polyTypeOK_p) {
353 0 : calMainCol()->polyType().getColumn (polyType_p);
354 0 : polyTypeOK_p = true;
355 : };
356 : };
357 46 : return polyType_p;
358 : };
359 :
360 : //----------------------------------------------------------------------------
361 :
362 66 : Vector<String>& GJonesPolyMBuf::polyMode()
363 : {
364 : // POLY_MODE data field accessor
365 : // Input from private data:
366 : // polyMode_p Vector<String> Polynomial mode (e.g. A&P)
367 : // polyModeOK_p Bool Polynomial mode cache ok
368 : //
369 : // Fill local cache for this column if cache not valid
370 66 : if (connectedToIter()) {
371 0 : if (!polyModeOK_p) {
372 0 : calMainCol()->polyMode().getColumn (polyMode_p);
373 0 : polyModeOK_p = true;
374 : };
375 : };
376 66 : return polyMode_p;
377 : };
378 :
379 : //----------------------------------------------------------------------------
380 :
381 66 : Vector<Complex>& GJonesPolyMBuf::scaleFactor()
382 : {
383 : // SCALE_FACTOR data field accessor
384 : // Input from private data:
385 : // scaleFactor_p Vector<Complex> Polynomial scale factor
386 : // scaleFactorOK_p Bool Polynomial scale factor cache ok
387 : //
388 : // Fill local cache for this column if cache not valid
389 66 : if (connectedToIter()) {
390 0 : if (!scaleFactorOK_p) {
391 0 : calMainCol()->scaleFactor().getColumn (scaleFactor_p);
392 0 : scaleFactorOK_p = true;
393 : };
394 : };
395 66 : return scaleFactor_p;
396 : };
397 :
398 : //----------------------------------------------------------------------------
399 :
400 46 : Vector<Int>& GJonesPolyMBuf::nPolyAmp()
401 : {
402 : // N_POLY_AMP data field accessor
403 : // Input from private data:
404 : // nPolyAmp_p Vector<Int> Polynomial degree (amplitude)
405 : // nPolyAmpOK_p Bool Poly. degree (amp) cache ok
406 : //
407 : // Fill local cache for this column if cache not valid
408 46 : if (connectedToIter()) {
409 0 : if (!nPolyAmpOK_p) {
410 0 : calMainCol()->nPolyAmp().getColumn (nPolyAmp_p);
411 0 : nPolyAmpOK_p = true;
412 : };
413 : };
414 46 : return nPolyAmp_p;
415 : };
416 :
417 : //----------------------------------------------------------------------------
418 :
419 46 : Vector<Int>& GJonesPolyMBuf::nPolyPhase()
420 : {
421 : // N_POLY_PHASE data field accessor
422 : // Input from private data:
423 : // nPolyPhase_p Vector<Int> Polynomial degree (phase)
424 : // nPolyPhaseOK_p Bool Poly. degree (phase) cache ok
425 : //
426 : // Fill local cache for this column if cache not valid
427 46 : if (connectedToIter()) {
428 0 : if (!nPolyPhaseOK_p) {
429 0 : calMainCol()->nPolyPhase().getColumn (nPolyPhase_p);
430 0 : nPolyPhaseOK_p = true;
431 : };
432 : };
433 46 : return nPolyPhase_p;
434 : };
435 :
436 : //----------------------------------------------------------------------------
437 :
438 429 : Array<Double>& GJonesPolyMBuf::polyCoeffAmp()
439 : {
440 : // POLY_COEFF_AMP data field accessor
441 : // Input from private data:
442 : // polyCoeffAmp_p Array<Double> Polynomial coeff. (amplitude)
443 : // polyCoeffAmpOK_p Bool Poly. coeff. (amp) cache ok
444 : //
445 : // Fill local cache for this column if cache not valid
446 429 : if (connectedToIter()) {
447 0 : if (!polyCoeffAmpOK_p) {
448 0 : calMainCol()->polyCoeffAmp().getColumn (polyCoeffAmp_p);
449 0 : polyCoeffAmpOK_p = true;
450 : };
451 : };
452 429 : return polyCoeffAmp_p;
453 : };
454 :
455 : //----------------------------------------------------------------------------
456 :
457 791 : Array<Double>& GJonesPolyMBuf::polyCoeffPhase()
458 : {
459 : // POLY_COEFF_PHASE data field accessor
460 : // Input from private data:
461 : // polyCoeffPhase_p Array<Double> Polynomial coeff. (phase)
462 : // polyCoeffPhaseOK_p Bool Poly. coeff. (phase) cache ok
463 : //
464 : // Fill local cache for this column if cache not valid
465 791 : if (connectedToIter()) {
466 0 : if (!polyCoeffPhaseOK_p) {
467 0 : calMainCol()->polyCoeffPhase().getColumn (polyCoeffPhase_p);
468 0 : polyCoeffPhaseOK_p = true;
469 : };
470 : };
471 791 : return polyCoeffPhase_p;
472 : };
473 :
474 : //----------------------------------------------------------------------------
475 :
476 46 : Vector<String>& GJonesPolyMBuf::phaseUnits()
477 : {
478 : // PHASE_UNITS data field accessor
479 : // Input from private data:
480 : // phaseUnits_p Vector<String> Phase units
481 : // phaseUnitsOK_p Bool Phase units cache ok
482 : //
483 : // Fill local cache for this column if cache not valid
484 46 : if (connectedToIter()) {
485 0 : if (!phaseUnitsOK_p) {
486 0 : calMainCol()->phaseUnits().getColumn (phaseUnits_p);
487 0 : phaseUnitsOK_p = true;
488 : };
489 : };
490 46 : return phaseUnits_p;
491 : };
492 :
493 : //----------------------------------------------------------------------------
494 :
495 1 : void GJonesPolyMBuf::fillAttributes (const Vector<Int>& /*calIndices*/)
496 : {
497 : // Resize all GJonesPoly attribute columns and set to their default values
498 : // Input:
499 : // calIndices const Vector<Int>& Vector of cal indices, specified
500 : // as enums from class MSCalEnums,
501 : // to exclude
502 : // Output to private data:
503 : // polyType_p Vector<String> Polynomial type
504 : // polyMode_p Vector<String> Polynomial mode (e.g. A&P)
505 : // scaleFactor_p Vector<Complex> Polynomial scale factor
506 : // nPolyAmp_p Vector<Int> Polynomial degree (amplitude)
507 : // nPolyPhase_p Vector<Int> Polynomial degree (phase)
508 : // polyCoeffAmp_p Array<Double> Polynomial coeff. (amplitude)
509 : // polyCoeffPhase_p Array<Double> Polynomial coeff. (phase)
510 : // phaseUnits_p Vector<String> Phase units
511 : //
512 : // Process each GJonesPoly cal buffer column separately
513 : //
514 : // Use the maximum number of rows currently defined in the cal buffer
515 1 : uInt nrow = nRow();
516 :
517 : // POLY_TYPE
518 1 : polyType().resize(nrow);
519 1 : polyType() = "";
520 :
521 : // POLY_MODE
522 1 : polyMode().resize(nrow);
523 1 : polyMode() = "";
524 :
525 : // SCALE_FACTOR
526 1 : scaleFactor().resize(nrow);
527 1 : scaleFactor() = Complex(1,0);
528 :
529 : // N_POLY_AMP
530 1 : nPolyAmp().resize(nrow);
531 1 : nPolyAmp() = 0;
532 :
533 : // NPOLY_PHASE
534 1 : nPolyPhase().resize(nrow);
535 1 : nPolyPhase() = 0;
536 :
537 : // Array-based columns POLY_COEFF_AMP and POLY_COEFF_PHASE (set
538 : // to default unit length in each dimension)
539 1 : uInt numSpw = 1;
540 1 : uInt numChan = 1;
541 1 : uInt numReceptors = 1;
542 1 : uInt numCoeff = 1;
543 1 : IPosition coeffSize(5, numReceptors, numSpw, numChan, numCoeff, nrow);
544 :
545 1 : polyCoeffAmp().resize(coeffSize);
546 1 : polyCoeffAmp() = 0;
547 1 : polyCoeffPhase().resize(coeffSize);
548 1 : polyCoeffPhase() = 0;
549 :
550 : // PHASE_UNITS
551 1 : phaseUnits().resize(nrow);
552 1 : phaseUnits() = "";
553 :
554 2 : return;
555 1 : };
556 :
557 : //----------------------------------------------------------------------------
558 :
559 0 : GJonesSplineMBuf::GJonesSplineMBuf() : GJonesPolyMBuf()
560 : {
561 : // Null constructor
562 : // Output to private data:
563 : // GJonesPolyMBuf GJonesPolyMBuf GJonesPoly cal main buffer
564 : // nKnotsAmp_p Vector<Int> No. of amplitude spline knots
565 : // nKnotsPhase_p Vector<Int> No. of phase spline knots
566 : // splineKnotsAmp_p Array<Double> Amp. spline knot positions
567 : // splineKnotsPhase_p Array<Double> Phase spline knot positions
568 : // nKnotsAmpOK_p Bool No. amp. spline knots cache ok
569 : // nKnotsPhaseOK_p Bool No. phase spline knots cache ok
570 : // splineKnotsAmpOK_p Bool Amp. spline knot posn. cache ok
571 : // splineKnotsPhaseOK_p Bool Phase spline knot posn. cache ok
572 : //
573 : // Invalidate cache
574 0 : invalidate();
575 0 : };
576 :
577 : //----------------------------------------------------------------------------
578 :
579 1 : GJonesSplineMBuf::GJonesSplineMBuf (const Vector<Int>& calIndices,
580 1 : const Block<Vector<Int> >& indexValues) :
581 1 : GJonesPolyMBuf (calIndices, indexValues)
582 : {
583 : // Construct from a set of cal buffer indices and specified index values
584 : // Output to private data:
585 : // GJonesPolyMBuf GJonesPolyMBuf Parent class cal main table buffer
586 : //
587 : // Set the local non-index columns to default values
588 1 : fillAttributes (calIndices);
589 :
590 1 : };
591 :
592 : //----------------------------------------------------------------------------
593 :
594 0 : GJonesSplineMBuf::GJonesSplineMBuf (CalIterBase& calIter) :
595 0 : GJonesPolyMBuf (calIter)
596 : {
597 : // Construct from a calibration table iterator
598 : // Input:
599 : // calIter CalIterBase& Calibration table iterator
600 : // Output to private data:
601 : // GJonesPolyMBuf GJonesPolyMBuf GJonesPoly cal main buffer
602 : // nKnotsAmp_p Vector<Int> No. of amplitude spline knots
603 : // nKnotsPhase_p Vector<Int> No. of phase spline knots
604 : // splineKnotsAmp_p Array<Double> Amp. spline knot positions
605 : // splineKnotsPhase_p Array<Double> Phase spline knot positions
606 : // nKnotsAmpOK_p Bool No. amp. spline knots cache ok
607 : // nKnotsPhaseOK_p Bool No. phase spline knots cache ok
608 : // splineKnotsAmpOK_p Bool Amp. spline knot posn. cache ok
609 : // splineKnotsPhaseOK_p Bool Phase spline knot posn. cache ok
610 : //
611 : // Invalidate cache
612 0 : invalidate();
613 0 : };
614 :
615 : //----------------------------------------------------------------------------
616 :
617 0 : void GJonesSplineMBuf::invalidate()
618 : {
619 : // Invalidate the current cache
620 : // Output to private data:
621 : // nKnotsAmpOK_p Bool No. amp. spline knots cache ok
622 : // nKnotsPhaseOK_p Bool No. phase spline knots cache ok
623 : // splineKnotsAmpOK_p Bool Amp. spline knot posn. cache ok
624 : // splineKnotsPhaseOK_p Bool Phase spline knot posn. cache ok
625 : //
626 : // Invalidate parent class cache
627 0 : GJonesPolyMBuf::invalidate();
628 :
629 : // Set all cache flags to false
630 0 : nKnotsAmpOK_p = false;
631 0 : nKnotsPhaseOK_p = false;
632 0 : splineKnotsAmpOK_p = false;
633 0 : splineKnotsPhaseOK_p = false;
634 0 : };
635 :
636 : //----------------------------------------------------------------------------
637 :
638 1 : Int GJonesSplineMBuf::append (CalTable& calTable)
639 : {
640 : // Append the current calibration buffer to a calibration table
641 : // Input:
642 : // calTable CalTable& Calibration table
643 : //
644 : // Extend the inherited parent class method
645 1 : Int nAdded = GJonesPolyMBuf::append(calTable);
646 :
647 : // Compute the row numbers already added by the parent class
648 1 : uInt endRow = calTable.nRowMain() - 1;
649 1 : uInt startRow = endRow - nAdded + 1;
650 :
651 : // Attach a calibration table columns accessor
652 1 : GJonesSplineMCol gjsMainCol(dynamic_cast<GJonesSplineTable&>(calTable));
653 :
654 : // Append the current cal buffer main columns
655 1 : RefRows refRows(startRow, endRow);
656 1 : gjsMainCol.nKnotsAmp().putColumnCells(refRows, nKnotsAmp());
657 1 : gjsMainCol.nKnotsPhase().putColumnCells(refRows, nKnotsPhase());
658 1 : gjsMainCol.splineKnotsAmp().putColumnCells(refRows, splineKnotsAmp());
659 1 : gjsMainCol.splineKnotsPhase().putColumnCells(refRows, splineKnotsPhase());
660 :
661 1 : return nAdded;
662 1 : };
663 :
664 : //----------------------------------------------------------------------------
665 :
666 22 : Int GJonesSplineMBuf::nRow()
667 : {
668 : // Return the maximum number of rows in the calibration buffer
669 : // Input from private data:
670 : // nKnotsAmp_p Vector<Int> No. of amplitude spline knots
671 : // nKnotsPhase_p Vector<Int> No. of phase spline knots
672 : // splineKnotsAmp_p Array<Double> Amp. spline knot positions
673 : // splineKnotsPhase_p Array<Double> Phase spline knot positions
674 : // nKnotsAmpOK_p Bool No. amp. spline knots cache ok
675 : // nKnotsPhaseOK_p Bool No. phase spline knots cache ok
676 : // splineKnotsAmpOK_p Bool Amp. spline knot posn. cache ok
677 : // splineKnotsPhaseOK_p Bool Phase spline knot posn. cache ok
678 : // Output:
679 : // nRow Int Maximum number of rows
680 : //
681 : // Extend the inherited parent class method
682 22 : Int nRowParent = GJonesPolyMBuf::nRow();
683 :
684 : // Process each local column individually
685 22 : Vector<Int> colLength(5);
686 22 : Int n = 0;
687 22 : colLength(n++) = nRowParent;
688 22 : colLength(n++) = nKnotsAmp().nelements();
689 22 : colLength(n++) = nKnotsPhase().nelements();
690 43 : colLength(n++) = splineKnotsAmp().shape().nelements() > 0 ?
691 43 : splineKnotsAmp().shape().getLast(1)(0) : 0;
692 43 : colLength(n++) = splineKnotsPhase().shape().nelements() > 0 ?
693 43 : splineKnotsPhase().shape().getLast(1)(0) : 0;
694 :
695 44 : return max(colLength);
696 22 : };
697 :
698 : //----------------------------------------------------------------------------
699 :
700 20 : Bool GJonesSplineMBuf::fillMatchingRows (const Vector<Int>& matchingRows,
701 : const String& sFreqGrpName,
702 : const String& sPolyType,
703 : const String& sPolyMode,
704 : const Complex& sScaleFactor,
705 : const Int& sNPolyAmp,
706 : const Int& sNPolyPhase,
707 : const Vector<Double>& sPolyCoeffAmp,
708 : const Vector<Double>& sPolyCoeffPhase,
709 : const String& sPhaseUnits,
710 : const Int& sNKnotsAmp,
711 : const Int& sNKnotsPhase,
712 : const Vector<Double>& sSplineKnotsAmp,
713 : const Vector<Double>&
714 : sSplineKnotsPhase,
715 : const MFrequency& sRefFreq,
716 : const Int& sRefAnt)
717 : {
718 : // Update the parametrized solution in each of a set of buffer rows
719 : // Input:
720 : // matchingRows const Vector<Int>& Buffer rows to update
721 : // sFreqGrpName const String& Freq. group name
722 : // sPolyType const String& Polynomial type
723 : // sPolyMode const String& Polynomial mode (e.g. A&P)
724 : // sScaleFactor const Complex& Polynomial scale factor
725 : // sNPolyAmp const Int& Poly. degree (amp)
726 : // sNPolyPhase const Int& Poly. degree (phase)
727 : // sPolyCoeffAmp const Vector<Double>& Poly. coeff. (amp)
728 : // sPolyCoeffPhase const Vector<Double>& Poly. coeff. (phase)
729 : // sPhaseUnits const String& Phase units
730 : // sNKnotsAmp const Int& No. of amp. spline knots
731 : // sNKnotsPhase const Int& No. of phase spline knots
732 : // sSplineKnotsAmp const Vector<Double>& Amp. spline knot positions
733 : // sSplineKnotsPhase const Vector<Double>& Phase spline knot positions
734 : // sRefFreq const MFrequency& Reference frequency
735 : // sRefAnt const Int & Reference antenna id.
736 : //
737 : // Initialization
738 20 : Bool retval = false;
739 :
740 : // Extend parent method
741 20 : GJonesPolyMBuf::fillMatchingRows (matchingRows, sFreqGrpName, sPolyType,
742 : sPolyMode, sScaleFactor, sNPolyAmp,
743 : sNPolyPhase, sPolyCoeffAmp,
744 : sPolyCoeffPhase, sPhaseUnits,
745 : sRefFreq, sRefAnt);
746 :
747 : // Add local spline parameters.
748 : //
749 20 : Int nMatch = matchingRows.nelements();
750 :
751 20 : if (nMatch > 0) {
752 20 : retval = true;
753 :
754 :
755 : // Resize the spline knot arrays in ampltidue and phase
756 20 : IPosition splineKnotsAmpShape = splineKnotsAmp().shape();
757 20 : if (sPolyMode.contains("AMP") && splineKnotsAmpShape(3) != sNKnotsAmp) {
758 1 : splineKnotsAmpShape(3) = sNKnotsAmp;
759 1 : splineKnotsAmp().resize(splineKnotsAmpShape);
760 : };
761 20 : IPosition splineKnotsPhaseShape = splineKnotsPhase().shape();
762 20 : if (sPolyMode.contains("PHAS") && splineKnotsPhaseShape(3) != sNKnotsPhase) {
763 1 : splineKnotsPhaseShape(3) = sNKnotsPhase;
764 1 : splineKnotsPhase().resize(splineKnotsPhaseShape);
765 : };
766 :
767 : // Update each matched row
768 40 : for (Int i=0; i < nMatch; i++) {
769 20 : uInt row = matchingRows(i);
770 :
771 : // No of knots in amplitude and phase splines
772 20 : if (sPolyMode.contains("AMP")) nKnotsAmp()(row) = sNKnotsAmp;
773 20 : if (sPolyMode.contains("PHAS")) nKnotsPhase()(row) = sNKnotsPhase;
774 :
775 : // Update all array elements
776 40 : for (Int recep=0; recep < splineKnotsAmpShape(0); recep++) {
777 40 : for (Int spw=0; spw < splineKnotsAmpShape(1); spw++) {
778 40 : for (Int chan=0; chan < splineKnotsAmpShape(2); chan++) {
779 :
780 : // Amplitude spline knot positions
781 20 : if (sPolyMode.contains("AMP")) {
782 200 : for (Int coeff=0; coeff < sNKnotsAmp; coeff++) {
783 180 : IPosition ipos5(5, recep, spw, chan, coeff, row);
784 180 : splineKnotsAmp()(ipos5) = sSplineKnotsAmp(coeff);
785 180 : };
786 : };
787 :
788 : // Phase spline knot positions
789 20 : if (sPolyMode.contains("PHAS")) {
790 200 : for (Int coeff=0; coeff < sNKnotsPhase; coeff++) {
791 180 : IPosition ipos5(5, recep, spw, chan, coeff, row);
792 180 : splineKnotsPhase()(ipos5) = sSplineKnotsPhase(coeff);
793 180 : };
794 : };
795 : };
796 : };
797 : };
798 : };
799 20 : };
800 20 : return retval;
801 : };
802 :
803 : //----------------------------------------------------------------------------
804 :
805 45 : Vector<Int>& GJonesSplineMBuf::nKnotsAmp()
806 : {
807 : // N_KNOTS_AMP data field accessor
808 : // Input from private data:
809 : // nKnotsAmp_p Vector<Int> No. of amp. spline knots
810 : // nKnotsAmpOK_p Bool No. amp. spline knots cache ok
811 : //
812 : // Fill local cache for this column if cache not valid
813 45 : if (connectedToIter()) {
814 0 : if (!nKnotsAmpOK_p) {
815 0 : calMainCol()->nKnotsAmp().getColumn (nKnotsAmp_p);
816 0 : nKnotsAmpOK_p = true;
817 : };
818 : };
819 45 : return nKnotsAmp_p;
820 : };
821 :
822 : //----------------------------------------------------------------------------
823 :
824 45 : Vector<Int>& GJonesSplineMBuf::nKnotsPhase()
825 : {
826 : // N_KNOTS_PHASE data field accessor
827 : // Input from private data:
828 : // nKnotsPhase_p Vector<Int> No. phase spline knots
829 : // nKnotsPhaseOK_p Bool No. phase spline knots cache ok
830 : //
831 : // Fill local cache for this column if cache not valid
832 45 : if (connectedToIter()) {
833 0 : if (!nKnotsPhaseOK_p) {
834 0 : calMainCol()->nKnotsPhase().getColumn (nKnotsPhase_p);
835 0 : nKnotsPhaseOK_p = true;
836 : };
837 : };
838 45 : return nKnotsPhase_p;
839 : };
840 :
841 : //----------------------------------------------------------------------------
842 :
843 247 : Array<Double>& GJonesSplineMBuf::splineKnotsAmp()
844 : {
845 : // SPLINE_KNOTS_AMP data field accessor
846 : // Input from private data:
847 : // splineKnotsAmp_p Array<Double> Amp. spline knot positions
848 : // splineKnotsAmpOK_p Bool Amp. spline knot posn. cache ok
849 : //
850 : // Fill local cache for this column if cache not valid
851 247 : if (connectedToIter()) {
852 0 : if (!splineKnotsAmpOK_p) {
853 0 : calMainCol()->splineKnotsAmp().getColumn (splineKnotsAmp_p);
854 0 : splineKnotsAmpOK_p = true;
855 : };
856 : };
857 247 : return splineKnotsAmp_p;
858 : };
859 :
860 : //----------------------------------------------------------------------------
861 :
862 247 : Array<Double>& GJonesSplineMBuf::splineKnotsPhase()
863 : {
864 : // SPLINE_KNOTS_PHASE data field accessor
865 : // Input from private data:
866 : // splineKnotsPhase_p Array<Double> Phase spline knot positions
867 : // splineKnotsPhaseOK_p Bool Phase spline knot posn. cache ok
868 : //
869 : // Fill local cache for this column if cache not valid
870 247 : if (connectedToIter()) {
871 0 : if (!splineKnotsPhaseOK_p) {
872 0 : calMainCol()->splineKnotsPhase().getColumn (splineKnotsPhase_p);
873 0 : splineKnotsPhaseOK_p = true;
874 : };
875 : };
876 247 : return splineKnotsPhase_p;
877 : };
878 :
879 : //----------------------------------------------------------------------------
880 :
881 1 : void GJonesSplineMBuf::fillAttributes (const Vector<Int>& /*calIndices*/)
882 : {
883 : // Resize all GJonesSpline attribute columns and set to their default values
884 : // Input:
885 : // calIndices const Vector<Int>& Vector of cal indices, specified
886 : // as enums from class MSCalEnums,
887 : // to exclude
888 : // Output to private data:
889 : // nKnotsAmp_p Vector<Int> No. of amplitude spline knots
890 : // nKnotsPhase_p Vector<Int> No. of phase spline knots
891 : // splineKnotsAmp_p Array<Double> Amp. spline knot positions
892 : // splineKnotsPhase_p Array<Double> Phase spline knot positions
893 : //
894 : // Process each GJonesSpline cal buffer column separately
895 : //
896 : // Use the maximum number of rows currently defined in the cal buffer
897 1 : uInt nrow = nRow();
898 :
899 : // N_KNOTS_AMP
900 1 : nKnotsAmp().resize(nrow);
901 1 : nKnotsAmp() = 0;
902 :
903 : // N_KNOTS_PHASE
904 1 : nKnotsPhase().resize(nrow);
905 1 : nKnotsPhase() = 0;
906 :
907 : // Array-based columns SPLINE_KNOTS_AMP and SPLINE_KNOTS_PHASE (set
908 : // to default unit length in each dimension)
909 1 : uInt numSpw = 1;
910 1 : uInt numChan = 1;
911 1 : uInt numReceptors = 1;
912 1 : uInt numCoeff = 1;
913 1 : IPosition knotSize(5, numReceptors, numSpw, numChan, numCoeff, nrow);
914 :
915 1 : splineKnotsAmp().resize(knotSize);
916 1 : splineKnotsAmp() = 0;
917 1 : splineKnotsPhase().resize(knotSize);
918 1 : splineKnotsPhase() = 0;
919 :
920 2 : return;
921 1 : };
922 :
923 : //----------------------------------------------------------------------------
924 :
925 :
926 : } //# NAMESPACE CASA - END
927 :
|