source: trunk/src/SDMath.cc@ 259

Last change on this file since 259 was 248, checked in by kil064, 20 years ago

remove function 'quotient' and put its functionality into
function 'binaryOperate'

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.9 KB
RevLine 
[2]1//#---------------------------------------------------------------------------
2//# SDMath.cc: A collection of single dish mathematical operations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
[125]5//# ATNF
[2]6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
[38]31#include <vector>
32
[81]33#include <casa/aips.h>
34#include <casa/BasicSL/String.h>
35#include <casa/Arrays/IPosition.h>
36#include <casa/Arrays/Array.h>
[130]37#include <casa/Arrays/ArrayIter.h>
38#include <casa/Arrays/VectorIter.h>
[81]39#include <casa/Arrays/ArrayMath.h>
40#include <casa/Arrays/ArrayLogical.h>
41#include <casa/Arrays/MaskedArray.h>
42#include <casa/Arrays/MaskArrMath.h>
43#include <casa/Arrays/MaskArrLogi.h>
[234]44#include <casa/BasicMath/Math.h>
[221]45#include <casa/Containers/Block.h>
46#include <casa/Quanta/QC.h>
[177]47#include <casa/Utilities/Assert.h>
[130]48#include <casa/Exceptions.h>
[2]49
[177]50#include <scimath/Mathematics/VectorKernel.h>
51#include <scimath/Mathematics/Convolver.h>
[227]52#include <scimath/Mathematics/InterpolateArray1D.h>
[234]53#include <scimath/Functionals/Polynomial.h>
[177]54
[81]55#include <tables/Tables/Table.h>
56#include <tables/Tables/ScalarColumn.h>
57#include <tables/Tables/ArrayColumn.h>
[227]58#include <tables/Tables/ReadAsciiTable.h>
[2]59
[130]60#include <lattices/Lattices/LatticeUtilities.h>
61#include <lattices/Lattices/RebinLattice.h>
[81]62#include <coordinates/Coordinates/SpectralCoordinate.h>
[130]63#include <coordinates/Coordinates/CoordinateSystem.h>
64#include <coordinates/Coordinates/CoordinateUtil.h>
[221]65#include <coordinates/Coordinates/VelocityAligner.h>
[38]66
67#include "MathUtils.h"
[232]68#include "SDDefs.h"
[2]69#include "SDContainer.h"
70#include "SDMemTable.h"
71
72#include "SDMath.h"
73
[125]74using namespace casa;
[83]75using namespace asap;
[2]76
[170]77
78SDMath::SDMath()
79{;}
80
[185]81SDMath::SDMath(const SDMath& other)
[170]82{
83
84// No state
85
86}
87
88SDMath& SDMath::operator=(const SDMath& other)
89{
90 if (this != &other) {
91// No state
92 }
93 return *this;
94}
95
[183]96SDMath::~SDMath()
97{;}
[170]98
[183]99
[185]100CountedPtr<SDMemTable> SDMath::average(const Block<CountedPtr<SDMemTable> >& in,
101 const Vector<Bool>& mask, Bool scanAv,
[248]102 const String& weightStr, Bool alignVelocity) const
[130]103//
[144]104// Weighted averaging of spectra from one or more Tables.
[130]105//
106{
[2]107
[163]108// Convert weight type
109
110 WeightType wtType = NONE;
[185]111 convertWeightString(wtType, weightStr);
[163]112
[144]113// Create output Table by cloning from the first table
[2]114
[144]115 SDMemTable* pTabOut = new SDMemTable(*in[0],True);
[130]116
[144]117// Setup
[130]118
[144]119 IPosition shp = in[0]->rowAsMaskedArray(0).shape(); // Must not change
120 Array<Float> arr(shp);
121 Array<Bool> barr(shp);
[221]122 const Bool useMask = (mask.nelements() == shp(asap::ChanAxis));
[130]123
[144]124// Columns from Tables
[130]125
[144]126 ROArrayColumn<Float> tSysCol;
127 ROScalarColumn<Double> mjdCol;
128 ROScalarColumn<String> srcNameCol;
129 ROScalarColumn<Double> intCol;
130 ROArrayColumn<uInt> fqIDCol;
[130]131
[144]132// Create accumulation MaskedArray. We accumulate for each channel,if,pol,beam
133// Note that the mask of the accumulation array will ALWAYS remain ALL True.
134// The MA is only used so that when data which is masked Bad is added to it,
135// that data does not contribute.
136
137 Array<Float> zero(shp);
138 zero=0.0;
139 Array<Bool> good(shp);
140 good = True;
141 MaskedArray<Float> sum(zero,good);
142
143// Counter arrays
144
145 Array<Float> nPts(shp); // Number of points
146 nPts = 0.0;
147 Array<Float> nInc(shp); // Increment
148 nInc = 1.0;
149
150// Create accumulation Array for variance. We accumulate for
151// each if,pol,beam, but average over channel. So we need
152// a shape with one less axis dropping channels.
153
154 const uInt nAxesSub = shp.nelements() - 1;
155 IPosition shp2(nAxesSub);
156 for (uInt i=0,j=0; i<(nAxesSub+1); i++) {
[221]157 if (i!=asap::ChanAxis) {
[144]158 shp2(j) = shp(i);
159 j++;
160 }
[2]161 }
[144]162 Array<Float> sumSq(shp2);
163 sumSq = 0.0;
164 IPosition pos2(nAxesSub,0); // For indexing
[130]165
[144]166// Time-related accumulators
[130]167
[144]168 Double time;
169 Double timeSum = 0.0;
170 Double intSum = 0.0;
171 Double interval = 0.0;
[130]172
[144]173// To get the right shape for the Tsys accumulator we need to
174// access a column from the first table. The shape of this
175// array must not change
[130]176
[144]177 Array<Float> tSysSum;
178 {
179 const Table& tabIn = in[0]->table();
180 tSysCol.attach(tabIn,"TSYS");
181 tSysSum.resize(tSysCol.shape(0));
182 }
183 tSysSum =0.0;
184 Array<Float> tSys;
185
186// Scan and row tracking
187
188 Int oldScanID = 0;
189 Int outScanID = 0;
190 Int scanID = 0;
191 Int rowStart = 0;
192 Int nAccum = 0;
193 Int tableStart = 0;
194
195// Source and FreqID
196
197 String sourceName, oldSourceName, sourceNameStart;
198 Vector<uInt> freqID, freqIDStart, oldFreqID;
199
[221]200// Velocity Aligner. We need an aligner for each Direction and FreqID
201// combination. I don't think there is anyway to know how many
202// directions there are.
203// For now, assume all Tables have the same Frequency Table
204
205/*
206 {
207 MEpoch::Ref timeRef(MEpoch::UTC); // Should be in header
208 MDirection::Types dirRef(MDirection::J2000); // Should be in header
209//
210 SDHeader sh = in[0].getSDHeader();
211 const uInt nChan = sh.nchan;
212//
213 const SDFrequencyTable freqTab = in[0]->getSDFreqTable();
214 const uInt nFreqID = freqTab.length();
215 PtrBlock<const VelocityAligner<Float>* > vA(nFreqID);
216
217// Get first time from first table
218
219 const Table& tabIn0 = in[0]->table();
220 mjdCol.attach(tabIn0, "TIME");
221 Double dTmp;
222 mjdCol.get(0, dTmp);
223 MVEpoch tmp2(Quantum<Double>(dTmp, Unit(String("d"))));
224 MEpoch epoch(tmp2, timeRef);
225//
226 for (uInt freqID=0; freqID<nFreqID; freqID++) {
227 SpectralCoordinate sC = in[0]->getCoordinate(freqID);
228 vA[freqID] = new VelocityAligner<Float>(sC, nChan, epoch, const MDirection& dir,
229 const MPosition& pos, const String& velUnit,
230 MDoppler::Types velType, MFrequency::Types velFreqSystem)
231 }
232 }
233*/
234
[144]235// Loop over tables
236
237 Float fac = 1.0;
238 const uInt nTables = in.nelements();
239 for (uInt iTab=0; iTab<nTables; iTab++) {
240
[221]241// Should check that the frequency tables don't change if doing VelocityAlignment
242
[144]243// Attach columns to Table
244
245 const Table& tabIn = in[iTab]->table();
246 tSysCol.attach(tabIn, "TSYS");
247 mjdCol.attach(tabIn, "TIME");
248 srcNameCol.attach(tabIn, "SRCNAME");
249 intCol.attach(tabIn, "INTERVAL");
250 fqIDCol.attach(tabIn, "FREQID");
251
252// Loop over rows in Table
253
254 const uInt nRows = in[iTab]->nRow();
255 for (uInt iRow=0; iRow<nRows; iRow++) {
256
257// Check conformance
258
259 IPosition shp2 = in[iTab]->rowAsMaskedArray(iRow).shape();
260 if (!shp.isEqual(shp2)) {
261 throw (AipsError("Shapes for all rows must be the same"));
262 }
263
264// If we are not doing scan averages, make checks for source and
265// frequency setup and warn if averaging across them
266
267// Get copy of Scan Container for this row
268
269 SDContainer sc = in[iTab]->getSDContainer(iRow);
270 scanID = sc.scanid;
271
272// Get quantities from columns
273
274 srcNameCol.getScalar(iRow, sourceName);
275 mjdCol.get(iRow, time);
276 tSysCol.get(iRow, tSys);
277 intCol.get(iRow, interval);
278 fqIDCol.get(iRow, freqID);
279
280// Initialize first source and freqID
281
282 if (iRow==0 && iTab==0) {
283 sourceNameStart = sourceName;
284 freqIDStart = freqID;
285 }
286
287// If we are doing scan averages, see if we are at the end of an
288// accumulation period (scan). We must check soutce names too,
289// since we might have two tables with one scan each but different
290// source names; we shouldn't average different sources together
291
292 if (scanAv && ( (scanID != oldScanID) ||
293 (iRow==0 && iTab>0 && sourceName!=oldSourceName))) {
294
295// Normalize data in 'sum' accumulation array according to weighting scheme
296
[221]297 normalize(sum, sumSq, nPts, wtType, asap::ChanAxis, nAxesSub);
[144]298
299// Fill scan container. The source and freqID come from the
300// first row of the first table that went into this average (
301// should be the same for all rows in the scan average)
302
303 Float nR(nAccum);
[185]304 fillSDC(sc, sum.getMask(), sum.getArray(), tSysSum/nR, outScanID,
[144]305 timeSum/nR, intSum, sourceNameStart, freqIDStart);
306
307// Write container out to Table
308
309 pTabOut->putSDContainer(sc);
310
311// Reset accumulators
312
313 sum = 0.0;
314 sumSq = 0.0;
315 nAccum = 0;
316//
317 tSysSum =0.0;
318 timeSum = 0.0;
319 intSum = 0.0;
[221]320 nPts = 0.0;
[144]321
322// Increment
323
324 rowStart = iRow; // First row for next accumulation
325 tableStart = iTab; // First table for next accumulation
326 sourceNameStart = sourceName; // First source name for next accumulation
327 freqIDStart = freqID; // First FreqID for next accumulation
328//
329 oldScanID = scanID;
330 outScanID += 1; // Scan ID for next accumulation period
[227]331 }
[144]332
[146]333// Accumulate
[144]334
[185]335 accumulate(timeSum, intSum, nAccum, sum, sumSq, nPts, tSysSum,
[221]336 tSys, nInc, mask, time, interval, in, iTab, iRow, asap::ChanAxis,
[146]337 nAxesSub, useMask, wtType);
[144]338//
339 oldSourceName = sourceName;
340 oldFreqID = freqID;
[184]341 }
[144]342 }
343
344// OK at this point we have accumulation data which is either
345// - accumulated from all tables into one row
346// or
347// - accumulated from the last scan average
348//
349// Normalize data in 'sum' accumulation array according to weighting scheme
[221]350 normalize(sum, sumSq, nPts, wtType, asap::ChanAxis, nAxesSub);
[144]351
352// Create and fill container. The container we clone will be from
353// the last Table and the first row that went into the current
354// accumulation. It probably doesn't matter that much really...
355
356 Float nR(nAccum);
357 SDContainer sc = in[tableStart]->getSDContainer(rowStart);
[185]358 fillSDC(sc, sum.getMask(), sum.getArray(), tSysSum/nR, outScanID,
[144]359 timeSum/nR, intSum, sourceNameStart, freqIDStart);
[221]360 pTabOut->putSDContainer(sc);
[144]361//
362 return CountedPtr<SDMemTable>(pTabOut);
[2]363}
[9]364
[144]365
366
[248]367CountedPtr<SDMemTable> SDMath::binaryOperate (const CountedPtr<SDMemTable>& left,
368 const CountedPtr<SDMemTable>& right,
369 const String& op, Bool preserve) const
[185]370{
[85]371
[248]372// Check operator
[130]373
[234]374 String op2(op);
375 op2.upcase();
376 uInt what = 0;
377 if (op2=="ADD") {
378 what = 0;
379 } else if (op2=="SUB") {
380 what = 1;
381 } else if (op2=="MUL") {
382 what = 2;
383 } else if (op2=="DIV") {
384 what = 3;
[248]385 } else if (op2=="QUOTIENT") {
386 what = 4;
[234]387 } else {
[248]388 throw( AipsError("Unrecognized operation"));
[234]389 }
390
391// Check rows
392
[248]393 const uInt nRowLeft = left->nRow();
394 const uInt nRowRight = right->nRow();
395 Bool ok = (nRowRight==1&&nRowLeft>0) ||
396 (nRowRight>=1&&nRowLeft==nRowRight);
397 if (!ok) {
398 throw (AipsError("The right Scan Table can have one row or the same number of rows as the left Scan Table"));
[234]399 }
400
[248]401// Input Tables
[234]402
403 const Table& tLeft = left->table();
404 const Table& tRight = right->table();
[248]405
406// TSys columns
407
[234]408 ROArrayColumn<Float> tSysLeft(tLeft, "TSYS");
409 ROArrayColumn<Float> tSysRight(tRight, "TSYS");
410
[248]411// First row for right
[234]412
[248]413 Array<Float> tSysLeftArr, tSysRightArr;
414 tSysRight.get(0, tSysRightArr);
415 MaskedArray<Float>* pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(0));
416 IPosition shpRight = pMRight->shape();
417
418// Output Table cloned from left
419
[234]420 SDMemTable* pTabOut = new SDMemTable(*left, True);
421
422// Loop over rows
423
[248]424 for (uInt i=0; i<nRowLeft; i++) {
[234]425
426// Get data
[248]427
[234]428 MaskedArray<Float> mLeft(left->rowAsMaskedArray(i));
[248]429 IPosition shpLeft = mLeft.shape();
430 tSysLeft.get(i, tSysLeftArr);
[234]431//
[248]432 if (nRowRight>1) {
433 delete pMRight;
434 pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(i));
435 shpRight = pMRight->shape();
436 tSysRight.get(i, tSysRightArr);
[234]437 }
[248]438//
439 if (!shpRight.isEqual(shpLeft)) {
440 throw(AipsError("left and right scan tables are not conformant"));
441 }
442 if (!tSysRightArr.shape().isEqual(tSysRightArr.shape())) {
443 throw(AipsError("left and right Tsys data are not conformant"));
444 }
445 if (!shpRight.isEqual(tSysRightArr.shape())) {
446 throw(AipsError("left and right scan tables are not conformant"));
447 }
[234]448
449// Make container
450
451 SDContainer sc = left->getSDContainer(i);
452
453// Operate on data and TSys
454
455 if (what==0) {
[248]456 MaskedArray<Float> tmp = mLeft + *pMRight;
[234]457 putDataInSDC(sc, tmp.getArray(), tmp.getMask());
458 sc.putTsys(tSysLeftArr+tSysRightArr);
459 } else if (what==1) {
[248]460 MaskedArray<Float> tmp = mLeft - *pMRight;
[234]461 putDataInSDC(sc, tmp.getArray(), tmp.getMask());
462 sc.putTsys(tSysLeftArr-tSysRightArr);
463 } else if (what==2) {
[248]464 MaskedArray<Float> tmp = mLeft * *pMRight;
[234]465 putDataInSDC(sc, tmp.getArray(), tmp.getMask());
466 sc.putTsys(tSysLeftArr*tSysRightArr);
467 } else if (what==3) {
[248]468 MaskedArray<Float> tmp = mLeft / *pMRight;
[234]469 putDataInSDC(sc, tmp.getArray(), tmp.getMask());
470 sc.putTsys(tSysLeftArr/tSysRightArr);
[248]471 } else if (what==4) {
472 if (preserve) {
473 MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysRightArr;
474 putDataInSDC(sc, tmp.getArray(), tmp.getMask());
475 } else {
476 MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysLeftArr;
477 putDataInSDC(sc, tmp.getArray(), tmp.getMask());
478 }
479 sc.putTsys(tSysRightArr);
[234]480 }
481
482// Put new row in output Table
483
[171]484 pTabOut->putSDContainer(sc);
[130]485 }
[248]486 if (pMRight) delete pMRight;
[130]487//
[171]488 return CountedPtr<SDMemTable>(pTabOut);
[9]489}
[48]490
[146]491
492
[185]493std::vector<float> SDMath::statistic(const CountedPtr<SDMemTable>& in,
[234]494 const Vector<Bool>& mask,
495 const String& which, Int row) const
[130]496//
497// Perhaps iteration over pol/beam/if should be in here
498// and inside the nrow iteration ?
499//
500{
501 const uInt nRow = in->nRow();
502
503// Specify cursor location
504
[152]505 IPosition start, end;
[185]506 getCursorLocation(start, end, *in);
[130]507
508// Loop over rows
509
[234]510 const uInt nEl = mask.nelements();
511 uInt iStart = 0;
512 uInt iEnd = in->nRow()-1;
513//
514 if (row>=0) {
515 iStart = row;
516 iEnd = row;
517 }
518//
519 std::vector<float> result(iEnd-iStart+1);
520 for (uInt ii=iStart; ii <= iEnd; ++ii) {
[130]521
522// Get row and deconstruct
523
524 MaskedArray<Float> marr(in->rowAsMaskedArray(ii));
525 Array<Float> arr = marr.getArray();
526 Array<Bool> barr = marr.getMask();
527
528// Access desired piece of data
529
530 Array<Float> v((arr(start,end)).nonDegenerate());
531 Array<Bool> m((barr(start,end)).nonDegenerate());
532
533// Apply OTF mask
534
535 MaskedArray<Float> tmp;
536 if (m.nelements()==nEl) {
[234]537 tmp.setData(v,m&&mask);
[130]538 } else {
539 tmp.setData(v,m);
540 }
541
542// Get statistic
543
[234]544 result[ii-iStart] = mathutil::statistics(which, tmp);
[130]545 }
546//
547 return result;
548}
549
[146]550
[234]551SDMemTable* SDMath::bin(const SDMemTable& in, Int width) const
[144]552{
[169]553 SDHeader sh = in.getSDHeader();
554 SDMemTable* pTabOut = new SDMemTable(in, True);
[163]555
[169]556// Bin up SpectralCoordinates
[163]557
[169]558 IPosition factors(1);
559 factors(0) = width;
560 for (uInt j=0; j<in.nCoordinates(); ++j) {
561 CoordinateSystem cSys;
562 cSys.addCoordinate(in.getCoordinate(j));
563 CoordinateSystem cSysBin =
[185]564 CoordinateUtil::makeBinnedCoordinateSystem(factors, cSys, False);
[169]565//
566 SpectralCoordinate sCBin = cSysBin.spectralCoordinate(0);
567 pTabOut->setCoordinate(sCBin, j);
568 }
[163]569
[169]570// Use RebinLattice to find shape
[130]571
[169]572 IPosition shapeIn(1,sh.nchan);
[185]573 IPosition shapeOut = RebinLattice<Float>::rebinShape(shapeIn, factors);
[169]574 sh.nchan = shapeOut(0);
575 pTabOut->putSDHeader(sh);
[144]576
577
[169]578// Loop over rows and bin along channel axis
579
580 for (uInt i=0; i < in.nRow(); ++i) {
581 SDContainer sc = in.getSDContainer(i);
[144]582//
[169]583 Array<Float> tSys(sc.getTsys()); // Get it out before sc changes shape
[144]584
[169]585// Bin up spectrum
[144]586
[169]587 MaskedArray<Float> marr(in.rowAsMaskedArray(i));
588 MaskedArray<Float> marrout;
[221]589 LatticeUtilities::bin(marrout, marr, asap::ChanAxis, width);
[144]590
[169]591// Put back the binned data and flags
[144]592
[169]593 IPosition ip2 = marrout.shape();
594 sc.resize(ip2);
[146]595//
[185]596 putDataInSDC(sc, marrout.getArray(), marrout.getMask());
[146]597
[169]598// Bin up Tsys.
[146]599
[169]600 Array<Bool> allGood(tSys.shape(),True);
601 MaskedArray<Float> tSysIn(tSys, allGood, True);
[146]602//
[169]603 MaskedArray<Float> tSysOut;
[221]604 LatticeUtilities::bin(tSysOut, tSysIn, asap::ChanAxis, width);
[169]605 sc.putTsys(tSysOut.getArray());
[146]606//
[169]607 pTabOut->putSDContainer(sc);
608 }
609 return pTabOut;
[146]610}
611
[248]612SDMemTable* SDMath::unaryOperate(const SDMemTable& in, Float val, Bool doAll,
613 uInt what) const
[152]614//
615// what = 0 Multiply
616// 1 Add
[146]617{
[152]618 SDMemTable* pOut = new SDMemTable(in,False);
619 const Table& tOut = pOut->table();
620 ArrayColumn<Float> spec(tOut,"SPECTRA");
[146]621//
[152]622 if (doAll) {
623 for (uInt i=0; i < tOut.nrow(); i++) {
624
625// Get
626
627 MaskedArray<Float> marr(pOut->rowAsMaskedArray(i));
628
629// Operate
630
631 if (what==0) {
632 marr *= val;
633 } else if (what==1) {
634 marr += val;
635 }
636
637// Put
638
639 spec.put(i, marr.getArray());
640 }
641 } else {
642
643// Get cursor location
644
645 IPosition start, end;
[185]646 getCursorLocation(start, end, in);
[152]647//
648 for (uInt i=0; i < tOut.nrow(); i++) {
649
650// Get
651
652 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i));
653
654// Modify. More work than we would like to deal with the mask
655
656 Array<Float>& values = dataIn.getRWArray();
657 Array<Bool> mask(dataIn.getMask());
658//
659 Array<Float> values2 = values(start,end);
660 Array<Bool> mask2 = mask(start,end);
661 MaskedArray<Float> t(values2,mask2);
662 if (what==0) {
663 t *= val;
664 } else if (what==1) {
665 t += val;
666 }
667 values(start, end) = t.getArray(); // Write back into 'dataIn'
668
669// Put
670 spec.put(i, dataIn.getArray());
671 }
672 }
673//
[146]674 return pOut;
675}
676
677
[152]678
[234]679SDMemTable* SDMath::averagePol(const SDMemTable& in, const Vector<Bool>& mask) const
[152]680//
[165]681// Average all polarizations together, weighted by variance
682//
683{
684// WeightType wtType = NONE;
[185]685// convertWeightString(wtType, weight);
[165]686
687 const uInt nRows = in.nRow();
[209]688 const uInt polAxis = asap::PolAxis; // Polarization axis
689 const uInt chanAxis = asap::ChanAxis; // Spectrum axis
[165]690
691// Create output Table and reshape number of polarizations
692
693 Bool clear=True;
694 SDMemTable* pTabOut = new SDMemTable(in, clear);
695 SDHeader header = pTabOut->getSDHeader();
696 header.npol = 1;
697 pTabOut->putSDHeader(header);
698
699// Shape of input and output data
700
701 const IPosition& shapeIn = in.rowAsMaskedArray(0u, False).shape();
702 IPosition shapeOut(shapeIn);
703 shapeOut(polAxis) = 1; // Average all polarizations
704//
705 const uInt nChan = shapeIn(chanAxis);
706 const IPosition vecShapeOut(4,1,1,1,nChan); // A multi-dim form of a Vector shape
707 IPosition start(4), end(4);
708
709// Output arrays
710
711 Array<Float> outData(shapeOut, 0.0);
712 Array<Bool> outMask(shapeOut, True);
713 const IPosition axes(2, 2, 3); // pol-channel plane
714//
715 const Bool useMask = (mask.nelements() == shapeIn(chanAxis));
716
717// Loop over rows
718
719 for (uInt iRow=0; iRow<nRows; iRow++) {
720
721// Get data for this row
722
723 MaskedArray<Float> marr(in.rowAsMaskedArray(iRow));
724 Array<Float>& arr = marr.getRWArray();
725 const Array<Bool>& barr = marr.getMask();
726
727// Make iterators to iterate by pol-channel planes
728
729 ReadOnlyArrayIterator<Float> itDataPlane(arr, axes);
730 ReadOnlyArrayIterator<Bool> itMaskPlane(barr, axes);
731
732// Accumulations
733
734 Float fac = 1.0;
735 Vector<Float> vecSum(nChan,0.0);
736
737// Iterate through data by pol-channel planes
738
739 while (!itDataPlane.pastEnd()) {
740
741// Iterate through plane by polarization and accumulate Vectors
742
743 Vector<Float> t1(nChan); t1 = 0.0;
744 Vector<Bool> t2(nChan); t2 = True;
745 MaskedArray<Float> vecSum(t1,t2);
746 Float varSum = 0.0;
747 {
748 ReadOnlyVectorIterator<Float> itDataVec(itDataPlane.array(), 1);
749 ReadOnlyVectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1);
750 while (!itDataVec.pastEnd()) {
751
752// Create MA of data & mask (optionally including OTF mask) and get variance
753
754 if (useMask) {
755 const MaskedArray<Float> spec(itDataVec.vector(),mask&&itMaskVec.vector());
756 fac = 1.0 / variance(spec);
757 } else {
758 const MaskedArray<Float> spec(itDataVec.vector(),itMaskVec.vector());
759 fac = 1.0 / variance(spec);
760 }
761
762// Normalize spectrum (without OTF mask) and accumulate
763
764 const MaskedArray<Float> spec(fac*itDataVec.vector(), itMaskVec.vector());
765 vecSum += spec;
766 varSum += fac;
767
768// Next
769
770 itDataVec.next();
771 itMaskVec.next();
772 }
773 }
774
775// Normalize summed spectrum
776
777 vecSum /= varSum;
778
779// FInd position in input data array. We are iterating by pol-channel
780// plane so all that will change is beam and IF and that's what we want.
781
782 IPosition pos = itDataPlane.pos();
783
784// Write out data. This is a bit messy. We have to reform the Vector
785// accumulator into an Array of shape (1,1,1,nChan)
786
787 start = pos;
788 end = pos;
789 end(chanAxis) = nChan-1;
790 outData(start,end) = vecSum.getArray().reform(vecShapeOut);
791 outMask(start,end) = vecSum.getMask().reform(vecShapeOut);
792
793// Step to next beam/IF combination
794
795 itDataPlane.next();
796 itMaskPlane.next();
797 }
798
799// Generate output container and write it to output table
800
801 SDContainer sc = in.getSDContainer();
802 sc.resize(shapeOut);
803//
[185]804 putDataInSDC(sc, outData, outMask);
[165]805 pTabOut->putSDContainer(sc);
806 }
807//
808 return pTabOut;
809}
[167]810
[169]811
[185]812SDMemTable* SDMath::smooth(const SDMemTable& in,
813 const casa::String& kernelType,
[234]814 casa::Float width, Bool doAll) const
[177]815{
[169]816
[177]817// Number of channels
[169]818
[209]819 const uInt chanAxis = asap::ChanAxis; // Spectral axis
[177]820 SDHeader sh = in.getSDHeader();
821 const uInt nChan = sh.nchan;
822
823// Generate Kernel
824
[185]825 VectorKernel::KernelTypes type = VectorKernel::toKernelType(kernelType);
[177]826 Vector<Float> kernel = VectorKernel::make(type, width, nChan, True, False);
827
828// Generate Convolver
829
830 IPosition shape(1,nChan);
831 Convolver<Float> conv(kernel, shape);
832
833// New Table
834
835 SDMemTable* pTabOut = new SDMemTable(in,True);
836
837// Get cursor location
838
839 IPosition start, end;
[185]840 getCursorLocation(start, end, in);
[177]841//
842 IPosition shapeOut(4,1);
843
844// Output Vectors
845
846 Vector<Float> valuesOut(nChan);
847 Vector<Bool> maskOut(nChan);
848
849// Loop over rows in Table
850
851 for (uInt ri=0; ri < in.nRow(); ++ri) {
852
853// Get copy of data
854
855 const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri));
856 AlwaysAssert(dataIn.shape()(chanAxis)==nChan, AipsError);
857//
858 Array<Float> valuesIn = dataIn.getArray();
859 Array<Bool> maskIn = dataIn.getMask();
860
861// Branch depending on whether we smooth all locations or just
862// those pointed at by the current selection cursor
863
864 if (doAll) {
[221]865 uInt axis = asap::ChanAxis;
[177]866 VectorIterator<Float> itValues(valuesIn, axis);
867 VectorIterator<Bool> itMask(maskIn, axis);
868 while (!itValues.pastEnd()) {
869
870// Smooth
871 if (kernelType==VectorKernel::HANNING) {
872 mathutil::hanning(valuesOut, maskOut, itValues.vector(), itMask.vector());
873 itMask.vector() = maskOut;
874 } else {
875 mathutil::replaceMaskByZero(itValues.vector(), itMask.vector());
876 conv.linearConv(valuesOut, itValues.vector());
877 }
878//
879 itValues.vector() = valuesOut;
880//
881 itValues.next();
882 itMask.next();
883 }
884 } else {
885
886// Set multi-dim Vector shape
887
888 shapeOut(chanAxis) = valuesIn.shape()(chanAxis);
889
890// Stuff about with shapes so that we don't have conformance run-time errors
891
892 Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate();
893 Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate();
894
895// Smooth
896
897 if (kernelType==VectorKernel::HANNING) {
898 mathutil::hanning(valuesOut, maskOut, valuesIn2, maskIn2);
899 maskIn(start,end) = maskOut.reform(shapeOut);
900 } else {
901 mathutil::replaceMaskByZero(valuesIn2, maskIn2);
902 conv.linearConv(valuesOut, valuesIn2);
903 }
904//
905 valuesIn(start,end) = valuesOut.reform(shapeOut);
906 }
907
908// Create and put back
909
910 SDContainer sc = in.getSDContainer(ri);
[185]911 putDataInSDC(sc, valuesIn, maskIn);
[177]912//
913 pTabOut->putSDContainer(sc);
914 }
915//
916 return pTabOut;
917}
918
919
[234]920SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float a, Float eta, Bool doAll) const
[221]921//
922// As it is, this function could be implemented with 'simpleOperate'
923// However, I anticipate that eventually we will look the conversion
924// values up in a Table and apply them in a frequency dependent way,
925// so I have implemented it fully here
926//
927{
928 SDHeader sh = in.getSDHeader();
929 SDMemTable* pTabOut = new SDMemTable(in, True);
[177]930
[221]931// FInd out how to convert values into Jy and K (e.g. units might be mJy or mK)
932// Also automatically find out what we are converting to according to the
933// flux unit
[177]934
[221]935 Unit fluxUnit(sh.fluxunit);
936 Unit K(String("K"));
937 Unit JY(String("Jy"));
938//
939 Bool toKelvin = True;
940 Double inFac = 1.0;
941 if (fluxUnit==JY) {
942 cerr << "Converting to K" << endl;
943//
944 Quantum<Double> t(1.0,fluxUnit);
945 Quantum<Double> t2 = t.get(JY);
946 inFac = (t2 / t).getValue();
947//
948 toKelvin = True;
949 sh.fluxunit = "K";
950 } else if (fluxUnit==K) {
951 cerr << "Converting to Jy" << endl;
952//
953 Quantum<Double> t(1.0,fluxUnit);
954 Quantum<Double> t2 = t.get(K);
955 inFac = (t2 / t).getValue();
956//
957 toKelvin = False;
958 sh.fluxunit = "Jy";
959 } else {
[248]960 throw(AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K"));
[221]961 }
962 pTabOut->putSDHeader(sh);
[177]963
[221]964// Compute conversion factor. 'a' and 'eta' are really frequency, time and
965// telescope dependent and should be looked// up in a table
966
[234]967 Float factor = 2.0 * inFac * 1.0e-7 * 1.0e26 *
968 QC::k.getValue(Unit(String("erg/K"))) / a / eta;
[221]969 if (toKelvin) {
970 factor = 1.0 / factor;
971 }
972 cerr << "Applying conversion factor = " << factor << endl;
973
974// For operations only on specified cursor location
975
976 IPosition start, end;
977 getCursorLocation(start, end, in);
978
979// Loop over rows and apply factor to spectra
980
981 const uInt axis = asap::ChanAxis;
982 for (uInt i=0; i < in.nRow(); ++i) {
983
984// Get data
985
986 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i));
987 Array<Float>& valuesIn = dataIn.getRWArray(); // writable reference
988 const Array<Bool>& maskIn = dataIn.getMask();
989
990// Need to apply correct conversion factor (frequency and time dependent)
991// which should be sourced from a Table. For now we just apply the given
992// factor to everything
993
994 if (doAll) {
995 VectorIterator<Float> itValues(valuesIn, asap::ChanAxis);
996 while (!itValues.pastEnd()) {
997 itValues.vector() *= factor; // Writes back into dataIn
998//
999 itValues.next();
1000 }
1001 } else {
1002 Array<Float> valuesIn2 = valuesIn(start,end);
1003 valuesIn2 *= factor;
1004 valuesIn(start,end) = valuesIn2;
1005 }
1006
1007// Write out
1008
1009 SDContainer sc = in.getSDContainer(i);
1010 putDataInSDC(sc, valuesIn, maskIn);
1011//
1012 pTabOut->putSDContainer(sc);
1013 }
1014 return pTabOut;
1015}
1016
1017
1018
[234]1019SDMemTable* SDMath::gainElevation (const SDMemTable& in, const Vector<Float>& coeffs,
1020 const String& fileName,
1021 const String& methodStr, Bool doAll) const
[227]1022{
[234]1023
1024// Get header and clone output table
1025
[227]1026 SDHeader sh = in.getSDHeader();
1027 SDMemTable* pTabOut = new SDMemTable(in, True);
1028
[234]1029// Get elevation data from SDMemTable and convert to degrees
[227]1030
1031 const Table& tab = in.table();
1032 ROScalarColumn<Float> elev(tab, "ELEVATION");
[234]1033 Vector<Float> x = elev.getColumn();
1034 x *= Float(180 / C::pi);
[227]1035//
[234]1036 const uInt nC = coeffs.nelements();
1037 if (fileName.length()>0 && nC>0) {
[248]1038 throw(AipsError("You must choose either polynomial coefficients or an ascii file, not both"));
[234]1039 }
1040
1041// Correct
1042
1043 if (nC>0 || fileName.length()==0) {
1044
1045// Find instrument
1046
1047 Bool throwIt = True;
1048 Instrument inst = SDMemTable::convertInstrument (sh.antennaname, throwIt);
1049
1050// Set polynomial
1051
1052 Polynomial<Float>* pPoly = 0;
1053 Vector<Float> coeff;
1054 String msg;
1055 if (nC>0) {
1056 pPoly = new Polynomial<Float>(nC);
1057 coeff = coeffs;
1058 msg = String("user");
1059 } else {
1060 if (inst==PKSMULTIBEAM) {
1061 } else if (inst==PKSSINGLEBEAM) {
1062 } else if (inst==TIDBINBILLA) {
1063 pPoly = new Polynomial<Float>(3);
1064 coeff.resize(3);
1065 coeff(0) = 3.58788e-1;
1066 coeff(1) = 2.87243e-2;
1067 coeff(2) = -3.219093e-4;
1068 } else if (inst==MOPRA) {
1069 }
1070 msg = String("built in");
1071 }
[227]1072//
[234]1073 if (coeff.nelements()>0) {
1074 pPoly->setCoefficients(coeff);
1075 } else {
[248]1076 throw(AipsError("There is no known gain-el polynomial known for this instrument"));
[234]1077 }
1078//
1079 cerr << "Making polynomial correction with " << msg << " coefficients" << endl;
1080 const uInt nRow = in.nRow();
1081 Vector<Float> factor(nRow);
1082 for (uInt i=0; i<nRow; i++) {
1083 factor[i] = (*pPoly)(x[i]);
1084 }
1085 delete pPoly;
1086//
1087 correctFromVector (pTabOut, in, doAll, factor);
1088 } else {
1089
1090// Indicate which columns to read from ascii file
1091
1092 String col0("ELEVATION");
1093 String col1("FACTOR");
1094
1095// Read and correct
1096
1097 cerr << "Making correction from ascii Table" << endl;
1098 correctFromAsciiTable (pTabOut, in, fileName, col0, col1,
1099 methodStr, doAll, x);
1100 }
1101//
1102 return pTabOut;
[230]1103}
[227]1104
[230]1105
[227]1106
[234]1107SDMemTable* SDMath::opacity (const SDMemTable& in, Float tau, Bool doAll) const
1108{
[227]1109
[234]1110// Get header and clone output table
[227]1111
[234]1112 SDHeader sh = in.getSDHeader();
1113 SDMemTable* pTabOut = new SDMemTable(in, True);
1114
1115// Get elevation data from SDMemTable and convert to degrees
1116
1117 const Table& tab = in.table();
1118 ROScalarColumn<Float> elev(tab, "ELEVATION");
1119 Vector<Float> zDist = elev.getColumn();
1120 zDist = Float(C::pi_2) - zDist;
1121
1122// Generate correction factor
1123
1124 const uInt nRow = in.nRow();
1125 Vector<Float> factor(nRow);
1126 Vector<Float> factor2(nRow);
1127 for (uInt i=0; i<nRow; i++) {
1128 factor[i] = exp(tau)/cos(zDist[i]);
1129 }
1130
1131// Correct
1132
1133 correctFromVector (pTabOut, in, doAll, factor);
1134//
1135 return pTabOut;
1136}
1137
1138
1139
1140
[169]1141// 'private' functions
1142
[185]1143void SDMath::fillSDC(SDContainer& sc,
1144 const Array<Bool>& mask,
1145 const Array<Float>& data,
1146 const Array<Float>& tSys,
1147 Int scanID, Double timeStamp,
1148 Double interval, const String& sourceName,
[227]1149 const Vector<uInt>& freqID) const
[167]1150{
[169]1151// Data and mask
[167]1152
[185]1153 putDataInSDC(sc, data, mask);
[167]1154
[169]1155// TSys
1156
1157 sc.putTsys(tSys);
1158
1159// Time things
1160
1161 sc.timestamp = timeStamp;
1162 sc.interval = interval;
1163 sc.scanid = scanID;
[167]1164//
[169]1165 sc.sourcename = sourceName;
1166 sc.putFreqMap(freqID);
1167}
[167]1168
[185]1169void SDMath::normalize(MaskedArray<Float>& sum,
[169]1170 const Array<Float>& sumSq,
1171 const Array<Float>& nPts,
1172 WeightType wtType, Int axis,
[227]1173 Int nAxesSub) const
[169]1174{
1175 IPosition pos2(nAxesSub,0);
1176//
1177 if (wtType==NONE) {
[167]1178
[169]1179// We just average by the number of points accumulated.
1180// We need to make a MA out of nPts so that no divide by
1181// zeros occur
[167]1182
[169]1183 MaskedArray<Float> t(nPts, (nPts>Float(0.0)));
1184 sum /= t;
1185 } else if (wtType==VAR) {
[167]1186
[169]1187// Normalize each spectrum by sum(1/var) where the variance
1188// is worked out for each spectrum
1189
1190 Array<Float>& data = sum.getRWArray();
1191 VectorIterator<Float> itData(data, axis);
1192 while (!itData.pastEnd()) {
1193 pos2 = itData.pos().getFirst(nAxesSub);
1194 itData.vector() /= sumSq(pos2);
1195 itData.next();
1196 }
1197 } else if (wtType==TSYS) {
1198 }
1199}
1200
1201
[185]1202void SDMath::accumulate(Double& timeSum, Double& intSum, Int& nAccum,
1203 MaskedArray<Float>& sum, Array<Float>& sumSq,
1204 Array<Float>& nPts, Array<Float>& tSysSum,
1205 const Array<Float>& tSys, const Array<Float>& nInc,
1206 const Vector<Bool>& mask, Double time, Double interval,
1207 const Block<CountedPtr<SDMemTable> >& in,
1208 uInt iTab, uInt iRow, uInt axis,
1209 uInt nAxesSub, Bool useMask,
[227]1210 WeightType wtType) const
[169]1211{
1212
1213// Get data
1214
1215 MaskedArray<Float> dataIn(in[iTab]->rowAsMaskedArray(iRow));
1216 Array<Float>& valuesIn = dataIn.getRWArray(); // writable reference
1217 const Array<Bool>& maskIn = dataIn.getMask(); // RO reference
[167]1218//
[169]1219 if (wtType==NONE) {
1220 const MaskedArray<Float> n(nInc,dataIn.getMask());
1221 nPts += n; // Only accumulates where mask==T
1222 } else if (wtType==VAR) {
[167]1223
[169]1224// We are going to average the data, weighted by the noise for each pol, beam and IF.
1225// So therefore we need to iterate through by spectrum (axis 3)
[167]1226
[169]1227 VectorIterator<Float> itData(valuesIn, axis);
1228 ReadOnlyVectorIterator<Bool> itMask(maskIn, axis);
1229 Float fac = 1.0;
1230 IPosition pos(nAxesSub,0);
1231//
1232 while (!itData.pastEnd()) {
[167]1233
[169]1234// Make MaskedArray of Vector, optionally apply OTF mask, and find scaling factor
[167]1235
[169]1236 if (useMask) {
1237 MaskedArray<Float> tmp(itData.vector(),mask&&itMask.vector());
1238 fac = 1.0/variance(tmp);
1239 } else {
1240 MaskedArray<Float> tmp(itData.vector(),itMask.vector());
1241 fac = 1.0/variance(tmp);
1242 }
1243
1244// Scale data
1245
1246 itData.vector() *= fac; // Writes back into 'dataIn'
[167]1247//
[169]1248// Accumulate variance per if/pol/beam averaged over spectrum
1249// This method to get pos2 from itData.pos() is only valid
1250// because the spectral axis is the last one (so we can just
1251// copy the first nAXesSub positions out)
[167]1252
[169]1253 pos = itData.pos().getFirst(nAxesSub);
1254 sumSq(pos) += fac;
1255//
1256 itData.next();
1257 itMask.next();
1258 }
1259 } else if (wtType==TSYS) {
1260 }
[167]1261
[169]1262// Accumulate sum of (possibly scaled) data
1263
1264 sum += dataIn;
1265
1266// Accumulate Tsys, time, and interval
1267
1268 tSysSum += tSys;
1269 timeSum += time;
1270 intSum += interval;
1271 nAccum += 1;
1272}
1273
1274
1275
1276
[185]1277void SDMath::getCursorLocation(IPosition& start, IPosition& end,
[227]1278 const SDMemTable& in) const
[169]1279{
1280 const uInt nDim = 4;
1281 const uInt i = in.getBeam();
1282 const uInt j = in.getIF();
1283 const uInt k = in.getPol();
1284 const uInt n = in.nChan();
[167]1285//
[169]1286 start.resize(nDim);
1287 start(0) = i;
1288 start(1) = j;
1289 start(2) = k;
1290 start(3) = 0;
[167]1291//
[169]1292 end.resize(nDim);
1293 end(0) = i;
1294 end(1) = j;
1295 end(2) = k;
1296 end(3) = n-1;
1297}
1298
1299
[227]1300void SDMath::convertWeightString(WeightType& wtType, const String& weightStr) const
[169]1301{
1302 String tStr(weightStr);
1303 tStr.upcase();
1304 if (tStr.contains(String("NONE"))) {
1305 wtType = NONE;
1306 } else if (tStr.contains(String("VAR"))) {
1307 wtType = VAR;
1308 } else if (tStr.contains(String("TSYS"))) {
1309 wtType = TSYS;
[185]1310 throw(AipsError("T_sys weighting not yet implemented"));
[169]1311 } else {
[185]1312 throw(AipsError("Unrecognized weighting type"));
[167]1313 }
1314}
1315
[227]1316void SDMath::convertInterpString(Int& type, const String& interp) const
1317{
1318 String tStr(interp);
1319 tStr.upcase();
1320 if (tStr.contains(String("NEAR"))) {
1321 type = InterpolateArray1D<Float,Float>::nearestNeighbour;
1322 } else if (tStr.contains(String("LIN"))) {
1323 type = InterpolateArray1D<Float,Float>::linear;
1324 } else if (tStr.contains(String("CUB"))) {
1325 type = InterpolateArray1D<Float,Float>::cubic;
1326 } else if (tStr.contains(String("SPL"))) {
1327 type = InterpolateArray1D<Float,Float>::spline;
1328 } else {
1329 throw(AipsError("Unrecognized interpolation type"));
1330 }
1331}
1332
[185]1333void SDMath::putDataInSDC(SDContainer& sc, const Array<Float>& data,
[227]1334 const Array<Bool>& mask) const
[169]1335{
1336 sc.putSpectrum(data);
1337//
1338 Array<uChar> outflags(data.shape());
1339 convertArray(outflags,!mask);
1340 sc.putFlags(outflags);
1341}
[227]1342
1343Table SDMath::readAsciiFile (const String& fileName) const
1344{
[230]1345 String formatString;
1346 Table tbl = readAsciiTable (formatString, Table::Memory, fileName, "", "", False);
[227]1347 return tbl;
1348}
[230]1349
1350
[234]1351
1352void SDMath::correctFromAsciiTable(SDMemTable* pTabOut,
1353 const SDMemTable& in, const String& fileName,
1354 const String& col0, const String& col1,
1355 const String& methodStr, Bool doAll,
1356 const Vector<Float>& xOut) const
[230]1357{
1358
1359// Read gain-elevation ascii file data into a Table.
1360
[234]1361 Table geTable = readAsciiFile (fileName);
[230]1362//
[234]1363 correctFromTable (pTabOut, in, geTable, col0, col1, methodStr, doAll, xOut);
[230]1364}
1365
[234]1366void SDMath::correctFromTable(SDMemTable* pTabOut, const SDMemTable& in,
1367 const Table& tTable, const String& col0,
1368 const String& col1,
1369 const String& methodStr, Bool doAll,
1370 const Vector<Float>& xOut) const
[230]1371{
1372
1373// Get data from Table
1374
1375 ROScalarColumn<Float> geElCol(tTable, col0);
1376 ROScalarColumn<Float> geFacCol(tTable, col1);
1377 Vector<Float> xIn = geElCol.getColumn();
1378 Vector<Float> yIn = geFacCol.getColumn();
1379 Vector<Bool> maskIn(xIn.nelements(),True);
1380
1381// Interpolate (and extrapolate) with desired method
1382
1383 Int method = 0;
1384 convertInterpString(method, methodStr);
1385//
1386 Vector<Float> yOut;
1387 Vector<Bool> maskOut;
1388 InterpolateArray1D<Float,Float>::interpolate(yOut, maskOut, xOut,
1389 xIn, yIn, maskIn, method,
1390 True, True);
[234]1391// Apply
[230]1392
[234]1393 correctFromVector (pTabOut, in, doAll, yOut);
1394}
1395
1396
1397void SDMath::correctFromVector (SDMemTable* pTabOut, const SDMemTable& in,
1398 Bool doAll, const Vector<Float>& factor) const
1399{
[230]1400// For operations only on specified cursor location
1401
1402 IPosition start, end;
1403 getCursorLocation(start, end, in);
1404
1405// Loop over rows and interpolate correction factor
1406
1407 const uInt axis = asap::ChanAxis;
1408 for (uInt i=0; i < in.nRow(); ++i) {
1409
1410// Get data
1411
1412 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i));
[234]1413 Array<Float>& valuesIn = dataIn.getRWArray();
[230]1414 const Array<Bool>& maskIn = dataIn.getMask();
1415
1416// Apply factor
1417
1418 if (doAll) {
1419 VectorIterator<Float> itValues(valuesIn, asap::ChanAxis);
1420 while (!itValues.pastEnd()) {
[234]1421 itValues.vector() *= factor(i);
[230]1422 itValues.next();
1423 }
1424 } else {
1425 Array<Float> valuesIn2 = valuesIn(start,end);
[234]1426 valuesIn2 *= factor(i);
[230]1427 valuesIn(start,end) = valuesIn2;
1428 }
1429
1430// Write out
1431
1432 SDContainer sc = in.getSDContainer(i);
1433 putDataInSDC(sc, valuesIn, maskIn);
1434//
1435 pTabOut->putSDContainer(sc);
1436 }
1437}
1438
[234]1439
Note: See TracBrowser for help on using the repository browser.