Changeset 465


Ignore:
Timestamp:
02/17/05 14:46:17 (19 years ago)
Author:
mar637
Message:

Added SDFitTable to handle fits and expose them to python vi the sdfit class.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile

    r460 r465  
    4545             SDAttr.o \
    4646             SDContainer.o \
     47             SDFitTable.o \
    4748             SDPol.o \
    4849             SDPol2.o \
     
    6263             python_SDMath.o \
    6364             python_SDFitter.o \
     65             python_SDFitTable.o \
    6466             python_SDLineFinder.o \
    6567             python_SD.o
     
    6971             SDAttr.h \
    7072             SDContainer.h \
     73             SDFitTable.h \
    7174             SDMemTable.h \
    7275             SDPol.h \
  • trunk/src/MathUtils.cc

    r452 r465  
    3434#include <casa/Arrays/MaskedArray.h>
    3535#include <casa/Arrays/MaskArrMath.h>
     36#include <casa/Arrays/VectorSTLIterator.h>
    3637#include <casa/BasicSL/String.h>
    3738
     
    107108  endInt.resize(j+1,True);
    108109}
     110
     111std::vector<std::string> mathutil::tovectorstring(const Vector<String>& in)
     112{
     113  std::vector<std::string> out;
     114  VectorSTLIterator<String> it(in);
     115  for (uInt i=0; it != in.end(); ++it,++i) {
     116    out.push_back(*it);
     117  }
     118  return out;
     119}
     120
     121Vector<String> mathutil::toVectorString(const std::vector<std::string>& in)
     122{
     123  Vector<String> out(in.size());
     124  uInt i=0;
     125  std::vector<std::string>::const_iterator it;
     126  for (it=in.begin();it != in.end();++it,++i) {
     127    out[i] = casa::String(*it);
     128  }
     129  return out;
     130}
  • trunk/src/MathUtils.h

    r452 r465  
    3232#define MATHUTILS_H
    3333
     34#include <string>
     35#include <vector>
    3436#include <casa/aips.h>
    3537#include <casa/Arrays/Vector.h>
     38#include <casa/BasicSL/String.h>
    3639
    3740namespace mathutil {
     
    4245
    4346// Find the scan boundaries from a list of ScanIDs
    44 void scanBoundaries (casa::Vector<casa::uInt>& startInt, 
    45                      casa::Vector<casa::uInt>& endInt,
    46                      const casa::Vector<casa::Int>& scanIDs);
     47void scanBoundaries(casa::Vector<casa::uInt>& startInt, 
     48                    casa::Vector<casa::uInt>& endInt,
     49                    const casa::Vector<casa::Int>& scanIDs);
    4750
    4851// Hanning smoothing
     
    5053void hanning(casa::Vector<T>& out, casa::Vector<casa::Bool>& outmask,
    5154             const casa::Vector<T>& in, const casa::Vector<casa::Bool>& mask,
    52              casa::Bool relaxed=False, casa::Bool ignoreOther=False);
     55             casa::Bool relaxed=casa::False,
     56             casa::Bool ignoreOther=casa::False);
    5357
    5458// Generate specified statistic
     
    5862// Replace masked value by zero
    5963void replaceMaskByZero(casa::Vector<casa::Float>& data,
    60                         const casa::Vector<casa::Bool>& mask);
     64                       const casa::Vector<casa::Bool>& mask);
    6165
    6266// Extend the
     
    6468void extendLastArrayAxis(casa::Array<T>& out, const casa::Array<T>& in,
    6569                         const T& initVal);
     70 
     71std::vector<std::string> tovectorstring(const casa::Vector<casa::String>& in);
     72
     73casa::Vector<casa::String> toVectorString(const std::vector<std::string>& in);
    6674
    6775};
  • trunk/src/SDContainer.cc

    r453 r465  
    582582}
    583583
    584 // SDFitTable
    585 
    586 
    587 const Vector<Double>& SDFitTable::getFitParameters(uInt whichRow) const
    588 {
    589   if (whichRow <= n_)
    590     return fitParms_[whichRow];
    591 }
    592 
    593 const Vector<Bool>& SDFitTable::getFitParameterMask(uInt whichRow) const
    594 {
    595   if (whichRow <= n_)
    596     return parMask_[whichRow];
    597 }
    598 
    599 const Vector<Int>& SDFitTable::getFitComponents(uInt whichRow) const
    600 {
    601   if (whichRow <= n_)
    602     return fitComps_[whichRow];
    603 }
    604 
    605 const Vector<String>& SDFitTable::getFitFunctions(uInt whichRow) const
    606 {
    607   if (whichRow <= n_)
    608     return fitFuncs_[whichRow];
    609 }
    610 
    611 void SDFitTable::putFitParameters(uInt whichRow, const Vector<Double>& arr)
    612 {
    613   if (whichRow <= n_)
    614     fitParms_[whichRow] = arr;
    615 }
    616 
    617 void SDFitTable::putFitParameterMask(uInt whichRow, const Vector<Bool>& arr)
    618 {
    619   if (whichRow <= n_)
    620     parMask_[whichRow] = arr;
    621 }
    622 
    623 void SDFitTable::putFitComponents(uInt whichRow, const Vector<Int>& arr)
    624 {
    625   if (whichRow <= n_)
    626     fitComps_[whichRow] = arr;
    627 }
    628 void SDFitTable::putFitFunctions(uInt whichRow, const Vector<String>& arr)
    629 {
    630   if (whichRow <= n_)
    631     fitFuncs_[whichRow] = arr;
    632 }
    633 
    634 
    635584// SDDataDesc
    636585
  • trunk/src/SDContainer.h

    r453 r465  
    261261};
    262262
    263 class SDFitTable {
    264 public:
    265   // Create a FitTable with "n" rows
    266   SDFitTable(casa::uInt n=0) : n_(n) {;};
    267  
    268   casa::uInt length() const { return n_; };
    269   const casa::Vector<casa::Double>& getFitParameters(casa::uInt which) const;
    270   const casa::Vector<casa::Bool>& getFitParameterMask(casa::uInt which) const;
    271   const casa::Vector<casa::String>& getFitFunctions(casa::uInt which) const;
    272   const casa::Vector<casa::Int>& getFitComponents(casa::uInt which) const;
    273 
    274   void putFitParameters(casa::uInt whichRow,
    275                         const casa::Vector<casa::Double>& arr);
    276   void putFitParameterMask(casa::uInt whichRow,
    277                            const casa::Vector<casa::Bool>& arr);
    278   void putFitFunctions(casa::uInt whichRow,
    279                        const casa::Vector<casa::String>& arr);
    280   void putFitComponents(casa::uInt whichRow,
    281                         const casa::Vector<casa::Int>& arr);
    282 
    283 private:
    284  
    285   casa::uInt n_;
    286   casa::Vector<casa::Vector<casa::Double> > fitParms_;
    287   // (npars,nrows)
    288   casa::Vector<casa::Vector<casa::Bool> > parMask_;
    289   // the fit function names (nnames,nrows)
    290   casa::Vector<casa::Vector<casa::String> > fitFuncs_;
    291   // the number of components of the function (ncomps, nrows)
    292   casa::Vector<casa::Vector<casa::Int> > fitComps_;
    293 
    294 };
    295263
    296264} // namespace
  • trunk/src/SDMemTable.cc

    r464 r465  
    6060
    6161#include "SDDefs.h"
    62 #include "SDMemTable.h"
    6362#include "SDContainer.h"
    6463#include "MathUtils.h"
    6564#include "SDPol.h"
    6665
    67 
     66#include "SDMemTable.h"
    6867
    6968using namespace casa;
     
    206205  tdf.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
    207206  tdf.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
     207  tdf.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
    208208  SetupNewTable fittab("fits", tdf, Table::New);
    209209  Table fitTable(fittab, Table::Memory);
     
    948948  td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
    949949  td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
     950  td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
    950951  SetupNewTable aNewTab("fits", td, Table::New);
    951952  Table aTable(aNewTab, Table::Memory);
     
    954955  ArrayColumn<Double> sc2(aTable, "PARAMETERS");
    955956  ArrayColumn<Bool> sc3(aTable, "PARMASK");
     957  ArrayColumn<String> sc4(aTable, "FRAMEINFO");
    956958  for (uInt i; i<sdft.length(); ++i) {
    957     const Vector<Double>& parms = sdft.getFitParameters(i);
    958     const Vector<Bool>& parmask = sdft.getFitParameterMask(i);
    959     const Vector<String>& funcs = sdft.getFitFunctions(i);
    960     const Vector<Int>& comps = sdft.getFitComponents(i);
     959    const Vector<Double>& parms = sdft.getParameters(i);
     960    const Vector<Bool>& parmask = sdft.getParameterMask(i);
     961    const Vector<String>& funcs = sdft.getFunctions(i);
     962    const Vector<Int>& comps = sdft.getComponents(i);
     963    const Vector<String>& finfo = sdft.getFrameInfo(i);
    961964    sc0.put(i,funcs);
    962965    sc1.put(i,comps);
    963966    sc3.put(i,parmask);
    964967    sc2.put(i,parms);
     968    sc4.put(i,finfo);
    965969  }
    966970  table_.rwKeywordSet().defineTable("FITS", aTable);
     
    974978  Vector<Bool> parmask;
    975979  Vector<String> funcs;
     980  Vector<String> finfo;
    976981  Vector<Int> comps; 
    977982  ROArrayColumn<Double> parmsCol(t, "PARAMETERS");
     
    979984  ROArrayColumn<Int> compsCol(t, "COMPONENTS");
    980985  ROArrayColumn<String> funcsCol(t, "FUNCTIONS");
     986  ROArrayColumn<String> finfoCol(t, "FRAMEINFO");
    981987  uInt n = t.nrow();
    982   SDFitTable sdft(n);
     988  SDFitTable sdft;
    983989  for (uInt i=0; i<n; ++i) {
    984990    parmaskCol.get(i, parmask);
    985     sdft.putFitParameterMask(i, parmask);
    986991    parmsCol.get(i, parms);
    987     sdft.putFitParameters(i, parms);
    988992    funcsCol.get(i, funcs);
    989     sdft.putFitFunctions(i, funcs);
    990993    compsCol.get(i, comps);
    991     sdft.putFitComponents(i, comps);
     994    finfoCol.get(i, finfo);
     995    sdft.addFit(parms, parmask, funcs, comps, finfo);
    992996  }
    993997  return sdft;
    994998}
    995999
     1000SDFitTable SDMemTable::getSDFitTable(uInt whichRow) const {
     1001  Array<Int> fitid;
     1002  fitCol_.get(whichRow, fitid);
     1003  if (fitid.nelements() == 0) return SDFitTable();
     1004
     1005  IPosition shp = fitid.shape();
     1006  IPosition start(4, beamSel_, IFSel_, polSel_,0);
     1007  IPosition end(4, beamSel_, IFSel_, polSel_, shp[3]-1);
     1008
     1009  // reform the output array slice to be of dim=1
     1010  Vector<Int> tmp = (fitid(start, end)).reform(IPosition(1,shp[3]));
     1011
     1012  const Table& t = table_.keywordSet().asTable("FITS");
     1013  Vector<Double> parms;
     1014  Vector<Bool> parmask;
     1015  Vector<String> funcs;
     1016  Vector<String> finfo;
     1017  Vector<Int> comps;   
     1018  ROArrayColumn<Double> parmsCol(t, "PARAMETERS");
     1019  ROArrayColumn<Bool> parmaskCol(t, "PARMASK");
     1020  ROArrayColumn<Int> compsCol(t, "COMPONENTS");
     1021  ROArrayColumn<String> funcsCol(t, "FUNCTIONS");
     1022  ROArrayColumn<String> finfoCol(t, "FRAMEINFO");
     1023  if (t.nrow() == 0) return SDFitTable();
     1024  SDFitTable sdft;
     1025  Int k=-1;
     1026  for (uInt i=0; i< tmp.nelements(); ++i) {
     1027    k = tmp[i];
     1028    if ( k > -1 && k < t.nrow() ) {
     1029      parms.resize();
     1030      parmsCol.get(k, parms);
     1031      parmask.resize();
     1032      parmaskCol.get(k, parmask);
     1033      funcs.resize();
     1034      funcsCol.get(k, funcs);
     1035      comps.resize();
     1036      compsCol.get(k, comps);
     1037      finfo.resize();
     1038      finfoCol.get(k, finfo);
     1039      sdft.addFit(parms, parmask, funcs, comps, finfo);
     1040    }
     1041  }
     1042  return sdft;
     1043}
    9961044
    9971045void SDMemTable::addFit(uInt whichRow,
     
    10091057  ArrayColumn<Int> compsCol(t, "COMPONENTS");
    10101058  ArrayColumn<String> funcsCol(t, "FUNCTIONS");
     1059  ArrayColumn<String> finfoCol(t, "FRAMEINFO");
    10111060  parmsCol.put(nrow, p);
    10121061  parmaskCol.put(nrow, m);
    10131062  compsCol.put(nrow, c);
    10141063  funcsCol.put(nrow, f);
     1064  Vector<String> fi = mathutil::toVectorString(getCoordInfo());
     1065  finfoCol.put(nrow, fi);
    10151066
    10161067  Array<Int> fitarr;
     
    14321483  Vector<String> history;
    14331484  histCol_.get(whichRow, history);
    1434   std::vector<std::string> stlout;
    1435   // there is no Array<String>.tovector(std::vector<std::string>), so
    1436   // do it by hand
    1437   for (uInt i=0; i<history.nelements(); ++i) {
    1438     stlout.push_back(history[i]);
    1439   }
     1485  std::vector<std::string> stlout = mathutil::tovectorstring(history);
    14401486  return stlout;
    14411487}
  • trunk/src/SDMemTable.h

    r457 r465  
    4545
    4646#include "SDDefs.h"
    47 
    48 
     47#include "SDFitTable.h"
    4948
    5049namespace asap {
     
    243242  bool putSDFitTable(const SDFitTable& sdft);
    244243  SDFitTable getSDFitTable() const;
     244  SDFitTable getSDFitTable(casa::uInt whichRow) const;
    245245
    246246  void addFit(casa::uInt whichRow,
     
    249249              const casa::Vector<casa::String>& f,
    250250              const casa::Vector<casa::Int>& c);
     251
    251252 
    252253private:
  • trunk/src/SDMemTableWrapper.h

    r457 r465  
    3636#include <casa/Arrays/Vector.h>
    3737
     38#include "MathUtils.h"
     39#include "SDFitTable.h"
    3840#include "SDMemTable.h"
    3941
     
    195197    casa::Vector<casa::Double> p2(p);
    196198    casa::Vector<casa::Bool> m2(m);
    197     casa::Vector<casa::String> f2(f.size());
    198     casa::uInt i=0;
    199     std::vector<std::string>::const_iterator it;
    200     for (it=f.begin();it != f.end();++it) {
    201       f2[i] = casa::String(*it);
    202     }
     199    casa::Vector<casa::String> f2 = mathutil::toVectorString(f);
    203200    casa::Vector<casa::Int> c2(c);
    204201    table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
    205202  }
     203  SDFitTable getSDFitTable(int whichRow) {
     204    return table_->getSDFitTable(casa::uInt(whichRow));
     205  }
     206
    206207
    207208private:
  • trunk/src/python_SD.cc

    r297 r465  
    5959  asap::python::python_SDMath();
    6060  asap::python::python_SDFitter();
     61  asap::python::python_SDFitTable();
    6162  asap::python::python_SDLineFinder();
    6263
  • trunk/src/python_SD.h

    r297 r465  
    4242    void python_SDMath();
    4343    void python_SDFitter();
     44    void python_SDFitTable();
    4445    void python_SDLineFinder();
    4546
  • trunk/src/python_SDMemTable.cc

    r457 r465  
    102102         (boost::python::arg("whichRow")=0) )
    103103    .def("_addfit", &SDMemTableWrapper::addFit)
     104    .def("_getfit", &SDMemTableWrapper::getSDFitTable)
    104105  ;
    105106};
Note: See TracChangeset for help on using the changeset viewer.