Changeset 960 for trunk/src/STFit.cpp
- Timestamp:
- 03/31/06 17:07:57 (18 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.