Changeset 2591 for trunk


Ignore:
Timestamp:
07/09/12 16:11:50 (12 years ago)
Author:
WataruKawasaki
Message:

New Development: Yes

JIRA Issue: Yes CSV-1869

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): asap

Description: added a scantable function to get/set moleculesID columns data.


Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2574 r2591  
    1919from asap.utils import _n_bools, mask_not, mask_and, mask_or, page
    2020from asap.asapfitter import fitter
    21 
    22 ###############################################################
    23 ### WK temporarily added these lines for testing 2011/11/28 ###
    24 ###############################################################
    25 #from asap._asap import TestClass
    26 
    27 #class testclass(TestClass):
    28 #    def __init__(self, nelem):
    29 #        TestClass.__init__(self, nelem)
    30 
    31 ###############################################################
    32 
    3321
    3422def preserve_selection(func):
  • trunk/src/Scantable.cpp

    r2575 r2591  
    1111//
    1212#include <map>
     13#include <sys/time.h>
    1314
    1415#include <atnf/PKSIO/SrcType.h>
     
    24442445void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile)
    24452446{
     2447  /*************/
     2448  //clock_t totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd;
     2449  double totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd, msTimeStart, msTimeEnd, seTimeStart, seTimeEnd, otTimeStart, otTimeEnd, prTimeStart, prTimeEnd;
     2450  double elapseMs = 0.0;
     2451  double elapseSe = 0.0;
     2452  double elapseOt = 0.0;
     2453  double elapsePr = 0.0;
     2454  double elapseBl = 0.0;
     2455  double elapseIo = 0.0;
     2456  //totTimeStart = clock();
     2457  totTimeStart = mathutil::gettimeofday_sec();
     2458  /*************/
     2459
    24462460  try {
    24472461    ofstream ofs;
     
    24742488    //--------------------------------
    24752489    for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     2490      /******************/
     2491      //ioTimeStart = clock();
     2492      ioTimeStart = mathutil::gettimeofday_sec();
     2493      /**/
     2494      std::vector<float> sp = getSpectrum(whichrow);
     2495      /**/
     2496      //ioTimeEnd = clock();
     2497      ioTimeEnd = mathutil::gettimeofday_sec();
     2498      elapseIo += (double)(ioTimeEnd - ioTimeStart);
     2499
     2500      //blTimeStart = clock();
     2501      msTimeStart = mathutil::gettimeofday_sec();
     2502      /******************/
     2503
    24762504      chanMask = getCompositeChanMask(whichrow, mask);
     2505
     2506      /**/
     2507      msTimeEnd = mathutil::gettimeofday_sec();
     2508      elapseMs += (double)(msTimeEnd - msTimeStart);
     2509      blTimeStart = mathutil::gettimeofday_sec();
     2510      /**/
     2511
    24772512      //fitBaseline(chanMask, whichrow, fitter);
    24782513      //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
     
    24802515      std::vector<float> params(nPiece*4);
    24812516      int nClipped = 0;
    2482       std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual);
     2517      std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual);
     2518
     2519      /**/
     2520      blTimeEnd = mathutil::gettimeofday_sec();
     2521      elapseBl += (double)(blTimeEnd - blTimeStart);
     2522      seTimeStart = mathutil::gettimeofday_sec();
     2523      /**/
     2524
     2525
    24832526      setSpectrum(res, whichrow);
    24842527      //
    24852528
     2529      /**/
     2530      seTimeEnd = mathutil::gettimeofday_sec();
     2531      elapseSe += (double)(seTimeEnd - seTimeStart);
     2532      otTimeStart = mathutil::gettimeofday_sec();
     2533      /**/
     2534
    24862535      outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped);
     2536
     2537      /**/
     2538      otTimeEnd = mathutil::gettimeofday_sec();
     2539      elapseOt += (double)(otTimeEnd - otTimeStart);
     2540      prTimeStart = mathutil::gettimeofday_sec();
     2541      /**/
     2542
    24872543      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
     2544
     2545      /******************/
     2546      //blTimeEnd = clock();
     2547      prTimeEnd = mathutil::gettimeofday_sec();
     2548      elapsePr += (double)(prTimeEnd - prTimeStart);
     2549      /******************/
    24882550    }
    24892551    //--------------------------------
     
    24942556    throw;
    24952557  }
     2558  /***************/
     2559  //totTimeEnd = clock();
     2560  totTimeEnd = mathutil::gettimeofday_sec();
     2561  //std::cout << "io    : " << elapseIo/CLOCKS_PER_SEC << " (sec.)" << endl;
     2562  //std::cout << "bl    : " << elapseBl/CLOCKS_PER_SEC << " (sec.)" << endl;
     2563  //std::cout << "total : " << (double)(totTimeEnd - totTimeStart)/CLOCKS_PER_SEC << " (sec.)" << endl;
     2564  std::cout << "io    : " << elapseIo << " (sec.)" << endl;
     2565  std::cout << "ms    : " << elapseMs << " (sec.)" << endl;
     2566  std::cout << "bl    : " << elapseBl << " (sec.)" << endl;
     2567  std::cout << "se    : " << elapseSe << " (sec.)" << endl;
     2568  std::cout << "ot    : " << elapseOt << " (sec.)" << endl;
     2569  std::cout << "pr    : " << elapsePr << " (sec.)" << endl;
     2570  std::cout << "total : " << (double)(totTimeEnd - totTimeStart) << " (sec.)" << endl;
     2571  /***************/
    24962572}
    24972573
    24982574void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile)
    24992575{
     2576  /*************
     2577  clock_t totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd;
     2578  double elapseBl = 0.0;
     2579  double elapseIo = 0.0;
     2580  totTimeStart = clock();
     2581  *************/
     2582
    25002583  try {
    25012584    ofstream ofs;
     
    25302613
    25312614    for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     2615      /******************
     2616      ioTimeStart = clock();
     2617      */
     2618      std::vector<float> sp = getSpectrum(whichrow);
     2619      /*
     2620      ioTimeEnd = clock();
     2621      elapseIo += (double)(ioTimeEnd - ioTimeStart);
     2622
     2623      blTimeStart = clock();
     2624      ******************/
    25322625
    25332626      //-------------------------------------------------------
     
    25602653      std::vector<float> params(nPiece*4);
    25612654      int nClipped = 0;
    2562       std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual);
     2655      std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual);
    25632656      setSpectrum(res, whichrow);
    25642657      //
     
    25662659      outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);
    25672660      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
     2661
     2662      /******************
     2663      blTimeEnd = clock();
     2664      elapseBl += (double)(blTimeEnd - blTimeStart);
     2665      ******************/
     2666
    25682667    }
    25692668
     
    25732672    throw;
    25742673  }
     2674
     2675  /***************
     2676  totTimeEnd = clock();
     2677  std::cout << "io    : " << elapseIo/CLOCKS_PER_SEC << " (sec.)" << endl;
     2678  std::cout << "bl    : " << elapseBl/CLOCKS_PER_SEC << " (sec.)" << endl;
     2679  std::cout << "total : " << (double)(totTimeEnd - totTimeStart)/CLOCKS_PER_SEC << " (sec.)" << endl;
     2680  ***************/
    25752681}
    25762682
     
    33813487std::vector<bool> Scantable::getCompositeChanMask(int whichrow, const std::vector<bool>& inMask)
    33823488{
     3489  /****
     3490  double ms1TimeStart, ms1TimeEnd, ms2TimeStart, ms2TimeEnd;
     3491  double elapse1 = 0.0;
     3492  double elapse2 = 0.0;
     3493
     3494  ms1TimeStart = mathutil::gettimeofday_sec();
     3495  ****/
     3496
    33833497  std::vector<bool> mask = getMask(whichrow);
     3498
     3499  /****
     3500  ms1TimeEnd = mathutil::gettimeofday_sec();
     3501  elapse1 = ms1TimeEnd - ms1TimeStart;
     3502  std::cout << "ms1   : " << elapse1 << " (sec.)" << endl;
     3503  ms2TimeStart = mathutil::gettimeofday_sec();
     3504  ****/
     3505
    33843506  uInt maskSize = mask.size();
    33853507  if (inMask.size() != 0) {
     
    33913513    }
    33923514  }
     3515
     3516  /****
     3517  ms2TimeEnd = mathutil::gettimeofday_sec();
     3518  elapse2 = ms2TimeEnd - ms2TimeStart;
     3519  std::cout << "ms2   : " << elapse2 << " (sec.)" << endl;
     3520  ****/
    33933521
    33943522  return mask;
     
    34443572{
    34453573  if (outLogger || outTextFile) {
     3574  /****
     3575  double ms1TimeStart, ms1TimeEnd, ms2TimeStart, ms2TimeEnd;
     3576  double elapse1 = 0.0;
     3577  double elapse2 = 0.0;
     3578
     3579  ms1TimeStart = mathutil::gettimeofday_sec();
     3580  ****/
     3581
    34463582    float rms = getRms(chanMask, whichrow);
     3583
     3584  /****
     3585  ms1TimeEnd = mathutil::gettimeofday_sec();
     3586  elapse1 = ms1TimeEnd - ms1TimeStart;
     3587  std::cout << "ot1   : " << elapse1 << " (sec.)" << endl;
     3588  ms2TimeStart = mathutil::gettimeofday_sec();
     3589  ****/
     3590
    34473591    String masklist = getMaskRangeList(chanMask, whichrow, coordInfo, hasSameNchan);
    34483592    std::vector<bool> fixed;
     
    34543598    }
    34553599    if (outTextFile) {
    3456       ofs << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, true) << flush;
    3457     }
     3600      ofs << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, true);// << flush;
     3601    }
     3602
     3603  /****
     3604  ms2TimeEnd = mathutil::gettimeofday_sec();
     3605  elapse2 = ms2TimeEnd - ms2TimeStart;
     3606  std::cout << "ot2   : " << elapse2 << " (sec.)" << endl;
     3607  ****/
     3608
    34583609  }
    34593610}
     
    35533704float Scantable::getRms(const std::vector<bool>& mask, int whichrow)
    35543705{
     3706  /****
     3707  double ms1TimeStart, ms1TimeEnd, ms2TimeStart, ms2TimeEnd;
     3708  double elapse1 = 0.0;
     3709  double elapse2 = 0.0;
     3710
     3711  ms1TimeStart = mathutil::gettimeofday_sec();
     3712  ****/
     3713
    35553714  Vector<Float> spec;
     3715
    35563716  specCol_.get(whichrow, spec);
     3717
     3718  /****
     3719  ms1TimeEnd = mathutil::gettimeofday_sec();
     3720  elapse1 = ms1TimeEnd - ms1TimeStart;
     3721  std::cout << "rm1   : " << elapse1 << " (sec.)" << endl;
     3722  ms2TimeStart = mathutil::gettimeofday_sec();
     3723  ****/
    35573724
    35583725  float mean = 0.0;
     
    35693736  mean /= (float)n;
    35703737  smean /= (float)n;
     3738
     3739  /****
     3740  ms2TimeEnd = mathutil::gettimeofday_sec();
     3741  elapse2 = ms2TimeEnd - ms2TimeStart;
     3742  std::cout << "rm2   : " << elapse2 << " (sec.)" << endl;
     3743  ****/
    35713744
    35723745  return sqrt(smean - mean*mean);
     
    37953968}
    37963969
     3970vector<uint> Scantable::getMoleculeIdColumnData() const
     3971{
     3972  Vector<uInt> molIds(mmolidCol_.getColumn());
     3973  vector<uint> res;
     3974  molIds.tovector(res);
     3975  return res;
     3976}
     3977
     3978void Scantable::setMoleculeIdColumnData(const std::vector<uint>& molids)
     3979{
     3980  Vector<uInt> molIds(molids);
     3981  Vector<uInt> arr(mmolidCol_.getColumn());
     3982  if ( molIds.nelements() != arr.nelements() )
     3983    throw AipsError("The input data size must be the number of rows.");
     3984  mmolidCol_.putColumn(molIds);
     3985}
     3986
    37973987
    37983988}
  • trunk/src/Scantable.h

    r2435 r2591  
    590590                                            int whichrow,
    591591                                            bool verbose=false) const;
     592  std::vector<uint> getMoleculeIdColumnData() const;
     593  void setMoleculeIdColumnData(const std::vector<uint>& molids);
    592594
    593595
     
    766768  void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval);
    767769
    768 
    769770};
    770771
  • trunk/src/ScantableWrapper.h

    r2587 r2591  
    310310  { return table_->execFFT(whichrow, mask, getRealImag, getAmplitudeOnly); }
    311311
     312  std::vector<uint> getMoleculeIdColumnData() const
     313  { return table_->getMoleculeIdColumnData(); }
     314  void setMoleculeIdColumnData(const std::vector<uint>& molids)
     315  { table_->setMoleculeIdColumnData(molids); }
    312316
    313317
  • trunk/src/python_Scantable.cpp

    r2526 r2591  
    161161    //.def("_sspline_baseline", &ScantableWrapper::smoothingSplineBaseline)
    162162    //.def("_test_cin", &ScantableWrapper::testCin)
     163    .def("_getmolidcol_list", &ScantableWrapper::getMoleculeIdColumnData)
     164    .def("_setmolidcol_list", &ScantableWrapper::setMoleculeIdColumnData)
    163165  ;
    164166};
Note: See TracChangeset for help on using the changeset viewer.