- Timestamp:
- 12/01/04 10:57:15 (20 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMemTable.cc
r89 r105 51 51 #include <measures/Measures/MFrequency.h> 52 52 #include <measures/Measures/MeasTable.h> 53 #include <coordinates/Coordinates/CoordinateUtil.h> 53 54 #include <casa/Quanta/MVTime.h> 54 55 … … 92 93 beamSel_(0), 93 94 polSel_(0) { 94 //cerr << exprs << endl;95 95 Table t = tableCommand(exprs,tab); 96 96 if (t.nrow() == 0) … … 100 100 101 101 SDMemTable::~SDMemTable(){ 102 cerr << "goodbye from SDMemTable @ " << this << endl;102 //cerr << "goodbye from SDMemTable @ " << this << endl; 103 103 } 104 104 … … 127 127 td.addColumn(ArrayColumnDesc<uInt>("FREQID")); 128 128 td.addColumn(ArrayColumnDesc<Double>("DIRECTION")); 129 td.addColumn(ScalarColumnDesc<String>("FIELDNAME")); 130 td.addColumn(ScalarColumnDesc<String>("TCALTIME")); 131 td.addColumn(ArrayColumnDesc<Float>("TCAL")); 132 td.addColumn(ScalarColumnDesc<Float>("AZIMUTH")); 133 td.addColumn(ScalarColumnDesc<Float>("ELEVATION")); 134 td.addColumn(ScalarColumnDesc<Float>("PARANGLE")); 135 td.addColumn(ScalarColumnDesc<Int>("REFBEAM")); 136 129 137 // Now create a new table from the description. 130 138 … … 145 153 src.get(whichRow, tm); 146 154 MVTime mvt(tm); 147 mvt.setFormat(MVTime:: YMD);155 mvt.setFormat(MVTime::TIME); 148 156 ostringstream oss; 149 157 oss << mvt; … … 186 194 std::vector<int>::iterator it; 187 195 uInt n = spec.shape(0)(3); 196 if (whichChans.empty()) { 197 chanMask_ = std::vector<bool>(n,true); 198 return true; 199 } 188 200 chanMask_.resize(n,true); 189 201 for (it = whichChans.begin(); it != whichChans.end(); ++it) { 190 if (*it < n) 202 if (*it < n) { 191 203 chanMask_[*it] = false; 204 } 192 205 } 193 206 return true; … … 240 253 return spectrum; 241 254 } 242 243 std::vector<double> SDMemTable::getAbscissa(Int whichRow, 244 const std::string& whichUnit, 245 const std::string& whichFrame, 246 double restfreq) { 255 std::vector<string> SDMemTable::getCoordInfo() const { 256 String un; 257 Table t = table_.keywordSet().asTable("FREQUENCIES"); 258 String sunit; 259 t.keywordSet().get("UNIT",sunit); 260 String dpl; 261 t.keywordSet().get("DOPPLER",dpl); 262 if (dpl == "") dpl = "RADIO"; 263 String rfrm; 264 t.keywordSet().get("REFFRAME",rfrm); 265 std::vector<string> inf; 266 inf.push_back(sunit); 267 inf.push_back(rfrm); 268 inf.push_back(dpl); 269 return inf; 270 } 271 272 void SDMemTable::setCoordInfo(std::vector<string> theinfo) { 273 274 std::vector<string>::iterator it; 275 String un,rfrm,dpl; 276 un = theinfo[0]; 277 rfrm = theinfo[1]; 278 dpl = theinfo[2]; 279 280 //String un(theunit); 281 Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); 282 Vector<Double> rstf; 283 t.keywordSet().get("RESTFREQS",rstf); 284 Bool canDo = True; 285 Unit u1("km/s");Unit u2("Hz"); 286 if (Unit(un) == u1) { 287 Vector<Double> rstf; 288 t.keywordSet().get("RESTFREQS",rstf); 289 if (rstf.nelements() == 0) { 290 throw(AipsError("Can't set unit to km/s if no restfrequencies are specified")); 291 } 292 } else if (Unit(un) != u2 && un != "") { 293 throw(AipsError("Unit not conformant with Spectral Coordinates")); 294 } 295 t.rwKeywordSet().define("UNIT", un); 296 297 MFrequency::Types mdr; 298 if (!MFrequency::getType(mdr, rfrm)) { 299 300 Int a,b;const uInt* c; 301 const String* valid = MFrequency::allMyTypes(a, b, c); 302 String pfix = "Please specify a legal frame type. Types are\n"; 303 throw(AipsError(pfix+(*valid))); 304 } else { 305 t.rwKeywordSet().define("REFFRAME",rfrm); 306 } 307 308 } 309 310 std::vector<double> SDMemTable::getAbscissa(Int whichRow) { 247 311 std::vector<double> absc(nChan()); 248 312 Vector<Double> absc1(nChan()); … … 252 316 fid.get(whichRow, v); 253 317 uInt specidx = v(IFSel_); 254 Unit u;255 if (whichUnit == "") {256 // get unit from table257 } else {258 u = String(whichUnit);259 }260 318 SpectralCoordinate spc = getCoordinate(specidx); 261 319 Table t = table_.keywordSet().asTable("FREQUENCIES"); 262 320 String rf; 263 t.keywordSet().get("REFFRAME",rf);321 //t.keywordSet().get("EQUINOX",rf); 264 322 MDirection::Types mdr; 265 MDirection::getType(mdr, rf); 323 //if (!MDirection::getType(mdr, rf)) { 324 mdr = MDirection::J2000; 325 //cout << "Unknown equinox using J2000" << endl; 326 //} 266 327 ROArrayColumn<Double> dir(table_, "DIRECTION"); 267 328 Array<Double> posit; … … 276 337 Double obstime; 277 338 tme.get(whichRow,obstime); 278 //Quantum<Double> tm(obstime, Unit(String("d")));279 339 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d")))); 280 340 MEpoch epoch(tm2); … … 282 342 Vector<Double> antpos; 283 343 table_.keywordSet().get("AntennaPosition", antpos); 284 //MPosition pos;285 344 MVPosition mvpos(antpos(0),antpos(1),antpos(2)); 286 345 MPosition pos(mvpos); 287 //MeasTable::Observatory(pos, String("ATCA")); 288 346 String sunit; 347 t.keywordSet().get("UNIT",sunit); 348 if (sunit == "") sunit = "pixel"; 349 Unit u(sunit); 350 String frm; 351 t.keywordSet().get("REFFRAME",frm); 352 if (frm == "") frm = "TOPO"; 353 String dpl; 354 t.keywordSet().get("DOPPLER",dpl); 355 if (dpl == "") dpl = "RADIO"; 289 356 MFrequency::Types mtype; 290 if (!MFrequency::getType(mtype, whichFrame)) {357 if (!MFrequency::getType(mtype, frm)) { 291 358 cout << "Frequency type unknown assuming TOPO" << endl; 292 359 mtype = MFrequency::TOPO; 293 360 } 294 spc.setReferenceConversion(mtype,epoch,pos,direct); 361 362 if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) { 363 throw(AipsError("Couldn't convert frequency frame.")); 364 } 295 365 296 366 if ( u == Unit("km/s") ) { … … 298 368 t.keywordSet().get("RESTFREQS",rstf); 299 369 if (rstf.nelements() > 0) { 300 cout << "converting to velocities"<< endl;301 //spc.setRestFrequency(Double(restfreq));302 370 spc.setVelocity(u.getName()); 303 371 Vector<Double> wrld; … … 313 381 Vector<String> wau(1); wau = u.getName(); 314 382 spc.setWorldAxisUnits(wau); 315 cout << " converting in frequency" << endl;316 383 std::vector<double>::iterator it; 317 384 Double tmp; … … 322 389 i++; 323 390 } 391 392 } else { 393 // assume channels/pixels 394 std::vector<double>::iterator it; 395 uInt i=0; 396 for (it = absc.begin(); it != absc.end(); ++it) { 397 (*it) = Double(i++); 398 } 324 399 } 325 400 return absc; 401 } 402 403 std::string SDMemTable::getAbscissaString(Int whichRow) 404 { 405 ROArrayColumn<uInt> fid(table_, "FREQID"); 406 Table t = table_.keywordSet().asTable("FREQUENCIES"); 407 String sunit; 408 t.keywordSet().get("UNIT",sunit); 409 if (sunit == "") sunit = "pixel"; 410 Unit u(sunit); 411 Vector<uInt> v; 412 fid.get(whichRow, v); 413 uInt specidx = v(IFSel_); 414 SpectralCoordinate spc = getCoordinate(specidx); 415 String frm; 416 t.keywordSet().get("REFFRAME",frm); 417 MFrequency::Types mtype; 418 if (!MFrequency::getType(mtype, frm)) { 419 cout << "Frequency type unknown assuming TOPO" << endl; 420 mtype = MFrequency::TOPO; 421 } 422 spc.setFrequencySystem(mtype); 423 String s = "Channel"; 424 if (u == Unit("km/s")) { 425 spc.setVelocity(u.getName()); 426 s = CoordinateUtil::axisLabel(spc,0,True,True,True); 427 } else if (u == Unit("Hz")) { 428 Vector<String> wau(1);wau = u.getName(); 429 spc.setWorldAxisUnits(wau); 430 s = CoordinateUtil::axisLabel(spc); 431 } 432 return s; 326 433 } 327 434 … … 472 579 ROScalarColumn<Double> incc(t, "INCREMENT"); 473 580 t.keywordSet().get("RESTFREQS",vec); 474 t.keywordSet().get(" REFFRAME",rf);581 t.keywordSet().get("BASEREFFRAME",rf); 475 582 476 583 MFrequency::Types mft; … … 482 589 rvc.get(whichIdx, rv); 483 590 incc.get(whichIdx, inc); 484 //cerr << "creating speccord from " << whichIdx << ": "485 // << rp <<", " << rv << ", " << inc << ", " << mft <<endl;486 591 SpectralCoordinate spec(mft,rv,inc,rp); 487 592 if (vec.nelements() > 0) … … 520 625 Table t = table_.keywordSet().asTable("FREQUENCIES"); 521 626 t.rwKeywordSet().define("RESTFREQS",tvec); 522 523 627 } 524 628 … … 538 642 sc2.put(i,sdft.increment(i)); 539 643 } 540 aTable.rwKeywordSet().define("REFFRAME", sdft.refFrame()); 644 String rf = sdft.refFrame(); 645 if (rf.contains("TOPO")) rf = "TOPO"; 646 647 aTable.rwKeywordSet().define("BASEREFFRAME", rf); 648 aTable.rwKeywordSet().define("REFFRAME", rf); 541 649 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox()); 542 aTable.rwKeywordSet().define("Unit", String("kms-1")); 650 aTable.rwKeywordSet().define("UNIT", String("")); 651 aTable.rwKeywordSet().define("DOPPLER", String("RADIO")); 543 652 Vector<Double> rfvec; 544 653 aTable.rwKeywordSet().define("RESTFREQS", rfvec); … … 556 665 ScalarColumn<Double> mjd(table_, "TIME"); 557 666 ScalarColumn<String> srcn(table_, "SRCNAME"); 667 ScalarColumn<String> fldn(table_, "FIELDNAME"); 558 668 ArrayColumn<Float> spec(table_, "SPECTRA"); 559 669 ArrayColumn<uChar> flags(table_, "FLAGTRA"); … … 563 673 ArrayColumn<uInt> freqid(table_, "FREQID"); 564 674 ArrayColumn<Double> dir(table_, "DIRECTION"); 675 ScalarColumn<Int> rbeam(table_, "REFBEAM"); 676 ArrayColumn<Float> tcal(table_, "TCAL"); 677 ScalarColumn<String> tcalt(table_, "TCALTIME"); 678 ScalarColumn<Float> az(table_, "AZIMUTH"); 679 ScalarColumn<Float> el(table_, "ELEVATION"); 680 ScalarColumn<Float> para(table_, "PARANGLE"); 565 681 566 682 uInt rno = table_.nrow(); … … 569 685 mjd.put(rno, sdc.timestamp); 570 686 srcn.put(rno, sdc.sourcename); 687 fldn.put(rno, sdc.fieldname); 571 688 spec.put(rno, sdc.getSpectrum()); 572 689 flags.put(rno, sdc.getFlags()); … … 576 693 freqid.put(rno, sdc.getFreqMap()); 577 694 dir.put(rno, sdc.getDirection()); 695 rbeam.put(rno, sdc.refbeam); 696 tcal.put(rno, sdc.tcal); 697 tcalt.put(rno, sdc.tcaltime); 698 az.put(rno, sdc.azimuth); 699 el.put(rno, sdc.elevation); 700 para.put(rno, sdc.parangle); 578 701 579 702 return true; … … 583 706 ROScalarColumn<Double> mjd(table_, "TIME"); 584 707 ROScalarColumn<String> srcn(table_, "SRCNAME"); 708 ROScalarColumn<String> fldn(table_, "FIELDNAME"); 585 709 ROArrayColumn<Float> spec(table_, "SPECTRA"); 586 710 ROArrayColumn<uChar> flags(table_, "FLAGTRA"); … … 590 714 ROArrayColumn<uInt> freqid(table_, "FREQID"); 591 715 ROArrayColumn<Double> dir(table_, "DIRECTION"); 716 ROScalarColumn<Int> rbeam(table_, "REFBEAM"); 717 ROArrayColumn<Float> tcal(table_, "TCAL"); 718 ROScalarColumn<String> tcalt(table_, "TCALTIME"); 719 ROScalarColumn<Float> az(table_, "AZIMUTH"); 720 ROScalarColumn<Float> el(table_, "ELEVATION"); 721 ROScalarColumn<Float> para(table_, "PARANGLE"); 592 722 593 723 SDContainer sdc(nBeam(),nIF(),nPol(),nChan()); … … 596 726 integr.get(whichRow, sdc.interval); 597 727 scan.get(whichRow, sdc.scanid); 728 fldn.get(whichRow, sdc.fieldname); 729 rbeam.get(whichRow, sdc.refbeam); 730 az.get(whichRow, sdc.azimuth); 731 el.get(whichRow, sdc.elevation); 732 para.get(whichRow, sdc.parangle); 733 Vector<Float> tc; 734 tcal.get(whichRow, tc); 735 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1]; 736 tcalt.get(whichRow, sdc.tcaltime); 598 737 Array<Float> spectrum; 599 738 Array<Float> tsys; … … 670 809 } 671 810 672 std::string SDMemTable::summary() const { 811 String SDMemTable::formatSec(Double x) { 812 Double xcop = x; 813 MVTime mvt(xcop/24./3600.); // make days 814 if (x < 59.95) 815 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s"; 816 return mvt.string(MVTime::TIME_CLEAN_NO_H, 7)+" "; 817 }; 818 819 std::string SDMemTable::summary() { 673 820 ROScalarColumn<Int> scans(table_, "SCANID"); 674 821 ROScalarColumn<String> srcs(table_, "SRCNAME"); … … 679 826 oss << "--------------------------------------------------" << endl; 680 827 oss.flags(std::ios_base::left); 681 //oss.width(15);682 828 oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl 683 829 << setw(15) << "IFs:" << setw(4) << nIF() << endl … … 694 840 table_.keywordSet().get("AntennaName", tmp); 695 841 oss << setw(15) << "Antenna Name:" << tmp << endl; 842 Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); 843 Vector<Double> vec; 844 t.keywordSet().get("RESTFREQS",vec); 845 oss << setw(15) << "Rest Freqs:"; 846 if (vec.nelements() > 0) { 847 oss << setprecision(0) << vec << " [Hz]" << endl; 848 } else { 849 oss << "None set" << endl; 850 } 851 oss << setw(15) << "Abscissa:" << getAbscissaString() << endl; 852 oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] " 853 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl; 696 854 oss << endl; 697 855 uInt count = 0; … … 703 861 << setw(21) << "Time" 704 862 << setw(11) << "Integration" << endl; 863 oss << "--------------------------------------------------" << endl; 705 864 for (uInt i=0; i< scans.nrow();i++) { 706 865 scans.getScalar(i,current); … … 708 867 srcs.getScalar(i,name); 709 868 previous = current; 710 Double t = getInterval(i); 711 String unit("s"); 712 if (t/3600.0 > 1.0) { 713 t/=3600.0;unit = "h"; 714 } else if (t/60.0 > 1.0) { 715 t/=60.0;unit = "m"; 716 } 869 String t = formatSec(Double(getInterval(i))); 717 870 oss << setw(6) << count << setw(12) << name << setw(21) << getTime(i) 718 << setw(2) << setprecision(1) << setiosflags(std::ios_base::fixed)719 << t << " " << unit <<endl;871 << setw(2) << setprecision(1) 872 << t << endl; 720 873 count++; 721 874 } else { -
trunk/src/SDMemTable.h
r88 r105 94 94 virtual void setSpectrum(std::vector<float> spectrum, int whichRow=0); 95 95 virtual void setRestFreqs(std::vector<double> freqs, const std::string& theunit); 96 96 virtual void setCoordInfo(std::vector<string> theinfo); 97 97 // set the current value 98 98 virtual bool setIF(Int whichIF=0); … … 109 109 virtual Int getBeam() { return beamSel_; } 110 110 virtual Int getPol() { return polSel_; } 111 virtual std::vector<string> getCoordInfo() const; 111 112 112 113 // number of scans in table … … 114 115 115 116 // print a summary to stdout 116 virtual std::string summary() const;117 virtual std::string summary(); 117 118 118 119 // write to disk as aips++ table … … 146 147 Int nCoordinates() const; 147 148 148 std::vector<double> getAbscissa(int whichRow, 149 const std::string& whichUnit="GHz", 150 const std::string& whichFrame="TOPO", 151 double restfreq=0.0); 149 std::vector<double> getAbscissa(int whichRow=0); 150 std::string getAbscissaString(Int whichRow=0); 151 152 152 private: 153 // set up table structure 153 // utility func for nice printout 154 String formatSec(Double x); 154 155 void setup(); 155 156 // the current cursor into the array -
trunk/src/SDMemTableWrapper.h
r90 r105 76 76 } 77 77 78 std::vector<double> getAbscissa(int whichRow ,79 const std::string& unit = "GHz",80 const std::string& frame = "TOPO",81 double restfreq=0.0) const {82 return table_->getAbscissa (whichRow,unit,frame,restfreq);78 std::vector<double> getAbscissa(int whichRow=0) const { 79 return table_->getAbscissa(whichRow); 80 } 81 std::string getAbscissaString(int whichRow=0) const { 82 return table_->getAbscissaString(whichRow); 83 83 } 84 84 … … 130 130 table_->setRestFreqs(freqs, theunit); 131 131 } 132 void setCoordInfo(std::vector<string> theinfo) { 133 table_->setCoordInfo(theinfo); 134 } 135 std::vector<string> getCoordInfo() const { 136 return table_->getCoordInfo(); 137 } 132 138 133 139 CountedPtr<SDMemTable> getCP() const {return table_;}
Note:
See TracChangeset
for help on using the changeset viewer.