[468] | 1 |
|
---|
[960] | 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>
|
---|
[3084] | 19 | #include <tables/TaQL/TableParse.h>
|
---|
[960] | 20 | #include <tables/Tables/TableRow.h>
|
---|
| 21 | #include <casa/Containers/RecordField.h>
|
---|
| 22 |
|
---|
[468] | 23 | #include "MathUtils.h"
|
---|
[960] | 24 | #include "STFitEntry.h"
|
---|
| 25 | #include "STFit.h"
|
---|
[468] | 26 |
|
---|
[3106] | 27 | using namespace casacore;
|
---|
[960] | 28 |
|
---|
| 29 | namespace asap {
|
---|
[468] | 30 |
|
---|
[3106] | 31 | const String STFit::name_ = "FIT";
|
---|
[468] | 32 |
|
---|
[960] | 33 | STFit::STFit(const Scantable& parent) :
|
---|
| 34 | STSubTable( parent, name_ )
|
---|
[468] | 35 | {
|
---|
[960] | 36 | setup();
|
---|
[468] | 37 | }
|
---|
| 38 |
|
---|
[960] | 39 | STFit& asap::STFit::operator =( const STFit & other )
|
---|
[468] | 40 | {
|
---|
[960] | 41 | if ( this != &other ) {
|
---|
| 42 | static_cast<STSubTable&>(*this) = other;
|
---|
| 43 | funcCol_.attach(table_,"FUNCTIONS");
|
---|
| 44 | compCol_.attach(table_,"COMPONENTS");
|
---|
| 45 | parCol_.attach(table_,"PARAMETERS");
|
---|
| 46 | maskCol_.attach(table_,"PARMASKS");
|
---|
| 47 | frameCol_.attach(table_,"FRAMEINFO");
|
---|
| 48 | }
|
---|
| 49 | return *this;
|
---|
[468] | 50 | }
|
---|
| 51 |
|
---|
[3106] | 52 | asap::STFit::STFit( casacore::Table tab ) : STSubTable(tab, name_)
|
---|
[468] | 53 | {
|
---|
[960] | 54 | funcCol_.attach(table_,"FUNCTIONS");
|
---|
| 55 | compCol_.attach(table_,"COMPONENTS");
|
---|
| 56 | parCol_.attach(table_,"PARAMETERS");
|
---|
| 57 | maskCol_.attach(table_,"PARMASKS");
|
---|
| 58 | frameCol_.attach(table_,"FRAMEINFO");
|
---|
[468] | 59 | }
|
---|
| 60 |
|
---|
[960] | 61 | STFit::~STFit()
|
---|
[468] | 62 | {
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[960] | 65 | void asap::STFit::setup( )
|
---|
[468] | 66 | {
|
---|
[960] | 67 | // add to base class table
|
---|
| 68 | table_.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
|
---|
| 69 | table_.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
|
---|
| 70 | table_.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
|
---|
[1932] | 71 | // table_.addColumn(ArrayColumnDesc<Double>("ERRORS"));
|
---|
[960] | 72 | table_.addColumn(ArrayColumnDesc<Bool>("PARMASKS"));
|
---|
| 73 | table_.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
|
---|
[468] | 74 |
|
---|
[960] | 75 | // new cached columns
|
---|
| 76 | funcCol_.attach(table_,"FUNCTIONS");
|
---|
| 77 | compCol_.attach(table_,"COMPONENTS");
|
---|
| 78 | parCol_.attach(table_,"PARAMETERS");
|
---|
[1932] | 79 | // errCol_.attach(table_,"ERRORS");
|
---|
[960] | 80 | maskCol_.attach(table_,"PARMASKS");
|
---|
| 81 | frameCol_.attach(table_,"FRAMEINFO");
|
---|
[468] | 82 | }
|
---|
| 83 |
|
---|
[960] | 84 | uInt STFit::addEntry( const STFitEntry& fit, Int id )
|
---|
[468] | 85 | {
|
---|
[960] | 86 | uInt rno = table_.nrow();
|
---|
[972] | 87 | uInt resultid = 0;
|
---|
[960] | 88 | bool foundentry = false;
|
---|
[972] | 89 | // replace
|
---|
[960] | 90 | if ( id > -1 ) {
|
---|
[2243] | 91 | Table t = table_(table_.col("ID") == id, 1 );
|
---|
[960] | 92 | if (t.nrow() > 0) {
|
---|
[1000] | 93 | rno = t.rowNumbers(table_)[0];
|
---|
[960] | 94 | resultid = id;
|
---|
| 95 | foundentry = true;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
[972] | 98 | // doesn't exist
|
---|
[960] | 99 | if ( rno > 0 && !foundentry ) {
|
---|
| 100 | idCol_.get(rno-1, resultid);
|
---|
| 101 | resultid++;
|
---|
| 102 | }
|
---|
[972] | 103 | // add new row if new id
|
---|
| 104 | if ( !foundentry ) table_.addRow();
|
---|
[1932] | 105 |
|
---|
[960] | 106 | funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
|
---|
| 107 | compCol_.put(rno, Vector<Int>(fit.getComponents()));
|
---|
[1932] | 108 | const std::vector<float>& pvec = fit.getParameters();
|
---|
| 109 | Vector<Double> dvec(pvec.size());
|
---|
| 110 | for (size_t i=0; i < dvec.nelements(); ++i) {
|
---|
| 111 | dvec[i] = Double(pvec[i]);
|
---|
| 112 | }
|
---|
| 113 | parCol_.put(rno, dvec);
|
---|
| 114 | /*
|
---|
| 115 | const std::vector<double>& evec = fit.getErrors();
|
---|
| 116 | for (size_t i=0; i < dvec.nelements(); ++i) {
|
---|
| 117 | dvec[i] = Double(evec[i]);
|
---|
| 118 | }
|
---|
| 119 | errCol_.put(rno, dvec);
|
---|
| 120 | */
|
---|
[960] | 121 | maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
|
---|
| 122 | frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
|
---|
| 123 | idCol_.put(rno, resultid);
|
---|
[1932] | 124 |
|
---|
[960] | 125 | return resultid;
|
---|
[468] | 126 | }
|
---|
| 127 |
|
---|
[972] | 128 | void STFit::getEntry( STFitEntry& fit, uInt id ) const
|
---|
[468] | 129 | {
|
---|
[2243] | 130 | Table t = table_(table_.col("ID") == Int(id), 1 );
|
---|
[960] | 131 | if (t.nrow() == 0 ) {
|
---|
| 132 | throw(AipsError("STFit::getEntry - id out of range"));
|
---|
| 133 | }
|
---|
| 134 | ROTableRow row(t);
|
---|
| 135 | // get first row - there should only be one matching id
|
---|
| 136 | const TableRecord& rec = row.get(0);
|
---|
| 137 | std::vector<std::string> outstr;
|
---|
| 138 | Vector<String> vec;
|
---|
| 139 | rec.get("FUNCTIONS", vec);
|
---|
| 140 | fit.setFunctions(mathutil::tovectorstring(vec));
|
---|
| 141 | Vector<Int> ivec;
|
---|
| 142 | std::vector<int> istl;
|
---|
| 143 | rec.get("COMPONENTS", ivec);
|
---|
| 144 | ivec.tovector(istl);
|
---|
| 145 | fit.setComponents(istl);
|
---|
| 146 | Vector<Double> dvec;
|
---|
| 147 | rec.get("PARAMETERS", dvec);
|
---|
[1932] | 148 | std::vector<float> dstl(dvec.begin(), dvec.end());
|
---|
| 149 | fit.setParameters(dstl);
|
---|
| 150 | /*
|
---|
[960] | 151 | dvec.tovector(dstl);
|
---|
| 152 | fit.setParameters(dstl);
|
---|
[1932] | 153 | dvec.resize();
|
---|
| 154 | rec.get("ERRORS", dvec);
|
---|
| 155 | dvec.tovector(dstl);
|
---|
| 156 | fit.setErrors(dstl);
|
---|
| 157 | */
|
---|
[960] | 158 | Vector<Bool> bvec;
|
---|
| 159 | std::vector<bool> bstl;
|
---|
| 160 | rec.get("PARMASKS", bvec);
|
---|
| 161 | bvec.tovector(bstl);
|
---|
| 162 | fit.setParmasks(bstl);
|
---|
| 163 | vec.resize();
|
---|
| 164 | rec.get("FRAMEINFO", vec);
|
---|
| 165 | fit.setFrameinfo(mathutil::tovectorstring(vec));
|
---|
[468] | 166 | }
|
---|
| 167 |
|
---|
[960] | 168 | } //namespace
|
---|