- Timestamp:
- 06/30/14 17:13:19 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STApplyCal.cpp
r2963 r2964 46 46 47 47 namespace { 48 // utility functions 49 Vector<uInt> indexSort(Vector<Double> &t) 50 { 51 Sort sort; 52 sort.sortKey(&t[0], TpDouble, 0, Sort::Ascending); 53 Vector<uInt> idx; 54 sort.sort(idx, t.nelements(), Sort::QuickSort|Sort::NoDuplicates); 55 return idx; 56 } 57 58 void getSortedData(const Vector<Double> key, const Vector<Float> data, 59 const Vector<uChar> flag, 60 Vector<Double> sortedKey, Vector<Float> sortedData, 61 Vector<uChar> sortedFlag) 62 { 63 } 48 template<class Accessor, class Type> 49 class AccessorInterface 50 { 51 public: 52 typedef Type TableType; 53 static void GetSortedData(const vector<TableType *> &tablelist, 54 const Vector<uInt> &tableIndex, 55 const uInt nrow, 56 const uInt nchan, 57 Vector<Double> &time, 58 Matrix<Float> &data, 59 Matrix<uChar> &flag) 60 { 61 Vector<Double> timeUnsorted; 62 Matrix<Float> dataUnsorted; 63 Matrix<uChar> flagUnsorted; 64 GetFromTable(tablelist, tableIndex, nrow, nchan, 65 timeUnsorted, dataUnsorted, flagUnsorted); 66 SortData(timeUnsorted, dataUnsorted, flagUnsorted, 67 time, data, flag); 68 } 69 private: 70 static void GetFromTable(const vector<TableType *> &tableList, 71 const Vector<uInt> &tableIndex, 72 const uInt nrow, 73 const uInt nchan, 74 Vector<Double> &time, 75 Matrix<Float> &data, 76 Matrix<uChar> &flag) 77 { 78 time.resize(nrow, False); 79 const IPosition shape(2, nrow, nchan); 80 data.resize(shape, False); 81 flag.resize(shape, False); 82 uInt rowIndex = 0; 83 for (uInt i = 0 ; i < tableIndex.nelements(); i++) { 84 TableType *p = tableList[tableIndex[i]]; 85 Vector<Double> t = Accessor::GetTime(p); 86 Matrix<Float> dt = Accessor::GetData(p); 87 Matrix<uChar> fl = Accessor::GetFlag(p); 88 for (uInt j = 0; j < t.nelements(); j++) { 89 time[rowIndex] = t[j]; 90 data.row(rowIndex) = dt.column(j); 91 flag.row(rowIndex) = fl.column(j); 92 rowIndex++; 93 } 94 } 95 } 96 97 static Vector<uInt> IndexSort(const Vector<Double> &t) 98 { 99 Sort sort; 100 sort.sortKey(&t[0], TpDouble, 0, Sort::Ascending); 101 Vector<uInt> idx; 102 sort.sort(idx, t.nelements(), Sort::QuickSort|Sort::NoDuplicates); 103 return idx; 104 } 105 106 static void SortData(const Vector<Double> &key, const Matrix<Float> &data, 107 const Matrix<uChar> &flag, 108 Vector<Double> &sortedKey, Matrix<Float> &sortedData, 109 Matrix<uChar> &sortedFlag) 110 { 111 Vector<uInt> sortIndex = IndexSort(key); 112 uInt len = sortIndex.nelements(); 113 IPosition shape = data.shape(); 114 shape[0] = len; 115 Int64 nelements = shape.product(); 116 sortedKey.takeStorage(IPosition(1, len), new Double[len], TAKE_OVER); 117 sortedData.takeStorage(shape, new Float[nelements], TAKE_OVER); 118 sortedFlag.takeStorage(shape, new uChar[nelements], TAKE_OVER); 119 for (uInt i = 0 ; i < len; i++) { 120 sortedKey[i] = key[sortIndex[i]]; 121 } 122 for (uInt i = 0; i < len; ++i) { 123 sortedData.row(i) = data.row(sortIndex[i]); 124 sortedFlag.row(i) = flag.row(sortIndex[i]); 125 } 126 } 127 128 }; 129 130 class SkyTableAccessor : public AccessorInterface<SkyTableAccessor, asap::STCalSkyTable> 131 { 132 public: 133 static Vector<Double> GetTime(const TableType *t) {return t->getTime();} 134 static Matrix<Float> GetData(const TableType *t) {return t->getSpectra();} 135 static Matrix<uChar> GetFlag(const TableType *t) {return t->getFlagtra();} 136 }; 137 138 class TsysTableAccessor : public AccessorInterface<TsysTableAccessor, asap::STCalTsysTable> 139 { 140 public: 141 static Vector<Double> GetTime(const TableType *t) {return t->getTime();} 142 static Matrix<Float> GetData(const TableType *t) {return t->getTsys();} 143 static Matrix<uChar> GetFlag(const TableType *t) {return t->getFlagtra();} 144 }; 64 145 } 65 146 … … 277 358 278 359 // apply selection to apply tables 279 uInt nrowSky = 0;280 uInt nrowTsys = 0;360 uInt nrowSkyTotal = 0; 361 uInt nrowTsysTotal = 0; 281 362 for (uInt i = 0; i < skylist.nelements(); i++) { 282 363 skytable_[skylist[i]]->setSelection(sel); 283 nrowSky += skytable_[skylist[i]]->nrow();284 os_ << "nrowSky =" << nrowSky<< LogIO::POST;364 nrowSkyTotal += skytable_[skylist[i]]->nrow(); 365 os_ << "nrowSkyTotal=" << nrowSkyTotal << LogIO::POST; 285 366 } 286 367 287 368 // Skip IFNO without sky data 288 if (nrowSky == 0)369 if (nrowSkyTotal == 0) 289 370 return; 290 371 … … 309 390 tsystable_[i]->setSelection(sel); 310 391 uInt nrowThisTsys = tsystable_[i]->nrow(); 311 nrowTsys += nrowThisTsys;392 nrowTsysTotal += nrowThisTsys; 312 393 if (nrowThisTsys > 0 && nchanTsys == 0) { 313 394 nchanTsys = tsystable_[i]->nchan(tsysifno); … … 315 396 } 316 397 } 317 interpolatorF_->setX(ftsys.data(), nchanTsys);318 398 } 319 399 320 400 uInt nchanSp = skytable_[skylist[0]]->nchan(ifno); 321 uInt nrowSkySorted = nrowSky; 322 Vector<Double> timeSkySorted; 323 Matrix<Float> spoffSorted; 324 Matrix<uChar> flagoffSorted; 325 { 326 Vector<Double> timeSky(nrowSky); 327 Matrix<Float> spoff(nrowSky, nchanSp); 328 Matrix<uChar> flagoff(nrowSky, nchanSp); 329 nrowSky = 0; 330 for (uInt i = 0 ; i < skylist.nelements(); i++) { 331 STCalSkyTable *p = skytable_[skylist[i]]; 332 Vector<Double> t = p->getTime(); 333 Matrix<Float> sp = p->getSpectra(); 334 Matrix<uChar> fl = p->getFlagtra(); 335 for (uInt j = 0; j < t.nelements(); j++) { 336 timeSky[nrowSky] = t[j]; 337 spoff.row(nrowSky) = sp.column(j); 338 flagoff.row(nrowSky) = fl.column(j); 339 nrowSky++; 340 } 341 } 342 343 Vector<uInt> skyIdx = indexSort(timeSky); 344 nrowSkySorted = skyIdx.nelements(); 345 346 timeSkySorted.takeStorage(IPosition(1, nrowSkySorted), 347 new Double[nrowSkySorted], 348 TAKE_OVER); 349 for (uInt i = 0 ; i < nrowSkySorted; i++) { 350 timeSkySorted[i] = timeSky[skyIdx[i]]; 351 } 352 interpolatorS_->setX(timeSkySorted.data(), nrowSkySorted); 353 354 spoffSorted.takeStorage(IPosition(2, nrowSky, nchanSp), 355 new Float[nrowSky * nchanSp], 356 TAKE_OVER); 357 flagoffSorted.takeStorage(IPosition(2, nrowSkySorted, nchanSp), 358 new uChar[nrowSkySorted * nchanSp], 359 TAKE_OVER); 360 for (uInt i = 0 ; i < nrowSky; i++) { 361 spoffSorted.row(i) = spoff.row(skyIdx[i]); 362 flagoffSorted.row(i) = flagoff.row(skyIdx[i]); 363 } 364 } 365 366 uInt nrowTsysSorted = nrowTsys; 367 Matrix<Float> tsysSorted; 368 Matrix<uChar> flagtsysSorted; 369 Vector<Double> timeTsysSorted; 401 uInt nrowSky = nrowSkyTotal; 402 Vector<Double> timeSky; 403 Matrix<Float> spoff; 404 Matrix<uChar> flagoff; 405 SkyTableAccessor::GetSortedData(skytable_, skylist, 406 nrowSkyTotal, nchanSp, 407 timeSky, spoff, flagoff); 408 nrowSky = timeSky.nelements(); 409 410 uInt nrowTsys = nrowTsysTotal; 411 Vector<Double> timeTsys; 412 Matrix<Float> tsys; 413 Matrix<uChar> flagtsys; 370 414 if (doTsys) { 371 415 //os_ << "doTsys" << LogIO::POST; 372 Vector<Double> timeTsys(nrowTsys); 373 Matrix<Float> tsys(nrowTsys, nchanTsys); 374 Matrix<uChar> flagtsys(nrowTsys, nchanTsys); 375 tsysSorted.takeStorage(IPosition(2, nrowTsys, nchanTsys), 376 new Float[nrowTsys * nchanTsys], 377 TAKE_OVER); 378 nrowTsys = 0; 379 for (uInt i = 0 ; i < tsystable_.size(); i++) { 380 STCalTsysTable *p = tsystable_[i]; 381 Vector<Double> t = p->getTime(); 382 Matrix<Float> ts = p->getTsys(); 383 Matrix<uChar> fl = p->getFlagtra(); 384 for (uInt j = 0; j < t.nelements(); j++) { 385 timeTsys[nrowTsys] = t[j]; 386 tsys.row(nrowTsys) = ts.column(j); 387 flagtsys.row(nrowTsys) = fl.column(j); 388 nrowTsys++; 389 } 390 } 391 Vector<uInt> tsysIdx = indexSort(timeTsys); 392 nrowTsysSorted = tsysIdx.nelements(); 393 394 timeTsysSorted.takeStorage(IPosition(1, nrowTsysSorted), 395 new Double[nrowTsysSorted], 396 TAKE_OVER); 397 flagtsysSorted.takeStorage(IPosition(2, nrowTsysSorted, nchanTsys), 398 new uChar[nrowTsysSorted * nchanTsys], 399 TAKE_OVER); 400 for (uInt i = 0 ; i < nrowTsysSorted; i++) { 401 timeTsysSorted[i] = timeTsys[tsysIdx[i]]; 402 } 403 interpolatorT_->setX(timeTsysSorted.data(), nrowTsysSorted); 404 405 for (uInt i = 0; i < nrowTsys; ++i) { 406 tsysSorted.row(i) = tsys.row(tsysIdx[i]); 407 flagtsysSorted.row(i) = flagtsys.row(tsysIdx[i]); 408 } 416 Vector<uInt> tsyslist(tsystable_.size()); 417 indgen(tsyslist); 418 TsysTableAccessor::GetSortedData(tsystable_, tsyslist, 419 nrowTsysTotal, nchanTsys, 420 timeTsys, tsys, flagtsys); 421 nrowTsys = timeTsys.nelements(); 409 422 } 410 423 … … 414 427 ArrayColumn<Float> tsysCol(tab, "TSYS"); 415 428 ScalarColumn<Double> timeCol(tab, "TIME"); 416 //Vector<Float> on;417 429 418 430 // Array for scaling factor (aka Tsys) … … 427 439 428 440 // working array for interpolation with flags 429 uInt arraySize = max(max(nrowTsys Sorted, nchanTsys), nrowSkySorted);441 uInt arraySize = max(max(nrowTsys, nchanTsys), nrowSky); 430 442 Vector<Double> xwork(IPosition(1, arraySize), new Double[arraySize], TAKE_OVER); 431 443 Vector<Float> ywork(IPosition(1, arraySize), new Float[arraySize], TAKE_OVER); … … 447 459 Float *ywork_p = ywork.data(); 448 460 for (uInt ichan = 0; ichan < nchanSp; ichan++) { 449 Float *tmpY = &(spoff Sorted.data()[ichan * nrowSkySorted]);450 uChar *tmpF = &(flagoff Sorted.data()[ichan * nrowSkySorted]);461 Float *tmpY = &(spoff.data()[ichan * nrowSky]); 462 uChar *tmpF = &(flagoff.data()[ichan * nrowSky]); 451 463 uInt wnrow = 0; 452 for (uInt ir = 0; ir < nrowSky Sorted; ++ir) {464 for (uInt ir = 0; ir < nrowSky; ++ir) { 453 465 if (tmpF[ir] == 0) { 454 xwork_p[wnrow] = timeSky Sorted.data()[ir];466 xwork_p[wnrow] = timeSky.data()[ir]; 455 467 ywork_p[wnrow] = tmpY[ir]; 456 468 wnrow++; 457 469 } 458 470 } 459 //if (allNE(flagoffSorted.column(ichan), (uChar)0)) {460 471 if (wnrow > 0) { 461 472 // any valid reference data … … 465 476 // no valid reference data 466 477 // interpolate data regardless of flag 467 interpolatorS_->setData(timeSky Sorted.data(), tmpY, nrowSkySorted);478 interpolatorS_->setData(timeSky.data(), tmpY, nrowSky); 468 479 // flag this channel for calibrated data 469 480 flag[ichan] = 1 << 7; // user flag 470 481 } 471 //interpolatorS_->setY(tmpY, nrowSkySorted);472 482 iOff[ichan] = interpolatorS_->interpolate(t0); 473 483 } … … 481 491 uChar *fwork_p = fwork.data(); 482 492 for (uInt ichan = 0; ichan < nchanTsys; ichan++) { 483 Float *tmpY = &(tsys Sorted.data()[ichan * nrowTsysSorted]);484 uChar *tmpF = &(flagtsys Sorted.data()[ichan * nrowTsysSorted]);493 Float *tmpY = &(tsys.data()[ichan * nrowTsys]); 494 uChar *tmpF = &(flagtsys.data()[ichan * nrowTsys]); 485 495 uInt wnrow = 0; 486 for (uInt ir = 0; ir < nrowTsys Sorted; ++ir) {496 for (uInt ir = 0; ir < nrowTsys; ++ir) { 487 497 if (tmpF[ir] == 0) { 488 xwork_p[wnrow] = timeTsys Sorted.data()[ir];498 xwork_p[wnrow] = timeTsys.data()[ir]; 489 499 ywork_p[wnrow] = tmpY[ir]; 490 500 wnrow++; … … 493 503 if (wnrow > 0) { 494 504 // any valid value exists 495 //interpolatorT_->setY(tmpY, nrowTsysSorted);496 505 interpolatorT_->setData(xwork_p, ywork_p, wnrow); 497 506 iTsysT[ichan] = interpolatorT_->interpolate(t0); -
trunk/src/STApplyTable.h
r2720 r2964 59 59 casa::uInt nrow() {return table_.nrow();} 60 60 61 casa::Vector<casa::uInt> getScan() {return scanCol_.getColumn();}62 casa::Vector<casa::uInt> getCycle() {return cycleCol_.getColumn();}63 casa::Vector<casa::uInt> getBeam() {return beamCol_.getColumn();}64 casa::Vector<casa::uInt> getIF() {return ifCol_.getColumn();}65 casa::Vector<casa::uInt> getPol() {return polCol_.getColumn();}66 casa::Vector<casa::Double> getTime() {return timeCol_.getColumn();}61 casa::Vector<casa::uInt> getScan() const {return scanCol_.getColumn();} 62 casa::Vector<casa::uInt> getCycle() const {return cycleCol_.getColumn();} 63 casa::Vector<casa::uInt> getBeam() const {return beamCol_.getColumn();} 64 casa::Vector<casa::uInt> getIF() const {return ifCol_.getColumn();} 65 casa::Vector<casa::uInt> getPol() const {return polCol_.getColumn();} 66 casa::Vector<casa::Double> getTime() const {return timeCol_.getColumn();} 67 67 68 68 void setSelection(STSelector &sel, bool sortByTime=false); -
trunk/src/STCalSkyTable.h
r2958 r2964 55 55 const casa::Vector<casa::uChar> &flagtra); 56 56 57 casa::Vector<casa::Float> getElevation() {return elCol_.getColumn();}58 casa::Matrix<casa::Float> getSpectra() {return spectraCol_.getColumn();}59 casa::Matrix<casa::uChar> getFlagtra() {return flagtraCol_.getColumn();}57 casa::Vector<casa::Float> getElevation() const {return elCol_.getColumn();} 58 casa::Matrix<casa::Float> getSpectra() const {return spectraCol_.getColumn();} 59 casa::Matrix<casa::uChar> getFlagtra() const {return flagtraCol_.getColumn();} 60 60 casa::uInt nchan(casa::uInt ifno); 61 61 -
trunk/src/STCalTsysTable.h
r2958 r2964 53 53 const casa::Vector<casa::uChar> &flagtra); 54 54 55 casa::Vector<casa::Float> getElevation() {return elCol_.getColumn();}56 casa::Matrix<casa::Float> getTsys() {return tsysCol_.getColumn();}57 casa::Matrix<casa::uChar> getFlagtra() {return flagtraCol_.getColumn();}55 casa::Vector<casa::Float> getElevation() const {return elCol_.getColumn();} 56 casa::Matrix<casa::Float> getTsys() const {return tsysCol_.getColumn();} 57 casa::Matrix<casa::uChar> getFlagtra() const {return flagtraCol_.getColumn();} 58 58 casa::uInt nchan(casa::uInt ifno); 59 59
Note:
See TracChangeset
for help on using the changeset viewer.