Changeset 2965 for trunk


Ignore:
Timestamp:
07/01/14 11:27:58 (10 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-6585, CAS-6571

Ready for Test: Yes

Interface Changes: Yes/No?

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Refactoring STApplyCal::doapply.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STApplyCal.cpp

    r2964 r2965  
    143143  static Matrix<uChar> GetFlag(const TableType *t) {return t->getFlagtra();}
    144144};
     145
     146inline 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
     160template<class InterpolationHelperImpl>
     161class InterpolationHelperInterface
     162{
     163public:
     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
     189class SkyInterpolationHelper : public InterpolationHelperInterface<SkyInterpolationHelper>
     190{
     191public:
     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
     212class TsysInterpolationHelper : public InterpolationHelperInterface<TsysInterpolationHelper>
     213{
     214public:
     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};
    145232}
    146233
     
    443530  Vector<Float> ywork(IPosition(1, arraySize), new Float[arraySize], TAKE_OVER);
    444531  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);
    445536 
    446537  for (uInt i = 0; i < rows.nelements(); i++) {
     
    449540
    450541    // 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);
    453544    //os_ << "on=" << on[0] << LogIO::POST;
    454545    calibrator_->setSource(on);
     
    458549    Double *xwork_p = xwork.data();
    459550    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());
    485556    calibrator_->setReference(iOff);
    486557   
     
    488559      // Tsys correction
    489560      // 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());
    491566      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 exists
    505           interpolatorT_->setData(xwork_p, ywork_p, wnrow);
    506           iTsysT[ichan] = interpolatorT_->interpolate(t0);
    507           fwork_p[ichan] = 0;
    508         }
    509         else {
    510           // no valid data
    511           fwork_p[ichan] = 1 << 7; // user flag
    512         }
    513       }
    514567      if (nchanSp == 1) {
    515568        // take average
     
    519572        // interpolation on frequency axis
    520573        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);
    530576        interpolatorF_->setData(xwork_p, ywork_p, wnchan);
    531577        for (uInt ichan = 0; ichan < nchanSp; ichan++) {
Note: See TracChangeset for help on using the changeset viewer.