Changeset 2963
- Timestamp:
- 06/30/14 12:46:50 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STApplyCal.cpp
r2960 r2963 45 45 using namespace std; 46 46 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 } 64 } 65 47 66 namespace asap { 48 49 67 STApplyCal::STApplyCal() 50 68 { … … 292 310 uInt nrowThisTsys = tsystable_[i]->nrow(); 293 311 nrowTsys += nrowThisTsys; 294 if (nrowThisTsys > 0 andnchanTsys == 0) {312 if (nrowThisTsys > 0 && nchanTsys == 0) { 295 313 nchanTsys = tsystable_[i]->nchan(tsysifno); 296 314 ftsys = tsystable_[i]->getBaseFrequency(0); … … 323 341 } 324 342 325 Vector<uInt> skyIdx = timeSort(timeSky);343 Vector<uInt> skyIdx = indexSort(timeSky); 326 344 nrowSkySorted = skyIdx.nelements(); 327 345 … … 371 389 } 372 390 } 373 Vector<uInt> tsysIdx = timeSort(timeTsys);391 Vector<uInt> tsysIdx = indexSort(timeTsys); 374 392 nrowTsysSorted = tsysIdx.nelements(); 375 393 … … 407 425 // Array for interpolated off spectrum 408 426 Vector<Float> iOff(IPosition(1, nchanSp), new Float[nchanSp], TAKE_OVER); 427 428 // working array for interpolation with flags 429 uInt arraySize = max(max(nrowTsysSorted, nchanTsys), nrowSkySorted); 430 Vector<Double> xwork(IPosition(1, arraySize), new Double[arraySize], TAKE_OVER); 431 Vector<Float> ywork(IPosition(1, arraySize), new Float[arraySize], TAKE_OVER); 432 Vector<uChar> fwork(IPosition(1, nchanTsys), new uChar[nchanTsys], TAKE_OVER); 409 433 410 434 for (uInt i = 0; i < rows.nelements(); i++) { … … 420 444 // interpolation 421 445 Double t0 = timeCol(irow); 446 Double *xwork_p = xwork.data(); 447 Float *ywork_p = ywork.data(); 422 448 for (uInt ichan = 0; ichan < nchanSp; ichan++) { 423 449 Float *tmpY = &(spoffSorted.data()[ichan * nrowSkySorted]); 424 if (allNE(flagoffSorted.column(ichan), (uChar)0)) { 450 uChar *tmpF = &(flagoffSorted.data()[ichan * nrowSkySorted]); 451 uInt wnrow = 0; 452 for (uInt ir = 0; ir < nrowSkySorted; ++ir) { 453 if (tmpF[ir] == 0) { 454 xwork_p[wnrow] = timeSkySorted.data()[ir]; 455 ywork_p[wnrow] = tmpY[ir]; 456 wnrow++; 457 } 458 } 459 //if (allNE(flagoffSorted.column(ichan), (uChar)0)) { 460 if (wnrow > 0) { 461 // any valid reference data 462 interpolatorS_->setData(xwork_p, ywork_p, wnrow); 463 } 464 else { 465 // no valid reference data 466 // interpolate data regardless of flag 467 interpolatorS_->setData(timeSkySorted.data(), tmpY, nrowSkySorted); 468 // flag this channel for calibrated data 425 469 flag[ichan] = 1 << 7; // user flag 426 470 } 427 interpolatorS_->setY(tmpY, nrowSkySorted);471 //interpolatorS_->setY(tmpY, nrowSkySorted); 428 472 iOff[ichan] = interpolatorS_->interpolate(t0); 429 473 } … … 433 477 if (doTsys) { 434 478 // Tsys correction 479 // interpolation on time axis 435 480 Float *yt = iTsysT.data(); 481 uChar *fwork_p = fwork.data(); 436 482 for (uInt ichan = 0; ichan < nchanTsys; ichan++) { 437 483 Float *tmpY = &(tsysSorted.data()[ichan * nrowTsysSorted]); 438 interpolatorT_->setY(tmpY, nrowTsysSorted); 439 iTsysT[ichan] = interpolatorT_->interpolate(t0); 484 uChar *tmpF = &(flagtsysSorted.data()[ichan * nrowTsysSorted]); 485 uInt wnrow = 0; 486 for (uInt ir = 0; ir < nrowTsysSorted; ++ir) { 487 if (tmpF[ir] == 0) { 488 xwork_p[wnrow] = timeTsysSorted.data()[ir]; 489 ywork_p[wnrow] = tmpY[ir]; 490 wnrow++; 491 } 492 } 493 if (wnrow > 0) { 494 // any valid value exists 495 //interpolatorT_->setY(tmpY, nrowTsysSorted); 496 interpolatorT_->setData(xwork_p, ywork_p, wnrow); 497 iTsysT[ichan] = interpolatorT_->interpolate(t0); 498 fwork_p[ichan] = 0; 499 } 500 else { 501 // no valid data 502 fwork_p[ichan] = 1 << 7; // user flag 503 } 440 504 } 441 505 if (nchanSp == 1) { … … 446 510 // interpolation on frequency axis 447 511 Vector<Double> fsp = getBaseFrequency(rows[i]); 448 interpolatorF_->setY(yt, nchanTsys); 512 uInt wnchan = 0; 513 for (uInt ichan = 0; ichan < nchanTsys; ++ichan) { 514 if (fwork_p[ichan] == 0) { 515 xwork_p[wnchan] = ftsys.data()[ichan]; 516 ywork_p[wnchan] = yt[ichan]; 517 ++wnchan; 518 } 519 } 520 //interpolatorF_->setY(yt, nchanTsys); 521 interpolatorF_->setData(xwork_p, ywork_p, wnchan); 449 522 for (uInt ichan = 0; ichan < nchanSp; ichan++) { 450 523 iTsys[ichan] = interpolatorF_->interpolate(fsp[ichan]); … … 488 561 interpolatorF_->reset(); 489 562 interpolatorT_->reset(); 490 }491 492 Vector<uInt> STApplyCal::timeSort(Vector<Double> &t)493 {494 Sort sort;495 sort.sortKey(&t[0], TpDouble, 0, Sort::Ascending);496 Vector<uInt> idx;497 sort.sort(idx, t.nelements(), Sort::QuickSort|Sort::NoDuplicates);498 return idx;499 563 } 500 564 … … 629 693 } 630 694 } 631 } 695 696 } -
trunk/src/STApplyCal.h
r2756 r2963 96 96 casa::Vector<casa::Double> getBaseFrequency(casa::uInt whichrow); 97 97 98 // time sort99 casa::Vector<casa::uInt> timeSort(casa::Vector<casa::Double> &t);100 101 98 // search spwmap_ to get IFNO for Tsys 102 99 casa::uInt getIFForTsys(casa::uInt to);
Note:
See TracChangeset
for help on using the changeset viewer.