Changeset 902 for trunk/src


Ignore:
Timestamp:
03/17/06 10:10:59 (19 years ago)
Author:
mar637
Message:

More work on polarisation. STPol and labelling

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STMath.cpp

    r896 r902  
    903903  TableIterator iter(tout, cols);
    904904  STPol* stpol = NULL;
    905   stpol =STPol::getPolClass(Scantable::getFactories(), out->getPolType() );
     905  stpol =STPol::getPolClass(out->factories_, out->getPolType() );
    906906  while (!iter.pastEnd()) {
    907907    Table t = iter.table();
  • trunk/src/STSelector.cpp

    r869 r902  
    1616#include <casa/iostream.h>
    1717#include <casa/iomanip.h>
     18#include <casa/Exceptions/Error.h>
    1819
    1920#include "MathUtils.h"
     21#include "STPol.h"
    2022#include "STSelector.h"
    2123
     
    99101}
    100102
     103
     104void asap::STSelector::setSortOrder( const std::vector< std::string > & order )
     105{
     106  order_.resize(order.size(), True);
     107  for (int i=0;i<order.size();++i) {
     108    order_[i] = order[i];
     109  }
     110}
     111
    101112Table STSelector::apply( const Table& tab )
    102113{
    103114  if ( empty() ) {
    104     return tab;
     115    return sort(tab);
    105116  }
    106117  TableExprNode query;
     
    132143      tmpt = tableCommand(taql_, tab);
    133144    }
    134     return tmpt;
     145    return sort(tmpt);
    135146  } else {
    136     return tab(query);
     147    if ( query.isNull() ) {
     148      return sort(tab);
     149    } else {
     150      return sort(tab(query));
     151    }
    137152  }
    138153}
     
    207222  return (intselections_.empty() && taql_.size() == 0 );
    208223}
     224
     225casa::Table asap::STSelector::sort( const casa::Table & tab )
     226{
     227  if (order_.nelements() > 0) {
     228    cout << "sorting" << endl;
     229    Table t = tab.sort(order_);
     230    return t;
     231  } else {
     232    return tab;
     233  }
     234}
     235
     236
     237void asap::STSelector::setPolFromStrings( const std::vector< std::string >& pols )
     238{
     239  poltypes_.clear();
     240  std::vector<int> polints;
     241  std::vector<std::string>::const_iterator strit = pols.begin();
     242  for (strit; strit != pols.end(); ++strit) {
     243    std::pair<int, std::string> val;
     244    try {
     245       val = STPol::polFromString(*strit);
     246    } catch (AipsError& e) {
     247      poltypes_.clear();
     248      throw(e);
     249    }
     250    polints.push_back(val.first);
     251    poltypes_.push_back(val.second);
     252  }
     253  setint("POLNO", polints);
     254}
     255
     256std::vector< std::string > asap::STSelector::getPolTypes( )
     257{
     258  return poltypes_;
     259}
  • trunk/src/STSelector.h

    r850 r902  
    1717#include <map>
    1818
     19#include <casa/Containers/Block.h>
     20#include <casa/BasicSL/String.h>
    1921#include <tables/Tables/Table.h>
    2022
     
    4042  void setIFs(const std::vector<int>& ifs);
    4143  void setPolarizations(const std::vector<int>& pols);
     44  void setPolFromStrings(const std::vector<std::string>& pols);
    4245  void setCycles(const std::vector<int>& cycs);
    4346  void setName(const std::string&);
    4447  virtual void setTaQL(const std::string& taql);
     48
     49  void setSortOrder(const std::vector<std::string>& order);
    4550
    4651  std::vector<int> getScans();
     
    4954  std::vector<int> getPols();
    5055  std::vector<int> getCycles();
     56  std::vector<std::string> getPolTypes();
    5157
    5258  casa::Table apply(const casa::Table& tab);
     
    6773
    6874private:
     75
     76  casa::Table sort(const casa::Table& tab);
     77
    6978  typedef std::map<std::string, std::vector<int> > intidmap;
    7079  typedef std::map<std::string, std::vector<std::string> > stringidmap;
     
    7281  mutable intidmap intselections_;
    7382  mutable stringidmap stringselections_;
     83  std::vector<std::string> poltypes_;
     84  casa::Block<casa::String> order_;
    7485  std::string taql_;
    7586};
  • trunk/src/Scantable.cpp

    r901 r902  
    2828#include <casa/Quanta/MVAngle.h>
    2929#include <casa/Containers/RecordField.h>
     30#include <casa/Utilities/GenSort.h>
    3031
    3132#include <tables/Tables/TableParse.h>
     
    5657#include "STPolLinear.h"
    5758#include "STAttr.h"
     59#include "MathUtils.h"
    5860
    5961using namespace casa;
     
    126128                            Bool(clear));
    127129      table_ = Table(newname, Table::Update);
    128       copySubtables(other);
     130      if ( clear ) copySubtables(other);
    129131      table_.markForDelete();
    130132  }
     
    328330int Scantable::nscan() const {
    329331  int n = 0;
    330   int previous = -1; int current = 0;
    331   for (uInt i=0; i< scanCol_.nrow();i++) {
    332     scanCol_.getScalar(i,current);
    333     if (previous != current) {
    334       previous = current;
    335       n++;
    336     }
    337   }
    338   return n;
     332  Int previous = -1; Int current = 0;
     333  Vector<uInt> scannos(scanCol_.getColumn());
     334  uInt nout = GenSort<uInt>::sort( scannos, Sort::Ascending,
     335                       Sort::QuickSort|Sort::NoDuplicates );
     336  return int(nout);
    339337}
    340338
     
    482480    while ( !it.pastEnd() ) {
    483481      ++n;
     482      ++it;
    484483    }
    485484    return n;
     
    595594
    596595std::vector<float> Scantable::getSpectrum( int whichrow,
    597                                            const std::string& poltype) const
    598 {
     596                                           const std::string& poltype ) const
     597{
     598  if ( whichrow  < 0 || whichrow >= nrow() )
     599    throw(AipsError("Illegal row number."));
    599600  std::vector<float> out;
    600601  Vector<Float> arr;
     
    610611      stpol->setSpectra(getPolMatrix(row));
    611612      Float frot,fang,ftan;
    612       focusTable_.getEntry(frot, fang, ftan, row);
     613      focusTable_.getEntry(frot, fang, ftan, mfocusidCol_(row));
    613614      stpol->setPhaseCorrections(frot, fang, ftan);
    614615      arr = stpol->getSpectrum(requestedpol, poltype);
     
    619620    }
    620621  }
     622  if ( arr.nelements() == 0 )
     623    pushLog("Not enough polarisations present to do the conversion.");
    621624  arr.tovector(out);
    622625  return out;
     
    653656{
    654657  return table_.keywordSet().asString("POLTYPE");
    655 }
    656 
    657 
    658 std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
    659                                             bool linpol, int polidx) const
    660 {
    661   uInt idx = 0;
    662   if (polidx >=0) idx = polidx;
    663   return "";
    664   //return SDPolUtil::polarizationLabel(idx, linear, stokes, linpol);
    665658}
    666659
     
    892885}
    893886
    894 
    895 }//namespace asap
     887std::vector< std::string > asap::Scantable::columnNames( ) const
     888{
     889  Vector<String> vec = table_.tableDesc().columnNames();
     890  return mathutil::tovectorstring(vec);
     891}
     892
     893} //namespace asap
  • trunk/src/Scantable.h

    r901 r902  
    6363class Scantable : private Logger
    6464{
     65
     66friend class STMath;
     67
    6568public:
    6669  /**
     
    177180  /**
    178181   * Return a list of row numbers with respect to the original table.
    179    * @return a lsi of rownumbers with respect to the original table
     182   * @return a list of unsigned ints
    180183   */
    181184  std::vector<unsigned int> rownumbers() const;
     
    252255  void setSpectrum(const std::vector<float>& spec, int whichrow);
    253256
    254   std::string getPolarizationLabel(bool linear, bool stokes,
    255                                    bool linpol,
    256                                    int polidx=-1) const;
     257  std::string getPolarizationLabel(int index, const std::string& ptype) const
     258    { return STPol::getPolLabel(index, ptype ); }
    257259
    258260  /**
     
    303305  STHistory& history() { return historyTable_; }
    304306
    305   static const std::map<std::string, STPol::STPolFactory *>& getFactories()
    306     { return factories_; }
     307  std::vector<std::string> columnNames() const;
    307308
    308309private:
  • trunk/src/ScantableWrapper.h

    r901 r902  
    6969  //  std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
    7070  // Boost fails with 4 arguments.
    71   std::string getPolarizationLabel(bool linear, bool stokes,
    72                                    bool linPol) const {
    73     int polIdx = -1;
    74     return table_->getPolarizationLabel(linear, stokes, linPol, polIdx);
     71  std::string getPolarizationLabel(int index, const std::string& ptype) const {
     72    return table_->getPolarizationLabel(index, ptype);
    7573  }
    7674
     
    132130  int nscan() const {return table_->nscan();}
    133131  int nrow() const {return table_->nrow();}
     132  int ncycle(int scanno) const {return table_->ncycle(scanno);}
    134133  ///@todo int nstokes() {return table_->nStokes();}
    135134
  • trunk/src/python_STSelector.cpp

    r853 r902  
    2525        .def("_getifs", &STSelector::getIFs)
    2626        .def("_getpols", &STSelector::getPols)
     27        .def("_getpoltypes", &STSelector::getPolTypes)
    2728        .def("_getscans", &STSelector::getScans)
    2829        .def("_getcycles", &STSelector::getCycles)
     
    3132        .def("_setifs", &STSelector::setIFs)
    3233        .def("_setpols", &STSelector::setPolarizations)
     34        .def("_setpolstrings", &STSelector::setPolFromStrings)
    3335        .def("_setscans", &STSelector::setScans)
    3436        .def("_setcycles", &STSelector::setCycles)
    3537        .def("_setname", &STSelector::setName)
    3638        .def("_settaql", &STSelector::setTaQL)
     39        .def("_setorder", &STSelector::setSortOrder)
    3740      ;
    3841    };
  • trunk/src/python_Scantable.cpp

    r896 r902  
    5353    .def("getscan", &ScantableWrapper::getScan)
    5454    .def("getcycle", &ScantableWrapper::getCycle)
    55     .def("nif", &ScantableWrapper::nif)
    56     .def("nbeam", &ScantableWrapper::nbeam)
    57     .def("npol", &ScantableWrapper::npol)
    58     .def("nchan", &ScantableWrapper::nchan)
     55    .def("nif", &ScantableWrapper::nif,
     56         (boost::python::arg("scanno")=-1) )
     57    .def("nbeam", &ScantableWrapper::nbeam,
     58         (boost::python::arg("scanno")=-1) )
     59    .def("npol", &ScantableWrapper::npol,
     60         (boost::python::arg("scanno")=-1) )
     61    .def("nchan", &ScantableWrapper::nchan,
     62         (boost::python::arg("ifno")=-1) )
     63    .def("ncycle", &ScantableWrapper::ncycle,
     64         (boost::python::arg("scanno")=-1) )
    5965    .def("nscan", &ScantableWrapper::nscan)
    6066    .def("nrow", &ScantableWrapper::nrow)
     
    6571         (arg("whichrow")=0, arg("poltype")=std::string("linear")) )
    6672    .def("poltype", &ScantableWrapper::getPolType )
    67     .def("_getpolarizationlabel", &ScantableWrapper::getPolarizationLabel,
    68          ( arg("linear")=false, arg("stokes")=false,
    69            arg("linpol")=false, arg("thepol")=0 ) )
     73    .def("_getpollabel", &ScantableWrapper::getPolarizationLabel)
    7074    .def("_setspectrum",&ScantableWrapper::setSpectrum,
    7175         (boost::python::arg("whichrow")=0) )
Note: See TracChangeset for help on using the changeset viewer.