Changeset 847
- Timestamp:
- 02/24/06 10:03:21 (19 years ago)
- Location:
- trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMemTableWrapper.h
r794 r847 1 //#--------------------------------------------------------------------------- 2 //# SDMemTableWrapper.h: Wrapper classes to use CountedPtr 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 SDMEMTABLEWRAPPER_H 32 #define SDMEMTABLEWRAPPER_H 1 // 2 // C++ Interface: Scantable 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 ASAPSCANTABLEWRAPPER_H 13 #define ASAPSCANTABLEWRAPPER_H 33 14 34 15 #include <vector> … … 38 19 #include "MathUtils.h" 39 20 #include "SDFitTable.h" 40 #include "S DMemTable.h"21 #include "Scantable.h" 41 22 42 23 namespace asap { 43 44 class SDMemTableWrapper { 24 /** 25 * This class contains and wraps a CountedPtr<Scantable>, as the CountedPtr 26 * class does not provide the dor operator which is need for references 27 * in boost::python 28 * see Scantable for interfce description 29 * 30 * @brief The main ASAP data container wrapper 31 * @author Malte Marquarding 32 * @date 2006-02-23 33 * @version 2.0a 34 */ 35 class ScantableWrapper { 45 36 46 37 public: 47 SDMemTableWrapper(const std::string& name) : 48 table_(new SDMemTable(name)) {;} 49 SDMemTableWrapper() : 50 table_(new SDMemTable()) {;} 51 52 SDMemTableWrapper(casa::CountedPtr<SDMemTable> cp) : table_(cp) {;} 53 //SDMemTableWrapper(SDMemTable* sdmt) : table_(sdmt) {;} 54 SDMemTableWrapper(const SDMemTableWrapper& mt) : 38 ScantableWrapper(const std::string& name) : 39 table_(new Scantable(name)) {;} 40 41 ScantableWrapper() : 42 table_(new Scantable()) {;} 43 44 ScantableWrapper(casa::CountedPtr<Scantable> cp) : table_(cp) {;} 45 46 ScantableWrapper(const ScantableWrapper& mt) : 55 47 table_(mt.getCP()) {;} 56 48 57 SDMemTableWrapper(const SDMemTableWrapper& mt, const std::string& expr) : 58 table_(new SDMemTable(mt.getCP()->table(), expr)) {;} 59 60 SDMemTableWrapper copy() { 61 //CountedPtr<SDMemTable> cp = new SDMemTable(*this, False); 62 return SDMemTableWrapper(new SDMemTable(*(this->getCP()), casa::False)); 63 } 64 65 SDMemTableWrapper getScan(std::vector<int> scan) { 66 casa::String cond("SELECT FROM $1 WHERE SCANID IN "); 67 casa::Vector<casa::Int> v(scan); 68 casa::ostringstream oss; 69 oss << v; 70 cond += casa::String(oss); 71 return SDMemTableWrapper(*this, cond); 72 } 73 74 SDMemTableWrapper getSource(const std::string& source) { 75 casa::String cond("SELECT * from $1 WHERE SRCNAME == pattern('"); 76 cond += source;cond += "')"; 77 return SDMemTableWrapper(*this, cond); 78 } 79 80 SDMemTableWrapper getSQL(const std::string& sqlexpr) { 81 return SDMemTableWrapper(*this, sqlexpr); 82 } 49 ScantableWrapper(const ScantableWrapper& mt, const std::string& expr) : 50 table_(new Scantable(mt.getCP()->table(), expr)) {;} 51 52 ScantableWrapper copy() { 53 return ScantableWrapper(new Scantable(*(this->getCP()), false)); 54 } 55 83 56 84 57 std::vector<float> getSpectrum(int whichRow=0) const { … … 148 121 } 149 122 150 void setSpectrum(std::vector<float> spectrum, int whichRow=0) { 151 table_->setSpectrum(spectrum, whichRow); 152 } 153 154 bool setIF(int whichIF=0) {return table_->setIF(whichIF);} 155 bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);} 156 bool setPol(int whichPol=0) {return table_->setPol(whichPol);} 157 158 int getIF() {return table_->getIF();} 159 int getBeam() {return table_->getBeam();} 160 int getPol() {return table_->getPol();} 161 162 int nIF() {return table_->nIF();} 163 int nBeam() {return table_->nBeam();} 164 int nPol() {return table_->nPol();} 165 int nChan() {return table_->nChan();} 166 int nScan() {return table_->nScan();} 167 int nRow() {return table_->nRow();} 168 int nStokes() {return table_->nStokes();} 169 170 //sets the mask 171 bool setChannels(const std::vector<int>& whichChans) { 172 return setChannels(whichChans); 173 } 123 void setSpectrum(std::vector<float> spectrum, int whichrow=0) { 124 table_->setSpectrum(spectrum, whichrow); 125 } 126 127 int getIF(int whichrow) {return table_->getIF(whichrow);} 128 int getBeam(int whichrow) {return table_->getBeam(whichrow);} 129 int getPol(int whichrow) {return table_->getPol(whichrow);} 130 131 STSelector getSelection() { return table_->getSelection(); } 132 133 int nif(int scanno=-1) {return table_->nif(scanno);} 134 int nbeam(int scanno=-1) {return table_->nbeam(scanno);} 135 int npol(int scanno=-1) {return table_->npol(scanno);} 136 int nchan(int ifno=-1) {return table_->nchan(ifno);} 137 int nscan() {return table_->nscan();} 138 int nrow() {return table_->nrow();} 139 ///@todo int nstokes() {return table_->nStokes();} 140 174 141 void makePersistent(const std::string& fname) { 175 142 table_->makePersistent(fname); 176 143 } 177 144 178 bool setRestFreqs(const std::vector<double>& restfreqs, 179 const std::string& unit, 180 const std::vector<std::string>& lines, 181 const std::string& source, int whichIF) { 182 casa::Vector<casa::Double> restFreqs2(restfreqs); 183 return table_->setRestFreqs(restFreqs2, casa::String(unit), 184 lines, casa::String(source), 185 casa::Int(whichIF)); 186 } 187 188 std::string spectralLines() const {return table_->spectralLines();} 189 190 std::vector<double> getRestFreqs() { 191 return table_->getRestFreqs(); 145 void setRestFreqs(double rf, const std::string& unit) { 146 table_->setRestFreqs(rf, unit); 147 } 148 149 void setRestFreqs(const std::string& name) { 150 table_->setRestFreqs(name); 151 } 152 153 std::vector<double> getRestFrequencies() { 154 return table_->getRestFrequencies(); 192 155 } 193 156 … … 199 162 } 200 163 201 casa::CountedPtr<S DMemTable> getCP() const {return table_;}202 S DMemTable* getPtr() {return &(*table_);}164 casa::CountedPtr<Scantable> getCP() const {return table_;} 165 Scantable* getPtr() {return &(*table_);} 203 166 204 167 std::string summary(bool verbose=false) const { … … 230 193 231 194 private: 232 casa::CountedPtr<S DMemTable> table_;195 casa::CountedPtr<Scantable> table_; 233 196 }; 234 197 -
trunk/src/STFiller.cpp
r846 r847 67 67 { 68 68 if (table_.null()) { 69 cout << "new scnatbale object" << endl;70 69 table_ = new Scantable(); 71 70 } -
trunk/src/STFrequencies.cpp
r840 r847 33 33 namespace asap { 34 34 35 const casa::String STFrequencies::name_ = "FREQUENCIES";36 37 STFrequencies::STFrequencies( casa::Table::TableType tt) :35 const String STFrequencies::name_ = "FREQUENCIES"; 36 37 STFrequencies::STFrequencies(Table::TableType tt) : 38 38 STSubTable( name_, tt ) 39 39 { … … 53 53 table_.addColumn(ScalarColumnDesc<Double>("INCREMENT")); 54 54 55 table_.rwKeywordSet().define("REFFRAME", String("TOPO")); 55 table_.rwKeywordSet().define("FRAME", String("TOPO")); 56 table_.rwKeywordSet().define("BASEFRAME", String("TOPO")); 56 57 table_.rwKeywordSet().define("EQUINOX",String( "J2000")); 57 58 table_.rwKeywordSet().define("UNIT", String("Hz")); … … 108 109 } 109 110 110 SpectralCoordinate STFrequencies::getSpectralCoordinate( uInt freqID )111 { 112 Table t = table_(table_.col("ID") == Int( freqID) );111 SpectralCoordinate STFrequencies::getSpectralCoordinate( uInt id ) const 112 { 113 Table t = table_(table_.col("ID") == Int(id) ); 113 114 114 115 if (t.nrow() == 0 ) { 115 throw(AipsError("STFrequencies::getSpectralCoordinate - freqID out of range"));116 throw(AipsError("STFrequencies::getSpectralCoordinate - ID out of range")); 116 117 } 117 118 … … 121 122 const TableRecord& rec = row.get(0); 122 123 123 return SpectralCoordinate( getFrame( ), rec.asDouble("REFVAL"),124 return SpectralCoordinate( getFrame(true), rec.asDouble("REFVAL"), 124 125 rec.asDouble("INCREMENT"), 125 126 rec.asDouble("REFPIX")); 126 127 } 127 128 128 void STFrequencies::rescale( casa::Float factor, const std::string& mode ) 129 SpectralCoordinate 130 asap::STFrequencies::getSpectralCoordinate( const MDirection& md, 131 const MPosition& mp, 132 const MEpoch& me, 133 Double restfreq, uInt id ) const 134 { 135 SpectralCoordinate spc = getSpectralCoordinate(id); 136 spc.setRestFrequency(restfreq, True); 137 if ( !spc.setReferenceConversion(getFrame(), me, mp, md) ) { 138 throw(AipsError("Couldn't convert frequency frame.")); 139 } 140 String unitstr = getUnitString(); 141 if ( !unitstr.empty() ) { 142 Unit unitu(unitstr); 143 if ( unitu == Unit("Hz") ) { 144 } else { 145 spc.setVelocity(unitstr, getDoppler()); 146 } 147 } 148 return spc; 149 } 150 151 152 void STFrequencies::rescale( Float factor, const std::string& mode ) 129 153 { 130 154 TableRow row(table_); … … 137 161 const TableRecord& rec = row.get(i); 138 162 139 SpectralCoordinate sc ( getFrame( ), rec.asDouble("REFVAL"),163 SpectralCoordinate sc ( getFrame(true), rec.asDouble("REFVAL"), 140 164 rec.asDouble("INCREMENT"), rec.asDouble("REFPIX") ); 141 165 … … 177 201 178 202 179 casa::MFrequency::Types STFrequencies::getFrame() const203 MFrequency::Types STFrequencies::getFrame(bool base) const 180 204 { 181 205 // get the ref frame 182 String rf; 183 table_.keywordSet().get("REFFRAME", rf); 206 String rf = table_.keywordSet().asString("BASEFRAME"); 184 207 185 208 // Create SpectralCoordinate (units Hz) … … 192 215 193 216 return mft; 217 } 218 219 std::string asap::STFrequencies::getFrameString( bool base ) const 220 { 221 if ( base ) return table_.keywordSet().asString("BASEFRAME"); 222 else return table_.keywordSet().asString("FRAME"); 223 } 224 225 std::string asap::STFrequencies::getUnitString( ) const 226 { 227 return table_.keywordSet().asString("UNIT"); 228 } 229 230 Unit asap::STFrequencies::getUnit( ) const 231 { 232 return Unit(table_.keywordSet().asString("UNIT")); 233 } 234 235 std::string asap::STFrequencies::getDopplerString( ) const 236 { 237 return table_.keywordSet().asString("DOPPLER"); 238 } 239 240 MDoppler::Types asap::STFrequencies::getDoppler( ) const 241 { 242 String dpl = table_.keywordSet().asString("DOPPLER"); 243 244 // Create SpectralCoordinate (units Hz) 245 MDoppler::Types mdt; 246 if (!MDoppler::getType(mdt, dpl)) { 247 throw(AipsError("Doppler type unknown")); 248 } 249 return mdt; 194 250 } 195 251 … … 226 282 const Record& r = table_.keywordSet(); 227 283 const Record& ro = other.table_.keywordSet(); 228 return ( r.asString(" REFFRAME") == ro.asString("REFFRAME") &&284 return ( r.asString("FRAME") == ro.asString("FRAME") && 229 285 r.asString("EQUINOX") == ro.asString("EQUINOX") && 230 286 r.asString("UNIT") == ro.asString("UNIT") && … … 233 289 } 234 290 291 std::vector< std::string > asap::STFrequencies::getInfo( ) const 292 { 293 const Record& r = table_.keywordSet(); 294 std::vector<std::string> out; 295 out.push_back(r.asString("UNIT")); 296 out.push_back(r.asString("FRAME")); 297 out.push_back(r.asString("DOPPLER")); 298 } 299 300 void asap::STFrequencies::setInfo( const std::vector< std::string >& theinfo ) 301 { 302 if ( theinfo.size() != 3 ) throw(AipsError("setInfo needs three parameters")); 303 String un,rfrm,dpl; 304 un = theinfo[0];rfrm = theinfo[1];dpl = theinfo[2]; 305 TableRecord& r = table_.rwKeywordSet(); 306 setFrame(rfrm); 307 MDoppler::Types dtype; 308 dpl.upcase(); 309 if (!MDoppler::getType(dtype, dpl)) { 310 throw(AipsError("Doppler type unknown")); 311 } else { 312 r.define("DOPPLER",dpl); 313 } 314 } 315 void asap::STFrequencies::setFrame( const std::string & frame ) 316 { 317 MFrequency::Types mdr; 318 if (!MFrequency::getType(mdr, frame)) { 319 Int a,b;const uInt* c; 320 const String* valid = MFrequency::allMyTypes(a, b, c); 321 String pfix = "Please specify a legal frame type. Types are\n"; 322 throw(AipsError(pfix+(*valid))); 323 } else { 324 table_.rwKeywordSet().define("FRAME", frame); 325 } 326 } 327 235 328 } // namespace -
trunk/src/STFrequencies.h
r840 r847 62 62 * @return casa::SpectralCoordinate 63 63 */ 64 casa::SpectralCoordinate getSpectralCoordinate( casa::uInt freqID ); 64 casa::SpectralCoordinate getSpectralCoordinate( casa::uInt freqID ) const; 65 66 casa::SpectralCoordinate getSpectralCoordinate( const casa::MDirection& md, 67 const casa::MPosition& mp, 68 const casa::MEpoch& me, 69 casa::Double restfreq, 70 casa::uInt freqID 71 ) const; 65 72 66 73 /** … … 68 75 * @return casa::Unit 69 76 */ 70 const casa::Unit& getUnit() const; 77 casa::Unit getUnit() const; 78 std::string getUnitString() const; 79 71 80 /** 72 81 * Return the doppler type of the values 73 * @return casa::MDoppler 82 * @return casa::MDoppler::Types 74 83 */ 75 casa::MDoppler getDoppler() const; 84 casa::MDoppler::Types getDoppler() const; 85 std::string getDopplerString() const; 76 86 77 87 78 88 /** 79 89 * Return the frame type, e.g MFrequency::TOPO 90 * @param base return the base frame or the user frame 80 91 * @return casa::MFrequency::Types 81 92 */ 82 casa::MFrequency::Types getFrame( ) const;93 casa::MFrequency::Types getFrame(bool base=false) const; 83 94 84 95 /** 85 96 * Return a string representation of the frame type, e.g TOPO 86 * @return 97 * @param base return the base frame or the user frame 98 * @return the string representation of the frame 87 99 */ 88 std::string getFrameString( ) const;100 std::string getFrameString(bool base=false) const; 89 101 90 102 /** … … 124 136 std::string print(int id=-1); 125 137 138 std::vector<std::string> getInfo() const; 139 void setInfo( const std::vector<std::string>& theinfo ); 140 126 141 private: 127 142 -
trunk/src/STMath.cpp
r841 r847 811 811 setInsitu(insitu); 812 812 Table& tout = out->table(); 813 cout << "nrows " << in[1]->table().nrow() << endl;814 813 ScalarColumn<uInt> freqidcol(tout,"FREQ_ID"), molidcol(tout, "MOLECULE_ID"); 815 814 ScalarColumn<uInt> scannocol(tout,"SCANNO"),focusidcol(tout,"FOCUS_ID"); -
trunk/src/STMolecules.cpp
r830 r847 93 93 } 94 94 95 std::vector< double > asap::STMolecules::getRestFrequencies( ) const 96 { 97 std::vector<double> out; 98 Vector<Double> rfs = restfreqCol_.getColumn(); 99 rfs.tovector(out); 100 return out; 101 } 102 95 103 } //namespace -
trunk/src/STMolecules.h
r830 r847 39 39 casa::String& formattedname, casa::uInt id); 40 40 41 std::vector<double> getRestFrequencies() const; 42 41 43 private: 42 44 void setup(); -
trunk/src/Scantable.cpp
r845 r847 224 224 scanCol_.attach(table_, "SCANNO"); 225 225 beamCol_.attach(table_, "BEAMNO"); 226 ifCol_.attach(table_, "IFNO"); 227 polCol_.attach(table_, "POLNO"); 226 228 integrCol_.attach(table_, "INTERVAL"); 227 229 azCol_.attach(table_, "AZIMUTH"); … … 292 294 293 295 294 int Scantable::rowToScanIndex( int therow )295 {296 int therealrow = -1;297 298 return therealrow;299 }300 301 296 int Scantable::nscan() const { 302 297 int n = 0; … … 344 339 std::string Scantable::getFluxUnit() const 345 340 { 346 String tmp; 347 table_.keywordSet().get("FluxUnit", tmp); 348 return tmp; 341 return table_.keywordSet().asString("FluxUnit"); 349 342 } 350 343 … … 485 478 } 486 479 return 0; 480 } 481 482 483 int Scantable::getBeam(int whichrow) const 484 { 485 return beamCol_(whichrow); 486 } 487 488 int Scantable::getIF(int whichrow) const 489 { 490 return ifCol_(whichrow); 491 } 492 493 int Scantable::getPol(int whichrow) const 494 { 495 return polCol_(whichrow); 487 496 } 488 497 … … 563 572 } 564 573 565 double Scantable::getInterval(int whichrow) const566 {567 if (whichrow < 0) return 0.0;568 Double intval;569 integrCol_.get(Int(whichrow), intval);570 return intval;571 }572 573 574 std::vector<bool> Scantable::getMask(int whichrow) const 574 575 { … … 619 620 { 620 621 table_ = originalTable_; 622 attach(); 621 623 selector_.reset(); 622 624 } … … 629 631 } 630 632 table_ = tab; 633 attach(); 631 634 selector_ = selection; 632 635 } … … 742 745 } 743 746 747 std::string Scantable::getAbcissaLabel( int whichrow ) const 748 { 749 if ( whichrow > table_.nrow() ) throw(AipsError("Illegal ro number")); 750 const MPosition& mp = getAntennaPosition(); 751 const MDirection& md = dirCol_(whichrow); 752 const MEpoch& me = timeCol_(whichrow); 753 const Double& rf = mmolidCol_(whichrow); 754 SpectralCoordinate spc = 755 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow)); 756 757 String s = "Channel"; 758 Unit u = Unit(freqTable_.getUnitString()); 759 if (u == Unit("km/s")) { 760 s = CoordinateUtil::axisLabel(spc,0,True,True,True); 761 } else if (u == Unit("Hz")) { 762 Vector<String> wau(1);wau = u.getName(); 763 spc.setWorldAxisUnits(wau); 764 765 s = CoordinateUtil::axisLabel(spc,0,True,True,False); 766 } 767 return s; 768 769 } 770 771 void asap::Scantable::setRestFrequencies( double rf, const std::string& unit ) 772 { 773 ///@todo lookup in line table 774 Unit u(unit); 775 Quantum<Double> urf(rf, u); 776 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), "", ""); 777 TableVector<uInt> tabvec(table_, "MOLECULE_ID"); 778 tabvec = id; 779 } 780 781 void asap::Scantable::setRestFrequencies( const std::string& name ) 782 { 783 throw(AipsError("setRestFrequencies( const std::string& name ) NYI")); 784 ///@todo implement 785 } 786 744 787 }//namespace asap -
trunk/src/Scantable.h
r845 r847 217 217 int ncycle(int scanno=-1) const; 218 218 219 double getInterval(int scanno=0) const; 220 221 float getTsys(int scanno=0) const; 222 223 std::vector<bool> getMask(int whichrow=0) const; 224 std::vector<float> getSpectrum(int whichrow=0) const; 219 int getBeam(int whichrow) const; 220 int getIF(int whichrow) const; 221 int getPol(int whichrow) const; 222 223 double getInterval(int whichrow) const 224 { return integrCol_(whichrow); } 225 226 float getTsys(int whichrow) const; 227 float getElevation(int whichrow) const 228 { return elCol_(whichrow); } 229 float getAzimuth(int whichrow) const 230 { return azCol_(whichrow); } 231 float getParangle(int whichrow) const 232 { return paraCol_(whichrow); } 233 234 std::vector<bool> getMask(int whichrow) const; 235 std::vector<float> getSpectrum(int whichrow) const; 225 236 226 237 std::vector<float> getStokesSpectrum( int whichrow=0, … … 245 256 std::string getTime(int whichrow=-1, bool showdate=true) const; 246 257 258 // returns unit, conversion frame, doppler, base-frame 259 260 /** 261 * Get the frequency set up 262 * This is forwarded to the STFrequencies subtable 263 * @return unit, frame, doppler 264 */ 265 std::vector<std::string> getCoordInfo() const 266 { return freqTable_.getInfo(); }; 267 268 void setCoordInfo(std::vector<string> theinfo) 269 { return freqTable_.setInfo(theinfo); }; 270 271 std::string getAbcissaLabel(int whichrow) const; 272 std::vector<double> getRestFrequencies() const 273 { return moleculeTable_.getRestFrequencies(); } 274 275 void setRestFrequencies(double rf, const std::string& = "Hz"); 276 void setRestFrequencies(const std::string& name); 247 277 248 278 STFrequencies& frequencies() { return freqTable_; } … … 316 346 317 347 // Cached Columns to avoid reconstructing them for each row get/put 318 casa::ScalarColumn<casa::Double> timeCol_,integrCol_;348 casa::ScalarColumn<casa::Double> integrCol_; 319 349 casa::MDirection::ScalarColumn dirCol_; 350 casa::MEpoch::ScalarColumn timeCol_; 320 351 casa::ScalarColumn<casa::Double> azCol_; 321 352 casa::ScalarColumn<casa::Double> elCol_; 322 353 casa::ScalarColumn<casa::Float> paraCol_; 323 354 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_; 324 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, cycleCol_;355 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_; 325 356 casa::ScalarColumn<casa::Int> rbeamCol_; 326 357 casa::ArrayColumn<casa::Float> specCol_, tsCol_;
Note:
See TracChangeset
for help on using the changeset viewer.