Changeset 2726


Ignore:
Timestamp:
01/10/13 20:37:28 (12 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: Yes (CAS-4141)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: moved various set methods in python to c++

Test Programs:

Put in Release Notes: No

Module(s): sbseparator

Description:

Moved set methods in sbseparator module to c++ (STSideBandSep class).
Defined boost python interface methods, set_freq, set_dirtol, set_shift,
set_limit, solve_both, subtract_other to access them from python codes.


Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STSideBandSep.cpp

    r2716 r2726  
    3232using namespace asap ;
    3333
    34 //#ifndef KS_DEBUG
    35 //#define KS_DEBUG
    36 //#endif
     34#ifndef KS_DEBUG
     35#define KS_DEBUG
     36#endif
    3737
    3838namespace asap {
    3939
    4040// constructors
    41 STSideBandSep::STSideBandSep()
    42   : sigIfno_(0), ftol_(-1),
    43     loTime_(-1), lo1Freq_(-1), loDir_("")
    44 {
    45 #ifdef KS_DEBUG
    46   cout << "Default constructor STSideBandSep()" << endl;
    47 #endif
    48   // Default LO frame is TOPO
    49   loFrame_ = MFrequency::TOPO;
     41STSideBandSep::STSideBandSep(const vector<string> &names)
     42{
     43  LogIO os(LogOrigin("STSideBandSep","STSideBandSep()", WHERE));
     44  os << "Setting scantable names to process." << LogIO::POST ;
     45  // Set file names
     46  ntable_ = names.size();
     47  infileList_.resize(ntable_);
     48  for (unsigned int i = 0; i < ntable_; i++){
     49    if (!checkFile(names[i], "d"))
     50      throw( AipsError("File does not exist") );
     51    infileList_[i] = names[i];
     52  }
     53  intabList_.resize(0);
     54
     55  init();
     56
     57  {// Summary
     58    os << ntable_ << " files are set: [";
     59    for (unsigned int i = 0; i < ntable_; i++) {
     60      os << " '" << infileList_[i] << "' ";
     61      if (i != ntable_-1) os << ",";
     62    }
     63    os << "] " << LogIO::POST;
     64  }
     65};
     66
     67STSideBandSep::STSideBandSep(const vector<ScantableWrapper> &tables)
     68{
     69  LogIO os(LogOrigin("STSideBandSep","STSideBandSep()", WHERE));
     70  os << "Setting list of scantables to process." << LogIO::POST ;
     71  // Set file names
     72  ntable_ = tables.size();
     73  intabList_.resize(ntable_);
     74  for (unsigned int i = 0; i < ntable_; i++){
     75    intabList_[i] = tables[i].getCP();
     76  }
     77  infileList_.resize(0);
     78
     79  init();
     80
     81  os << ntable_ << " tables are set." << LogIO::POST;
    5082};
    5183
     
    5789};
    5890
    59 
    60 void STSideBandSep::setFrequency(const unsigned int ifno, const double freqtol, string frame)
    61 {
    62 #ifdef KS_DEBUG
    63   cout << "STSideBandSep::setFrequency" << endl;
    64   cout << "IFNO = " << ifno << endl;
    65   cout << "freq tol = " << freqtol << " [Hz]" << endl;
    66   cout << "frame = " << frame << endl;
    67 #endif
     91void STSideBandSep::init()
     92{
     93  // frequency setup
     94  sigIfno_= 0;
     95  ftol_ = -1;
     96  solFrame_ = MFrequency::N_Types;
     97  // shifts
     98  initshift();
     99  // direction tolerance
     100  xtol_ = ytol_ = 9.69627e-6; // 2arcsec
     101  // solution parameters
     102  otherside_ = false;
     103  doboth_ = false;
     104  rejlimit_ = 0.2;
     105  // LO1 values
     106  lo1Freq_ = -1;
     107  loTime_ = -1;
     108  loDir_ = "";
     109  // Default LO frame is TOPO
     110  loFrame_ = MFrequency::TOPO;
     111};
     112
     113void STSideBandSep::initshift()
     114{
     115  // shifts
     116  nshift_ = 0;
     117  nchan_ = 0;
     118  sigShift_.resize(0);
     119  imgShift_.resize(0);
     120  tableList_.resize(0);
     121};
     122
     123void STSideBandSep::setFrequency(const unsigned int ifno,
     124                                 const string freqtol,
     125                                 const string frame)
     126{
     127  LogIO os(LogOrigin("STSideBandSep","setFrequency()", WHERE));
     128
     129  initshift();
     130
     131  // IFNO
     132  sigIfno_ = ifno;
     133
     134  // Frequency tolerance
     135  Quantum<Double> qftol;
     136  readQuantity(qftol, String(freqtol));
     137  if (!qftol.getUnit().empty()){
     138    // make sure the quantity is frequency
     139    if (qftol.getFullUnit().getValue() != Unit("Hz").getValue())
     140      throw( AipsError("Invalid quantity for frequency tolerance.") );
     141    qftol.convert("Hz");
     142  }
     143  ftol_ = qftol;
     144
     145  // Frequency Frame
     146  if (!frame.empty()){
     147    MFrequency::Types mft;
     148    if (!MFrequency::getType(mft, frame))
     149      throw( AipsError("Invalid frame type.") );
     150    solFrame_ = mft;
     151  } else {
     152    solFrame_ = MFrequency::N_Types;
     153  }
     154
     155  {// Summary
     156    const String sframe = ( (solFrame_ == MFrequency::N_Types) ?
     157                            "table frame" :
     158                            MFrequency::showType(solFrame_) );
     159    os << "Frequency setup to search IF group: "
     160       << "IFNO of table[0] = " << sigIfno_
     161       << " , Freq tolerance = " << ftol_.getValue() << " [ "
     162       << (ftol_.getUnit().empty() ? "channel" : ftol_.getUnit() )
     163       << " ] (in " << sframe <<")" << LogIO::POST;
     164  }
     165};
     166
     167
     168void STSideBandSep::setDirTolerance(const vector<string> dirtol)
     169{
     170  LogIO os(LogOrigin("STSideBandSep","setDirTolerance()", WHERE));
     171  Quantum<Double> qcell;
     172  if ( (dirtol.size() == 1) && !dirtol[0].empty() ) {
     173    readQuantity(qcell, String(dirtol[0]));
     174    if (qcell.getFullUnit().getValue() == Unit("rad").getValue())
     175      xtol_ = ytol_ = qcell.getValue("rad");
     176    else
     177      throw( AipsError("Invalid unit for direction tolerance.") );
     178  }
     179  else if (dirtol.size() > 1) {
     180    if ( dirtol[0].empty() && dirtol[1].empty() )
     181      throw( AipsError("Direction tolerance is empty.") );
     182    if ( !dirtol[0].empty() ) {
     183      readQuantity(qcell, String(dirtol[0]));
     184      if (qcell.getFullUnit().getValue() == Unit("rad").getValue())
     185        xtol_ = qcell.getValue("rad");
     186      else
     187        throw( AipsError("Invalid unit for direction tolerance.") );
     188    }
     189    if ( !dirtol[1].empty() ) {
     190      readQuantity(qcell, String(dirtol[1]));
     191      if (qcell.getFullUnit().getValue() == Unit("rad").getValue())
     192        ytol_ = qcell.getValue("rad");
     193      else
     194        throw( AipsError("Invalid unit for direction tolerance.") );
     195    }
     196    else {
     197      ytol_ = xtol_;
     198    }
     199  }
     200  else throw( AipsError("Invalid direction tolerance.") );
     201
     202  os << "Direction tolerance: ( "
     203     << xtol_ << " , " << ytol_ << " ) [rad]" << LogIO::POST;
     204};
     205
     206void STSideBandSep::setShift(const vector<double> &shift)
     207{
     208  LogIO os(LogOrigin("STSideBandSep","setShift()", WHERE));
     209  imgShift_.resize(shift.size());
     210  for (unsigned int i = 0; i < shift.size(); i++)
     211    imgShift_[i] = shift[i];
     212
     213  if (imgShift_.size() == 0) {
     214    os << "Channel shifts are cleared." << LogIO::POST;
     215  } else {
     216    os << "Channel shifts of image sideband are set: ( ";
     217    for (unsigned int i = 0; i < imgShift_.size(); i++) {
     218      os << imgShift_[i];
     219      if (i != imgShift_.size()-1) os << " , ";
     220    }
     221    os << " ) [channel]" << LogIO::POST;
     222  }
     223};
     224
     225void STSideBandSep::setThreshold(const double limit)
     226{
     227  LogIO os(LogOrigin("STSideBandSep","setThreshold()", WHERE));
     228  if (limit < 0)
     229    throw( AipsError("Rejection limit should be positive number.") );
     230
     231  rejlimit_ = limit;
     232  os << "Rejection limit is set to " << rejlimit_;
    68233};
    69234
     
    81246
    82247//
    83 void STSideBandSep::setLO1(const double lo1, string frame, double reftime, string refdir)
     248void STSideBandSep::setLO1(const double lo1, const string frame,
     249                           const double reftime, const string refdir)
    84250{
    85251  lo1Freq_ = lo1;
  • trunk/src/STSideBandSep.h

    r2712 r2726  
    3636   * constructors and a destructor
    3737   **/
    38   STSideBandSep();
    39   //explicit STSideBandSep(const vector<string> infile);
    40   //explicit STSideBandSep(const vector<ScantableWrapper> &tables);
     38  STSideBandSep() { throw( AipsError("No data set to process") ); };
     39  explicit STSideBandSep(const vector<string> &names);
     40  explicit STSideBandSep(const vector<ScantableWrapper> &tables);
    4141  virtual ~STSideBandSep();
    4242
    4343  /**
    44    * Set parameters for sideband separation
     44   * Set IFNO and frequency tolerance to select data to process
    4545   **/
    46   void setFrequency(const unsigned int ifno, const double freqtol, string frame="");
     46  void setFrequency(const unsigned int ifno, const string freqtol,
     47                    const string frame="");
     48
     49  /**
     50   * Set direction tolerance to group spectra.
     51   * The spectra within this range will be averaged before procesing.
     52   **/
     53  void setDirTolerance(const vector<string> dirtol);
     54
     55  /**
     56   * Set the number of channels shifted in image side band
     57   * of each of scantable.
     58   **/
     59  void setShift(const vector<double> &shift);
     60
     61  /**
     62   * Set rejection limit of solution.
     63   **/
     64  void setThreshold(const double limit);
     65
     66  /**
     67   * Resolve both image and signal sideband when true is set.
     68   **/
     69  void solveBoth(const bool flag) { doboth_ = flag; };
     70
     71  /**
     72   * Obtain spectra by subtracting the solution of the other sideband.
     73   **/
     74  void solvefromOther(const bool flag) { otherside_ = flag; };
    4775
    4876  /**
     
    5179  void setImageTable(const ScantableWrapper &s);
    5280  void setScanTb0(const ScantableWrapper &s);
     81
    5382  /**
    5483   * Set additional information to fill frequencies of image sideband
    5584   **/
    56   void setLO1(const double lo1, string frame="TOPO", double reftime=-1, string refdir="");
     85  void setLO1(const double lo1, const string frame="TOPO",
     86              const double reftime=-1, string refdir="");
    5787  void setLO1Root(const string name);
     88
    5889  /**
    5990   * Actual calculation of frequencies of image sideband
     
    6293
    6394private:
     95  /** Initialize member variables **/
     96  void init();
     97  void initshift();
     98
     99  /** Return if the path exists (optionally, check file type) **/
    64100  Bool checkFile(const string name, string type="");
     101
     102  /**
     103   * Get LO1 frequency to solve the frequencies of image side band
     104   **/
    65105  bool getLo1FromAsdm(const string asdmname,
    66106                      const double refval, const double refpix,
     
    73113                         const double increment, const int nChan);
    74114
     115  /** Member variables **/
     116  // input tables
     117  vector<string> infileList_;
     118  vector< CountedPtr<Scantable> > intabList_;
     119  unsigned int ntable_;
     120  // frequency and direction setup to select data.
    75121  unsigned int sigIfno_;
    76   double ftol_;
     122  Quantum<Double> ftol_;
     123  MFrequency::Types solFrame_;
     124  vector<double> sigShift_, imgShift_;
     125  unsigned int nshift_, nchan_;
     126  vector< CountedPtr<Scantable> > tableList_;
     127  Double xtol_, ytol_;
     128  // solution parameters
     129  bool otherside_, doboth_;
     130  double rejlimit_;
     131  // LO1
    77132  double lo1Freq_;
    78133  MFrequency::Types loFrame_;
  • trunk/src/python_STSideBandSep.cpp

    r2712 r2726  
    1010#include <boost/python/args.hpp>
    1111
    12 
    1312#include "STSideBandSep.h"
    1413
     
    2120  class_<STSideBandSep>("SBSeparator")
    2221    .def( init <> () )
     22    .def( init < const std::vector<std::string> > () )
     23    .def( init < const std::vector<ScantableWrapper> > () )
    2324    .def( "set_freq", &STSideBandSep::setFrequency,
    2425          (boost::python::arg("frame")="") )
     26    .def( "set_dirtol", &STSideBandSep::setDirTolerance )
     27    .def( "set_shift", &STSideBandSep::setShift )
     28    .def( "set_limit", &STSideBandSep::setThreshold )
     29    .def( "solve_both", &STSideBandSep::solveBoth )
     30    .def( "subtract_other", &STSideBandSep::solvefromOther )
    2531    .def( "set_lo1", &STSideBandSep::setLO1,
    2632          (boost::python::arg("frame")="TOPO",
Note: See TracChangeset for help on using the changeset viewer.