[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> |
---|
[262] | 46 | #include <casa/Exceptions.h> |
---|
| 47 | #include <casa/Quanta/Quantum.h> |
---|
| 48 | #include <casa/Quanta/Unit.h> |
---|
| 49 | #include <casa/Quanta/MVEpoch.h> |
---|
[221] | 50 | #include <casa/Quanta/QC.h> |
---|
[272] | 51 | #include <casa/Quanta/MVTime.h> |
---|
[177] | 52 | #include <casa/Utilities/Assert.h> |
---|
[2] | 53 | |
---|
[262] | 54 | #include <coordinates/Coordinates/SpectralCoordinate.h> |
---|
| 55 | #include <coordinates/Coordinates/CoordinateSystem.h> |
---|
| 56 | #include <coordinates/Coordinates/CoordinateUtil.h> |
---|
[309] | 57 | #include <coordinates/Coordinates/FrequencyAligner.h> |
---|
[262] | 58 | |
---|
| 59 | #include <lattices/Lattices/LatticeUtilities.h> |
---|
| 60 | #include <lattices/Lattices/RebinLattice.h> |
---|
| 61 | |
---|
| 62 | #include <measures/Measures/MEpoch.h> |
---|
| 63 | #include <measures/Measures/MDirection.h> |
---|
| 64 | #include <measures/Measures/MPosition.h> |
---|
| 65 | |
---|
[177] | 66 | #include <scimath/Mathematics/VectorKernel.h> |
---|
| 67 | #include <scimath/Mathematics/Convolver.h> |
---|
[227] | 68 | #include <scimath/Mathematics/InterpolateArray1D.h> |
---|
[234] | 69 | #include <scimath/Functionals/Polynomial.h> |
---|
[177] | 70 | |
---|
[81] | 71 | #include <tables/Tables/Table.h> |
---|
| 72 | #include <tables/Tables/ScalarColumn.h> |
---|
| 73 | #include <tables/Tables/ArrayColumn.h> |
---|
[227] | 74 | #include <tables/Tables/ReadAsciiTable.h> |
---|
[2] | 75 | |
---|
[38] | 76 | #include "MathUtils.h" |
---|
[232] | 77 | #include "SDDefs.h" |
---|
[2] | 78 | #include "SDContainer.h" |
---|
| 79 | #include "SDMemTable.h" |
---|
| 80 | |
---|
| 81 | #include "SDMath.h" |
---|
| 82 | |
---|
[125] | 83 | using namespace casa; |
---|
[83] | 84 | using namespace asap; |
---|
[2] | 85 | |
---|
[170] | 86 | |
---|
| 87 | SDMath::SDMath() |
---|
| 88 | {;} |
---|
| 89 | |
---|
[185] | 90 | SDMath::SDMath(const SDMath& other) |
---|
[170] | 91 | { |
---|
| 92 | |
---|
| 93 | // No state |
---|
| 94 | |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | SDMath& SDMath::operator=(const SDMath& other) |
---|
| 98 | { |
---|
| 99 | if (this != &other) { |
---|
| 100 | // No state |
---|
| 101 | } |
---|
| 102 | return *this; |
---|
| 103 | } |
---|
| 104 | |
---|
[183] | 105 | SDMath::~SDMath() |
---|
| 106 | {;} |
---|
[170] | 107 | |
---|
[183] | 108 | |
---|
[262] | 109 | |
---|
[309] | 110 | SDMemTable* SDMath::frequencyAlignment (const SDMemTable& in, const String& refTime) const |
---|
[262] | 111 | { |
---|
| 112 | |
---|
[309] | 113 | // Get frame info from Table |
---|
[262] | 114 | |
---|
| 115 | std::vector<std::string> info = in.getCoordInfo(); |
---|
[294] | 116 | |
---|
[309] | 117 | // Parse frequency system |
---|
[294] | 118 | |
---|
[309] | 119 | String systemStr(info[1]); |
---|
| 120 | String baseSystemStr(info[3]); |
---|
| 121 | if (baseSystemStr==systemStr) { |
---|
| 122 | throw(AipsError("You have not set a frequency frame different from the initial - use function set_freqframe")); |
---|
[262] | 123 | } |
---|
[309] | 124 | // |
---|
| 125 | MFrequency::Types freqSystem; |
---|
| 126 | MFrequency::getType(freqSystem, systemStr); |
---|
[294] | 127 | |
---|
[267] | 128 | // Do it |
---|
[262] | 129 | |
---|
[309] | 130 | return frequencyAlign (in, freqSystem, refTime); |
---|
[267] | 131 | } |
---|
[262] | 132 | |
---|
| 133 | |
---|
| 134 | |
---|
[185] | 135 | CountedPtr<SDMemTable> SDMath::average(const Block<CountedPtr<SDMemTable> >& in, |
---|
| 136 | const Vector<Bool>& mask, Bool scanAv, |
---|
[309] | 137 | const String& weightStr, Bool alignFreq) const |
---|
[130] | 138 | // |
---|
[144] | 139 | // Weighted averaging of spectra from one or more Tables. |
---|
[130] | 140 | // |
---|
| 141 | { |
---|
[2] | 142 | |
---|
[163] | 143 | // Convert weight type |
---|
| 144 | |
---|
| 145 | WeightType wtType = NONE; |
---|
[185] | 146 | convertWeightString(wtType, weightStr); |
---|
[163] | 147 | |
---|
[144] | 148 | // Create output Table by cloning from the first table |
---|
[2] | 149 | |
---|
[144] | 150 | SDMemTable* pTabOut = new SDMemTable(*in[0],True); |
---|
[130] | 151 | |
---|
[144] | 152 | // Setup |
---|
[130] | 153 | |
---|
[144] | 154 | IPosition shp = in[0]->rowAsMaskedArray(0).shape(); // Must not change |
---|
| 155 | Array<Float> arr(shp); |
---|
| 156 | Array<Bool> barr(shp); |
---|
[221] | 157 | const Bool useMask = (mask.nelements() == shp(asap::ChanAxis)); |
---|
[130] | 158 | |
---|
[144] | 159 | // Columns from Tables |
---|
[130] | 160 | |
---|
[144] | 161 | ROArrayColumn<Float> tSysCol; |
---|
| 162 | ROScalarColumn<Double> mjdCol; |
---|
| 163 | ROScalarColumn<String> srcNameCol; |
---|
| 164 | ROScalarColumn<Double> intCol; |
---|
| 165 | ROArrayColumn<uInt> fqIDCol; |
---|
[130] | 166 | |
---|
[144] | 167 | // Create accumulation MaskedArray. We accumulate for each channel,if,pol,beam |
---|
| 168 | // Note that the mask of the accumulation array will ALWAYS remain ALL True. |
---|
| 169 | // The MA is only used so that when data which is masked Bad is added to it, |
---|
| 170 | // that data does not contribute. |
---|
| 171 | |
---|
| 172 | Array<Float> zero(shp); |
---|
| 173 | zero=0.0; |
---|
| 174 | Array<Bool> good(shp); |
---|
| 175 | good = True; |
---|
| 176 | MaskedArray<Float> sum(zero,good); |
---|
| 177 | |
---|
| 178 | // Counter arrays |
---|
| 179 | |
---|
| 180 | Array<Float> nPts(shp); // Number of points |
---|
| 181 | nPts = 0.0; |
---|
| 182 | Array<Float> nInc(shp); // Increment |
---|
| 183 | nInc = 1.0; |
---|
| 184 | |
---|
| 185 | // Create accumulation Array for variance. We accumulate for |
---|
| 186 | // each if,pol,beam, but average over channel. So we need |
---|
| 187 | // a shape with one less axis dropping channels. |
---|
| 188 | |
---|
| 189 | const uInt nAxesSub = shp.nelements() - 1; |
---|
| 190 | IPosition shp2(nAxesSub); |
---|
| 191 | for (uInt i=0,j=0; i<(nAxesSub+1); i++) { |
---|
[221] | 192 | if (i!=asap::ChanAxis) { |
---|
[144] | 193 | shp2(j) = shp(i); |
---|
| 194 | j++; |
---|
| 195 | } |
---|
[2] | 196 | } |
---|
[144] | 197 | Array<Float> sumSq(shp2); |
---|
| 198 | sumSq = 0.0; |
---|
| 199 | IPosition pos2(nAxesSub,0); // For indexing |
---|
[130] | 200 | |
---|
[144] | 201 | // Time-related accumulators |
---|
[130] | 202 | |
---|
[144] | 203 | Double time; |
---|
| 204 | Double timeSum = 0.0; |
---|
| 205 | Double intSum = 0.0; |
---|
| 206 | Double interval = 0.0; |
---|
[130] | 207 | |
---|
[144] | 208 | // To get the right shape for the Tsys accumulator we need to |
---|
| 209 | // access a column from the first table. The shape of this |
---|
| 210 | // array must not change |
---|
[130] | 211 | |
---|
[144] | 212 | Array<Float> tSysSum; |
---|
| 213 | { |
---|
| 214 | const Table& tabIn = in[0]->table(); |
---|
| 215 | tSysCol.attach(tabIn,"TSYS"); |
---|
| 216 | tSysSum.resize(tSysCol.shape(0)); |
---|
| 217 | } |
---|
| 218 | tSysSum =0.0; |
---|
| 219 | Array<Float> tSys; |
---|
| 220 | |
---|
| 221 | // Scan and row tracking |
---|
| 222 | |
---|
| 223 | Int oldScanID = 0; |
---|
| 224 | Int outScanID = 0; |
---|
| 225 | Int scanID = 0; |
---|
| 226 | Int rowStart = 0; |
---|
| 227 | Int nAccum = 0; |
---|
| 228 | Int tableStart = 0; |
---|
| 229 | |
---|
| 230 | // Source and FreqID |
---|
| 231 | |
---|
| 232 | String sourceName, oldSourceName, sourceNameStart; |
---|
| 233 | Vector<uInt> freqID, freqIDStart, oldFreqID; |
---|
| 234 | |
---|
| 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 | |
---|
[309] | 241 | // Should check that the frequency tables don't change if doing FreqAlignment |
---|
[221] | 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); |
---|
[304] | 361 | pTabOut->resetCursor(); |
---|
[144] | 362 | // |
---|
| 363 | return CountedPtr<SDMemTable>(pTabOut); |
---|
[2] | 364 | } |
---|
[9] | 365 | |
---|
[144] | 366 | |
---|
| 367 | |
---|
[248] | 368 | CountedPtr<SDMemTable> SDMath::binaryOperate (const CountedPtr<SDMemTable>& left, |
---|
| 369 | const CountedPtr<SDMemTable>& right, |
---|
[294] | 370 | const String& op, Bool preserve, |
---|
| 371 | Bool doTSys) const |
---|
[185] | 372 | { |
---|
[85] | 373 | |
---|
[248] | 374 | // Check operator |
---|
[130] | 375 | |
---|
[234] | 376 | String op2(op); |
---|
| 377 | op2.upcase(); |
---|
| 378 | uInt what = 0; |
---|
| 379 | if (op2=="ADD") { |
---|
| 380 | what = 0; |
---|
| 381 | } else if (op2=="SUB") { |
---|
| 382 | what = 1; |
---|
| 383 | } else if (op2=="MUL") { |
---|
| 384 | what = 2; |
---|
| 385 | } else if (op2=="DIV") { |
---|
| 386 | what = 3; |
---|
[248] | 387 | } else if (op2=="QUOTIENT") { |
---|
| 388 | what = 4; |
---|
[294] | 389 | doTSys = True; |
---|
[234] | 390 | } else { |
---|
[248] | 391 | throw( AipsError("Unrecognized operation")); |
---|
[234] | 392 | } |
---|
| 393 | |
---|
| 394 | // Check rows |
---|
| 395 | |
---|
[248] | 396 | const uInt nRowLeft = left->nRow(); |
---|
| 397 | const uInt nRowRight = right->nRow(); |
---|
| 398 | Bool ok = (nRowRight==1&&nRowLeft>0) || |
---|
| 399 | (nRowRight>=1&&nRowLeft==nRowRight); |
---|
| 400 | if (!ok) { |
---|
| 401 | throw (AipsError("The right Scan Table can have one row or the same number of rows as the left Scan Table")); |
---|
[234] | 402 | } |
---|
| 403 | |
---|
[248] | 404 | // Input Tables |
---|
[234] | 405 | |
---|
| 406 | const Table& tLeft = left->table(); |
---|
| 407 | const Table& tRight = right->table(); |
---|
[248] | 408 | |
---|
| 409 | // TSys columns |
---|
| 410 | |
---|
[294] | 411 | ROArrayColumn<Float> tSysLeftCol, tSysRightCol; |
---|
| 412 | if (doTSys) { |
---|
| 413 | tSysLeftCol.attach(tLeft, "TSYS"); |
---|
| 414 | tSysRightCol.attach(tRight, "TSYS"); |
---|
| 415 | } |
---|
[234] | 416 | |
---|
[248] | 417 | // First row for right |
---|
[234] | 418 | |
---|
[248] | 419 | Array<Float> tSysLeftArr, tSysRightArr; |
---|
[294] | 420 | if (doTSys) tSysRightCol.get(0, tSysRightArr); |
---|
[248] | 421 | MaskedArray<Float>* pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(0)); |
---|
| 422 | IPosition shpRight = pMRight->shape(); |
---|
| 423 | |
---|
| 424 | // Output Table cloned from left |
---|
| 425 | |
---|
[234] | 426 | SDMemTable* pTabOut = new SDMemTable(*left, True); |
---|
| 427 | |
---|
| 428 | // Loop over rows |
---|
| 429 | |
---|
[248] | 430 | for (uInt i=0; i<nRowLeft; i++) { |
---|
[234] | 431 | |
---|
| 432 | // Get data |
---|
[248] | 433 | |
---|
[234] | 434 | MaskedArray<Float> mLeft(left->rowAsMaskedArray(i)); |
---|
[248] | 435 | IPosition shpLeft = mLeft.shape(); |
---|
[294] | 436 | if (doTSys) tSysLeftCol.get(i, tSysLeftArr); |
---|
[234] | 437 | // |
---|
[248] | 438 | if (nRowRight>1) { |
---|
| 439 | delete pMRight; |
---|
| 440 | pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(i)); |
---|
| 441 | shpRight = pMRight->shape(); |
---|
[294] | 442 | if (doTSys) tSysRightCol.get(i, tSysRightArr); |
---|
[234] | 443 | } |
---|
[248] | 444 | // |
---|
| 445 | if (!shpRight.isEqual(shpLeft)) { |
---|
| 446 | throw(AipsError("left and right scan tables are not conformant")); |
---|
| 447 | } |
---|
[294] | 448 | if (doTSys) { |
---|
| 449 | if (!tSysRightArr.shape().isEqual(tSysRightArr.shape())) { |
---|
| 450 | throw(AipsError("left and right Tsys data are not conformant")); |
---|
| 451 | } |
---|
| 452 | if (!shpRight.isEqual(tSysRightArr.shape())) { |
---|
| 453 | throw(AipsError("left and right scan tables are not conformant")); |
---|
| 454 | } |
---|
[248] | 455 | } |
---|
[234] | 456 | |
---|
| 457 | // Make container |
---|
| 458 | |
---|
| 459 | SDContainer sc = left->getSDContainer(i); |
---|
| 460 | |
---|
| 461 | // Operate on data and TSys |
---|
| 462 | |
---|
| 463 | if (what==0) { |
---|
[248] | 464 | MaskedArray<Float> tmp = mLeft + *pMRight; |
---|
[234] | 465 | putDataInSDC(sc, tmp.getArray(), tmp.getMask()); |
---|
[294] | 466 | if (doTSys) sc.putTsys(tSysLeftArr+tSysRightArr); |
---|
[234] | 467 | } else if (what==1) { |
---|
[248] | 468 | MaskedArray<Float> tmp = mLeft - *pMRight; |
---|
[234] | 469 | putDataInSDC(sc, tmp.getArray(), tmp.getMask()); |
---|
[294] | 470 | if (doTSys) sc.putTsys(tSysLeftArr-tSysRightArr); |
---|
[234] | 471 | } else if (what==2) { |
---|
[248] | 472 | MaskedArray<Float> tmp = mLeft * *pMRight; |
---|
[234] | 473 | putDataInSDC(sc, tmp.getArray(), tmp.getMask()); |
---|
[294] | 474 | if (doTSys) sc.putTsys(tSysLeftArr*tSysRightArr); |
---|
[234] | 475 | } else if (what==3) { |
---|
[248] | 476 | MaskedArray<Float> tmp = mLeft / *pMRight; |
---|
[234] | 477 | putDataInSDC(sc, tmp.getArray(), tmp.getMask()); |
---|
[294] | 478 | if (doTSys) sc.putTsys(tSysLeftArr/tSysRightArr); |
---|
[248] | 479 | } else if (what==4) { |
---|
| 480 | if (preserve) { |
---|
| 481 | MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysRightArr; |
---|
| 482 | putDataInSDC(sc, tmp.getArray(), tmp.getMask()); |
---|
| 483 | } else { |
---|
| 484 | MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysLeftArr; |
---|
| 485 | putDataInSDC(sc, tmp.getArray(), tmp.getMask()); |
---|
| 486 | } |
---|
| 487 | sc.putTsys(tSysRightArr); |
---|
[234] | 488 | } |
---|
| 489 | |
---|
| 490 | // Put new row in output Table |
---|
| 491 | |
---|
[171] | 492 | pTabOut->putSDContainer(sc); |
---|
[130] | 493 | } |
---|
[248] | 494 | if (pMRight) delete pMRight; |
---|
[304] | 495 | pTabOut->resetCursor(); |
---|
[130] | 496 | // |
---|
[171] | 497 | return CountedPtr<SDMemTable>(pTabOut); |
---|
[9] | 498 | } |
---|
[48] | 499 | |
---|
[146] | 500 | |
---|
| 501 | |
---|
[185] | 502 | std::vector<float> SDMath::statistic(const CountedPtr<SDMemTable>& in, |
---|
[234] | 503 | const Vector<Bool>& mask, |
---|
| 504 | const String& which, Int row) const |
---|
[130] | 505 | // |
---|
| 506 | // Perhaps iteration over pol/beam/if should be in here |
---|
| 507 | // and inside the nrow iteration ? |
---|
| 508 | // |
---|
| 509 | { |
---|
| 510 | const uInt nRow = in->nRow(); |
---|
| 511 | |
---|
| 512 | // Specify cursor location |
---|
| 513 | |
---|
[152] | 514 | IPosition start, end; |
---|
[185] | 515 | getCursorLocation(start, end, *in); |
---|
[130] | 516 | |
---|
| 517 | // Loop over rows |
---|
| 518 | |
---|
[234] | 519 | const uInt nEl = mask.nelements(); |
---|
| 520 | uInt iStart = 0; |
---|
| 521 | uInt iEnd = in->nRow()-1; |
---|
| 522 | // |
---|
| 523 | if (row>=0) { |
---|
| 524 | iStart = row; |
---|
| 525 | iEnd = row; |
---|
| 526 | } |
---|
| 527 | // |
---|
| 528 | std::vector<float> result(iEnd-iStart+1); |
---|
| 529 | for (uInt ii=iStart; ii <= iEnd; ++ii) { |
---|
[130] | 530 | |
---|
| 531 | // Get row and deconstruct |
---|
| 532 | |
---|
| 533 | MaskedArray<Float> marr(in->rowAsMaskedArray(ii)); |
---|
| 534 | Array<Float> arr = marr.getArray(); |
---|
| 535 | Array<Bool> barr = marr.getMask(); |
---|
| 536 | |
---|
| 537 | // Access desired piece of data |
---|
| 538 | |
---|
| 539 | Array<Float> v((arr(start,end)).nonDegenerate()); |
---|
| 540 | Array<Bool> m((barr(start,end)).nonDegenerate()); |
---|
| 541 | |
---|
| 542 | // Apply OTF mask |
---|
| 543 | |
---|
| 544 | MaskedArray<Float> tmp; |
---|
| 545 | if (m.nelements()==nEl) { |
---|
[234] | 546 | tmp.setData(v,m&&mask); |
---|
[130] | 547 | } else { |
---|
| 548 | tmp.setData(v,m); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | // Get statistic |
---|
| 552 | |
---|
[234] | 553 | result[ii-iStart] = mathutil::statistics(which, tmp); |
---|
[130] | 554 | } |
---|
| 555 | // |
---|
| 556 | return result; |
---|
| 557 | } |
---|
| 558 | |
---|
[146] | 559 | |
---|
[234] | 560 | SDMemTable* SDMath::bin(const SDMemTable& in, Int width) const |
---|
[144] | 561 | { |
---|
[169] | 562 | SDHeader sh = in.getSDHeader(); |
---|
| 563 | SDMemTable* pTabOut = new SDMemTable(in, True); |
---|
[163] | 564 | |
---|
[169] | 565 | // Bin up SpectralCoordinates |
---|
[163] | 566 | |
---|
[169] | 567 | IPosition factors(1); |
---|
| 568 | factors(0) = width; |
---|
| 569 | for (uInt j=0; j<in.nCoordinates(); ++j) { |
---|
| 570 | CoordinateSystem cSys; |
---|
[288] | 571 | cSys.addCoordinate(in.getSpectralCoordinate(j)); |
---|
[169] | 572 | CoordinateSystem cSysBin = |
---|
[185] | 573 | CoordinateUtil::makeBinnedCoordinateSystem(factors, cSys, False); |
---|
[169] | 574 | // |
---|
| 575 | SpectralCoordinate sCBin = cSysBin.spectralCoordinate(0); |
---|
| 576 | pTabOut->setCoordinate(sCBin, j); |
---|
| 577 | } |
---|
[163] | 578 | |
---|
[169] | 579 | // Use RebinLattice to find shape |
---|
[130] | 580 | |
---|
[169] | 581 | IPosition shapeIn(1,sh.nchan); |
---|
[185] | 582 | IPosition shapeOut = RebinLattice<Float>::rebinShape(shapeIn, factors); |
---|
[169] | 583 | sh.nchan = shapeOut(0); |
---|
| 584 | pTabOut->putSDHeader(sh); |
---|
[144] | 585 | |
---|
[169] | 586 | // Loop over rows and bin along channel axis |
---|
| 587 | |
---|
| 588 | for (uInt i=0; i < in.nRow(); ++i) { |
---|
| 589 | SDContainer sc = in.getSDContainer(i); |
---|
[144] | 590 | // |
---|
[169] | 591 | Array<Float> tSys(sc.getTsys()); // Get it out before sc changes shape |
---|
[144] | 592 | |
---|
[169] | 593 | // Bin up spectrum |
---|
[144] | 594 | |
---|
[169] | 595 | MaskedArray<Float> marr(in.rowAsMaskedArray(i)); |
---|
| 596 | MaskedArray<Float> marrout; |
---|
[221] | 597 | LatticeUtilities::bin(marrout, marr, asap::ChanAxis, width); |
---|
[144] | 598 | |
---|
[169] | 599 | // Put back the binned data and flags |
---|
[144] | 600 | |
---|
[169] | 601 | IPosition ip2 = marrout.shape(); |
---|
| 602 | sc.resize(ip2); |
---|
[146] | 603 | // |
---|
[185] | 604 | putDataInSDC(sc, marrout.getArray(), marrout.getMask()); |
---|
[146] | 605 | |
---|
[169] | 606 | // Bin up Tsys. |
---|
[146] | 607 | |
---|
[169] | 608 | Array<Bool> allGood(tSys.shape(),True); |
---|
| 609 | MaskedArray<Float> tSysIn(tSys, allGood, True); |
---|
[146] | 610 | // |
---|
[169] | 611 | MaskedArray<Float> tSysOut; |
---|
[221] | 612 | LatticeUtilities::bin(tSysOut, tSysIn, asap::ChanAxis, width); |
---|
[169] | 613 | sc.putTsys(tSysOut.getArray()); |
---|
[146] | 614 | // |
---|
[169] | 615 | pTabOut->putSDContainer(sc); |
---|
| 616 | } |
---|
| 617 | return pTabOut; |
---|
[146] | 618 | } |
---|
| 619 | |
---|
[299] | 620 | SDMemTable* SDMath::resample (const SDMemTable& in, const String& methodStr, |
---|
| 621 | Float width) const |
---|
| 622 | // |
---|
| 623 | // Should add the possibility of width being specified in km/s. This means |
---|
| 624 | // that for each freqID (SpectralCoordinate) we will need to convert to an |
---|
| 625 | // average channel width (say at the reference pixel). Then we would need |
---|
| 626 | // to be careful to make sure each spectrum (of different freqID) |
---|
| 627 | // is the same length. |
---|
| 628 | // |
---|
| 629 | { |
---|
| 630 | Bool doVel = False; |
---|
[309] | 631 | if (doVel) { |
---|
| 632 | for (uInt j=0; j<in.nCoordinates(); ++j) { |
---|
| 633 | SpectralCoordinate sC = in.getSpectralCoordinate(j); |
---|
| 634 | } |
---|
| 635 | } |
---|
[299] | 636 | |
---|
[309] | 637 | |
---|
[299] | 638 | // Interpolation method |
---|
| 639 | |
---|
| 640 | Int interpMethod = 0; |
---|
| 641 | convertInterpString(interpMethod, methodStr); |
---|
| 642 | |
---|
| 643 | // Make output table |
---|
| 644 | |
---|
| 645 | SDMemTable* pTabOut = new SDMemTable(in, True); |
---|
| 646 | |
---|
| 647 | // Resample SpectralCoordinates (one per freqID) |
---|
| 648 | |
---|
| 649 | const uInt nCoord = in.nCoordinates(); |
---|
| 650 | Vector<Float> offset(1,0.0); |
---|
| 651 | Vector<Float> factors(1,1.0/width); |
---|
| 652 | Vector<Int> newShape; |
---|
| 653 | for (uInt j=0; j<in.nCoordinates(); ++j) { |
---|
| 654 | CoordinateSystem cSys; |
---|
| 655 | cSys.addCoordinate(in.getSpectralCoordinate(j)); |
---|
| 656 | CoordinateSystem cSys2 = cSys.subImage(offset, factors, newShape); |
---|
| 657 | SpectralCoordinate sC = cSys2.spectralCoordinate(0); |
---|
| 658 | // |
---|
| 659 | pTabOut->setCoordinate(sC, j); |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | // Get header |
---|
| 663 | |
---|
| 664 | SDHeader sh = in.getSDHeader(); |
---|
| 665 | |
---|
| 666 | // Generate resampling vectors |
---|
| 667 | |
---|
| 668 | const uInt nChanIn = sh.nchan; |
---|
| 669 | Vector<Float> xIn(nChanIn); |
---|
| 670 | indgen(xIn); |
---|
| 671 | // |
---|
| 672 | Int fac = Int(nChanIn/width); |
---|
| 673 | Vector<Float> xOut(fac+10); // 10 to be safe - resize later |
---|
| 674 | uInt i = 0; |
---|
| 675 | Float x = 0.0; |
---|
| 676 | Bool more = True; |
---|
| 677 | while (more) { |
---|
| 678 | xOut(i) = x; |
---|
| 679 | // |
---|
| 680 | i++; |
---|
| 681 | x += width; |
---|
| 682 | if (x>nChanIn-1) more = False; |
---|
| 683 | } |
---|
| 684 | const uInt nChanOut = i; |
---|
| 685 | xOut.resize(nChanOut,True); |
---|
| 686 | // |
---|
| 687 | IPosition shapeIn(in.rowAsMaskedArray(0).shape()); |
---|
| 688 | sh.nchan = nChanOut; |
---|
| 689 | pTabOut->putSDHeader(sh); |
---|
| 690 | |
---|
| 691 | // Loop over rows and resample along channel axis |
---|
| 692 | |
---|
| 693 | Array<Float> valuesOut; |
---|
| 694 | Array<Bool> maskOut; |
---|
| 695 | Array<Float> tSysOut; |
---|
| 696 | Array<Bool> tSysMaskIn(shapeIn,True); |
---|
| 697 | Array<Bool> tSysMaskOut; |
---|
| 698 | for (uInt i=0; i < in.nRow(); ++i) { |
---|
| 699 | |
---|
| 700 | // Get container |
---|
| 701 | |
---|
| 702 | SDContainer sc = in.getSDContainer(i); |
---|
| 703 | |
---|
| 704 | // Get data and Tsys |
---|
| 705 | |
---|
| 706 | const Array<Float>& tSysIn = sc.getTsys(); |
---|
| 707 | const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(i)); |
---|
| 708 | Array<Float> valuesIn = dataIn.getArray(); |
---|
| 709 | Array<Bool> maskIn = dataIn.getMask(); |
---|
| 710 | |
---|
| 711 | // Interpolate data |
---|
| 712 | |
---|
| 713 | InterpolateArray1D<Float,Float>::interpolate(valuesOut, maskOut, xOut, |
---|
| 714 | xIn, valuesIn, maskIn, |
---|
| 715 | interpMethod, True, True); |
---|
| 716 | sc.resize(valuesOut.shape()); |
---|
| 717 | putDataInSDC(sc, valuesOut, maskOut); |
---|
| 718 | |
---|
| 719 | // Interpolate TSys |
---|
| 720 | |
---|
| 721 | InterpolateArray1D<Float,Float>::interpolate(tSysOut, tSysMaskOut, xOut, |
---|
| 722 | xIn, tSysIn, tSysMaskIn, |
---|
| 723 | interpMethod, True, True); |
---|
| 724 | sc.putTsys(tSysOut); |
---|
| 725 | |
---|
| 726 | // Put container in output |
---|
| 727 | |
---|
| 728 | pTabOut->putSDContainer(sc); |
---|
| 729 | } |
---|
| 730 | // |
---|
| 731 | return pTabOut; |
---|
| 732 | } |
---|
| 733 | |
---|
[248] | 734 | SDMemTable* SDMath::unaryOperate(const SDMemTable& in, Float val, Bool doAll, |
---|
[294] | 735 | uInt what, Bool doTSys) const |
---|
[152] | 736 | // |
---|
| 737 | // what = 0 Multiply |
---|
| 738 | // 1 Add |
---|
[146] | 739 | { |
---|
[152] | 740 | SDMemTable* pOut = new SDMemTable(in,False); |
---|
| 741 | const Table& tOut = pOut->table(); |
---|
[294] | 742 | ArrayColumn<Float> specCol(tOut,"SPECTRA"); |
---|
| 743 | ArrayColumn<Float> tSysCol(tOut,"TSYS"); |
---|
| 744 | Array<Float> tSysArr; |
---|
[146] | 745 | // |
---|
[152] | 746 | if (doAll) { |
---|
| 747 | for (uInt i=0; i < tOut.nrow(); i++) { |
---|
[294] | 748 | |
---|
| 749 | // Modify data |
---|
| 750 | |
---|
[270] | 751 | MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); |
---|
[152] | 752 | if (what==0) { |
---|
[270] | 753 | dataIn *= val; |
---|
[152] | 754 | } else if (what==1) { |
---|
[270] | 755 | dataIn += val; |
---|
[152] | 756 | } |
---|
[294] | 757 | specCol.put(i, dataIn.getArray()); |
---|
| 758 | |
---|
| 759 | // Modify Tsys |
---|
| 760 | |
---|
| 761 | if (doTSys) { |
---|
| 762 | tSysCol.get(i, tSysArr); |
---|
| 763 | if (what==0) { |
---|
| 764 | tSysArr *= val; |
---|
| 765 | } else if (what==1) { |
---|
| 766 | tSysArr += val; |
---|
| 767 | } |
---|
| 768 | tSysCol.put(i, tSysArr); |
---|
| 769 | } |
---|
[152] | 770 | } |
---|
| 771 | } else { |
---|
| 772 | |
---|
| 773 | // Get cursor location |
---|
| 774 | |
---|
| 775 | IPosition start, end; |
---|
[185] | 776 | getCursorLocation(start, end, in); |
---|
[152] | 777 | // |
---|
| 778 | for (uInt i=0; i < tOut.nrow(); i++) { |
---|
[294] | 779 | |
---|
| 780 | // Modify data |
---|
| 781 | |
---|
[152] | 782 | MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); |
---|
[270] | 783 | MaskedArray<Float> dataIn2 = dataIn(start,end); // Reference |
---|
[152] | 784 | if (what==0) { |
---|
[270] | 785 | dataIn2 *= val; |
---|
[152] | 786 | } else if (what==1) { |
---|
[270] | 787 | dataIn2 += val; |
---|
[152] | 788 | } |
---|
[294] | 789 | specCol.put(i, dataIn.getArray()); |
---|
| 790 | |
---|
| 791 | // Modify Tsys |
---|
| 792 | |
---|
| 793 | if (doTSys) { |
---|
| 794 | tSysCol.get(i, tSysArr); |
---|
| 795 | Array<Float> tSysArr2 = tSysArr(start,end); // Reference |
---|
| 796 | if (what==0) { |
---|
| 797 | tSysArr2 *= val; |
---|
| 798 | } else if (what==1) { |
---|
| 799 | tSysArr2 += val; |
---|
| 800 | } |
---|
| 801 | tSysCol.put(i, tSysArr); |
---|
| 802 | } |
---|
[152] | 803 | } |
---|
| 804 | } |
---|
| 805 | // |
---|
[146] | 806 | return pOut; |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | |
---|
[152] | 810 | |
---|
[234] | 811 | SDMemTable* SDMath::averagePol(const SDMemTable& in, const Vector<Bool>& mask) const |
---|
[152] | 812 | // |
---|
[165] | 813 | // Average all polarizations together, weighted by variance |
---|
| 814 | // |
---|
| 815 | { |
---|
| 816 | // WeightType wtType = NONE; |
---|
[185] | 817 | // convertWeightString(wtType, weight); |
---|
[165] | 818 | |
---|
| 819 | const uInt nRows = in.nRow(); |
---|
| 820 | |
---|
| 821 | // Create output Table and reshape number of polarizations |
---|
| 822 | |
---|
| 823 | Bool clear=True; |
---|
| 824 | SDMemTable* pTabOut = new SDMemTable(in, clear); |
---|
| 825 | SDHeader header = pTabOut->getSDHeader(); |
---|
| 826 | header.npol = 1; |
---|
| 827 | pTabOut->putSDHeader(header); |
---|
| 828 | |
---|
| 829 | // Shape of input and output data |
---|
| 830 | |
---|
| 831 | const IPosition& shapeIn = in.rowAsMaskedArray(0u, False).shape(); |
---|
| 832 | IPosition shapeOut(shapeIn); |
---|
[262] | 833 | shapeOut(asap::PolAxis) = 1; // Average all polarizations |
---|
[165] | 834 | // |
---|
[262] | 835 | const uInt nChan = shapeIn(asap::ChanAxis); |
---|
[165] | 836 | const IPosition vecShapeOut(4,1,1,1,nChan); // A multi-dim form of a Vector shape |
---|
| 837 | IPosition start(4), end(4); |
---|
| 838 | |
---|
| 839 | // Output arrays |
---|
| 840 | |
---|
| 841 | Array<Float> outData(shapeOut, 0.0); |
---|
| 842 | Array<Bool> outMask(shapeOut, True); |
---|
[262] | 843 | const IPosition axes(2, asap::PolAxis, asap::ChanAxis); // pol-channel plane |
---|
[165] | 844 | // |
---|
[262] | 845 | const Bool useMask = (mask.nelements() == shapeIn(asap::ChanAxis)); |
---|
[165] | 846 | |
---|
| 847 | // Loop over rows |
---|
| 848 | |
---|
| 849 | for (uInt iRow=0; iRow<nRows; iRow++) { |
---|
| 850 | |
---|
| 851 | // Get data for this row |
---|
| 852 | |
---|
| 853 | MaskedArray<Float> marr(in.rowAsMaskedArray(iRow)); |
---|
| 854 | Array<Float>& arr = marr.getRWArray(); |
---|
| 855 | const Array<Bool>& barr = marr.getMask(); |
---|
| 856 | |
---|
| 857 | // Make iterators to iterate by pol-channel planes |
---|
| 858 | |
---|
| 859 | ReadOnlyArrayIterator<Float> itDataPlane(arr, axes); |
---|
| 860 | ReadOnlyArrayIterator<Bool> itMaskPlane(barr, axes); |
---|
| 861 | |
---|
| 862 | // Accumulations |
---|
| 863 | |
---|
| 864 | Float fac = 1.0; |
---|
| 865 | Vector<Float> vecSum(nChan,0.0); |
---|
| 866 | |
---|
| 867 | // Iterate through data by pol-channel planes |
---|
| 868 | |
---|
| 869 | while (!itDataPlane.pastEnd()) { |
---|
| 870 | |
---|
| 871 | // Iterate through plane by polarization and accumulate Vectors |
---|
| 872 | |
---|
| 873 | Vector<Float> t1(nChan); t1 = 0.0; |
---|
| 874 | Vector<Bool> t2(nChan); t2 = True; |
---|
| 875 | MaskedArray<Float> vecSum(t1,t2); |
---|
| 876 | Float varSum = 0.0; |
---|
| 877 | { |
---|
| 878 | ReadOnlyVectorIterator<Float> itDataVec(itDataPlane.array(), 1); |
---|
| 879 | ReadOnlyVectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1); |
---|
| 880 | while (!itDataVec.pastEnd()) { |
---|
| 881 | |
---|
| 882 | // Create MA of data & mask (optionally including OTF mask) and get variance |
---|
| 883 | |
---|
| 884 | if (useMask) { |
---|
| 885 | const MaskedArray<Float> spec(itDataVec.vector(),mask&&itMaskVec.vector()); |
---|
| 886 | fac = 1.0 / variance(spec); |
---|
| 887 | } else { |
---|
| 888 | const MaskedArray<Float> spec(itDataVec.vector(),itMaskVec.vector()); |
---|
| 889 | fac = 1.0 / variance(spec); |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | // Normalize spectrum (without OTF mask) and accumulate |
---|
| 893 | |
---|
| 894 | const MaskedArray<Float> spec(fac*itDataVec.vector(), itMaskVec.vector()); |
---|
| 895 | vecSum += spec; |
---|
| 896 | varSum += fac; |
---|
| 897 | |
---|
| 898 | // Next |
---|
| 899 | |
---|
| 900 | itDataVec.next(); |
---|
| 901 | itMaskVec.next(); |
---|
| 902 | } |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | // Normalize summed spectrum |
---|
| 906 | |
---|
| 907 | vecSum /= varSum; |
---|
| 908 | |
---|
| 909 | // FInd position in input data array. We are iterating by pol-channel |
---|
| 910 | // plane so all that will change is beam and IF and that's what we want. |
---|
| 911 | |
---|
| 912 | IPosition pos = itDataPlane.pos(); |
---|
| 913 | |
---|
| 914 | // Write out data. This is a bit messy. We have to reform the Vector |
---|
| 915 | // accumulator into an Array of shape (1,1,1,nChan) |
---|
| 916 | |
---|
| 917 | start = pos; |
---|
| 918 | end = pos; |
---|
[262] | 919 | end(asap::ChanAxis) = nChan-1; |
---|
[165] | 920 | outData(start,end) = vecSum.getArray().reform(vecShapeOut); |
---|
| 921 | outMask(start,end) = vecSum.getMask().reform(vecShapeOut); |
---|
| 922 | |
---|
| 923 | // Step to next beam/IF combination |
---|
| 924 | |
---|
| 925 | itDataPlane.next(); |
---|
| 926 | itMaskPlane.next(); |
---|
| 927 | } |
---|
| 928 | |
---|
| 929 | // Generate output container and write it to output table |
---|
| 930 | |
---|
| 931 | SDContainer sc = in.getSDContainer(); |
---|
| 932 | sc.resize(shapeOut); |
---|
| 933 | // |
---|
[185] | 934 | putDataInSDC(sc, outData, outMask); |
---|
[165] | 935 | pTabOut->putSDContainer(sc); |
---|
| 936 | } |
---|
[304] | 937 | |
---|
| 938 | // Set polarization cursor to 0 |
---|
| 939 | |
---|
| 940 | pTabOut->setPol(0); |
---|
[165] | 941 | // |
---|
| 942 | return pTabOut; |
---|
| 943 | } |
---|
[167] | 944 | |
---|
[169] | 945 | |
---|
[185] | 946 | SDMemTable* SDMath::smooth(const SDMemTable& in, |
---|
| 947 | const casa::String& kernelType, |
---|
[234] | 948 | casa::Float width, Bool doAll) const |
---|
[299] | 949 | // |
---|
| 950 | // Should smooth TSys as well |
---|
| 951 | // |
---|
[177] | 952 | { |
---|
[169] | 953 | |
---|
[177] | 954 | // Number of channels |
---|
[169] | 955 | |
---|
[177] | 956 | SDHeader sh = in.getSDHeader(); |
---|
| 957 | const uInt nChan = sh.nchan; |
---|
| 958 | |
---|
| 959 | // Generate Kernel |
---|
| 960 | |
---|
[185] | 961 | VectorKernel::KernelTypes type = VectorKernel::toKernelType(kernelType); |
---|
[177] | 962 | Vector<Float> kernel = VectorKernel::make(type, width, nChan, True, False); |
---|
| 963 | |
---|
| 964 | // Generate Convolver |
---|
| 965 | |
---|
| 966 | IPosition shape(1,nChan); |
---|
| 967 | Convolver<Float> conv(kernel, shape); |
---|
| 968 | |
---|
| 969 | // New Table |
---|
| 970 | |
---|
| 971 | SDMemTable* pTabOut = new SDMemTable(in,True); |
---|
| 972 | |
---|
| 973 | // Get cursor location |
---|
| 974 | |
---|
| 975 | IPosition start, end; |
---|
[185] | 976 | getCursorLocation(start, end, in); |
---|
[177] | 977 | // |
---|
| 978 | IPosition shapeOut(4,1); |
---|
| 979 | |
---|
| 980 | // Output Vectors |
---|
| 981 | |
---|
| 982 | Vector<Float> valuesOut(nChan); |
---|
| 983 | Vector<Bool> maskOut(nChan); |
---|
| 984 | |
---|
| 985 | // Loop over rows in Table |
---|
| 986 | |
---|
| 987 | for (uInt ri=0; ri < in.nRow(); ++ri) { |
---|
| 988 | |
---|
| 989 | // Get copy of data |
---|
| 990 | |
---|
| 991 | const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri)); |
---|
[262] | 992 | AlwaysAssert(dataIn.shape()(asap::ChanAxis)==nChan, AipsError); |
---|
[177] | 993 | // |
---|
| 994 | Array<Float> valuesIn = dataIn.getArray(); |
---|
| 995 | Array<Bool> maskIn = dataIn.getMask(); |
---|
| 996 | |
---|
| 997 | // Branch depending on whether we smooth all locations or just |
---|
| 998 | // those pointed at by the current selection cursor |
---|
| 999 | |
---|
| 1000 | if (doAll) { |
---|
[299] | 1001 | VectorIterator<Float> itValues(valuesIn, asap::ChanAxis); |
---|
| 1002 | VectorIterator<Bool> itMask(maskIn, asap::ChanAxis); |
---|
[177] | 1003 | while (!itValues.pastEnd()) { |
---|
| 1004 | |
---|
| 1005 | // Smooth |
---|
| 1006 | if (kernelType==VectorKernel::HANNING) { |
---|
| 1007 | mathutil::hanning(valuesOut, maskOut, itValues.vector(), itMask.vector()); |
---|
| 1008 | itMask.vector() = maskOut; |
---|
| 1009 | } else { |
---|
| 1010 | mathutil::replaceMaskByZero(itValues.vector(), itMask.vector()); |
---|
| 1011 | conv.linearConv(valuesOut, itValues.vector()); |
---|
| 1012 | } |
---|
| 1013 | // |
---|
| 1014 | itValues.vector() = valuesOut; |
---|
| 1015 | // |
---|
| 1016 | itValues.next(); |
---|
| 1017 | itMask.next(); |
---|
| 1018 | } |
---|
| 1019 | } else { |
---|
| 1020 | |
---|
| 1021 | // Set multi-dim Vector shape |
---|
| 1022 | |
---|
[299] | 1023 | shapeOut(asap::ChanAxis) = valuesIn.shape()(asap::ChanAxis); |
---|
[177] | 1024 | |
---|
| 1025 | // Stuff about with shapes so that we don't have conformance run-time errors |
---|
| 1026 | |
---|
| 1027 | Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate(); |
---|
| 1028 | Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate(); |
---|
| 1029 | |
---|
| 1030 | // Smooth |
---|
| 1031 | |
---|
| 1032 | if (kernelType==VectorKernel::HANNING) { |
---|
| 1033 | mathutil::hanning(valuesOut, maskOut, valuesIn2, maskIn2); |
---|
| 1034 | maskIn(start,end) = maskOut.reform(shapeOut); |
---|
| 1035 | } else { |
---|
| 1036 | mathutil::replaceMaskByZero(valuesIn2, maskIn2); |
---|
| 1037 | conv.linearConv(valuesOut, valuesIn2); |
---|
| 1038 | } |
---|
| 1039 | // |
---|
| 1040 | valuesIn(start,end) = valuesOut.reform(shapeOut); |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | // Create and put back |
---|
| 1044 | |
---|
| 1045 | SDContainer sc = in.getSDContainer(ri); |
---|
[185] | 1046 | putDataInSDC(sc, valuesIn, maskIn); |
---|
[177] | 1047 | // |
---|
| 1048 | pTabOut->putSDContainer(sc); |
---|
| 1049 | } |
---|
| 1050 | // |
---|
| 1051 | return pTabOut; |
---|
| 1052 | } |
---|
| 1053 | |
---|
| 1054 | |
---|
[262] | 1055 | |
---|
[234] | 1056 | SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float a, Float eta, Bool doAll) const |
---|
[221] | 1057 | // |
---|
| 1058 | // As it is, this function could be implemented with 'simpleOperate' |
---|
| 1059 | // However, I anticipate that eventually we will look the conversion |
---|
| 1060 | // values up in a Table and apply them in a frequency dependent way, |
---|
| 1061 | // so I have implemented it fully here |
---|
| 1062 | // |
---|
| 1063 | { |
---|
| 1064 | SDHeader sh = in.getSDHeader(); |
---|
| 1065 | SDMemTable* pTabOut = new SDMemTable(in, True); |
---|
[177] | 1066 | |
---|
[221] | 1067 | // FInd out how to convert values into Jy and K (e.g. units might be mJy or mK) |
---|
| 1068 | // Also automatically find out what we are converting to according to the |
---|
| 1069 | // flux unit |
---|
[177] | 1070 | |
---|
[221] | 1071 | Unit fluxUnit(sh.fluxunit); |
---|
| 1072 | Unit K(String("K")); |
---|
| 1073 | Unit JY(String("Jy")); |
---|
| 1074 | // |
---|
| 1075 | Bool toKelvin = True; |
---|
| 1076 | Double inFac = 1.0; |
---|
| 1077 | if (fluxUnit==JY) { |
---|
| 1078 | cerr << "Converting to K" << endl; |
---|
| 1079 | // |
---|
| 1080 | Quantum<Double> t(1.0,fluxUnit); |
---|
| 1081 | Quantum<Double> t2 = t.get(JY); |
---|
| 1082 | inFac = (t2 / t).getValue(); |
---|
| 1083 | // |
---|
| 1084 | toKelvin = True; |
---|
| 1085 | sh.fluxunit = "K"; |
---|
| 1086 | } else if (fluxUnit==K) { |
---|
| 1087 | cerr << "Converting to Jy" << endl; |
---|
| 1088 | // |
---|
| 1089 | Quantum<Double> t(1.0,fluxUnit); |
---|
| 1090 | Quantum<Double> t2 = t.get(K); |
---|
| 1091 | inFac = (t2 / t).getValue(); |
---|
| 1092 | // |
---|
| 1093 | toKelvin = False; |
---|
| 1094 | sh.fluxunit = "Jy"; |
---|
| 1095 | } else { |
---|
[248] | 1096 | throw(AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K")); |
---|
[221] | 1097 | } |
---|
| 1098 | pTabOut->putSDHeader(sh); |
---|
[177] | 1099 | |
---|
[221] | 1100 | // Compute conversion factor. 'a' and 'eta' are really frequency, time and |
---|
| 1101 | // telescope dependent and should be looked// up in a table |
---|
| 1102 | |
---|
[234] | 1103 | Float factor = 2.0 * inFac * 1.0e-7 * 1.0e26 * |
---|
| 1104 | QC::k.getValue(Unit(String("erg/K"))) / a / eta; |
---|
[221] | 1105 | if (toKelvin) { |
---|
| 1106 | factor = 1.0 / factor; |
---|
| 1107 | } |
---|
| 1108 | cerr << "Applying conversion factor = " << factor << endl; |
---|
| 1109 | |
---|
[270] | 1110 | // Generate correction vector. Apply same factor regardless |
---|
| 1111 | // of beam/pol/IF. This will need to change somewhen. |
---|
[221] | 1112 | |
---|
[270] | 1113 | Vector<Float> factors(in.nRow(), factor); |
---|
[221] | 1114 | |
---|
[270] | 1115 | // Correct |
---|
[221] | 1116 | |
---|
[270] | 1117 | correctFromVector (pTabOut, in, doAll, factors); |
---|
[221] | 1118 | // |
---|
| 1119 | return pTabOut; |
---|
| 1120 | } |
---|
| 1121 | |
---|
| 1122 | |
---|
[234] | 1123 | SDMemTable* SDMath::gainElevation (const SDMemTable& in, const Vector<Float>& coeffs, |
---|
| 1124 | const String& fileName, |
---|
| 1125 | const String& methodStr, Bool doAll) const |
---|
[227] | 1126 | { |
---|
[234] | 1127 | |
---|
| 1128 | // Get header and clone output table |
---|
| 1129 | |
---|
[227] | 1130 | SDHeader sh = in.getSDHeader(); |
---|
| 1131 | SDMemTable* pTabOut = new SDMemTable(in, True); |
---|
| 1132 | |
---|
[234] | 1133 | // Get elevation data from SDMemTable and convert to degrees |
---|
[227] | 1134 | |
---|
| 1135 | const Table& tab = in.table(); |
---|
| 1136 | ROScalarColumn<Float> elev(tab, "ELEVATION"); |
---|
[234] | 1137 | Vector<Float> x = elev.getColumn(); |
---|
| 1138 | x *= Float(180 / C::pi); |
---|
[227] | 1139 | // |
---|
[234] | 1140 | const uInt nC = coeffs.nelements(); |
---|
| 1141 | if (fileName.length()>0 && nC>0) { |
---|
[248] | 1142 | throw(AipsError("You must choose either polynomial coefficients or an ascii file, not both")); |
---|
[234] | 1143 | } |
---|
| 1144 | |
---|
| 1145 | // Correct |
---|
| 1146 | |
---|
| 1147 | if (nC>0 || fileName.length()==0) { |
---|
| 1148 | |
---|
| 1149 | // Find instrument |
---|
| 1150 | |
---|
| 1151 | Bool throwIt = True; |
---|
| 1152 | Instrument inst = SDMemTable::convertInstrument (sh.antennaname, throwIt); |
---|
| 1153 | |
---|
| 1154 | // Set polynomial |
---|
| 1155 | |
---|
| 1156 | Polynomial<Float>* pPoly = 0; |
---|
| 1157 | Vector<Float> coeff; |
---|
| 1158 | String msg; |
---|
| 1159 | if (nC>0) { |
---|
| 1160 | pPoly = new Polynomial<Float>(nC); |
---|
| 1161 | coeff = coeffs; |
---|
| 1162 | msg = String("user"); |
---|
| 1163 | } else { |
---|
[292] | 1164 | if (inst==ATPKSMB) { |
---|
| 1165 | } else if (inst==ATPKSHOH) { |
---|
[234] | 1166 | } else if (inst==TIDBINBILLA) { |
---|
| 1167 | pPoly = new Polynomial<Float>(3); |
---|
| 1168 | coeff.resize(3); |
---|
| 1169 | coeff(0) = 3.58788e-1; |
---|
| 1170 | coeff(1) = 2.87243e-2; |
---|
| 1171 | coeff(2) = -3.219093e-4; |
---|
[292] | 1172 | } else if (inst==ATMOPRA) { |
---|
| 1173 | } else { |
---|
[234] | 1174 | } |
---|
| 1175 | msg = String("built in"); |
---|
| 1176 | } |
---|
[227] | 1177 | // |
---|
[234] | 1178 | if (coeff.nelements()>0) { |
---|
| 1179 | pPoly->setCoefficients(coeff); |
---|
| 1180 | } else { |
---|
[248] | 1181 | throw(AipsError("There is no known gain-el polynomial known for this instrument")); |
---|
[234] | 1182 | } |
---|
| 1183 | // |
---|
| 1184 | cerr << "Making polynomial correction with " << msg << " coefficients" << endl; |
---|
| 1185 | const uInt nRow = in.nRow(); |
---|
| 1186 | Vector<Float> factor(nRow); |
---|
| 1187 | for (uInt i=0; i<nRow; i++) { |
---|
| 1188 | factor[i] = (*pPoly)(x[i]); |
---|
| 1189 | } |
---|
| 1190 | delete pPoly; |
---|
| 1191 | // |
---|
| 1192 | correctFromVector (pTabOut, in, doAll, factor); |
---|
| 1193 | } else { |
---|
| 1194 | |
---|
| 1195 | // Indicate which columns to read from ascii file |
---|
| 1196 | |
---|
| 1197 | String col0("ELEVATION"); |
---|
| 1198 | String col1("FACTOR"); |
---|
| 1199 | |
---|
| 1200 | // Read and correct |
---|
| 1201 | |
---|
| 1202 | cerr << "Making correction from ascii Table" << endl; |
---|
| 1203 | correctFromAsciiTable (pTabOut, in, fileName, col0, col1, |
---|
| 1204 | methodStr, doAll, x); |
---|
| 1205 | } |
---|
| 1206 | // |
---|
| 1207 | return pTabOut; |
---|
[230] | 1208 | } |
---|
[227] | 1209 | |
---|
[230] | 1210 | |
---|
[227] | 1211 | |
---|
[234] | 1212 | SDMemTable* SDMath::opacity (const SDMemTable& in, Float tau, Bool doAll) const |
---|
| 1213 | { |
---|
[227] | 1214 | |
---|
[234] | 1215 | // Get header and clone output table |
---|
[227] | 1216 | |
---|
[234] | 1217 | SDHeader sh = in.getSDHeader(); |
---|
| 1218 | SDMemTable* pTabOut = new SDMemTable(in, True); |
---|
| 1219 | |
---|
| 1220 | // Get elevation data from SDMemTable and convert to degrees |
---|
| 1221 | |
---|
| 1222 | const Table& tab = in.table(); |
---|
| 1223 | ROScalarColumn<Float> elev(tab, "ELEVATION"); |
---|
| 1224 | Vector<Float> zDist = elev.getColumn(); |
---|
| 1225 | zDist = Float(C::pi_2) - zDist; |
---|
| 1226 | |
---|
| 1227 | // Generate correction factor |
---|
| 1228 | |
---|
| 1229 | const uInt nRow = in.nRow(); |
---|
| 1230 | Vector<Float> factor(nRow); |
---|
| 1231 | Vector<Float> factor2(nRow); |
---|
| 1232 | for (uInt i=0; i<nRow; i++) { |
---|
| 1233 | factor[i] = exp(tau)/cos(zDist[i]); |
---|
| 1234 | } |
---|
| 1235 | |
---|
| 1236 | // Correct |
---|
| 1237 | |
---|
| 1238 | correctFromVector (pTabOut, in, doAll, factor); |
---|
| 1239 | // |
---|
| 1240 | return pTabOut; |
---|
| 1241 | } |
---|
| 1242 | |
---|
| 1243 | |
---|
| 1244 | |
---|
| 1245 | |
---|
[169] | 1246 | // 'private' functions |
---|
| 1247 | |
---|
[309] | 1248 | |
---|
| 1249 | SDMemTable* SDMath::frequencyAlign (const SDMemTable& in, |
---|
| 1250 | MFrequency::Types freqSystem, |
---|
[272] | 1251 | const String& refTime) const |
---|
[267] | 1252 | { |
---|
| 1253 | // Get Header |
---|
| 1254 | |
---|
| 1255 | SDHeader sh = in.getSDHeader(); |
---|
| 1256 | const uInt nChan = sh.nchan; |
---|
| 1257 | const uInt nRows = in.nRow(); |
---|
| 1258 | |
---|
| 1259 | // Get Table reference |
---|
| 1260 | |
---|
| 1261 | const Table& tabIn = in.table(); |
---|
| 1262 | |
---|
| 1263 | // Get Columns from Table |
---|
| 1264 | |
---|
[294] | 1265 | ROScalarColumn<Double> mjdCol(tabIn, "TIME"); |
---|
| 1266 | ROScalarColumn<String> srcCol(tabIn, "SRCNAME"); |
---|
| 1267 | ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID"); |
---|
[267] | 1268 | // |
---|
[294] | 1269 | Vector<Double> times = mjdCol.getColumn(); |
---|
| 1270 | Vector<String> srcNames = srcCol.getColumn(); |
---|
| 1271 | Vector<uInt> freqID; |
---|
[267] | 1272 | |
---|
| 1273 | // Generate Source table |
---|
| 1274 | |
---|
| 1275 | Vector<String> srcTab; |
---|
| 1276 | Vector<uInt> srcIdx, firstRow; |
---|
| 1277 | generateSourceTable (srcTab, srcIdx, firstRow, srcNames); |
---|
| 1278 | const uInt nSrcTab = srcTab.nelements(); |
---|
| 1279 | cerr << "Found " << srcTab.nelements() << " sources to align " << endl; |
---|
| 1280 | |
---|
[294] | 1281 | // Get reference Epoch to time of first row or given String |
---|
[267] | 1282 | |
---|
| 1283 | Unit DAY(String("d")); |
---|
[272] | 1284 | MEpoch::Ref epochRef(in.getTimeReference()); |
---|
| 1285 | MEpoch refEpoch; |
---|
| 1286 | if (refTime.length()>0) { |
---|
| 1287 | refEpoch = epochFromString(refTime, in.getTimeReference()); |
---|
| 1288 | } else { |
---|
[288] | 1289 | refEpoch = in.getEpoch(0); |
---|
[272] | 1290 | } |
---|
[309] | 1291 | cerr << "Aligning at reference Epoch " << formatEpoch(refEpoch) << |
---|
| 1292 | " in frame " << MFrequency::showType(freqSystem) << endl; |
---|
[267] | 1293 | |
---|
[294] | 1294 | // Get Reference Position |
---|
[267] | 1295 | |
---|
[288] | 1296 | MPosition refPos = in.getAntennaPosition(); |
---|
[267] | 1297 | |
---|
| 1298 | // Get Frequency Table |
---|
| 1299 | |
---|
| 1300 | SDFrequencyTable fTab = in.getSDFreqTable(); |
---|
| 1301 | const uInt nFreqIDs = fTab.length(); |
---|
| 1302 | |
---|
[309] | 1303 | // Create FrequencyAligner Block. One VA for each possible |
---|
[267] | 1304 | // source/freqID combination |
---|
| 1305 | |
---|
[309] | 1306 | PtrBlock<FrequencyAligner<Float>* > a(nFreqIDs*nSrcTab); |
---|
| 1307 | generateFrequencyAligners (a, in, nChan, nFreqIDs, nSrcTab, firstRow, |
---|
| 1308 | freqSystem, refPos, refEpoch); |
---|
[267] | 1309 | |
---|
| 1310 | // New output Table |
---|
| 1311 | |
---|
| 1312 | SDMemTable* pTabOut = new SDMemTable(in,True); |
---|
| 1313 | |
---|
| 1314 | // Loop over rows in Table |
---|
| 1315 | |
---|
[294] | 1316 | const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis); |
---|
[309] | 1317 | FrequencyAligner<Float>::Method method = FrequencyAligner<Float>::LINEAR; |
---|
[294] | 1318 | Bool extrapolate=False; |
---|
| 1319 | Bool useCachedAbcissa = False; |
---|
| 1320 | Bool first = True; |
---|
| 1321 | Bool ok; |
---|
| 1322 | Vector<Float> yOut; |
---|
| 1323 | Vector<Bool> maskOut; |
---|
[309] | 1324 | uInt ifIdx, faIdx; |
---|
[267] | 1325 | // |
---|
[294] | 1326 | for (uInt iRow=0; iRow<nRows; ++iRow) { |
---|
| 1327 | if (iRow%10==0) { |
---|
| 1328 | cerr << "Processing row " << iRow << endl; |
---|
| 1329 | } |
---|
[267] | 1330 | |
---|
| 1331 | // Get EPoch |
---|
| 1332 | |
---|
[294] | 1333 | Quantum<Double> tQ2(times[iRow],DAY); |
---|
| 1334 | MVEpoch mv2(tQ2); |
---|
| 1335 | MEpoch epoch(mv2, epochRef); |
---|
[267] | 1336 | |
---|
| 1337 | // Get FreqID vector. One freqID per IF |
---|
| 1338 | |
---|
[294] | 1339 | fqIDCol.get(iRow, freqID); |
---|
[267] | 1340 | |
---|
| 1341 | // Get copy of data |
---|
| 1342 | |
---|
[294] | 1343 | const MaskedArray<Float>& mArrIn(in.rowAsMaskedArray(iRow)); |
---|
| 1344 | Array<Float> values = mArrIn.getArray(); |
---|
| 1345 | Array<Bool> mask = mArrIn.getMask(); |
---|
[267] | 1346 | |
---|
| 1347 | // cerr << "values in = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; |
---|
| 1348 | |
---|
[309] | 1349 | // For each row, the Frequency abcissa will be the same regardless |
---|
[267] | 1350 | // of polarization. For all other axes (IF and BEAM) the abcissa |
---|
| 1351 | // will change. So we iterate through the data by pol-chan planes |
---|
| 1352 | // to mimimize the work. At this point, I think the Direction |
---|
| 1353 | // is stored as the same for each beam. DOn't know where the |
---|
| 1354 | // offsets are or what to do about them right now. For now |
---|
| 1355 | // all beams get same position and velocoity abcissa. |
---|
| 1356 | |
---|
[294] | 1357 | ArrayIterator<Float> itValuesPlane(values, polChanAxes); |
---|
| 1358 | ArrayIterator<Bool> itMaskPlane(mask, polChanAxes); |
---|
| 1359 | while (!itValuesPlane.pastEnd()) { |
---|
[267] | 1360 | |
---|
[309] | 1361 | // Find the IF index and then the FA PtrBlock index |
---|
[267] | 1362 | |
---|
[294] | 1363 | const IPosition& pos = itValuesPlane.pos(); |
---|
| 1364 | ifIdx = pos(asap::IFAxis); |
---|
[309] | 1365 | faIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx]; |
---|
[267] | 1366 | // |
---|
[294] | 1367 | VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1); |
---|
| 1368 | VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1); |
---|
[267] | 1369 | // |
---|
[294] | 1370 | first = True; |
---|
| 1371 | useCachedAbcissa=False; |
---|
| 1372 | while (!itValuesVec.pastEnd()) { |
---|
[309] | 1373 | ok = a[faIdx]->align (yOut, maskOut, itValuesVec.vector(), |
---|
[294] | 1374 | itMaskVec.vector(), epoch, useCachedAbcissa, |
---|
| 1375 | method, extrapolate); |
---|
| 1376 | itValuesVec.vector() = yOut; |
---|
| 1377 | itMaskVec.vector() = maskOut; |
---|
[267] | 1378 | // |
---|
[294] | 1379 | itValuesVec.next(); |
---|
| 1380 | itMaskVec.next(); |
---|
[267] | 1381 | // |
---|
[294] | 1382 | if (first) { |
---|
| 1383 | useCachedAbcissa = True; |
---|
| 1384 | first = False; |
---|
| 1385 | } |
---|
| 1386 | } |
---|
[267] | 1387 | // |
---|
| 1388 | itValuesPlane.next(); |
---|
| 1389 | itMaskPlane.next(); |
---|
[294] | 1390 | } |
---|
[267] | 1391 | |
---|
| 1392 | // cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; |
---|
| 1393 | |
---|
| 1394 | // Create and put back |
---|
| 1395 | |
---|
| 1396 | SDContainer sc = in.getSDContainer(iRow); |
---|
| 1397 | putDataInSDC(sc, values, mask); |
---|
| 1398 | // |
---|
| 1399 | pTabOut->putSDContainer(sc); |
---|
[294] | 1400 | } |
---|
[267] | 1401 | |
---|
[309] | 1402 | |
---|
| 1403 | // Write out correct frequency table information for output. |
---|
| 1404 | // CLone from input and overwrite |
---|
| 1405 | |
---|
| 1406 | SDFrequencyTable freqTab = in.getSDFreqTable(); |
---|
| 1407 | freqTab.setLength(0); |
---|
| 1408 | |
---|
| 1409 | // Note that we don't have anyway to hold frequency table information |
---|
| 1410 | // in the SDMemTable which is source dependent. Each FrequencyAligner |
---|
| 1411 | // is generated for an freqID/Source combination. Don't know what to |
---|
| 1412 | // do about this apart from to pick the aligned SC from the first source |
---|
| 1413 | // at the moment. ASAP really needs to handle data description id |
---|
| 1414 | // like in aips++ which is a combination of source and freqid. Otherwise |
---|
| 1415 | // all else I can do in this function is disallow multiple sources |
---|
| 1416 | |
---|
| 1417 | Bool linear=True; |
---|
| 1418 | Vector<String> units(1); |
---|
| 1419 | units = String("Hz"); |
---|
| 1420 | for (uInt fqID=0; fqID<nFreqIDs; fqID++) { |
---|
| 1421 | for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) { |
---|
| 1422 | uInt idx = (iSrc*nFreqIDs) + fqID; |
---|
| 1423 | |
---|
| 1424 | // Get Aligned SC in Hz |
---|
| 1425 | |
---|
| 1426 | if (iSrc==0) { |
---|
| 1427 | SpectralCoordinate sC = a[idx]->alignedSpectralCoordinate(linear); |
---|
| 1428 | sC.setWorldAxisUnits(units); |
---|
| 1429 | |
---|
| 1430 | // Write out frequency table information to SDMemTable |
---|
| 1431 | |
---|
| 1432 | Int idx = freqTab.addFrequency(sC.referencePixel()[0], |
---|
| 1433 | sC.referenceValue()[0], |
---|
| 1434 | sC.increment()[0]); |
---|
| 1435 | } |
---|
| 1436 | } |
---|
| 1437 | } |
---|
| 1438 | pTabOut->putSDFreqTable(freqTab); |
---|
| 1439 | |
---|
| 1440 | // Now we must set the base and extra frames to the |
---|
| 1441 | // input frame |
---|
| 1442 | |
---|
| 1443 | std::vector<string> info = pTabOut->getCoordInfo(); |
---|
| 1444 | info[1] = MFrequency::showType(freqSystem); // Conversion frame |
---|
| 1445 | info[3] = info[1]; // Base frame |
---|
| 1446 | pTabOut->setCoordInfo(info); |
---|
| 1447 | |
---|
[267] | 1448 | // Clean up PointerBlock |
---|
| 1449 | |
---|
[309] | 1450 | for (uInt i=0; i<a.nelements(); i++) delete a[i]; |
---|
[267] | 1451 | // |
---|
[309] | 1452 | return pTabOut; |
---|
[267] | 1453 | } |
---|
| 1454 | |
---|
| 1455 | |
---|
[185] | 1456 | void SDMath::fillSDC(SDContainer& sc, |
---|
| 1457 | const Array<Bool>& mask, |
---|
| 1458 | const Array<Float>& data, |
---|
| 1459 | const Array<Float>& tSys, |
---|
| 1460 | Int scanID, Double timeStamp, |
---|
| 1461 | Double interval, const String& sourceName, |
---|
[227] | 1462 | const Vector<uInt>& freqID) const |
---|
[167] | 1463 | { |
---|
[169] | 1464 | // Data and mask |
---|
[167] | 1465 | |
---|
[185] | 1466 | putDataInSDC(sc, data, mask); |
---|
[167] | 1467 | |
---|
[169] | 1468 | // TSys |
---|
| 1469 | |
---|
| 1470 | sc.putTsys(tSys); |
---|
| 1471 | |
---|
| 1472 | // Time things |
---|
| 1473 | |
---|
| 1474 | sc.timestamp = timeStamp; |
---|
| 1475 | sc.interval = interval; |
---|
| 1476 | sc.scanid = scanID; |
---|
[167] | 1477 | // |
---|
[169] | 1478 | sc.sourcename = sourceName; |
---|
| 1479 | sc.putFreqMap(freqID); |
---|
| 1480 | } |
---|
[167] | 1481 | |
---|
[185] | 1482 | void SDMath::normalize(MaskedArray<Float>& sum, |
---|
[169] | 1483 | const Array<Float>& sumSq, |
---|
| 1484 | const Array<Float>& nPts, |
---|
| 1485 | WeightType wtType, Int axis, |
---|
[227] | 1486 | Int nAxesSub) const |
---|
[169] | 1487 | { |
---|
| 1488 | IPosition pos2(nAxesSub,0); |
---|
| 1489 | // |
---|
| 1490 | if (wtType==NONE) { |
---|
[167] | 1491 | |
---|
[169] | 1492 | // We just average by the number of points accumulated. |
---|
| 1493 | // We need to make a MA out of nPts so that no divide by |
---|
| 1494 | // zeros occur |
---|
[167] | 1495 | |
---|
[169] | 1496 | MaskedArray<Float> t(nPts, (nPts>Float(0.0))); |
---|
| 1497 | sum /= t; |
---|
| 1498 | } else if (wtType==VAR) { |
---|
[167] | 1499 | |
---|
[169] | 1500 | // Normalize each spectrum by sum(1/var) where the variance |
---|
| 1501 | // is worked out for each spectrum |
---|
| 1502 | |
---|
| 1503 | Array<Float>& data = sum.getRWArray(); |
---|
| 1504 | VectorIterator<Float> itData(data, axis); |
---|
| 1505 | while (!itData.pastEnd()) { |
---|
| 1506 | pos2 = itData.pos().getFirst(nAxesSub); |
---|
| 1507 | itData.vector() /= sumSq(pos2); |
---|
| 1508 | itData.next(); |
---|
| 1509 | } |
---|
| 1510 | } else if (wtType==TSYS) { |
---|
| 1511 | } |
---|
| 1512 | } |
---|
| 1513 | |
---|
| 1514 | |
---|
[185] | 1515 | void SDMath::accumulate(Double& timeSum, Double& intSum, Int& nAccum, |
---|
| 1516 | MaskedArray<Float>& sum, Array<Float>& sumSq, |
---|
| 1517 | Array<Float>& nPts, Array<Float>& tSysSum, |
---|
| 1518 | const Array<Float>& tSys, const Array<Float>& nInc, |
---|
| 1519 | const Vector<Bool>& mask, Double time, Double interval, |
---|
| 1520 | const Block<CountedPtr<SDMemTable> >& in, |
---|
| 1521 | uInt iTab, uInt iRow, uInt axis, |
---|
| 1522 | uInt nAxesSub, Bool useMask, |
---|
[227] | 1523 | WeightType wtType) const |
---|
[169] | 1524 | { |
---|
| 1525 | |
---|
| 1526 | // Get data |
---|
| 1527 | |
---|
| 1528 | MaskedArray<Float> dataIn(in[iTab]->rowAsMaskedArray(iRow)); |
---|
| 1529 | Array<Float>& valuesIn = dataIn.getRWArray(); // writable reference |
---|
| 1530 | const Array<Bool>& maskIn = dataIn.getMask(); // RO reference |
---|
[167] | 1531 | // |
---|
[169] | 1532 | if (wtType==NONE) { |
---|
| 1533 | const MaskedArray<Float> n(nInc,dataIn.getMask()); |
---|
| 1534 | nPts += n; // Only accumulates where mask==T |
---|
| 1535 | } else if (wtType==VAR) { |
---|
[167] | 1536 | |
---|
[169] | 1537 | // We are going to average the data, weighted by the noise for each pol, beam and IF. |
---|
| 1538 | // So therefore we need to iterate through by spectrum (axis 3) |
---|
[167] | 1539 | |
---|
[169] | 1540 | VectorIterator<Float> itData(valuesIn, axis); |
---|
| 1541 | ReadOnlyVectorIterator<Bool> itMask(maskIn, axis); |
---|
| 1542 | Float fac = 1.0; |
---|
| 1543 | IPosition pos(nAxesSub,0); |
---|
| 1544 | // |
---|
| 1545 | while (!itData.pastEnd()) { |
---|
[167] | 1546 | |
---|
[169] | 1547 | // Make MaskedArray of Vector, optionally apply OTF mask, and find scaling factor |
---|
[167] | 1548 | |
---|
[169] | 1549 | if (useMask) { |
---|
| 1550 | MaskedArray<Float> tmp(itData.vector(),mask&&itMask.vector()); |
---|
| 1551 | fac = 1.0/variance(tmp); |
---|
| 1552 | } else { |
---|
| 1553 | MaskedArray<Float> tmp(itData.vector(),itMask.vector()); |
---|
| 1554 | fac = 1.0/variance(tmp); |
---|
| 1555 | } |
---|
| 1556 | |
---|
| 1557 | // Scale data |
---|
| 1558 | |
---|
| 1559 | itData.vector() *= fac; // Writes back into 'dataIn' |
---|
[167] | 1560 | // |
---|
[169] | 1561 | // Accumulate variance per if/pol/beam averaged over spectrum |
---|
| 1562 | // This method to get pos2 from itData.pos() is only valid |
---|
| 1563 | // because the spectral axis is the last one (so we can just |
---|
| 1564 | // copy the first nAXesSub positions out) |
---|
[167] | 1565 | |
---|
[169] | 1566 | pos = itData.pos().getFirst(nAxesSub); |
---|
| 1567 | sumSq(pos) += fac; |
---|
| 1568 | // |
---|
| 1569 | itData.next(); |
---|
| 1570 | itMask.next(); |
---|
| 1571 | } |
---|
| 1572 | } else if (wtType==TSYS) { |
---|
| 1573 | } |
---|
[167] | 1574 | |
---|
[169] | 1575 | // Accumulate sum of (possibly scaled) data |
---|
| 1576 | |
---|
| 1577 | sum += dataIn; |
---|
| 1578 | |
---|
| 1579 | // Accumulate Tsys, time, and interval |
---|
| 1580 | |
---|
| 1581 | tSysSum += tSys; |
---|
| 1582 | timeSum += time; |
---|
| 1583 | intSum += interval; |
---|
| 1584 | nAccum += 1; |
---|
| 1585 | } |
---|
| 1586 | |
---|
| 1587 | |
---|
| 1588 | |
---|
| 1589 | |
---|
[185] | 1590 | void SDMath::getCursorLocation(IPosition& start, IPosition& end, |
---|
[227] | 1591 | const SDMemTable& in) const |
---|
[169] | 1592 | { |
---|
| 1593 | const uInt nDim = 4; |
---|
| 1594 | const uInt i = in.getBeam(); |
---|
| 1595 | const uInt j = in.getIF(); |
---|
| 1596 | const uInt k = in.getPol(); |
---|
| 1597 | const uInt n = in.nChan(); |
---|
[167] | 1598 | // |
---|
[169] | 1599 | start.resize(nDim); |
---|
| 1600 | start(0) = i; |
---|
| 1601 | start(1) = j; |
---|
| 1602 | start(2) = k; |
---|
| 1603 | start(3) = 0; |
---|
[167] | 1604 | // |
---|
[169] | 1605 | end.resize(nDim); |
---|
| 1606 | end(0) = i; |
---|
| 1607 | end(1) = j; |
---|
| 1608 | end(2) = k; |
---|
| 1609 | end(3) = n-1; |
---|
| 1610 | } |
---|
| 1611 | |
---|
| 1612 | |
---|
[227] | 1613 | void SDMath::convertWeightString(WeightType& wtType, const String& weightStr) const |
---|
[169] | 1614 | { |
---|
| 1615 | String tStr(weightStr); |
---|
| 1616 | tStr.upcase(); |
---|
| 1617 | if (tStr.contains(String("NONE"))) { |
---|
| 1618 | wtType = NONE; |
---|
| 1619 | } else if (tStr.contains(String("VAR"))) { |
---|
| 1620 | wtType = VAR; |
---|
| 1621 | } else if (tStr.contains(String("TSYS"))) { |
---|
| 1622 | wtType = TSYS; |
---|
[185] | 1623 | throw(AipsError("T_sys weighting not yet implemented")); |
---|
[169] | 1624 | } else { |
---|
[185] | 1625 | throw(AipsError("Unrecognized weighting type")); |
---|
[167] | 1626 | } |
---|
| 1627 | } |
---|
| 1628 | |
---|
[227] | 1629 | void SDMath::convertInterpString(Int& type, const String& interp) const |
---|
| 1630 | { |
---|
| 1631 | String tStr(interp); |
---|
| 1632 | tStr.upcase(); |
---|
| 1633 | if (tStr.contains(String("NEAR"))) { |
---|
| 1634 | type = InterpolateArray1D<Float,Float>::nearestNeighbour; |
---|
| 1635 | } else if (tStr.contains(String("LIN"))) { |
---|
| 1636 | type = InterpolateArray1D<Float,Float>::linear; |
---|
| 1637 | } else if (tStr.contains(String("CUB"))) { |
---|
| 1638 | type = InterpolateArray1D<Float,Float>::cubic; |
---|
| 1639 | } else if (tStr.contains(String("SPL"))) { |
---|
| 1640 | type = InterpolateArray1D<Float,Float>::spline; |
---|
| 1641 | } else { |
---|
| 1642 | throw(AipsError("Unrecognized interpolation type")); |
---|
| 1643 | } |
---|
| 1644 | } |
---|
| 1645 | |
---|
[185] | 1646 | void SDMath::putDataInSDC(SDContainer& sc, const Array<Float>& data, |
---|
[227] | 1647 | const Array<Bool>& mask) const |
---|
[169] | 1648 | { |
---|
| 1649 | sc.putSpectrum(data); |
---|
| 1650 | // |
---|
| 1651 | Array<uChar> outflags(data.shape()); |
---|
| 1652 | convertArray(outflags,!mask); |
---|
| 1653 | sc.putFlags(outflags); |
---|
| 1654 | } |
---|
[227] | 1655 | |
---|
| 1656 | Table SDMath::readAsciiFile (const String& fileName) const |
---|
| 1657 | { |
---|
[230] | 1658 | String formatString; |
---|
| 1659 | Table tbl = readAsciiTable (formatString, Table::Memory, fileName, "", "", False); |
---|
[227] | 1660 | return tbl; |
---|
| 1661 | } |
---|
[230] | 1662 | |
---|
| 1663 | |
---|
[234] | 1664 | |
---|
| 1665 | void SDMath::correctFromAsciiTable(SDMemTable* pTabOut, |
---|
| 1666 | const SDMemTable& in, const String& fileName, |
---|
| 1667 | const String& col0, const String& col1, |
---|
| 1668 | const String& methodStr, Bool doAll, |
---|
| 1669 | const Vector<Float>& xOut) const |
---|
[230] | 1670 | { |
---|
| 1671 | |
---|
| 1672 | // Read gain-elevation ascii file data into a Table. |
---|
| 1673 | |
---|
[234] | 1674 | Table geTable = readAsciiFile (fileName); |
---|
[230] | 1675 | // |
---|
[234] | 1676 | correctFromTable (pTabOut, in, geTable, col0, col1, methodStr, doAll, xOut); |
---|
[230] | 1677 | } |
---|
| 1678 | |
---|
[234] | 1679 | void SDMath::correctFromTable(SDMemTable* pTabOut, const SDMemTable& in, |
---|
| 1680 | const Table& tTable, const String& col0, |
---|
| 1681 | const String& col1, |
---|
| 1682 | const String& methodStr, Bool doAll, |
---|
| 1683 | const Vector<Float>& xOut) const |
---|
[230] | 1684 | { |
---|
| 1685 | |
---|
| 1686 | // Get data from Table |
---|
| 1687 | |
---|
| 1688 | ROScalarColumn<Float> geElCol(tTable, col0); |
---|
| 1689 | ROScalarColumn<Float> geFacCol(tTable, col1); |
---|
| 1690 | Vector<Float> xIn = geElCol.getColumn(); |
---|
| 1691 | Vector<Float> yIn = geFacCol.getColumn(); |
---|
| 1692 | Vector<Bool> maskIn(xIn.nelements(),True); |
---|
| 1693 | |
---|
| 1694 | // Interpolate (and extrapolate) with desired method |
---|
| 1695 | |
---|
| 1696 | Int method = 0; |
---|
| 1697 | convertInterpString(method, methodStr); |
---|
| 1698 | // |
---|
| 1699 | Vector<Float> yOut; |
---|
| 1700 | Vector<Bool> maskOut; |
---|
| 1701 | InterpolateArray1D<Float,Float>::interpolate(yOut, maskOut, xOut, |
---|
| 1702 | xIn, yIn, maskIn, method, |
---|
| 1703 | True, True); |
---|
[234] | 1704 | // Apply |
---|
[230] | 1705 | |
---|
[234] | 1706 | correctFromVector (pTabOut, in, doAll, yOut); |
---|
| 1707 | } |
---|
| 1708 | |
---|
| 1709 | |
---|
| 1710 | void SDMath::correctFromVector (SDMemTable* pTabOut, const SDMemTable& in, |
---|
| 1711 | Bool doAll, const Vector<Float>& factor) const |
---|
| 1712 | { |
---|
[270] | 1713 | |
---|
[230] | 1714 | // For operations only on specified cursor location |
---|
| 1715 | |
---|
| 1716 | IPosition start, end; |
---|
| 1717 | getCursorLocation(start, end, in); |
---|
| 1718 | |
---|
[270] | 1719 | // Loop over rows and apply correction factor |
---|
[230] | 1720 | |
---|
| 1721 | const uInt axis = asap::ChanAxis; |
---|
| 1722 | for (uInt i=0; i < in.nRow(); ++i) { |
---|
| 1723 | |
---|
| 1724 | // Get data |
---|
| 1725 | |
---|
| 1726 | MaskedArray<Float> dataIn(in.rowAsMaskedArray(i)); |
---|
| 1727 | |
---|
| 1728 | // Apply factor |
---|
| 1729 | |
---|
| 1730 | if (doAll) { |
---|
[270] | 1731 | dataIn *= factor[i]; |
---|
[230] | 1732 | } else { |
---|
[270] | 1733 | MaskedArray<Float> dataIn2 = dataIn(start,end); // reference |
---|
| 1734 | dataIn2 *= factor[i]; |
---|
[230] | 1735 | } |
---|
| 1736 | |
---|
| 1737 | // Write out |
---|
| 1738 | |
---|
| 1739 | SDContainer sc = in.getSDContainer(i); |
---|
[270] | 1740 | putDataInSDC(sc, dataIn.getArray(), dataIn.getMask()); |
---|
[230] | 1741 | // |
---|
| 1742 | pTabOut->putSDContainer(sc); |
---|
| 1743 | } |
---|
| 1744 | } |
---|
| 1745 | |
---|
[234] | 1746 | |
---|
[262] | 1747 | void SDMath::generateSourceTable (Vector<String>& srcTab, |
---|
| 1748 | Vector<uInt>& srcIdx, |
---|
| 1749 | Vector<uInt>& firstRow, |
---|
| 1750 | const Vector<String>& srcNames) const |
---|
| 1751 | // |
---|
| 1752 | // This algorithm assumes that if there are multiple beams |
---|
| 1753 | // that the source names are diffent. Oterwise we would need |
---|
| 1754 | // to look atthe direction for each beam... |
---|
| 1755 | // |
---|
| 1756 | { |
---|
| 1757 | const uInt nRow = srcNames.nelements(); |
---|
| 1758 | srcTab.resize(0); |
---|
| 1759 | srcIdx.resize(nRow); |
---|
| 1760 | firstRow.resize(0); |
---|
| 1761 | // |
---|
| 1762 | uInt nSrc = 0; |
---|
| 1763 | for (uInt i=0; i<nRow; i++) { |
---|
| 1764 | String srcName = srcNames[i]; |
---|
| 1765 | |
---|
| 1766 | // Do we have this source already ? |
---|
| 1767 | |
---|
| 1768 | Int idx = -1; |
---|
| 1769 | if (nSrc>0) { |
---|
| 1770 | for (uInt j=0; j<nSrc; j++) { |
---|
| 1771 | if (srcName==srcTab[j]) { |
---|
| 1772 | idx = j; |
---|
| 1773 | break; |
---|
| 1774 | } |
---|
| 1775 | } |
---|
| 1776 | } |
---|
| 1777 | |
---|
| 1778 | // Add new entry if not found |
---|
| 1779 | |
---|
| 1780 | if (idx==-1) { |
---|
| 1781 | nSrc++; |
---|
| 1782 | srcTab.resize(nSrc,True); |
---|
| 1783 | srcTab(nSrc-1) = srcName; |
---|
| 1784 | idx = nSrc-1; |
---|
| 1785 | // |
---|
| 1786 | firstRow.resize(nSrc,True); |
---|
| 1787 | firstRow(nSrc-1) = i; // First row for which this source occurs |
---|
| 1788 | } |
---|
| 1789 | |
---|
| 1790 | // Set index for this row |
---|
| 1791 | |
---|
| 1792 | srcIdx[i] = idx; |
---|
| 1793 | } |
---|
| 1794 | } |
---|
[272] | 1795 | |
---|
| 1796 | MEpoch SDMath::epochFromString (const String& str, MEpoch::Types timeRef) const |
---|
| 1797 | { |
---|
| 1798 | Quantum<Double> qt; |
---|
| 1799 | if (MVTime::read(qt,str)) { |
---|
| 1800 | MVEpoch mv(qt); |
---|
| 1801 | MEpoch me(mv, timeRef); |
---|
| 1802 | return me; |
---|
| 1803 | } else { |
---|
| 1804 | throw(AipsError("Invalid format for Epoch string")); |
---|
| 1805 | } |
---|
| 1806 | } |
---|
| 1807 | |
---|
| 1808 | |
---|
| 1809 | String SDMath::formatEpoch(const MEpoch& epoch) const |
---|
| 1810 | { |
---|
| 1811 | MVTime mvt(epoch.getValue()); |
---|
| 1812 | return mvt.string(MVTime::YMD) + String(" (") + epoch.getRefString() + String(")"); |
---|
| 1813 | } |
---|
| 1814 | |
---|
[294] | 1815 | |
---|
[309] | 1816 | |
---|
| 1817 | void SDMath::generateFrequencyAligners (PtrBlock<FrequencyAligner<Float>* >& a, |
---|
[294] | 1818 | const SDMemTable& in, uInt nChan, |
---|
| 1819 | uInt nFreqIDs, uInt nSrcTab, |
---|
| 1820 | const Vector<uInt>& firstRow, |
---|
[309] | 1821 | MFrequency::Types system, |
---|
[294] | 1822 | const MPosition& refPos, |
---|
| 1823 | const MEpoch& refEpoch) const |
---|
| 1824 | { |
---|
| 1825 | for (uInt fqID=0; fqID<nFreqIDs; fqID++) { |
---|
| 1826 | SpectralCoordinate sC = in.getSpectralCoordinate(fqID); |
---|
| 1827 | for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) { |
---|
| 1828 | MDirection refDir = in.getDirection(firstRow[iSrc]); |
---|
| 1829 | uInt idx = (iSrc*nFreqIDs) + fqID; |
---|
[309] | 1830 | a[idx] = new FrequencyAligner<Float>(sC, nChan, refEpoch, refDir, refPos, system); |
---|
[294] | 1831 | } |
---|
| 1832 | } |
---|
| 1833 | } |
---|
| 1834 | |
---|
[309] | 1835 | |
---|