Ignore:
Timestamp:
01/10/13 20:37:28 (11 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.


File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.