Changeset 2965
- Timestamp:
- 07/01/14 11:27:58 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STApplyCal.cpp
r2964 r2965 143 143 static Matrix<uChar> GetFlag(const TableType *t) {return t->getFlagtra();} 144 144 }; 145 146 inline uInt setupWorkingData(const uInt n, const Double *xin, const Float *yin, 147 const uChar *f, Double *xout, Float *yout) 148 { 149 uInt nValid = 0; 150 for (uInt i = 0; i < n; ++i) { 151 if (f[i] == 0) { 152 xout[nValid] = xin[i]; 153 yout[nValid] = yin[i]; 154 nValid++; 155 } 156 } 157 return nValid; 158 } 159 160 template<class InterpolationHelperImpl> 161 class InterpolationHelperInterface 162 { 163 public: 164 static void Interpolate(const Double xref, const uInt nx, const uInt ny, 165 Double *xin, Float *yin, uChar *fin, 166 asap::Interpolator1D<Double, Float> *interpolator, 167 Double *xwork, Float *ywork, 168 Float *yout, uChar *fout) 169 { 170 for (uInt i = 0; i < ny; i++) { 171 Float *tmpY = &(yin[i * nx]); 172 uInt wnrow = setupWorkingData(nx, xin, tmpY, &(fin[i * nx]), xwork, ywork); 173 if (wnrow > 0) { 174 // any valid reference data 175 InterpolationHelperImpl::ProcessValid(xref, i, interpolator, 176 xwork, ywork, wnrow, 177 yout, fout); 178 } 179 else { 180 // no valid reference data 181 InterpolationHelperImpl::ProcessInvalid(xref, i, interpolator, 182 xin, tmpY, nx, 183 yout, fout); 184 } 185 } 186 } 187 }; 188 189 class SkyInterpolationHelper : public InterpolationHelperInterface<SkyInterpolationHelper> 190 { 191 public: 192 static void ProcessValid(const Double xref, const uInt index, 193 asap::Interpolator1D<Double, Float> *interpolator, 194 Double *xwork, Float *ywork, 195 const uInt wnrow, Float *yout, uChar *fout) 196 { 197 interpolator->setData(xwork, ywork, wnrow); 198 yout[index] = interpolator->interpolate(xref); 199 } 200 static void ProcessInvalid(const Double xref, const uInt index, 201 asap::Interpolator1D<Double, Float> *interpolator, 202 Double *xwork, Float *ywork, 203 const uInt wnrow, Float *yout, uChar *fout) 204 { 205 // interpolate data regardless of flag 206 ProcessValid(xref, index, interpolator, xwork, ywork, wnrow, yout, fout); 207 // flag this channel for calibrated data 208 fout[index] = 1 << 7; // user flag 209 } 210 }; 211 212 class TsysInterpolationHelper : public InterpolationHelperInterface<TsysInterpolationHelper> 213 { 214 public: 215 static void ProcessValid(const Double xref, const uInt index, 216 asap::Interpolator1D<Double, Float> *interpolator, 217 Double *xwork, Float *ywork, 218 const uInt wnrow, Float *yout, uChar *fout) 219 { 220 interpolator->setData(xwork, ywork, wnrow); 221 yout[index] = interpolator->interpolate(xref); 222 fout[index] = 0; 223 } 224 static void ProcessInvalid(const Double xref, const uInt index, 225 asap::Interpolator1D<Double, Float> *interpolator, 226 Double *xwork, Float *ywork, 227 const uInt wnrow, Float *yout, uChar *fout) 228 { 229 fout[index] = 1 << 7; // user flag 230 } 231 }; 145 232 } 146 233 … … 443 530 Vector<Float> ywork(IPosition(1, arraySize), new Float[arraySize], TAKE_OVER); 444 531 Vector<uChar> fwork(IPosition(1, nchanTsys), new uChar[nchanTsys], TAKE_OVER); 532 533 // data array 534 Vector<Float> on(IPosition(1, nchanSp), new Float[nchanSp], TAKE_OVER); 535 Vector<uChar> flag(on.shape(), new uChar[on.shape().product()], TAKE_OVER); 445 536 446 537 for (uInt i = 0; i < rows.nelements(); i++) { … … 449 540 450 541 // target spectral data 451 Vector<Float> on = spCol(irow);452 Vector<uChar> flag = flCol(irow);542 spCol.get(irow, on); 543 flCol.get(irow, flag); 453 544 //os_ << "on=" << on[0] << LogIO::POST; 454 545 calibrator_->setSource(on); … … 458 549 Double *xwork_p = xwork.data(); 459 550 Float *ywork_p = ywork.data(); 460 for (uInt ichan = 0; ichan < nchanSp; ichan++) { 461 Float *tmpY = &(spoff.data()[ichan * nrowSky]); 462 uChar *tmpF = &(flagoff.data()[ichan * nrowSky]); 463 uInt wnrow = 0; 464 for (uInt ir = 0; ir < nrowSky; ++ir) { 465 if (tmpF[ir] == 0) { 466 xwork_p[wnrow] = timeSky.data()[ir]; 467 ywork_p[wnrow] = tmpY[ir]; 468 wnrow++; 469 } 470 } 471 if (wnrow > 0) { 472 // any valid reference data 473 interpolatorS_->setData(xwork_p, ywork_p, wnrow); 474 } 475 else { 476 // no valid reference data 477 // interpolate data regardless of flag 478 interpolatorS_->setData(timeSky.data(), tmpY, nrowSky); 479 // flag this channel for calibrated data 480 flag[ichan] = 1 << 7; // user flag 481 } 482 iOff[ichan] = interpolatorS_->interpolate(t0); 483 } 484 //os_ << "iOff=" << iOff[0] << LogIO::POST; 551 SkyInterpolationHelper::Interpolate(t0, nrowSky, nchanSp, 552 timeSky.data(), spoff.data(), 553 flagoff.data(), &(*interpolatorS_), 554 xwork_p, ywork_p, 555 iOff.data(), flag.data()); 485 556 calibrator_->setReference(iOff); 486 557 … … 488 559 // Tsys correction 489 560 // interpolation on time axis 490 Float *yt = iTsysT.data(); 561 TsysInterpolationHelper::Interpolate(t0, nrowTsys, nchanTsys, 562 timeTsys.data(), tsys.data(), 563 flagtsys.data(), &(*interpolatorT_), 564 xwork_p, ywork_p, 565 iTsysT.data(), fwork.data()); 491 566 uChar *fwork_p = fwork.data(); 492 for (uInt ichan = 0; ichan < nchanTsys; ichan++) {493 Float *tmpY = &(tsys.data()[ichan * nrowTsys]);494 uChar *tmpF = &(flagtsys.data()[ichan * nrowTsys]);495 uInt wnrow = 0;496 for (uInt ir = 0; ir < nrowTsys; ++ir) {497 if (tmpF[ir] == 0) {498 xwork_p[wnrow] = timeTsys.data()[ir];499 ywork_p[wnrow] = tmpY[ir];500 wnrow++;501 }502 }503 if (wnrow > 0) {504 // any valid value exists505 interpolatorT_->setData(xwork_p, ywork_p, wnrow);506 iTsysT[ichan] = interpolatorT_->interpolate(t0);507 fwork_p[ichan] = 0;508 }509 else {510 // no valid data511 fwork_p[ichan] = 1 << 7; // user flag512 }513 }514 567 if (nchanSp == 1) { 515 568 // take average … … 519 572 // interpolation on frequency axis 520 573 Vector<Double> fsp = getBaseFrequency(rows[i]); 521 uInt wnchan = 0; 522 for (uInt ichan = 0; ichan < nchanTsys; ++ichan) { 523 if (fwork_p[ichan] == 0) { 524 xwork_p[wnchan] = ftsys.data()[ichan]; 525 ywork_p[wnchan] = yt[ichan]; 526 ++wnchan; 527 } 528 } 529 //interpolatorF_->setY(yt, nchanTsys); 574 uInt wnchan = setupWorkingData(nchanTsys, ftsys.data(), iTsysT.data(), 575 fwork_p, xwork_p, ywork_p); 530 576 interpolatorF_->setData(xwork_p, ywork_p, wnchan); 531 577 for (uInt ichan = 0; ichan < nchanSp; ichan++) {
Note:
See TracChangeset
for help on using the changeset viewer.