Changeset 960
- Timestamp:
- 03/31/06 17:07:57 (19 years ago)
- 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> 31 22 32 23 #include "MathUtils.h" 33 #include "SDFitTable.h" 24 #include "STFitEntry.h" 25 #include "STFit.h" 26 34 27 35 28 using namespace casa; 36 using namespace asap;37 29 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 } 30 namespace asap { 31 32 const casa::String STFit::name_ = "FIT"; 33 34 STFit::STFit(const Scantable& parent) : 35 STSubTable( parent, name_ ) 36 { 37 setup(); 49 38 } 50 39 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) 40 STFit& asap::STFit::operator =( const STFit & other ) 57 41 { 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; 64 51 } 65 52 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) 53 asap::STFit::STFit( casa::Table tab ) : STSubTable(tab, name_) 71 54 { 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"); 88 60 } 89 61 90 std::vector<double> SDFitTable::getSTLParameters(int which) const 62 STFit::~STFit() 91 63 { 92 if (which >= nfits_)93 return std::vector<double>();94 return pars_[which];95 64 } 96 65 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]); 66 void 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"); 101 81 } 102 82 103 std::vector<bool> SDFitTable::getSTLParameterMask(int which) const 83 uInt STFit::addEntry( const STFitEntry& fit, Int id ) 104 84 { 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; 108 109 } 109 110 110 Vector<Bool> SDFitTable::getParameterMask(uInt which) const 111 void STFit::getEntry( STFitEntry& fit, uInt id ) 111 112 { 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)); 115 142 } 116 143 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 33 14 34 15 #include <casa/aips.h> 35 #include <casa/Arrays/Vector.h>36 16 #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> 39 20 21 #include "STSubTable.h" 40 22 namespace asap { 41 23 42 class SDFitTable { 24 class STFitEntry; 25 /** 26 The Fit subtable of the Scantable 27 28 @author Malte Marquarding 29 */ 30 class STFit : public STSubTable { 43 31 public: 44 S DFitTable() : nfits_(0) {;};45 ~SDFitTable() {;};46 S DFitTable(const SDFitTable& other);32 STFit() {;} 33 STFit(casa::Table tab); 34 STFit( const Scantable& parent); 47 35 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(); 69 37 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); 75 39 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_; } 76 44 77 45 private: 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_; 84 54 }; 85 55 86 } //56 } 87 57 88 58 #endif -
trunk/src/STFitEntry.h
r955 r960 26 26 public: 27 27 STFitEntry(); 28 28 29 29 ~STFitEntry(); 30 30 31 31 void setFunctions(const std::vector<std::string>& f) 32 32 { functions_ = f; } … … 40 40 { frameinfo_ = f; } 41 41 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_; } 47 47 48 48 private: 49 50 51 52 53 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_; 54 54 }; 55 55 -
trunk/src/Scantable.h
r923 r960 40 40 #include "STHistory.h" 41 41 #include "STPol.h" 42 #include "STFit.h" 42 43 43 44 namespace asap { … … 345 346 void setupMainTable(); 346 347 347 void setupFitTable();348 349 348 void attachSubtables(); 350 349 void copySubtables(const Scantable& other); … … 373 372 STMolecules moleculeTable_; 374 373 STHistory historyTable_; 375 376 casa::Table fitTable_; 374 STFit fitTable_; 377 375 378 376 // Cached Columns to avoid reconstructing them for each row get/put … … 395 393 396 394 casa::ArrayColumn<casa::String> histitemCol_; 397 casa::ScalarColumn<casa::uInt> mfitidCol_ , fitidCol_;395 casa::ScalarColumn<casa::uInt> mfitidCol_; 398 396 // id in weather table and main table 399 397 casa::ScalarColumn<casa::uInt> mweatheridCol_; -
trunk/src/python_STFitEntry.cpp
r956 r960 1 1 //#--------------------------------------------------------------------------- 2 //# python_S DFitTable.cc: python exposure of c++ SDFitTableclass2 //# python_STFitEntry: python exposure of c++ STFitEntry class 3 3 //#--------------------------------------------------------------------------- 4 //# Copyright (C) 200 44 //# Copyright (C) 2006 5 5 //# ATNF 6 6 //# … … 27 27 //# AUSTRALIA 28 28 //# 29 //# $Id: 29 //# $Id:$ 30 30 //#--------------------------------------------------------------------------- 31 31 #include <boost/python.hpp> 32 32 33 #include "S DFitTable.h"33 #include "STFitEntry.h" 34 34 35 35 using namespace boost::python; … … 38 38 namespace python { 39 39 40 void python_S DFitTable() {41 class_<S DFitTable>("sdfit")40 void python_STFitEntry() { 41 class_<STFitEntry>("fitentry") 42 42 .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) 50 48 ; 51 49 }; -
trunk/src/python_asap.cpp
r894 r960 62 62 asap::python::python_Fitter(); 63 63 asap::python::python_STLineFinder(); 64 asap::python::python_STFitEntry(); 64 65 /* 65 66 asap::python::python_SDWriter(); 66 asap::python::python_SDFitTable();67 67 */ 68 68 asap::python::python_Logger(); -
trunk/src/python_asap.h
r894 r960 43 43 void python_Fitter(); 44 44 void python_STLineFinder(); 45 void python_STFitEntry(); 45 46 /* 46 47 void python_SDWriter(); 47 void python_SDFitTable();48 48 */ 49 49 void python_Logger();
Note:
See TracChangeset
for help on using the changeset viewer.