Changeset 960


Ignore:
Timestamp:
03/31/06 17:07:57 (18 years ago)
Author:
mar637
Message:

c++ side of Ticket #7

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STFit.cpp

    r898 r960  
    1 //#---------------------------------------------------------------------------
    2 //# SDFitTable.h: A wrapper for fit parameters
    3 //#---------------------------------------------------------------------------
    4 //# Copyright (C) 2004
    5 //# ATNF
    6 //#
    7 //# This program is free software; you can redistribute it and/or modify it
    8 //# under the terms of the GNU General Public License as published by the Free
    9 //# Software Foundation; either version 2 of the License, or (at your option)
    10 //# any later version.
    11 //#
    12 //# This program is distributed in the hope that it will be useful, but
    13 //# WITHOUT ANY WARRANTY; without even the implied warranty of
    14 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    15 //# Public License for more details.
    16 //#
    17 //# You should have received a copy of the GNU General Public License along
    18 //# with this program; if not, write to the Free Software Foundation, Inc.,
    19 //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
    20 //#
    21 //# Correspondence concerning this software should be addressed as follows:
    22 //#        Internet email: Malte.Marquarding@csiro.au
    23 //#        Postal address: Malte Marquarding,
    24 //#                        Australia Telescope National Facility,
    25 //#                        P.O. Box 76,
    26 //#                        Epping, NSW, 2121,
    27 //#                        AUSTRALIA
    28 //#
    29 //# $Id:
    30 //#---------------------------------------------------------------------------
     1
     2//
     3// C++ Implementation: STFit
     4//
     5// Description:
     6//
     7//
     8// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
     9//
     10// Copyright: See COPYING file that comes with this distribution
     11//
     12//
     13#include <casa/Exceptions/Error.h>
     14#include <tables/Tables/TableDesc.h>
     15#include <tables/Tables/SetupNewTab.h>
     16#include <tables/Tables/ScaColDesc.h>
     17#include <tables/Tables/ArrColDesc.h>
     18#include <tables/Tables/TableRecord.h>
     19#include <tables/Tables/TableParse.h>
     20#include <tables/Tables/TableRow.h>
     21#include <casa/Containers/RecordField.h>
    3122
    3223#include "MathUtils.h"
    33 #include "SDFitTable.h"
     24#include "STFitEntry.h"
     25#include "STFit.h"
     26
    3427
    3528using namespace casa;
    36 using namespace asap;
    3729
    38 SDFitTable::SDFitTable(const SDFitTable& other) { 
    39   if (other.length() > 0) {
    40     this->nfits_ = other.nfits_;
    41     this->pars_ = other.pars_;
    42     this->mask_ = other.mask_;
    43     this->funcs_ = other.funcs_;
    44     this->comps_ = other.comps_;
    45     this->frameinfo_ = other.frameinfo_;
    46   } else {
    47     this->nfits_ = 0;
    48   }
     30namespace asap {
     31
     32const casa::String STFit::name_ = "FIT";
     33
     34STFit::STFit(const Scantable& parent) :
     35  STSubTable( parent, name_ )
     36{
     37  setup();
    4938}
    5039
    51 
    52 void SDFitTable::addSTLFit(const std::vector<double>& p,
    53                       const std::vector<bool>& m,
    54                       const std::vector<std::string>& f,
    55                       const std::vector<Int>& c,
    56                       const std::vector<std::string>& fi)
     40STFit& asap::STFit::operator =( const STFit & other )
    5741{
    58   pars_.push_back(p);
    59   mask_.push_back(m);
    60   funcs_.push_back(f);
    61   comps_.push_back(c);
    62   frameinfo_.push_back(fi);
    63   nfits_++;
     42  if ( this != &other ) {
     43    static_cast<STSubTable&>(*this) = other;
     44    funcCol_.attach(table_,"FUNCTIONS");
     45    compCol_.attach(table_,"COMPONENTS");
     46    parCol_.attach(table_,"PARAMETERS");
     47    maskCol_.attach(table_,"PARMASKS");
     48    frameCol_.attach(table_,"FRAMEINFO");
     49  }
     50  return *this;
    6451}
    6552
    66 void SDFitTable::addFit(const Vector<Double>& p,
    67                    const Vector<Bool>& m,
    68                    const Vector<String>& f,
    69                    const Vector<Int>& c,
    70                    const Vector<String>& fi)
     53asap::STFit::STFit( casa::Table tab ) : STSubTable(tab, name_)
    7154{
    72   std::vector<double> p1;
    73   p.tovector(p1);
    74   pars_.push_back(p1);
    75   std::vector<bool> m1;
    76   m.tovector(m1);
    77   mask_.push_back(m1);
    78   std::vector<string> f1;
    79   f1 = mathutil::tovectorstring(f);
    80   funcs_.push_back(f1);
    81   std::vector<int> c1;
    82   c.tovector(c1);
    83   comps_.push_back(c1);
    84   std::vector<string> fi1;
    85   fi1 = mathutil::tovectorstring(fi);
    86   frameinfo_.push_back(fi1);
    87   nfits_++;
     55    funcCol_.attach(table_,"FUNCTIONS");
     56    compCol_.attach(table_,"COMPONENTS");
     57    parCol_.attach(table_,"PARAMETERS");
     58    maskCol_.attach(table_,"PARMASKS");
     59    frameCol_.attach(table_,"FRAMEINFO");
    8860}
    8961
    90 std::vector<double> SDFitTable::getSTLParameters(int which) const
     62STFit::~STFit()
    9163{
    92   if (which >= nfits_)
    93     return std::vector<double>(); 
    94   return pars_[which];
    9564}
    9665
    97 Vector<Double> SDFitTable::getParameters(uInt which) const{
    98   if (int(which) >= nfits_)
    99     return Vector<Double>(std::vector<double>()); 
    100   return Vector<Double>(pars_[which]);
     66void asap::STFit::setup( )
     67{
     68  // add to base class table
     69  table_.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
     70  table_.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
     71  table_.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
     72  table_.addColumn(ArrayColumnDesc<Bool>("PARMASKS"));
     73  table_.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
     74
     75  // new cached columns
     76  funcCol_.attach(table_,"FUNCTIONS");
     77  compCol_.attach(table_,"COMPONENTS");
     78  parCol_.attach(table_,"PARAMETERS");
     79  maskCol_.attach(table_,"PARMASKS");
     80  frameCol_.attach(table_,"FRAMEINFO");
    10181}
    10282
    103 std::vector<bool> SDFitTable::getSTLParameterMask(int which) const
     83uInt STFit::addEntry( const STFitEntry& fit, Int id )
    10484{
    105   if (which >= nfits_)
    106     return  std::vector<bool>();
    107   return mask_[which];
     85  uInt rno = table_.nrow();
     86  uInt resultid;
     87  bool foundentry = false;
     88  if ( id > -1 ) {
     89    Table t = table_(table_.col("ID") == id );
     90    if (t.nrow() > 0) {
     91      rno = t.rowNumbers()[0];
     92      resultid = id;
     93      foundentry = true;
     94    }
     95  }
     96  if ( rno > 0  && !foundentry ) {
     97    idCol_.get(rno-1, resultid);
     98    resultid++;
     99  }
     100  if ( !foundentry )table_.addRow();
     101
     102  funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
     103  compCol_.put(rno, Vector<Int>(fit.getComponents()));
     104  parCol_.put(rno, Vector<Double>(fit.getParameters()));
     105  maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
     106  frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
     107  idCol_.put(rno, resultid);
     108  return resultid;
    108109}
    109110
    110 Vector<Bool> SDFitTable::getParameterMask(uInt which) const
     111void STFit::getEntry( STFitEntry& fit, uInt id )
    111112{
    112   if (which >= nfits_)
    113     return  Vector<Bool>(std::vector<bool>()); 
    114   return Vector<Bool>(mask_[which]);
     113  Table t = table_(table_.col("ID") == Int(id) );
     114  if (t.nrow() == 0 ) {
     115    throw(AipsError("STFit::getEntry - id out of range"));
     116  }
     117  ROTableRow row(t);
     118  // get first row - there should only be one matching id
     119  const TableRecord& rec = row.get(0);
     120  std::vector<std::string> outstr;
     121  Vector<String> vec;
     122  rec.get("FUNCTIONS", vec);
     123  fit.setFunctions(mathutil::tovectorstring(vec));
     124  Vector<Int> ivec;
     125  std::vector<int> istl;
     126  rec.get("COMPONENTS", ivec);
     127  ivec.tovector(istl);
     128  fit.setComponents(istl);
     129  Vector<Double> dvec;
     130  std::vector<double> dstl;
     131  rec.get("PARAMETERS", dvec);
     132  dvec.tovector(dstl);
     133  fit.setParameters(dstl);
     134  Vector<Bool> bvec;
     135  std::vector<bool> bstl;
     136  rec.get("PARMASKS", bvec);
     137  bvec.tovector(bstl);
     138  fit.setParmasks(bstl);
     139  vec.resize();
     140  rec.get("FRAMEINFO", vec);
     141  fit.setFrameinfo(mathutil::tovectorstring(vec));
    115142}
    116143
    117 std::vector<std::string> SDFitTable::getSTLFunctions(int which) const
    118 {
    119   if (which >= nfits_)
    120     return std::vector<std::string>(); 
    121   return funcs_[which];
    122 }
    123 
    124 Vector<String> SDFitTable::getFunctions(uInt which) const
    125 {
    126   if (int(which) >= nfits_)
    127     return mathutil::toVectorString(std::vector<std::string>());
    128   return mathutil::toVectorString(funcs_[which]);
    129 }
    130 
    131 std::vector<int> SDFitTable::getSTLComponents(int which) const
    132 {
    133   if (which >= nfits_)
    134     return std::vector<int>(); 
    135   return comps_[which];
    136 }
    137 
    138 Vector<Int> SDFitTable::getComponents(uInt which) const
    139 {
    140   if (int(which) >= nfits_)
    141     return Vector<Int>(std::vector<int>()); 
    142   return Vector<Int>(comps_[which]);
    143 }
    144 
    145 std::vector<std::string> SDFitTable::getSTLFrameInfo(int which) const
    146 {
    147   if (which >= nfits_)
    148     return std::vector<std::string>(); 
    149   return frameinfo_[which];
    150 }
    151 
    152 Vector<String> SDFitTable::getFrameInfo(uInt which) const
    153 {
    154   if (int(which) >= nfits_)
    155     return mathutil::toVectorString(std::vector<std::string>());
    156   return mathutil::toVectorString(frameinfo_[which]);
    157 }
    158 
     144} //namespace
  • trunk/src/STFit.h

    r898 r960  
    1 //#---------------------------------------------------------------------------
    2 //# SDFitTable.h: A wrapper for fit parameters
    3 //#---------------------------------------------------------------------------
    4 //# Copyright (C) 2004
    5 //# ATNF
    6 //#
    7 //# This program is free software; you can redistribute it and/or modify it
    8 //# under the terms of the GNU General Public License as published by the Free
    9 //# Software Foundation; either version 2 of the License, or (at your option)
    10 //# any later version.
    11 //#
    12 //# This program is distributed in the hope that it will be useful, but
    13 //# WITHOUT ANY WARRANTY; without even the implied warranty of
    14 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    15 //# Public License for more details.
    16 //#
    17 //# You should have received a copy of the GNU General Public License along
    18 //# with this program; if not, write to the Free Software Foundation, Inc.,
    19 //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
    20 //#
    21 //# Correspondence concerning this software should be addressed as follows:
    22 //#        Internet email: Malte.Marquarding@csiro.au
    23 //#        Postal address: Malte Marquarding,
    24 //#                        Australia Telescope National Facility,
    25 //#                        P.O. Box 76,
    26 //#                        Epping, NSW, 2121,
    27 //#                        AUSTRALIA
    28 //#
    29 //# $Id:
    30 //#---------------------------------------------------------------------------
    31 #ifndef SDFITTABLE_H
    32 #define SDFITTABLE_H
     1//
     2// C++ Interface: STFit
     3//
     4// Description:
     5//
     6//
     7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
     8//
     9// Copyright: See COPYING file that comes with this distribution
     10//
     11//
     12#ifndef ASAPSTFIT_H
     13#define ASAPSTFIT_H
    3314
    3415#include <casa/aips.h>
    35 #include <casa/Arrays/Vector.h>
    3616#include <casa/BasicSL/String.h>
    37 #include <vector>
    38 #include <string>
     17#include <tables/Tables/Table.h>
     18#include <tables/Tables/ScalarColumn.h>
     19#include <tables/Tables/ArrayColumn.h>
    3920
     21#include "STSubTable.h"
    4022namespace asap {
    4123
    42 class SDFitTable {
     24class STFitEntry;
     25/**
     26The Fit subtable of the Scantable
     27
     28@author Malte Marquarding
     29*/
     30class STFit : public STSubTable {
    4331public:
    44   SDFitTable() : nfits_(0) {;};
    45   ~SDFitTable() {;};
    46   SDFitTable(const SDFitTable& other);
     32  STFit() {;}
     33  STFit(casa::Table tab);
     34  STFit( const Scantable& parent);
    4735
    48   void addFit(const casa::Vector<casa::Double>& p,
    49               const casa::Vector<casa::Bool>& m,
    50               const casa::Vector<casa::String>& f,
    51               const casa::Vector<casa::Int>& c,
    52               const casa::Vector<casa::String>& fi);
    53  
    54   void addSTLFit(const std::vector<double>& p,
    55                  const std::vector<bool>& m,
    56                  const std::vector<std::string>& f,
    57                  const std::vector<int>& c,
    58                  const std::vector<std::string>& fi);
    59  
    60   int STLlength() const { return nfits_; };
    61  
    62   casa::uInt length() const { return casa::uInt(nfits_); };
    63  
    64   std::vector<double> getSTLParameters(int which) const;
    65   std::vector<bool> getSTLParameterMask(int which) const;
    66   std::vector<std::string> getSTLFunctions(int which) const;
    67   std::vector<int> getSTLComponents(int which) const;
    68   std::vector<std::string> getSTLFrameInfo(int which) const;
     36  virtual ~STFit();
    6937
    70   casa::Vector<casa::Double> getParameters(casa::uInt which) const;
    71   casa::Vector<casa::Bool> getParameterMask(casa::uInt which) const;
    72   casa::Vector<casa::String> getFunctions(casa::uInt which) const;
    73   casa::Vector<casa::Int> getComponents(casa::uInt which) const;
    74   casa::Vector<casa::String> getFrameInfo(casa::uInt which) const;
     38  STFit& operator=(const STFit& other);
    7539
     40  casa::uInt addEntry( const STFitEntry& fit, casa::Int id=-1 );
     41  void getEntry( STFitEntry& fit, casa::uInt id );
     42
     43  const casa::String& name() const { return name_; }
    7644
    7745private:
    78   int nfits_;
    79   std::vector<std::vector<double> > pars_;
    80   std::vector<std::vector<bool> > mask_;
    81   std::vector<std::vector<std::string> > funcs_;
    82   std::vector<std::vector<int> > comps_;
    83   std::vector<std::vector<std::string> > frameinfo_;
     46  void setup();
     47  static const casa::String name_;
     48  //casa::Table table_;
     49  casa::ArrayColumn<casa::String> funcCol_;
     50  casa::ArrayColumn<casa::Int> compCol_;
     51  casa::ArrayColumn<casa::Double> parCol_;
     52  casa::ArrayColumn<casa::Bool> maskCol_;
     53  casa::ArrayColumn<casa::String> frameCol_;
    8454};
    8555
    86 }//
     56}
    8757
    8858#endif
  • trunk/src/STFitEntry.h

    r955 r960  
    2626public:
    2727  STFitEntry();
    28 
     28 
    2929  ~STFitEntry();
    30 
     30 
    3131  void setFunctions(const std::vector<std::string>& f)
    3232    { functions_ = f; }
     
    4040    { frameinfo_ = f; }
    4141
    42   const std::vector<std::string>& getFunctions() const { return functions_; }
    43   const std::vector<int>& getComponents() const { return components_; }
    44   const std::vector<double>& getParameters() const { return parameters_; }
    45   const std::vector<bool>& getParmasks() const { return parmasks_; }
    46   const std::vector<std::string>& getFrameinfo() const { return frameinfo_; }
     42  std::vector<std::string> getFunctions() const { return functions_; }
     43  std::vector<int> getComponents() const { return components_; }
     44  std::vector<double> getParameters() const { return parameters_; }
     45  std::vector<bool> getParmasks() const { return parmasks_; }
     46  std::vector<std::string> getFrameinfo() const { return frameinfo_; }
    4747
    4848private:
    49     std::vector<std::string> functions_;
    50     std::vector<int> components_;
    51     std::vector<double> parameters_;
    52     std::vector<bool> parmasks_;
    53     std::vector<std::string> frameinfo_;
     49  std::vector<std::string> functions_;
     50  std::vector<int> components_;
     51  std::vector<double> parameters_;
     52  std::vector<bool> parmasks_;
     53  std::vector<std::string> frameinfo_;
    5454};
    5555
  • trunk/src/Scantable.h

    r923 r960  
    4040#include "STHistory.h"
    4141#include "STPol.h"
     42#include "STFit.h"
    4243
    4344namespace asap {
     
    345346  void setupMainTable();
    346347
    347   void setupFitTable();
    348 
    349348  void attachSubtables();
    350349  void copySubtables(const Scantable& other);
     
    373372  STMolecules moleculeTable_;
    374373  STHistory historyTable_;
    375 
    376   casa::Table fitTable_;
     374  STFit fitTable_;
    377375
    378376  // Cached Columns to avoid reconstructing them for each row get/put
     
    395393
    396394  casa::ArrayColumn<casa::String> histitemCol_;
    397   casa::ScalarColumn<casa::uInt> mfitidCol_, fitidCol_;
     395  casa::ScalarColumn<casa::uInt> mfitidCol_;
    398396  // id in weather table and main table
    399397  casa::ScalarColumn<casa::uInt> mweatheridCol_;
  • trunk/src/python_STFitEntry.cpp

    r956 r960  
    11//#---------------------------------------------------------------------------
    2 //# python_SDFitTable.cc: python exposure of c++ SDFitTable class
     2//# python_STFitEntry: python exposure of c++ STFitEntry class
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2004
     4//# Copyright (C) 2006
    55//# ATNF
    66//#
     
    2727//#                        AUSTRALIA
    2828//#
    29 //# $Id:
     29//# $Id:$
    3030//#---------------------------------------------------------------------------
    3131#include <boost/python.hpp>
    3232
    33 #include "SDFitTable.h"
     33#include "STFitEntry.h"
    3434
    3535using namespace boost::python;
     
    3838  namespace python {
    3939
    40     void python_SDFitTable() {
    41       class_<SDFitTable>("sdfit")
     40    void python_STFitEntry() {
     41      class_<STFitEntry>("fitentry")
    4242        .def( init <> () )
    43         .def( init < const SDFitTable& > () )
    44         .def("__len__", &SDFitTable::STLlength)
    45         .def("getfixedparameters", &SDFitTable::getSTLParameterMask)
    46         .def("getparameters", &SDFitTable::getSTLParameters)
    47         .def("getfunctions", &SDFitTable::getSTLFunctions)
    48         .def("getcomponents", &SDFitTable::getSTLComponents)
    49         .def("getframeinfo", &SDFitTable::getSTLFrameInfo)
     43        .def("getfixedparameters", &STFitEntry::getParmasks)
     44        .def("getparameters", &STFitEntry::getParameters)
     45        .def("getfunctions", &STFitEntry::getFunctions)
     46        .def("getcomponents", &STFitEntry::getComponents)
     47        .def("getframeinfo", &STFitEntry::getFrameinfo)
    5048      ;
    5149    };
  • trunk/src/python_asap.cpp

    r894 r960  
    6262  asap::python::python_Fitter();
    6363  asap::python::python_STLineFinder();
     64  asap::python::python_STFitEntry();
    6465  /*
    6566  asap::python::python_SDWriter();
    66   asap::python::python_SDFitTable();
    6767  */
    6868  asap::python::python_Logger();
  • trunk/src/python_asap.h

    r894 r960  
    4343    void python_Fitter();
    4444    void python_STLineFinder();
     45    void python_STFitEntry();
    4546    /*
    4647    void python_SDWriter();
    47     void python_SDFitTable();
    4848    */
    4949    void python_Logger();
Note: See TracChangeset for help on using the changeset viewer.