Ignore:
Timestamp:
09/14/10 12:17:16 (14 years ago)
Author:
Malte Marquarding
Message:

Ticket #206: use STFitEntry as return objetc instead of pointer wrnagling.

Location:
branches/polybatch/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/polybatch/src/STFit.cpp

    r1000 r1924  
    7070  table_.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
    7171  table_.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
     72  //  table_.addColumn(ArrayColumnDesc<Double>("ERRORS"));
    7273  table_.addColumn(ArrayColumnDesc<Bool>("PARMASKS"));
    7374  table_.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
     
    7778  compCol_.attach(table_,"COMPONENTS");
    7879  parCol_.attach(table_,"PARAMETERS");
     80  //  errCol_.attach(table_,"ERRORS");
    7981  maskCol_.attach(table_,"PARMASKS");
    8082  frameCol_.attach(table_,"FRAMEINFO");
     
    102104  // add new row if new id
    103105  if ( !foundentry ) table_.addRow();
     106
    104107  funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
    105108  compCol_.put(rno, Vector<Int>(fit.getComponents()));
    106   parCol_.put(rno, Vector<Double>(fit.getParameters()));
     109  const std::vector<float>& pvec = fit.getParameters();
     110  Vector<Double> dvec(pvec.size());
     111  for (size_t i=0; i < dvec.nelements(); ++i) {
     112    dvec[i] = Double(pvec[i]);
     113  }
     114  parCol_.put(rno, dvec);
     115  /*
     116  const std::vector<double>& evec = fit.getErrors();
     117  for (size_t i=0; i < dvec.nelements(); ++i) {
     118    dvec[i] = Double(evec[i]);
     119  }
     120  errCol_.put(rno, dvec);
     121  */
    107122  maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
    108123  frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
    109124  idCol_.put(rno, resultid);
     125
    110126  return resultid;
    111127}
     
    130146  fit.setComponents(istl);
    131147  Vector<Double> dvec;
    132   std::vector<double> dstl;
    133148  rec.get("PARAMETERS", dvec);
     149  std::vector<float> dstl(dvec.begin(), dvec.end());
     150  fit.setParameters(dstl);
     151  /*
    134152  dvec.tovector(dstl);
    135153  fit.setParameters(dstl);
     154  dvec.resize();
     155  rec.get("ERRORS", dvec);
     156  dvec.tovector(dstl);
     157  fit.setErrors(dstl);
     158  */
    136159  Vector<Bool> bvec;
    137160  std::vector<bool> bstl;
  • branches/polybatch/src/STFit.h

    r1353 r1924  
    4949  casa::ArrayColumn<casa::Int> compCol_;
    5050  casa::ArrayColumn<casa::Double> parCol_;
     51  //  casa::ArrayColumn<casa::Double> errCol_;
    5152  casa::ArrayColumn<casa::Bool> maskCol_;
    5253  casa::ArrayColumn<casa::String> frameCol_;
  • branches/polybatch/src/STFitEntry.cpp

    r972 r1924  
    1111//
    1212#include "STFitEntry.h"
     13#include <casa/iostream.h>
    1314
     15using namespace casa;
    1416namespace asap {
    1517
    16 STFitEntry::STFitEntry()
     18  STFitEntry::STFitEntry()
     19  /* :
     20    functions_( std::vector<std::string>()),
     21    components_(std::vector<int>()),
     22    parameters_(std::vector<float>()),
     23    errors_(std::vector<float>()),
     24    parmasks_(std::vector<bool>()),
     25    frameinfo_(std::vector<std::string>())
     26  */
    1727{
    1828}
     
    2030{
    2131  if ( this != &other ) {
    22     this->functions_ = other.functions_;
     32    this->functions_ = std::vector<std::string>();
    2333    this->components_ = other.components_;
    2434    this->parameters_ = other.parameters_;
    25     this->parmasks_ = other.parmasks_;
     35    this->errors_ = other.errors_;
    2636    this->frameinfo_ = other.frameinfo_;
    2737  }
    2838}
    2939
     40STFitEntry& STFitEntry::operator=(const STFitEntry& other)
     41{
     42  if ( this != &other ) {
     43    this->functions_ = other.functions_;
     44    this->components_ = other.components_;
     45    this->parameters_ = other.parameters_;
     46    this->errors_ = other.errors_;
     47    this->parmasks_ = other.parmasks_;
     48    this->frameinfo_ = other.frameinfo_;
     49  }
     50  return *this;
     51}
    3052
    3153STFitEntry::~STFitEntry()
  • branches/polybatch/src/STFitEntry.h

    r972 r1924  
    2828  STFitEntry(const STFitEntry& other);
    2929
     30  STFitEntry& operator=(const STFitEntry& other);
     31
    3032  ~STFitEntry();
    3133
     
    3436  void setComponents(const std::vector<int>& c)
    3537    { components_ = c; }
    36   void setParameters(const std::vector<double>& p)
     38  void setParameters(const std::vector<float>& p)
    3739    { parameters_ = p; }
     40  void setErrors(const std::vector<float>& p)
     41    { errors_ = p; }
    3842  void setParmasks(const std::vector<bool>& m)
    3943    { parmasks_ = m; }
    4044  void setFrameinfo(const std::vector<std::string>& f)
    4145    { frameinfo_ = f; }
    42 
    4346  std::vector<std::string> getFunctions() const { return functions_; }
    4447  std::vector<int> getComponents() const { return components_; }
    45   std::vector<double> getParameters() const { return parameters_; }
     48  std::vector<float> getParameters() const { return parameters_; }
     49  std::vector<float> getErrors() const { return errors_; }
    4650  std::vector<bool> getParmasks() const { return parmasks_; }
    4751  std::vector<std::string> getFrameinfo() const { return frameinfo_; }
    4852
    4953private:
     54
    5055  std::vector<std::string> functions_;
    5156  std::vector<int> components_;
    52   std::vector<double> parameters_;
     57  std::vector<float> parameters_;
     58  std::vector<float> errors_;
    5359  std::vector<bool> parmasks_;
    5460  std::vector<std::string> frameinfo_;
  • branches/polybatch/src/STFitter.cpp

    r1819 r1924  
    142142    if (ncomp < 1) throw (AipsError("Need at least one gaussian to fit."));
    143143    funcs_.resize(ncomp);
     144    funcnames_.clear();
     145    funccomponents_.clear();
    144146    for (Int k=0; k<ncomp; ++k) {
    145147      funcs_[k] = new Gaussian1D<Float>();
     148      funcnames_.push_back(expr);
     149      funccomponents_.push_back(3);
    146150    }
    147151  } else if (expr == "poly") {
    148152    funcs_.resize(1);
     153    funcnames_.clear();
     154    funccomponents_.clear();
    149155    funcs_[0] = new Polynomial<Float>(ncomp);
     156      funcnames_.push_back(expr);
     157      funccomponents_.push_back(ncomp);
    150158  } else if (expr == "lorentz") {
    151159    if (ncomp < 1) throw (AipsError("Need at least one lorentzian to fit."));
    152160    funcs_.resize(ncomp);
     161    funcnames_.clear();
     162    funccomponents_.clear();
    153163    for (Int k=0; k<ncomp; ++k) {
    154164      funcs_[k] = new Lorentzian1D<Float>();
     165      funcnames_.push_back(expr);
     166      funccomponents_.push_back(3);
    155167    }
    156168  } else {
     
    409421}
    410422
     423STFitEntry Fitter::getFitEntry() const
     424{
     425  STFitEntry fit;
     426  fit.setParameters(getParameters());
     427  fit.setErrors(getErrors());
     428  fit.setComponents(funccomponents_);
     429  fit.setFunctions(funcnames_);
     430  fit.setParmasks(getFixedParameters());
     431  return fit;
     432}
  • branches/polybatch/src/STFitter.h

    r1391 r1924  
    4040#include <scimath/Functionals/CompoundFunction.h>
    4141
     42#include "STFitEntry.h"
     43
    4244namespace asap {
    4345
     
    6971
    7072  std::vector<float> evaluate(int whichComp) const;
     73
     74  STFitEntry getFitEntry() const;
     75
    7176private:
    7277  void clear();
     
    7580  casa::Vector<casa::Bool> m_;
    7681  casa::PtrBlock<casa::Function<casa::Float>* > funcs_;
     82  std::vector<std::string> funcnames_;
     83  std::vector<int> funccomponents_;
     84 
    7785  //Bool estimateSet_;
    7886  casa::Float chisquared_;
  • branches/polybatch/src/Scantable.cpp

    r1919 r1924  
    17501750}
    17511751
    1752 void Scantable::polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno)
     1752void Scantable::polyBaselineBatch(const std::vector<bool>& mask, int order)
     1753{
     1754  Fitter fitter = Fitter();
     1755  for (uInt rowno=0; rowno < nrow(); ++rowno) {
     1756    doPolyBaseline(mask, order, rowno, fitter);
     1757    setSpectrum(fitter.getResidual(), rowno);
     1758  }
     1759}
     1760
     1761STFitEntry Scantable::polyBaseline(const std::vector<bool>& mask, int order, int rowno)
    17531762{
    17541763  Fitter fitter = Fitter();
    17551764  doPolyBaseline(mask, order, rowno, fitter);
    17561765  setSpectrum(fitter.getResidual(), rowno);
    1757 }
    1758 
    1759 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size)
    1760 {
    1761   Fitter fitter = Fitter();
    1762   doPolyBaseline(mask, order, rowno, fitter);
    1763   setSpectrum(fitter.getResidual(), rowno);
    1764 
    1765   std::vector<float> pars = fitter.getParameters();
    1766   if (pars_size != pars.size()) {
    1767     throw(AipsError("wrong pars size"));
    1768   }
    1769   float *ppars = reinterpret_cast<float*>(pars_ptr);
    1770   for (int i = 0; i < pars_size; i++) {
    1771     ppars[i] = pars[i];
    1772   }
    1773 
    1774   std::vector<float> errs = fitter.getErrors();
    1775   if (errs_size != errs.size()) {
    1776     throw(AipsError("wrong errors size"));
    1777   }
    1778   float *perrs = reinterpret_cast<float*>(errs_ptr);
    1779   for (int i = 0; i < errs_size; i++) {
    1780     perrs[i] = errs[i];
    1781   }
    1782 
    1783   std::vector<bool> fmask = getMask(rowno);
    1784   if (fmask_size != fmask.size()) {
    1785     throw(AipsError("wrong fmask size"));
    1786   }
    1787   int *pfmask = reinterpret_cast<int*>(fmask_ptr);
    1788   for (int i = 0; i < fmask_size; i++) {
    1789     pfmask[i] = ((fmask[i] && mask[i]) ? 1 : 0);
    1790   }
     1766  return fitter.getFitEntry();
    17911767}
    17921768
  • branches/polybatch/src/Scantable.h

    r1919 r1924  
    1818// AIPS++
    1919#include <casa/aips.h>
     20#include <casa/Containers/Record.h>
    2021#include <casa/Arrays/MaskedArray.h>
    2122#include <casa/BasicSL/String.h>
     
    489490  bool getFlagtraFast(int whichrow);
    490491
    491   void polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno);
    492   void polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size);
    493 
     492  void polyBaselineBatch(const std::vector<bool>& mask, int order);
     493  STFitEntry polyBaseline(const std::vector<bool>& mask, int order, int rowno);
    494494
    495495private:
  • branches/polybatch/src/ScantableWrapper.h

    r1919 r1924  
    1919#include "MathUtils.h"
    2020#include "STFit.h"
     21#include "STFitEntry.h"
    2122#include "Scantable.h"
    2223#include "STCoordinate.h"
     
    250251  { table_->reshapeSpectrum( nmin, nmax ); }
    251252
    252   void polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size)
    253   { table_->polyBaseline(mask, order, rowno, pars_ptr, pars_size, errs_ptr, errs_size, fmask_ptr, fmask_size); }
    254 
    255   void polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno)
    256   { table_->polyBaselineBatch(mask, order, rowno); }
     253  STFitEntry polyBaseline(const std::vector<bool>& mask, int order, int rowno)
     254  { return table_->polyBaseline(mask, order, rowno); }
     255
     256  void polyBaselineBatch(const std::vector<bool>& mask, int order)
     257  { table_->polyBaselineBatch(mask, order); }
    257258
    258259  bool getFlagtraFast(int whichrow=0) const
  • branches/polybatch/src/python_STFitEntry.cpp

    r972 r1924  
    4444        .def("getfixedparameters", &STFitEntry::getParmasks)
    4545        .def("getparameters", &STFitEntry::getParameters)
     46        .def("geterrors", &STFitEntry::getErrors)
    4647        .def("getfunctions", &STFitEntry::getFunctions)
    4748        .def("getcomponents", &STFitEntry::getComponents)
     
    4950        .def("setfixedparameters", &STFitEntry::setParmasks)
    5051        .def("setparameters", &STFitEntry::setParameters)
     52        .def("seterrors", &STFitEntry::setErrors)
    5153        .def("setfunctions", &STFitEntry::setFunctions)
    5254        .def("setcomponents", &STFitEntry::setComponents)
Note: See TracChangeset for help on using the changeset viewer.