Changeset 89
- Timestamp:
- 11/12/04 12:14:41 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMemTable.cc
r83 r89 94 94 //cerr << exprs << endl; 95 95 Table t = tableCommand(exprs,tab); 96 if (t.nrow() == 0) 97 throw(AipsError("Query unsuccessful.")); 96 98 table_ = t.copyToMemoryTable("dummy"); 97 99 } 98 100 99 101 SDMemTable::~SDMemTable(){ 100 //cerr << "goodbye from SDMemTable @ " << this << endl;102 cerr << "goodbye from SDMemTable @ " << this << endl; 101 103 } 102 104 … … 120 122 td.addColumn(ArrayColumnDesc<Float>("SPECTRA")); 121 123 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); 122 td.addColumn(ArrayColumnDesc<Float>("TSYS")); 123 td.addColumn(ScalarColumnDesc<Int>("SCANID")); 124 td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); 124 td.addColumn(ArrayColumnDesc<Float>("TSYS")); 125 td.addColumn(ScalarColumnDesc<Int>("SCANID")); 126 td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); 125 127 td.addColumn(ArrayColumnDesc<uInt>("FREQID")); 126 128 td.addColumn(ArrayColumnDesc<Double>("DIRECTION")); … … 128 130 129 131 SetupNewTable aNewTab("dummy", td, Table::New); 130 table_ = Table(aNewTab, Table::Memory, 0); 132 table_ = Table(aNewTab, Table::Memory, 0); 131 133 } 132 134 … … 182 184 bool SDMemTable::setMask(std::vector<int> whichChans) { 183 185 ROArrayColumn<uChar> spec(table_, "FLAGTRA"); 184 185 186 std::vector<int>::iterator it; 186 187 uInt n = spec.shape(0)(3); … … 219 220 } 220 221 mask.push_back(out); 221 } 222 } 222 223 return mask; 223 224 } … … 240 241 } 241 242 242 std::vector<double> SDMemTable::getAbscissa(Int whichRow, 243 244 245 243 std::vector<double> SDMemTable::getAbscissa(Int whichRow, 244 const std::string& whichUnit, 245 const std::string& whichFrame, 246 double restfreq) { 246 247 std::vector<double> absc(nChan()); 247 Vector<Double> absc1(nChan()); 248 Vector<Double> absc1(nChan()); 248 249 indgen(absc1); 249 250 ROArrayColumn<uInt> fid(table_, "FREQID"); … … 262 263 t.keywordSet().get("REFFRAME",rf); 263 264 MDirection::Types mdr; 264 MDirection::getType(mdr, rf); 265 MDirection::getType(mdr, rf); 265 266 ROArrayColumn<Double> dir(table_, "DIRECTION"); 266 267 Array<Double> posit; … … 275 276 Double obstime; 276 277 tme.get(whichRow,obstime); 277 Quantum<Double> tm(obstime, Unit(String("d")));278 MVEpoch tm2( tm);278 //Quantum<Double> tm(obstime, Unit(String("d"))); 279 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d")))); 279 280 MEpoch epoch(tm2); 280 281 … … 288 289 MFrequency::Types mtype; 289 290 if (!MFrequency::getType(mtype, whichFrame)) { 290 c err<< "Frequency type unknown assuming TOPO" << endl;291 cout << "Frequency type unknown assuming TOPO" << endl; 291 292 mtype = MFrequency::TOPO; 292 293 } 293 spc.setReferenceConversion(mtype,epoch,pos,direct); 294 spc.setReferenceConversion(mtype,epoch,pos,direct); 294 295 295 296 if ( u == Unit("km/s") ) { 296 if (Double(restfreq) > Double(0.000001)) { 297 cerr << "converting to velocities"<< endl; 298 spc.setRestFrequency(Double(restfreq)); 299 spc.setVelocity(u.getName()); 297 Vector<Double> rstf; 298 t.keywordSet().get("RESTFREQS",rstf); 299 if (rstf.nelements() > 0) { 300 cout << "converting to velocities"<< endl; 301 //spc.setRestFrequency(Double(restfreq)); 302 spc.setVelocity(u.getName()); 300 303 Vector<Double> wrld; 301 304 spc.pixelToVelocity(wrld,absc1); … … 303 306 uInt i = 0; 304 307 for (it = absc.begin(); it != absc.end(); ++it) { 305 306 308 (*it) = wrld[i]; 309 i++; 307 310 } 308 311 } … … 310 313 Vector<String> wau(1); wau = u.getName(); 311 314 spc.setWorldAxisUnits(wau); 312 c err<< " converting in frequency" << endl;315 cout << " converting in frequency" << endl; 313 316 std::vector<double>::iterator it; 314 317 Double tmp; 315 318 uInt i = 0; 316 for (it = absc.begin(); it != absc.end(); ++it) { 319 for (it = absc.begin(); it != absc.end(); ++it) { 317 320 spc.toWorld(tmp,absc1[i]); 318 321 (*it) = tmp; … … 321 324 } 322 325 return absc; 326 } 327 328 void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow) { 329 ArrayColumn<Float> spec(table_, "SPECTRA"); 330 Array<Float> arr; 331 spec.get(whichRow, arr); 332 if (spectrum.size() != arr.shape()(3)) { 333 throw(AipsError("Attempting to set spectrum with incorrect length.")); 334 } 335 336 ArrayAccessor<Float, Axis<0> > aa0(arr); 337 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam 338 ArrayAccessor<Float, Axis<1> > aa1(aa0); 339 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF 340 ArrayAccessor<Float, Axis<2> > aa2(aa1); 341 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol 342 343 std::vector<float>::iterator it = spectrum.begin(); 344 for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { 345 (*i) = Float(*it); 346 it++; 347 } 348 spec.put(whichRow, arr); 323 349 } 324 350 … … 341 367 } 342 368 } 343 369 /* 344 370 void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const { 345 371 ROArrayColumn<uChar> spec(table_, "FLAGTRA"); … … 356 382 357 383 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); 358 384 359 385 ArrayAccessor<Bool, Axis<0> > va(mask); 360 386 std::vector<bool> tmp; 361 387 tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The 362 388 // iterator should work on chanMask_?? 363 389 std::vector<bool>::iterator miter; 364 390 miter = tmp.begin(); … … 372 398 (*va) = out; 373 399 va++; 374 } 375 } 376 400 } 401 } 402 */ 377 403 MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, 378 404 Bool useSelection) { 379 405 ROArrayColumn<Float> spec(table_, "SPECTRA"); 380 406 Array<Float> arr; … … 392 418 ArrayAccessor<Float, Axis<2> > aa2(aa1); 393 419 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol 394 420 395 421 ArrayAccessor<Bool, Axis<0> > baa0(barr); 396 422 baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam … … 438 464 return SpectralCoordinate(); 439 465 } 440 466 441 467 Double rp,rv,inc; 442 468 String rf; 469 Vector<Double> vec; 443 470 ROScalarColumn<Double> rpc(t, "REFPIX"); 444 471 ROScalarColumn<Double> rvc(t, "REFVAL"); 445 472 ROScalarColumn<Double> incc(t, "INCREMENT"); 473 t.keywordSet().get("RESTFREQS",vec); 446 474 t.keywordSet().get("REFFRAME",rf); 447 475 448 476 MFrequency::Types mft; 449 477 if (!MFrequency::getType(mft, rf)) { 450 478 cerr << "Frequency type unknown assuming TOPO" << endl; 451 mft = MFrequency::TOPO; 452 } 479 mft = MFrequency::TOPO; 480 } 453 481 rpc.get(whichIdx, rp); 454 482 rvc.get(whichIdx, rv); … … 457 485 // << rp <<", " << rv << ", " << inc << ", " << mft <<endl; 458 486 SpectralCoordinate spec(mft,rv,inc,rp); 487 if (vec.nelements() > 0) 488 spec.setRestFrequencies(vec); 459 489 return spec; 460 490 } 461 491 462 Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, 463 492 Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, 493 uInt whichIdx) { 464 494 Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); 465 495 if (whichIdx > t.nrow() ) { 466 cerr << "SDMemTable::setCoordinate - whichIdx out of range" << endl; 467 return False; 496 throw(AipsError("SDMemTable::setCoordinate - coord no out of range")); 468 497 } 469 498 ScalarColumn<Double> rpc(t, "REFPIX"); 470 499 ScalarColumn<Double> rvc(t, "REFVAL"); 471 500 ScalarColumn<Double> incc(t, "INCREMENT"); 472 501 473 502 rpc.put(whichIdx, speccord.referencePixel()[0]); 474 503 rvc.put(whichIdx, speccord.referenceValue()[0]); … … 478 507 } 479 508 509 Int SDMemTable::nCoordinates() const 510 { 511 return table_.keywordSet().asTable("FREQUENCIES").nrow(); 512 } 513 514 void SDMemTable::setRestFreqs(std::vector<double> freqs, const std::string& theunit) 515 { 516 Vector<Double> tvec(freqs); 517 Quantum<Vector<Double> > q(tvec, String(theunit)); 518 tvec.resize(); 519 tvec = q.getValue("Hz"); 520 Table t = table_.keywordSet().asTable("FREQUENCIES"); 521 t.rwKeywordSet().define("RESTFREQS",tvec); 522 523 } 480 524 481 525 bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) { … … 497 541 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox()); 498 542 aTable.rwKeywordSet().define("Unit", String("kms-1")); 543 Vector<Double> rfvec; 544 aTable.rwKeywordSet().define("RESTFREQS", rfvec); 499 545 table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable); 500 546 return True; … … 503 549 SDFrequencyTable SDMemTable::getSDFreqTable() const { 504 550 SDFrequencyTable sdft; 505 551 506 552 return sdft; 507 553 } … … 520 566 uInt rno = table_.nrow(); 521 567 table_.addRow(); 522 568 523 569 mjd.put(rno, sdc.timestamp); 524 570 srcn.put(rno, sdc.sourcename); … … 530 576 freqid.put(rno, sdc.getFreqMap()); 531 577 dir.put(rno, sdc.getDirection()); 532 578 533 579 return true; 534 580 } … … 610 656 } 611 657 612 Int SDMemTable::nScan s() const {658 Int SDMemTable::nScan() const { 613 659 Int n = 0; 614 660 ROScalarColumn<Int> scans(table_, "SCANID"); … … 617 663 scans.getScalar(i,current); 618 664 if (previous != current) { 619 previous = current; 665 previous = current; 620 666 n++; 621 667 } … … 624 670 } 625 671 626 voidSDMemTable::summary() const {672 std::string SDMemTable::summary() const { 627 673 ROScalarColumn<Int> scans(table_, "SCANID"); 628 674 ROScalarColumn<String> srcs(table_, "SRCNAME"); 629 cout << "*************** Header ***************" << endl; 630 cout << "nBeam = " << nBeam() << "\t" 631 << "nIF = " << nIF() << endl 632 << "nPol = " << nPol() << "\t" 633 << "nChan = " << nChan() << "\t" << endl; 634 cout << "*************** Header ***************" << endl; 675 ostringstream oss; 676 oss << endl; 677 oss << "--------------------------------------------------" << endl; 678 oss << " Scan Table Summary" << endl; 679 oss << "--------------------------------------------------" << endl; 680 oss.flags(std::ios_base::left); 681 //oss.width(15); 682 oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl 683 << setw(15) << "IFs:" << setw(4) << nIF() << endl 684 << setw(15) << "Polarisations:" << setw(4) << nPol() << endl 685 << setw(15) << "Channels:" << setw(4) << nChan() << endl; 686 oss << endl; 687 String tmp; 688 table_.keywordSet().get("Observer", tmp); 689 oss << setw(15) << "Observer:" << tmp << endl; 690 table_.keywordSet().get("Project", tmp); 691 oss << setw(15) << "Project:" << tmp << endl; 692 table_.keywordSet().get("Obstype", tmp); 693 oss << setw(15) << "Obs. Type:" << tmp << endl; 694 table_.keywordSet().get("AntennaName", tmp); 695 oss << setw(15) << "Antenna Name:" << tmp << endl; 696 oss << endl; 635 697 uInt count = 0; 636 698 String name; 637 699 Int previous = -1;Int current=0; 638 cout << "Scan\tSource\t\tTime\t\tIntegration" << endl; 700 Int integ = 0; 701 oss << setw(6) << "Scan" 702 << setw(12) << "Source" 703 << setw(21) << "Time" 704 << setw(11) << "Integration" << endl; 639 705 for (uInt i=0; i< scans.nrow();i++) { 640 706 scans.getScalar(i,current); … … 642 708 srcs.getScalar(i,name); 643 709 previous = current; 644 Double t = getInterval(); 645 String unit("sec"); 646 if (t/60.0 > 1.0) { 647 t/=60.0;unit = "min"; 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"; 648 716 } 649 cout << count << "\t" 650 << name << "\t" 651 << getTime() << "\t" 652 << setprecision(2) << setiosflags(std::ios_base::fixed) 653 << t << " " << unit << endl 654 << endl; 717 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; 655 720 count++; 721 } else { 722 integ++; 656 723 } 657 724 } 658 cout << "Table contains " << table_.nrow() << " integration(s)." << endl; 659 cout << "in " << count << " scan(s)." << endl; 725 oss << endl; 726 oss << "Table contains " << table_.nrow() << " integration(s)." << endl; 727 oss << "in " << count << " scan(s)." << endl; 728 oss << "--------------------------------------------------"; 729 return String(oss); 660 730 } 661 731 … … 682 752 /* 683 753 void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) { 684 754 685 755 std::vector<int>::iterator it; 686 756 ArrayAccessor<uChar, Axis<2> > j(flags_); … … 689 759 for (ArrayAccessor<uChar, Axis<0> > i(j); i != i.end(); ++i) { 690 760 for (ArrayAccessor<uChar, Axis<1> > ii(i); ii != ii.end(); ++ii) { 691 for (ArrayAccessor<uChar, Axis<3> > iii(ii); 692 iii != iii.end(); ++iii) { 693 (*iii) = 694 761 for (ArrayAccessor<uChar, Axis<3> > iii(ii); 762 iii != iii.end(); ++iii) { 763 (*iii) = 764 } 695 765 } 696 766 } 697 767 } 698 768 699 769 } 700 770 */ 771 void SDMemTable::flag(int whichRow) { 772 ArrayColumn<uChar> spec(table_, "FLAGTRA"); 773 Array<uChar> arr; 774 spec.get(whichRow, arr); 775 776 ArrayAccessor<uChar, Axis<0> > aa0(arr); 777 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam 778 ArrayAccessor<uChar, Axis<1> > aa1(aa0); 779 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF 780 ArrayAccessor<uChar, Axis<2> > aa2(aa1); 781 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol 782 783 for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) { 784 (*i) = uChar(True); 785 } 786 787 spec.put(whichRow, arr); 788 }
Note:
See TracChangeset
for help on using the changeset viewer.