Changeset 483
- Timestamp:
- 02/21/05 08:21:00 (20 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDContainer.cc
r473 r483 479 479 } 480 480 481 Bool SDContainer::appendHistory(const String& hist)482 {483 history_.resize(history_.nelements()+1,True);484 history_[history_.nelements()-1] = hist;485 return True;486 }487 Bool SDContainer::putHistory(const Vector<String>& hist)488 {489 history_.resize();490 history_ = hist;491 return True;492 }493 494 481 Bool SDContainer::putFitMap(const Array<Int>& arr) { 495 482 fitIDMap_.resize(); -
trunk/src/SDContainer.h
r465 r483 167 167 { return restfreqidx_; } 168 168 169 const casa::Vector<casa::String>& getHistory() const { return history_; }170 casa::Bool putHistory(const casa::Vector<casa::String>& hist);171 casa::Bool appendHistory(const casa::String& hist);172 173 169 casa::Bool putFitMap(const casa::Array<casa::Int>& arr); 174 170 … … 210 206 //(nBeam,2) maybe use Measures here... 211 207 casa::Array<casa::Double> direction_; 212 casa::Vector<casa::String> history_;213 208 casa::Array<casa::Int> fitIDMap_; 214 209 -
trunk/src/SDFitter.cc
r125 r483 60 60 for (uInt i=0;i< funcs_.nelements();++i) { 61 61 delete funcs_[i]; funcs_[i] = 0; 62 } ;62 } 63 63 funcs_.resize(0, True); 64 64 parameters_.resize(); … … 146 146 funcs_[0] = new Polynomial<Float>(ncomp); 147 147 } else { 148 cerr << " compiled functions not yet implemented" << endl;148 //cerr << " compiled functions not yet implemented" << endl; 149 149 //funcs_.resize(1); 150 150 //funcs_[0] = new CompiledFunction<Float>(); … … 285 285 //computeEstimates(); 286 286 for (uInt i=0; i<funcs_.nelements(); i++) { 287 Gaussian1D<AutoDiff<Float> > gauss; 288 for (uInt j=0; j<funcs_[i]->nparameters(); j++) { 289 gauss[j] = AutoDiff<Float>((*funcs_[i])[j], gauss.nparameters(), j); 290 gauss.mask(j) = funcs_[i]->mask(j); 287 Gaussian1D<AutoDiff<Float> > gauss;//(*funcs_[i]); 288 289 for (uInt j=0; j<funcs_[i]->nparameters(); j++) { 290 gauss[j] = AutoDiff<Float>((*funcs_[i])[j], 291 gauss.nparameters(), j); 292 gauss.mask(j) = funcs_[i]->mask(j); 291 293 } 294 292 295 func.addFunction(gauss); 293 296 } 294 297 } else if (dynamic_cast<Polynomial<Float>* >(funcs_[0]) != 0) { 295 Polynomial<AutoDiff<Float> > poly(funcs_[0]->nparameters()-1); 296 for (uInt j=0; j<funcs_[0]->nparameters(); j++) { 297 poly[j] = AutoDiff<Float>(0, poly.nparameters(), j); 298 poly.mask(j) = funcs_[0]->mask(j); 299 } 300 func.addFunction(poly); 298 Polynomial<AutoDiff<Float> > poly(funcs_[0]->nparameters()-1); 299 //Polynomial<AutoDiff<Float> > poly(*funcs_[0]); 300 for (uInt j=0; j<funcs_[0]->nparameters(); j++) { 301 poly[j] = AutoDiff<Float>(0, poly.nparameters(), j); 302 poly.mask(j) = funcs_[0]->mask(j); 303 } 304 func.addFunction(poly); 301 305 } else if (dynamic_cast<CompiledFunction<Float>* >(funcs_[0]) != 0) { 302 303 // CompiledFunction<AutoDiff<Float> > comp;304 // for (uInt j=0; j<funcs_[0]->nparameters(); j++) {306 307 // CompiledFunction<AutoDiff<Float> > comp; 308 // for (uInt j=0; j<funcs_[0]->nparameters(); j++) { 305 309 // comp[j] = AutoDiff<Float>(0, comp.nparameters(), j); 306 310 // comp.mask(j) = funcs_[0]->mask(j); 307 311 // } 308 312 // func.addFunction(comp); 309 313 310 314 cout << "NYI." << endl; 311 315 } else { 312 throw 316 throw(AipsError("Fitter not set up correctly.")); 313 317 } 314 318 fitter.setFunction(func); … … 316 320 // Convergence criterium 317 321 fitter.setCriteria(0.001); 322 318 323 // Fit 319 324 Vector<Float> sigma(x_.nelements()); 320 325 sigma = 1.0; 321 //Vector<Float> sol; 326 322 327 parameters_.resize(); 323 //Vector<Float> err; 328 parameters_ = fitter.fit(x_, y_, sigma, &m_); 329 324 330 error_.resize(); 325 parameters_ = fitter.fit(x_, y_, sigma, &m_);326 /*327 CompoundFunction<Float> f;328 for (uInt i=0; i<funcs_.nelements(); i++) {329 f.addFunction(*funcs_[i]);330 }331 f.parameters().setParameters(parameters_);332 */333 331 error_ = fitter.errors(); 332 334 333 chisquared_ = fitter.getChi2(); 334 335 335 residual_.resize(); 336 336 residual_ = y_; 337 337 fitter.residual(residual_,x_); 338 338 339 // use fitter.residual(model=True) to get the model 339 340 thefit_.resize(x_.nelements()); -
trunk/src/SDMemTable.cc
r476 r483 85 85 { 86 86 Table tab(name); 87 uInt version; 88 tab.keywordSet().get("VERSION", version); 89 if (version != version_) { 90 throw(AipsError("Unsupported version of ASAP file.")); 91 } 87 92 table_ = tab.copyToMemoryTable("dummy"); 88 93 //cerr << "hello from C SDMemTable @ " << this << endl; … … 92 97 SDMemTable::SDMemTable(const SDMemTable& other, Bool clear) 93 98 { 94 IFSel_= other.IFSel_;95 beamSel_= other.beamSel_;96 polSel_= other.polSel_;97 chanMask_ = other.chanMask_;98 99 table_ = other.table_.copyToMemoryTable(String("dummy")); 99 100 // clear all rows() 100 101 if (clear) { 101 102 table_.removeRow(this->table_.rowNumbers()); 103 IFSel_= 0; 104 beamSel_= 0; 105 polSel_= 0; 106 chanMask_.resize(0); 102 107 } else { 103 IFSel_ = other.IFSel_; 104 beamSel_ = other.beamSel_; 105 polSel_ = other.polSel_; 106 } 107 // 108 IFSel_= other.IFSel_; 109 beamSel_= other.beamSel_; 110 polSel_= other.polSel_; 111 chanMask_.resize(0); 112 chanMask_ = other.chanMask_; 113 } 114 108 115 attach(); 109 116 //cerr << "hello from CC SDMemTable @ " << this << endl; … … 146 153 attach(); 147 154 } 148 //cerr << "hello from ASS SDMemTable @ " << this << endl;149 155 return *this; 150 156 } … … 161 167 TableDesc td("", "1", TableDesc::Scratch); 162 168 td.comment() = "A SDMemTable"; 163 169 td.rwKeywordSet().define("VERSION", Int(version_)); 170 164 171 td.addColumn(ScalarColumnDesc<Double>("TIME")); 165 172 td.addColumn(ScalarColumnDesc<String>("SRCNAME")); … … 180 187 td.addColumn(ScalarColumnDesc<Float>("PARANGLE")); 181 188 td.addColumn(ScalarColumnDesc<Int>("REFBEAM")); 182 td.addColumn(ArrayColumnDesc<String>("HISTORY"));183 189 td.addColumn(ArrayColumnDesc<Int>("FITID")); 184 190 185 186 191 // Now create Table SetUp from the description. 187 188 192 SetupNewTable aNewTab("dummy", td, Table::New); 189 193 … … 192 196 // point, we must bind the Virtual Engine regardless. The STOKES 193 197 // column won't be accessed if not appropriate (nPol=4) 194 195 196 SDStokesEngine::registerClass(); 197 SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA")); 198 aNewTab.bindColumn ("STOKES", stokesEngine); 199 200 // Create Table 201 table_ = Table(aNewTab, Table::Memory, 0); 198 SDStokesEngine::registerClass(); 199 SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA")); 200 aNewTab.bindColumn("STOKES", stokesEngine); 201 202 // Create Table 203 table_ = Table(aNewTab, Table::Memory, 0); 202 204 // add subtable 203 205 TableDesc tdf("", "1", TableDesc::Scratch); … … 211 213 table_.rwKeywordSet().defineTable("FITS", fitTable); 212 214 213 215 TableDesc tdh("", "1", TableDesc::Scratch); 216 tdh.addColumn(ScalarColumnDesc<String>("ITEM")); 217 SetupNewTable histtab("hist", tdh, Table::New); 218 Table histTable(histtab, Table::Memory); 219 table_.rwKeywordSet().defineTable("HISTORY", histTable); 214 220 } 215 221 … … 234 240 paraCol_.attach(table_, "PARANGLE"); 235 241 rbeamCol_.attach(table_, "REFBEAM"); 236 histCol_.attach(table_, "HISTORY");237 242 fitCol_.attach(table_,"FITID"); 238 243 } … … 359 364 std::vector<float> SDMemTable::getSpectrum(Int whichRow) const 360 365 { 361 362 366 Array<Float> arr; 363 367 specCol_.get(whichRow, arr); … … 385 389 const IPosition& shape = arr.shape(); 386 390 IPosition start, end; 387 setCursorSlice(start, end, shape);391 getCursorSlice(start, end, shape); 388 392 389 393 // Get Q and U slices … … 433 437 const IPosition& shape = arr.shape(); 434 438 IPosition start, end; 435 setCursorSlice(start, end, shape);439 getCursorSlice(start, end, shape); 436 440 437 441 // Get I and V slices … … 1199 1203 elCol_.put(rno, sdc.elevation); 1200 1204 paraCol_.put(rno, sdc.parangle); 1201 histCol_.put(rno, sdc.getHistory());1202 1205 fitCol_.put(rno, sdc.getFitMap()); 1203 1206 return true; … … 1226 1229 Vector<uInt> fmap; 1227 1230 Array<Double> direction; 1228 Vector<String> histo;1229 1231 Array<Int> fits; 1230 1232 … … 1241 1243 dirCol_.get(whichRow, direction); 1242 1244 sdc.putDirection(direction); 1243 histCol_.get(whichRow, histo);1244 sdc.putHistory(histo);1245 1245 fitCol_.get(whichRow, fits); 1246 1246 sdc.putFitMap(fits); … … 1291 1291 } 1292 1292 void SDMemTable::makePersistent(const std::string& filename) 1293 { 1293 { 1294 1294 table_.deepCopy(filename,Table::New); 1295 1295 1296 } 1296 1297 … … 1472 1473 return String(oss); 1473 1474 } 1474 1475 /* 1476 std::string SDMemTable::scanSummary(const std::vector<int>& whichScans) { 1477 ostringstream oss; 1478 Vector<Int> scanIDs = scanCol_.getColumn(); 1479 Vector<uInt> startInt, endInt; 1480 mathutil::scanBoundaries(startInt, endInt, scanIDs); 1481 const uInt nScans = startInt.nelements(); 1482 std::vector<int>::const_iterator it(whichScans); 1483 return String(oss); 1484 } 1485 */ 1475 1486 Int SDMemTable::nBeam() const 1476 1487 { … … 1498 1509 } 1499 1510 1500 bool SDMemTable::appendHistory(const std::string& hist, int whichRow) 1511 void SDMemTable::addHistory(const std::string& hist) 1512 { 1513 Table t = table_.rwKeywordSet().asTable("HISTORY"); 1514 uInt nrow = t.nrow(); 1515 t.addRow(); 1516 ScalarColumn<String> itemCol(t, "ITEM"); 1517 itemCol.put(nrow, hist); 1518 } 1519 1520 std::vector<std::string> SDMemTable::getHistory() const 1501 1521 { 1502 1522 Vector<String> history; 1503 histCol_.get(whichRow, history); 1504 history.resize(history.nelements()+1,True); 1505 history[history.nelements()-1] = hist; 1506 histCol_.put(whichRow, history); 1507 } 1508 1509 std::vector<std::string> SDMemTable::history(int whichRow) const 1510 { 1511 Vector<String> history; 1512 histCol_.get(whichRow, history); 1513 std::vector<std::string> stlout = mathutil::tovectorstring(history); 1523 const Table& t = table_.keywordSet().asTable("HISTORY"); 1524 uInt nrow = t.nrow(); 1525 ROScalarColumn<String> itemCol(t, "ITEM"); 1526 std::vector<std::string> stlout; 1527 String hist; 1528 for (uInt i=0; i<nrow; ++i) { 1529 itemCol.get(i, hist); 1530 stlout.push_back(hist); 1531 } 1514 1532 return stlout; 1515 1533 } 1516 1534 /* 1517 void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {1535 void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) { 1518 1536 1519 1537 std::vector<int>::iterator it; … … 1534 1552 */ 1535 1553 void SDMemTable::flag(int whichRow) 1536 {1554 { 1537 1555 Array<uChar> arr; 1538 1556 flagsCol_.get(whichRow, arr); … … 1719 1737 1720 1738 1721 void SDMemTable:: setCursorSlice(IPosition& start, IPosition& end,1739 void SDMemTable::getCursorSlice(IPosition& start, IPosition& end, 1722 1740 const IPosition& shape) const 1723 1741 { -
trunk/src/SDMemTable.h
r476 r483 192 192 virtual std::string summary(bool verbose=false) const; 193 193 194 std::vector<std::string> history(int whichRow=0) const; 195 bool appendHistory(const std::string& hist, int whichRow=0); 194 // get/set the history 195 std::vector<std::string> getHistory() const; 196 void addHistory(const std::string& hist); 197 196 198 // write to disk as aips++ table 197 199 void makePersistent(const std::string& filename); … … 269 271 270 272 // Generate start and end for shape and current cursor selection 271 void setCursorSlice(casa::IPosition& start, casa::IPosition& end,273 void getCursorSlice(casa::IPosition& start, casa::IPosition& end, 272 274 const casa::IPosition& shape) const; 273 275 … … 277 279 // the underlying memory table 278 280 casa::Table table_; 281 // The current table version 282 static const casa::uInt version_ = 1; 279 283 280 284 // Cached Columns to avoid reconstructing them for each row get/put -
trunk/src/SDMemTableWrapper.h
r465 r483 63 63 } 64 64 65 //SDMemTableWrapper getScan(int scan) {66 65 SDMemTableWrapper getScan(std::vector<int> scan) { 67 66 casa::String cond("SELECT FROM $1 WHERE SCANID IN "); … … 77 76 cond += source;cond += "')"; 78 77 return SDMemTableWrapper(*this, cond); 78 } 79 80 SDMemTableWrapper getSQL(const std::string& sqlexpr) { 81 return SDMemTableWrapper(*this, sqlexpr); 79 82 } 80 83 … … 166 169 casa::Int(whichIF)); 167 170 } 168 171 169 172 void spectralLines() const {table_->spectralLines();} 170 173 … … 187 190 } 188 191 189 std::vector<std::string> history(int whichRow=0) { 190 return table_->history(whichRow); 192 std::vector<std::string> getHistory() { 193 return table_->getHistory(); 194 } 195 void addHistory(const std::string& hist) { 196 table_->addHistory(hist); 191 197 } 192 198 -
trunk/src/python_SDMemTable.cc
r465 r483 99 99 .def("_setcoordinfo", &SDMemTableWrapper::setCoordInfo) 100 100 .def("_getcoordinfo", &SDMemTableWrapper::getCoordInfo) 101 .def("_ history", &SDMemTableWrapper::history,102 (boost::python::arg("whichRow")=0))101 .def("_gethistory", &SDMemTableWrapper::getHistory) 102 .def("_addhistory", &SDMemTableWrapper::addHistory) 103 103 .def("_addfit", &SDMemTableWrapper::addFit) 104 104 .def("_getfit", &SDMemTableWrapper::getSDFitTable)
Note:
See TracChangeset
for help on using the changeset viewer.