Changeset 2928 for trunk


Ignore:
Timestamp:
04/16/14 12:19:06 (10 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes/No?

What Interface Changed: Please list interface changes

Test Programs: test_sdcal2, test_tsdcal2

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Improved performance of apply mode by revisiting array structure.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STApplyCal.cpp

    r2925 r2928  
    206206
    207207  // list of apply tables for sky calibration
    208   Vector<uInt> skycalList;
     208  Vector<uInt> skycalList(skytable_.size());
    209209  uInt numSkyCal = 0;
    210   uInt nrowSky = 0;
    211210
    212211  // list of apply tables for Tsys calibration
     
    214213    STCalEnum::CalType caltype = STApplyTable::getCalType(skytable_[i]);
    215214    if (caltype == caltype_) {
    216       skycalList.resize(numSkyCal+1, True);
    217215      skycalList[numSkyCal] = i;
    218216      numSkyCal++;
    219       nrowSky += skytable_[i]->nrow();
    220     }
    221   }
     217    }
     218  }
     219  skycalList.resize(numSkyCal, True);
    222220
    223221
     
    303301
    304302  uInt nchanSp = skytable_[skylist[0]]->nchan(ifno);
    305   Vector<Double> timeSky(nrowSky);
    306   Matrix<Float> spoff(nrowSky, nchanSp);
    307   Vector<Float> iOff(nchanSp);
    308   nrowSky = 0;
    309   for (uInt i = 0 ; i < skylist.nelements(); i++) {
    310     STCalSkyTable *p = skytable_[skylist[i]];
    311     Vector<Double> t = p->getTime();
    312     Matrix<Float> sp = p->getSpectra();
    313     for (uInt j = 0; j < t.nelements(); j++) {
    314       timeSky[nrowSky] = t[j];
    315       spoff.row(nrowSky) = sp.column(j);
    316       nrowSky++;
    317     }
    318   }
    319 
    320   Vector<uInt> skyIdx = timeSort(timeSky);
    321 
    322   Double *xa = new Double[skyIdx.nelements()];
    323   Float *ya = new Float[skyIdx.nelements()];
    324   IPosition ipos(1, skyIdx.nelements());
    325   Vector<Double> timeSkySorted(ipos, xa, TAKE_OVER);
    326   Vector<Float> tmpOff(ipos, ya, TAKE_OVER);
    327   for (uInt i = 0 ; i < skyIdx.nelements(); i++) {
    328     timeSkySorted[i] = timeSky[skyIdx[i]];
    329   }
    330 
    331   interpolatorS_->setX(xa, skyIdx.nelements());
    332 
    333   Vector<uInt> tsysIdx;
    334   Vector<Double> timeTsys(nrowTsys);
    335   Matrix<Float> tsys;
     303  uInt nrowSkySorted = nrowSky;
     304  Vector<Double> timeSkySorted;
     305  Matrix<Float> spoffSorted;
     306  {
     307    Vector<Double> timeSky(nrowSky);
     308    Matrix<Float> spoff(nrowSky, nchanSp);
     309    nrowSky = 0;
     310    for (uInt i = 0 ; i < skylist.nelements(); i++) {
     311      STCalSkyTable *p = skytable_[skylist[i]];
     312      Vector<Double> t = p->getTime();
     313      Matrix<Float> sp = p->getSpectra();
     314      for (uInt j = 0; j < t.nelements(); j++) {
     315        timeSky[nrowSky] = t[j];
     316        spoff.row(nrowSky) = sp.column(j);
     317        nrowSky++;
     318      }
     319    }
     320   
     321    Vector<uInt> skyIdx = timeSort(timeSky);
     322    nrowSkySorted = skyIdx.nelements();
     323   
     324    timeSkySorted.takeStorage(IPosition(1, nrowSkySorted),
     325                              new Double[nrowSkySorted],
     326                              TAKE_OVER);
     327    for (uInt i = 0 ; i < nrowSkySorted; i++) {
     328      timeSkySorted[i] = timeSky[skyIdx[i]];
     329    }
     330    interpolatorS_->setX(timeSkySorted.data(), nrowSkySorted);
     331   
     332    spoffSorted.takeStorage(IPosition(2, nrowSky, nchanSp),
     333                            new Float[nrowSky * nchanSp],
     334                            TAKE_OVER);
     335    for (uInt i = 0 ; i < nrowSky; i++) {
     336      spoffSorted.row(i) = spoff.row(skyIdx[i]);
     337    }
     338  }
     339
     340  uInt nrowTsysSorted = nrowTsys;
     341  Matrix<Float> tsysSorted;
    336342  Vector<Double> timeTsysSorted;
    337   Vector<Float> tmpTsys;
    338343  if (doTsys) {
    339344    //os_ << "doTsys" << LogIO::POST;
    340     timeTsys.resize(nrowTsys);
    341     tsys.resize(nrowTsys, nchanTsys);
     345    Vector<Double> timeTsys(nrowTsys);
     346    Matrix<Float> tsys(nrowTsys, nchanTsys);
     347    tsysSorted.takeStorage(IPosition(2, nrowTsys, nchanTsys),
     348                           new Float[nrowTsys * nchanTsys],
     349                           TAKE_OVER);
    342350    nrowTsys = 0;
    343351    for (uInt i = 0 ; i < tsystable_.size(); i++) {
     
    351359      }
    352360    }
    353     tsysIdx = timeSort(timeTsys);
    354 
    355     Double *xb = new Double[tsysIdx.nelements()];
    356     Float *yb = new Float[tsysIdx.nelements()];
    357     IPosition ipos(1, tsysIdx.nelements());
    358     timeTsysSorted.takeStorage(ipos, xb, TAKE_OVER);
    359     tmpTsys.takeStorage(ipos, yb, TAKE_OVER);
    360     for (uInt i = 0 ; i < tsysIdx.nelements(); i++) {
     361    Vector<uInt> tsysIdx = timeSort(timeTsys);
     362    nrowTsysSorted = tsysIdx.nelements();
     363
     364    timeTsysSorted.takeStorage(IPosition(1, nrowTsysSorted),
     365                               new Double[nrowTsysSorted],
     366                               TAKE_OVER);
     367    for (uInt i = 0 ; i < nrowTsysSorted; i++) {
    361368      timeTsysSorted[i] = timeTsys[tsysIdx[i]];
    362369    }
    363     interpolatorT_->setX(xb, tsysIdx.nelements());
     370    interpolatorT_->setX(timeTsysSorted.data(), nrowTsysSorted);
     371
     372    for (uInt i = 0; i < nrowTsys; ++i) {
     373      tsysSorted.row(i) = tsys.row(tsysIdx[i]);
     374    }
    364375  }
    365376
     
    371382
    372383  // Array for scaling factor (aka Tsys)
    373   Vector<Float> iTsys(IPosition(1,nchanSp), new Float[nchanSp], TAKE_OVER);
     384  Vector<Float> iTsys(IPosition(1, nchanSp), new Float[nchanSp], TAKE_OVER);
     385  // Array for Tsys interpolation
     386  // This is empty array and is never referenced if doTsys == false
     387  // (i.e. nchanTsys == 0)
     388  Vector<Float> iTsysT(IPosition(1, nchanTsys), new Float[nchanTsys], TAKE_OVER);
     389
     390  // Array for interpolated off spectrum
     391  Vector<Float> iOff(IPosition(1, nchanSp), new Float[nchanSp], TAKE_OVER);
    374392 
    375393  for (uInt i = 0; i < rows.nelements(); i++) {
     
    385403    Double t0 = timeCol(irow);
    386404    for (uInt ichan = 0; ichan < nchanSp; ichan++) {
    387       for (uInt j = 0; j < skyIdx.nelements(); j++) {
    388         tmpOff[j] = spoff(skyIdx[j], ichan);
    389       }
    390       interpolatorS_->setY(ya, skyIdx.nelements());
     405      Float *tmpY = &(spoffSorted.data()[ichan * nrowSkySorted]);
     406      interpolatorS_->setY(tmpY, nrowSkySorted);
    391407      iOff[ichan] = interpolatorS_->interpolate(t0);
    392408    }
     
    396412    if (doTsys) {
    397413      // Tsys correction
    398       Float *yt = new Float[nchanTsys];
    399       Vector<Float> iTsysT(IPosition(1,nchanTsys), yt, TAKE_OVER);
    400       Float *yb = tmpTsys.data();
     414      Float *yt = iTsysT.data();
    401415      for (uInt ichan = 0; ichan < nchanTsys; ichan++) {
    402         for (uInt j = 0; j < tsysIdx.nelements(); j++) {
    403           tmpTsys[j] = tsys(tsysIdx[j], ichan);
    404         }
    405         interpolatorT_->setY(yb, tsysIdx.nelements());
     416        Float *tmpY = &(tsysSorted.data()[ichan * nrowTsysSorted]);
     417        interpolatorT_->setY(tmpY, nrowTsysSorted);
    406418        iTsysT[ichan] = interpolatorT_->interpolate(t0);
    407419      }
Note: See TracChangeset for help on using the changeset viewer.