Changeset 2719


Ignore:
Timestamp:
01/09/13 18:16:07 (11 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added two new methods, get_gref() and get_gcellval() in plothelper class.

Test Programs: test_sdplot[sdplot_gridTest]

Put in Release Notes: No

Module(s): asapplotter and sdplot

Description:

Added two new methods in plothelper class to get grid center
and spacings of plot grids.

  • get_gref(): returns the reference direction (grid center) of grid (a string)
  • get_gcellval(): returns the absolute increment (in radian) of grid (a double vector)


Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/PlotHelper.cpp

    r2718 r2719  
    1515#include <casa/Quanta/Quantum.h>
    1616#include <casa/Quanta/QuantumHolder.h>
     17#include <casa/Quanta/MVAngle.h>
    1718#include <casa/Logging/LogIO.h>
    1819
     
    3334namespace asap {
    3435
    35 PlotHelper::PlotHelper() : dircoord_(0)
     36PlotHelper::PlotHelper() : dircoord_p(0)
    3637{
    3738#ifdef KS_DEBUG
     
    4041};
    4142
    42 PlotHelper::PlotHelper( const ScantableWrapper &s) : dircoord_(0)
     43PlotHelper::PlotHelper( const ScantableWrapper &s) : dircoord_p(0)
    4344{
    4445#ifdef KS_DEBUG
     
    5253  cout << "Called PlotHelper destructor" << endl;
    5354#endif
    54   if (dircoord_){
    55 #ifdef KS_DEBUG
    56     cout << "Destructing dircoord_" << endl;
    57 #endif
    58     delete dircoord_;
    59     dircoord_ = 0;
     55  if (dircoord_p){
     56#ifdef KS_DEBUG
     57    cout << "Destructing dircoord_p" << endl;
     58#endif
     59    delete dircoord_p;
     60    dircoord_p = 0;
    6061  }
    6162};
     
    132133    throw(AipsError("ny should be > 0"));
    133134  // Destroy old coord
    134   if (dircoord_){
    135 #ifdef KS_DEBUG
    136     cout << "Destructing dircoord_" << endl;
    137 #endif
    138     delete dircoord_;
    139     dircoord_ = 0;
     135  if (dircoord_p){
     136#ifdef KS_DEBUG
     137    cout << "Destructing old dircoord_p" << endl;
     138#endif
     139    delete dircoord_p;
     140    dircoord_p = 0;
    140141  }
    141142
     
    227228    if (!MDirection::getType(mdt,sepoch))
    228229      throw AipsError("Invalid direction reference in center");
    229     if (stset && (mdt != stdt))
    230       throw AipsError("Direction reference of center should be the same as input scantable");
     230    if (stset){
     231      if ( !needst &&
     232           !MDirection::getType( stdt, data_p->getDirectionRefString() ) )
     233        throw AipsError("Failed to get direction reference from scantable.");
     234      if (mdt != stdt)
     235        throw AipsError("Direction reference of center should be the same as input scantable");
     236    }
    231237    QuantumHolder qh ;
    232238    String err ;
     
    288294  os << "Spacing: ( " << abs(incx) << " rad , " << abs(incy) << " rad )" <<endl;
    289295
    290   Matrix<Double> xform(2,2) ;
    291   xform = 0.0 ;
    292   xform.diagonal() = 1.0 ;
    293   dircoord_ = new DirectionCoordinate(mdt, projtype,
    294                                       centx, centy, incx, incy,
    295                                       xform,
    296                                       0.5*Double(nx),
    297                                       0.5*Double(ny)) ; // pixel at center
    298   {//Summary
    299     os << "Successfully generated grid coordinate:" << LogIO::POST;
    300     Vector<String> units = dircoord_->worldAxisUnits();
    301     Vector<Double> refv = dircoord_->referenceValue();
    302     os <<"- Reference Direction : " << MDirection::showType(dircoord_->directionType())
    303        << " " << refv[0] << units[0] << " " << refv[1] << units[1]  << LogIO::POST;
    304     Vector<Double> refpix = dircoord_->referencePixel();
    305     os <<"- Reference Pixel     : [" << refpix[0] << ", " << refpix[1] << "]" << LogIO::POST;
    306     Vector<Double> inc = dircoord_->increment();
    307     os <<"- Increments          : [" << inc[0] << ", " << inc[1] << "]" << LogIO::POST;
    308     os <<"- Projection Type     : " << dircoord_->projection().name() << LogIO::POST;
    309   }
     296  setupCoord(mdt, projtype, centx, centy, incx, incy,
     297             0.5*Double(nx), 0.5*Double(ny)) ; // pixel at center)
     298
    310299};
    311300
     
    321310    throw(AipsError("ny should be > 0"));
    322311  // Destroy old coord
    323   if (dircoord_){
    324 #ifdef KS_DEBUG
    325     cout << "Destructing dircoord_" << endl;
    326 #endif
    327     delete dircoord_;
    328     dircoord_ = 0;
     312  if (dircoord_p){
     313#ifdef KS_DEBUG
     314    cout << "Destructing old dircoord_p" << endl;
     315#endif
     316    delete dircoord_p;
     317    dircoord_p = 0;
    329318  }
    330319
     
    339328  Projection::Type projType(Projection::type(String(projname)));
    340329
     330  setupCoord(mdt, projType, centX, centY, incX, incY,
     331             0.5*Double(nx), 0.5*Double(ny)) ; // pixel at center
     332//           0.5*Double(nx-1), 0.5*Double(ny-1)) ; // pixel at grid
     333
     334};
     335
     336
     337void PlotHelper::setupCoord(const MDirection::Types mdt,
     338                            const Projection::Type pjt,
     339                            const Double centx, const Double centy,
     340                            const Double incx, const Double incy,
     341                            const Double refx, const Double refy)
     342{
     343  LogIO os(LogOrigin("PlotHelper","setupCoord()", WHERE));
     344  // Destroy old coord
     345  if (dircoord_p){
     346#ifdef KS_DEBUG
     347    cout << "Destructing old dircoord_p" << endl;
     348#endif
     349    delete dircoord_p;
     350    dircoord_p = 0;
     351  }
     352
    341353  Matrix<Double> xform(2,2) ;
    342354  xform = 0.0 ;
    343355  xform.diagonal() = 1.0 ;
    344   dircoord_ = new DirectionCoordinate(mdt, projType,
    345                                       centX, centY, incX, incY,
    346                                       xform,
    347                                       0.5*Double(nx),
    348                                       0.5*Double(ny)) ; // pixel at center
    349 //                                    0.5*Double(nx-1),
    350 //                                    0.5*Double(ny-1)) ; // pixel at grid
     356  dircoord_p = new DirectionCoordinate(mdt, pjt, centx, centy, incx, incy,
     357                                      xform, refx, refy);
    351358  {//Summary
    352359    os << "Successfully generated grid coordinate:" << LogIO::POST;
    353     Vector<String> units = dircoord_->worldAxisUnits();
    354     Vector<Double> refv = dircoord_->referenceValue();
    355     os <<"- Reference Direction : " << MDirection::showType(dircoord_->directionType())
    356        << " " << refv[0] << units[0] << " " << refv[1] << units[1]  << LogIO::POST;
    357     Vector<Double> refpix = dircoord_->referencePixel();
     360    Vector<String> units = dircoord_p->worldAxisUnits();
     361    Vector<Double> refv = dircoord_p->referenceValue();
     362    os <<"- Reference Direction : "
     363       << MDirection::showType(dircoord_p->directionType())
     364       << " " << refv[0] << units[0] << " " << refv[1] << units[1] << LogIO::POST;
     365    Vector<Double> refpix = dircoord_p->referencePixel();
    358366    os <<"- Reference Pixel     : [" << refpix[0] << ", " << refpix[1] << "]" << LogIO::POST;
    359     Vector<Double> inc = dircoord_->increment();
     367    Vector<Double> inc = dircoord_p->increment();
    360368    os <<"- Increments          : [" << inc[0] << ", " << inc[1] << "]" << LogIO::POST;
    361     os <<"- Projection Type     : " << dircoord_->projection().name() << LogIO::POST;
    362   }
    363 };
    364 
    365 vector<double>  PlotHelper::getGridPixel(const int whichrow){
     369    os <<"- Projection Type     : " << dircoord_p->projection().name() << LogIO::POST;
     370  }
     371};
     372
     373vector<double>  PlotHelper::getGridPixel(const int whichrow)
     374{
    366375  if (data_p->nrow() < 1)
    367376    throw AipsError("Scantable is not set. Could not get direction.");
    368377  else if (whichrow > int(data_p->nrow()) - 1)
    369378    throw AipsError("Row index out of range.");
    370   if (!dircoord_)
     379  if (!dircoord_p)
    371380    throw AipsError("Direction coordinate is not defined.");
    372381
     
    378387  cout << "searching pixel position (world = " << data_p->getDirectionString(whichrow) << " = [" << world.getAngle("rad").getValue()[0] << ", " << world.getAngle("rad").getValue()[1] << "])" << endl;
    379388#endif
    380   dircoord_->toPixel(pixel, world);
     389  dircoord_p->toPixel(pixel, world);
    381390#ifdef KS_DEBUG
    382391  cout << "got pixel = [" << pixel[0] << ", " << pixel[1] << "]" << endl;
     
    387396};
    388397
     398string PlotHelper::getGridRef()
     399{
     400  if (!dircoord_p)
     401    throw AipsError("Direction coordinate is not defined. Please set it first.");
     402
     403  string outref;
     404
     405  Vector<String> units = dircoord_p->worldAxisUnits();
     406  Vector<Double> refv = dircoord_p->referenceValue();
     407  MVAngle lon( Quantum<Double>(refv[0], units[0]) );
     408  MVAngle lat ( Quantum<Double>(refv[1], units[1]) );
     409  outref = MDirection::showType(dircoord_p->directionType()) + " "
     410    + lon(0.0).string(MVAngle::TIME, 9) + " "
     411    + lat.string(MVAngle::ANGLE+MVAngle::DIG2, 9);
     412
     413  return outref;
     414};
     415
     416vector<double>  PlotHelper::getGridCellVal()
     417{
     418  if (!dircoord_p)
     419    throw AipsError("Direction coordinate is not defined. Please set it first.");
     420
     421  vector<double> outinc(2);
     422  Vector<Double> inc = dircoord_p->increment();
     423  Vector<String> units = dircoord_p->worldAxisUnits();
     424  MVAngle qincx( Quantum<Double>(inc[0], units[0]) );
     425  MVAngle qincy( Quantum<Double>(inc[1], units[1]) );
     426  outinc[0] = (double) abs(qincx.radian());
     427  outinc[1] = (double) abs(qincy.radian());
     428
     429  return outinc;
     430};
     431
     432
    389433} //namespace asap
  • trunk/src/PlotHelper.h

    r2717 r2719  
    3838  virtual ~PlotHelper();
    3939  /**
    40    * Set scantable for automatic resolution of grid parameter
     40   * Set scantable
    4141   **/
    4242  void setScantable( const ScantableWrapper &s ) ;
     
    5858
    5959  /**
    60    * Get Pixel position of a row
     60   * Get Pixel position of a row in the scantable
    6161   **/
    6262  vector<double> getGridPixel(const int whichrow=0);
    6363
     64  /**
     65   * Get the reference direction of grid coordinate (grid center)
     66   **/
     67  string getGridRef();
     68
     69  /**
     70   * Get the cell size (>0) of the grid coordinate (in radian)
     71   **/
     72  vector<double> getGridCellVal();
     73
     74
    6475private:
     76  /** Generate temporal coordinate from the DIRECTION column of a scantable**/
    6577  casa::DirectionCoordinate getSTCoord(const int nx, const int ny,
    6678                                       const casa::Projection::Type ptype);
    6779
    68   casa::DirectionCoordinate *dircoord_;
     80  /** Generation of direction coordinate **/
     81  void setupCoord(const casa::MDirection::Types mdt,
     82                  const casa::Projection::Type pjt,
     83                  const casa::Double centx, const casa::Double centy,
     84                  const casa::Double incx, const casa::Double incy,
     85                  const casa::Double refx, const casa::Double refy);
     86
     87  casa::DirectionCoordinate *dircoord_p;
    6988  casa::CountedPtr<Scantable> data_p;
    7089
  • trunk/src/python_PlotHelper.cpp

    r2717 r2719  
    3333    .def("get_gpos", &PlotHelper::getGridPixel,
    3434         (boost::python::arg("whichrow")=0) )
     35    //
     36    .def("get_gref", &PlotHelper::getGridRef)
     37    .def("get_gcellval", &PlotHelper::getGridCellVal)
    3538    /** TODO
     39    .def("get_gcell", &PlotHelper::getGridCell)
    3640    .def("get_gdir", &PlotHelper::getGridDirection)
    3741    .def("get_gdirval", &PlotHelper::getGridWorld)
Note: See TracChangeset for help on using the changeset viewer.