Changeset 896 for trunk/src


Ignore:
Timestamp:
03/10/06 12:09:29 (19 years ago)
Author:
mar637
Message:

enable polarimetry in asap2

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STFocus.cpp

    r856 r896  
    4545}
    4646
    47 STFocus & asap::STFocus::operator =( const STFocus & other )
     47STFocus& asap::STFocus::operator =( const STFocus & other )
    4848{
    4949  if (this != &other) {
     
    9494
    9595void asap::STFocus::getEntry( Float& rotation, Float& angle, Float& ftan,
    96                               uInt id)
     96                              uInt id) const
    9797{
    9898  Table t = table_(table_.col("ID") == Int(id) );
  • trunk/src/STFocus.h

    r856 r896  
    4141
    4242  void getEntry( casa::Float& rotation, casa::Float& angle,
    43                        casa::Float& ftan, casa::uInt id);
     43                       casa::Float& ftan, casa::uInt id) const;
    4444
    4545  const casa::String& name() const { return name_; }
  • trunk/src/STMath.cpp

    r878 r896  
    871871  return out;
    872872}
     873
     874CountedPtr< Scantable >
     875  STMath::invertPhase( const CountedPtr < Scantable >& in )
     876{
     877  applyToPol(in, &STPol::invertPhase, Float(0.0));
     878}
     879
     880CountedPtr< Scantable >
     881  STMath::rotateXYPhase( const CountedPtr < Scantable >& in, float phase )
     882{
     883   return applyToPol(in, &STPol::rotatePhase, Float(phase));
     884}
     885
     886CountedPtr< Scantable >
     887  STMath::rotateLinPolPhase( const CountedPtr < Scantable >& in, float phase )
     888{
     889  return applyToPol(in, &STPol::rotateLinPolPhase, Float(phase));
     890}
     891
     892CountedPtr< Scantable > STMath::applyToPol( const CountedPtr<Scantable>& in,
     893                                             STPol::polOperation fptr,
     894                                             Float phase )
     895{
     896  CountedPtr< Scantable > out = getScantable(in, false);
     897  Table& tout = out->table();
     898  Block<String> cols(4);
     899  cols[0] = String("SCANNO");
     900  cols[1] = String("BEAMNO");
     901  cols[2] = String("IFNO");
     902  cols[3] = String("CYCLENO");
     903  TableIterator iter(tout, cols);
     904  STPol* stpol = NULL;
     905  stpol =STPol::getPolClass(Scantable::getFactories(), out->getPolType() );
     906  while (!iter.pastEnd()) {
     907    Table t = iter.table();
     908    ArrayColumn<Float> speccol(t, "SPECTRA");
     909    Matrix<Float> pols = speccol.getColumn();
     910    Matrix<Float> out;
     911    try {
     912      stpol->setSpectra(pols);
     913      (stpol->*fptr)(phase);
     914      speccol.putColumn(stpol->getSpectra());
     915      delete stpol;stpol=0;
     916    } catch (AipsError& e) {
     917      delete stpol;stpol=0;
     918      throw(e);
     919    }
     920    ++iter;
     921  }
     922  return out;
     923}
     924
     925CountedPtr< Scantable >
     926  STMath::swapPolarisations( const CountedPtr< Scantable > & in )
     927{
     928  CountedPtr< Scantable > out = getScantable(in, false);
     929  Table& tout = out->table();
     930  Table t0 = tout(tout.col("POLNO") == 0);
     931  Table t1 = tout(tout.col("POLNO") == 1);
     932  if ( t0.nrow() != t1.nrow() )
     933    throw(AipsError("Inconsistent number of polarisations"));
     934  ArrayColumn<Float> speccol0(t0, "SPECTRA");
     935  ArrayColumn<uChar> flagcol0(t0, "FLAGTRA");
     936  ArrayColumn<Float> speccol1(t1, "SPECTRA");
     937  ArrayColumn<uChar> flagcol1(t1, "FLAGTRA");
     938  Matrix<Float> s0 = speccol0.getColumn();
     939  Matrix<uChar> f0 = flagcol0.getColumn();
     940  speccol0.putColumn(speccol1.getColumn());
     941  flagcol0.putColumn(flagcol1.getColumn());
     942  speccol1.putColumn(s0);
     943  flagcol1.putColumn(f0);
     944  return out;
     945}
  • trunk/src/STMath.h

    r894 r896  
    2424#include "Scantable.h"
    2525#include "STDefs.h"
     26#include "STPol.h"
    2627#include "Logger.h"
    2728
     
    99100    merge(const std::vector<casa::CountedPtr<Scantable> >& in);
    100101
     102  casa::CountedPtr<Scantable>
     103    invertPhase( const casa::CountedPtr<Scantable>& in);
     104  casa::CountedPtr<Scantable>
     105    rotateXYPhase( const casa::CountedPtr<Scantable>& in, float phase);
     106  casa::CountedPtr<Scantable>
     107    rotateLinPolPhase( const casa::CountedPtr<Scantable>& in, float phase);
     108
    101109  /// @todo frequency alignment
    102110
     111  casa::CountedPtr<Scantable>
     112    swapPolarisations(const casa::CountedPtr<Scantable>& in);
     113
    103114private:
     115  casa::CountedPtr<Scantable>  applyToPol( const casa::CountedPtr<Scantable>& in,
     116                                           STPol::polOperation fptr,
     117                                           casa::Float phase);
     118
    104119  static imethod stringToIMethod(const std::string& in);
    105120  static WeightType stringToWeight(const std::string& in);
  • trunk/src/Scantable.cpp

    r888 r896  
    5454
    5555#include "Scantable.h"
     56#include "STPolLinear.h"
    5657#include "STAttr.h"
    5758
     
    5960
    6061namespace asap {
     62
     63std::map<std::string, STPol::STPolFactory *> Scantable::factories_;
     64
     65void Scantable::initFactories() {
     66  if ( factories_.empty() ) {
     67    Scantable::factories_["linear"] = &STPolLinear::myFactory;
     68  }
     69}
    6170
    6271Scantable::Scantable(Table::TableType ttype) :
    6372  type_(ttype)
    6473{
     74  initFactories();
    6575  setupMainTable();
    6676  freqTable_ = STFrequencies(*this);
     
    8595  type_(ttype)
    8696{
     97  initFactories();
    8798  Table tab(name, Table::Update);
    8899  Int version;
     
    566577  if ( selector_.empty() )
    567578    throw(AipsError("Trying to flag whole scantable. Aborted."));
     579  TableVector<uChar> tvec(table_, "FLAGTRA");
     580  uChar userflag = 1 << 7;
     581  tvec = userflag;
    568582}
    569583
     
    580594}
    581595
    582 std::vector<float> Scantable::getSpectrum(int whichrow) const
    583 {
     596std::vector<float> Scantable::getSpectrum( int whichrow,
     597                                           const std::string& poltype) const
     598{
     599  std::vector<float> out;
    584600  Vector<Float> arr;
    585   specCol_.get(whichrow, arr);
    586   std::vector<float> out;
     601  uInt requestedpol = polCol_(whichrow);
     602  String basetype = getPolType();
     603  if ( String(poltype) == basetype) {
     604    specCol_.get(whichrow, arr);
     605  } else {
     606    STPol* stpol = 0;
     607    stpol =STPol::getPolClass(Scantable::factories_, basetype);
     608    try {
     609      uInt row = uInt(whichrow);
     610      stpol->setSpectra(getPolMatrix(row));
     611      Float frot,fang,ftan;
     612      focusTable_.getEntry(frot, fang, ftan, row);
     613      stpol->setPhaseCorrections(frot, fang, ftan);
     614      arr = stpol->getSpectrum(requestedpol, poltype);
     615      delete stpol;
     616    } catch (AipsError& e) {
     617      delete stpol;
     618      throw(e);
     619    }
     620  }
    587621  arr.tovector(out);
    588622  return out;
    589623}
    590 
    591624
    592625void asap::Scantable::setSpectrum( const std::vector<float>& spec,
     
    597630  specCol_.get(whichrow, arr);
    598631  if ( spectrum.nelements() != arr.nelements() )
    599     throw AipsError("The specturm has incorrect number of channels.");
     632    throw AipsError("The spectrum has incorrect number of channels.");
    600633  specCol_.put(whichrow, spectrum);
    601634}
     
    616649  return table_;
    617650}
     651
     652std::string Scantable::getPolType() const
     653{
     654  return table_.keywordSet().asString("POLTYPE");
     655}
     656
    618657
    619658std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
     
    655694  oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
    656695      << setw(15) << "IFs:" << setw(4) << nif() << endl
    657       << setw(15) << "Polarisations:" << setw(4) << npol() << endl
     696      << setw(15) << "Polarisations:" << setw(4) << npol()
     697      << "(" << getPolType() << ")" << endl
    658698      << setw(15) << "Channels:"  << setw(4) << nchan() << endl;
    659699  oss << endl;
     
    839879
    840880
     881Matrix<Float> asap::Scantable::getPolMatrix( uInt whichrow ) const
     882{
     883  ROTableRow row(table_);
     884  const TableRecord& rec = row.get(whichrow);
     885  Table t =
     886    originalTable_( originalTable_.col("SCANNO") == Int(rec.asuInt("SCANNO"))
     887                    && originalTable_.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
     888                    && originalTable_.col("IFNO") == Int(rec.asuInt("IFNO"))
     889                    && originalTable_.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) );
     890  ROArrayColumn<Float> speccol(t, "SPECTRA");
     891  return speccol.getColumn();
     892}
     893
    841894
    842895}//namespace asap
  • trunk/src/Scantable.h

    r894 r896  
    3939#include "STSelector.h"
    4040#include "STHistory.h"
    41 
    42 
     41#include "STPol.h"
    4342
    4443namespace asap {
     
    205204  int npol(int scanno=-1) const;
    206205
     206  std::string getPolType() const;
     207
    207208  /**
    208209   * Get the number of channels in the data or a specific IF. This currently
     
    246247
    247248  std::vector<bool> getMask(int whichrow) const;
    248   std::vector<float> getSpectrum(int whichrow) const;
     249  std::vector<float> getSpectrum(int whichrow,
     250                                 const std::string& poltype ="linear") const;
    249251
    250252  void setSpectrum(const std::vector<float>& spec, int whichrow);
    251253
    252   std::vector<float> getStokesSpectrum( int whichrow=0,
    253                                         bool dopol=false) const;
    254254  std::string getPolarizationLabel(bool linear, bool stokes,
    255255                                   bool linpol,
     
    303303  STHistory& history() { return historyTable_; }
    304304
     305  static const std::map<std::string, STPol::STPolFactory *>& getFactories()
     306    { return factories_; }
     307
    305308private:
     309
     310  casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
     311
    306312  /**
    307313   * Turns a time vale into a formatted string
     
    395401  casa::ScalarColumn<casa::uInt> mmolidCol_;
    396402
     403  static std::map<std::string, STPol::STPolFactory *> factories_;
     404  void initFactories();
     405
    397406};
    398407
  • trunk/src/ScantableWrapper.h

    r884 r896  
    6363  }
    6464
    65   std::vector<float> getSpectrum(int whichRow=0) const {
    66     return table_->getSpectrum(whichRow);
     65  std::vector<float> getSpectrum( int whichrow=0,
     66                                  const std::string& poltype="linear" ) const {
     67    return table_->getSpectrum(whichrow, poltype);
    6768  }
    68   /*
    69   std::vector<float> getStokesSpectrum(int whichRow=0,
    70                                        bool linPol=false) const {
    71     return table_->getStokesSpectrum(whichRow, linPol);
    72   }
    73 
    74   std::vector<float> stokesToPolSpectrum(int whichRow=0, bool linear=false,
    75                                          int polIdx=-1) const {
    76     return table_->stokesToPolSpectrum(whichRow, linear, polIdx);
    77   }
    78   */
    7969  //  std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
    8070  // Boost fails with 4 arguments.
     
    8575  }
    8676
    87   std::vector<double> getAbcissa(int whichRow=0) const
    88     { return table_->getAbcissa(whichRow); }
     77  std::vector<double> getAbcissa(int whichrow=0) const
     78    { return table_->getAbcissa(whichrow); }
    8979
    90   std::string getAbcissaLabel(int whichRow=0) const
    91     { return table_->getAbcissaLabel(whichRow); }
     80  std::string getAbcissaLabel(int whichrow=0) const
     81    { return table_->getAbcissaLabel(whichrow); }
    9282
    93   float getTsys(int whichRow=0) const
    94     { return table_->getTsys(whichRow); }
     83  float getTsys(int whichrow=0) const
     84    { return table_->getTsys(whichrow); }
    9585
    96   std::string getTime(int whichRow=0) const
    97     { return table_->getTime(whichRow); }
     86  std::string getTime(int whichrow=0) const
     87    { return table_->getTime(whichrow); }
    9888
    9989  std::string getFluxUnit() const { return table_->getFluxUnit(); }
     
    10393  void setInstrument(const std::string& name) {table_->setInstrument(name);}
    10494
    105   std::vector<bool> getMask(int whichRow=0) const
    106     { return table_->getMask(whichRow); }
     95  std::vector<bool> getMask(int whichrow=0) const
     96    { return table_->getMask(whichrow); }
    10797
    10898  void flag() { table_->flag(); }
    10999
    110   std::string getSourceName(int whichRow=0) const
    111     { return table_->getSourceName(whichRow); }
     100  std::string getSourceName(int whichrow=0) const
     101    { return table_->getSourceName(whichrow); }
    112102
    113   float getElevation(int whichRow=0) const
    114     { return table_->getElevation(whichRow); }
     103  float getElevation(int whichrow=0) const
     104    { return table_->getElevation(whichrow); }
    115105
    116   float getAzimuth(int whichRow=0) const
    117     { return table_->getAzimuth(whichRow); }
     106  float getAzimuth(int whichrow=0) const
     107    { return table_->getAzimuth(whichrow); }
    118108
    119   float getParAngle(int whichRow=0) const
    120     { return table_->getParAngle(whichRow); }
     109  float getParAngle(int whichrow=0) const
     110    { return table_->getParAngle(whichrow); }
    121111
    122112
     
    133123  void setSelection(const STSelector& sts)
    134124    { return table_->setSelection(sts);}
     125
     126  std::string getPolType() const { return table_->getPolType(); }
    135127
    136128  int nif(int scanno=-1) const {return table_->nif(scanno);}
     
    175167    { table_->addHistory(hist); }
    176168  /*
    177   void addFit(int whichRow, const std::vector<double>& p,
     169  void addFit(int whichrow, const std::vector<double>& p,
    178170              const std::vector<bool>& m, const std::vector<string>& f,
    179171              const std::vector<int>& c) {
     
    183175    casa::Vector<casa::String> f2 = mathutil::toVectorString(f);
    184176    casa::Vector<casa::Int> c2(c);
    185     table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
     177    table_->addFit(casa::uInt(whichrow), p2,m2,f2,c2);
    186178  }
    187   SDFitTable getSDFitTable(int whichRow) {
    188     return table_->getSDFitTable(casa::uInt(whichRow));
     179  SDFitTable getSDFitTable(int whichrow) {
     180    return table_->getSDFitTable(casa::uInt(whichrow));
    189181  }
    190182  */
  • trunk/src/Templates.cpp

    r894 r896  
    7474template class TabVecRep<Float>;
    7575
     76template class ROTableVector<uChar>;
     77template class TableVector<uChar>;
     78template class TabVecScaCol<uChar>;
     79template class TabVecTemp<uChar>;
     80template class TabVecRep<uChar>;
     81
    7682template void convertArray<Bool, uChar>(Array<Bool> &, Array<uChar> const &);
    7783template void convertArray<uChar, Bool>(Array<uChar> &, Array<Bool> const &);
     
    110116                        Bool, Bool);
    111117}
    112 //template Array<Bool> SDPolUtil::stokesData (Array<Bool>& dataIn, Bool);
    113 //template Array<Float> SDPolUtil::computeStokesDataForWriter(Array<Float>& dataIn, Bool);
    114 //template Array<uChar> SDPolUtil::computeStokesDataForWriter(Array<uChar>& dataIn, Bool);
    115118
  • trunk/src/python_Scantable.cpp

    r884 r896  
    6363    .def("_setInstrument", &ScantableWrapper::setInstrument)
    6464    .def("_getspectrum", &ScantableWrapper::getSpectrum,
    65          (boost::python::arg("whichrow")=0))
    66     /*
    67     .def("nstokes", &ScantableWrapper::nStokes)
    68     .def("_getstokesspectrum", &ScantableWrapper::getStokesSpectrum,
    69          (boost::python::arg("whichrow")=0),
    70          (boost::python::arg("linpol")=false) )
    71     .def("_stokestopolspectrum", &ScantableWrapper::stokesToPolSpectrum,
    72          (boost::python::arg("whichrow")=0),
    73          (boost::python::arg("linear")=false),
    74          (boost::python::arg("thepol")=-1) )
    75     */
     65         (arg("whichrow")=0, arg("poltype")=std::string("linear")) )
     66    .def("poltype", &ScantableWrapper::getPolType )
    7667    .def("_getpolarizationlabel", &ScantableWrapper::getPolarizationLabel,
    77          (boost::python::arg("linear")=false),
    78          (boost::python::arg("stokes")=false),
    79          (boost::python::arg("linpol")=false) )
    80 //         (boost::python::arg("thepol")=0) )        // Boost fails with 4 arguments
    81    .def("_setspectrum",&ScantableWrapper::setSpectrum,
     68         ( arg("linear")=false, arg("stokes")=false,
     69           arg("linpol")=false, arg("thepol")=0 ) )
     70    .def("_setspectrum",&ScantableWrapper::setSpectrum,
    8271         (boost::python::arg("whichrow")=0) )
    8372    .def("_getabcissa", &ScantableWrapper::getAbcissa,
Note: See TracChangeset for help on using the changeset viewer.