Changeset 286
- Timestamp:
- 01/24/05 17:53:53 (20 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMemTable.cc
r281 r286 41 41 #include <casa/Arrays/ArrayAccessor.h> 42 42 #include <casa/Arrays/Vector.h> 43 #include <casa/Quanta/MVAngle.h> 43 44 44 45 #include <tables/Tables/TableParse.h> … … 364 365 } 365 366 367 366 368 std::vector<double> SDMemTable::getAbcissa(Int whichRow) const 367 369 { 368 std::vector<double> absc(nChan()); 369 Vector<Double> absc1(nChan()); 370 indgen(absc1); 371 ROArrayColumn<uInt> fid(table_, "FREQID"); 372 Vector<uInt> v; 373 fid.get(whichRow, v); 374 uInt specidx = v(IFSel_); 375 SpectralCoordinate spc = getCoordinate(specidx); 376 Table t = table_.keywordSet().asTable("FREQUENCIES"); 377 378 MDirection direct = getDirection(whichRow); 379 380 ROScalarColumn<Double> tme(table_, "TIME"); 381 Double obstime; 382 tme.get(whichRow,obstime); 383 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d")))); 384 MEpoch::Types met = getTimeReference(); 385 MEpoch epoch(tm2, met); 386 387 Vector<Double> antpos; 388 table_.keywordSet().get("AntennaPosition", antpos); 389 MVPosition mvpos(antpos(0),antpos(1),antpos(2)); 390 MPosition pos(mvpos); 391 String sunit; 392 t.keywordSet().get("UNIT",sunit); 393 if (sunit == "") sunit = "pixel"; 394 Unit u(sunit); 395 String frm; 396 t.keywordSet().get("REFFRAME",frm); 397 if (frm == "") frm = "TOPO"; 398 String dpl; 399 t.keywordSet().get("DOPPLER",dpl); 400 if (dpl == "") dpl = "RADIO"; 401 MFrequency::Types mtype; 402 if (!MFrequency::getType(mtype, frm)) { 403 cout << "Frequency type unknown assuming TOPO" << endl; // SHould never happen 404 mtype = MFrequency::TOPO; 405 } 406 MDoppler::Types dtype; 407 if (!MDoppler::getType(dtype, dpl)) { 408 cout << "Doppler type unknown assuming RADIO" << endl; // SHould never happen 409 dtype = MDoppler::RADIO; 410 } 411 412 if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) { 413 throw(AipsError("Couldn't convert frequency frame.")); 414 } 415 416 if ( u == Unit("km/s") ) { 417 Vector<Double> rstf; 418 t.keywordSet().get("RESTFREQS",rstf); 419 if (rstf.nelements() > 0) { 420 if (rstf.nelements() >= nIF()) 421 spc.selectRestFrequency(uInt(IFSel_)); 422 spc.setVelocity(u.getName(),dtype); 423 Vector<Double> wrld; 424 spc.pixelToVelocity(wrld,absc1); 425 std::vector<double>::iterator it; 426 uInt i = 0; 427 for (it = absc.begin(); it != absc.end(); ++it) { 428 (*it) = wrld[i]; 429 i++; 430 } 431 } 432 } else if (u == Unit("Hz")) { 433 Vector<String> wau(1); wau = u.getName(); 434 spc.setWorldAxisUnits(wau); 435 std::vector<double>::iterator it; 436 Double tmp; 437 uInt i = 0; 438 for (it = absc.begin(); it != absc.end(); ++it) { 439 spc.toWorld(tmp,absc1[i]); 440 (*it) = tmp; 441 i++; 442 } 443 444 } else { 445 // assume channels/pixels 446 std::vector<double>::iterator it; 447 uInt i=0; 448 for (it = absc.begin(); it != absc.end(); ++it) { 449 (*it) = Double(i++); 450 } 451 } 452 return absc; 453 } 454 455 std::string SDMemTable::getAbcissaString(Int whichRow) const 456 { 457 ROArrayColumn<uInt> fid(table_, "FREQID"); 370 std::vector<double> abc(nChan()); 371 372 // Get header units keyword 373 458 374 Table t = table_.keywordSet().asTable("FREQUENCIES"); 459 375 String sunit; … … 461 377 if (sunit == "") sunit = "pixel"; 462 378 Unit u(sunit); 379 380 // Easy if just wanting pixels 381 382 if (sunit==String("pixel")) { 383 // assume channels/pixels 384 std::vector<double>::iterator it; 385 uInt i=0; 386 for (it = abc.begin(); it != abc.end(); ++it) { 387 (*it) = Double(i++); 388 } 389 // 390 return abc; 391 } 392 393 // Continue with km/s or Hz. Get FreqID 394 395 ROArrayColumn<uInt> fid(table_, "FREQID"); 463 396 Vector<uInt> v; 464 397 fid.get(whichRow, v); 465 398 uInt specidx = v(IFSel_); 466 SpectralCoordinate spc = getCoordinate(specidx); 467 String frm; 468 t.keywordSet().get("REFFRAME",frm); 469 // 470 MFrequency::Types mtype; 471 if (!MFrequency::getType(mtype, frm)) { 472 cout << "Frequency type unknown assuming TOPO" << endl; 473 mtype = MFrequency::TOPO; 474 } 475 spc.setFrequencySystem(mtype); 476 // 477 String dpl; 478 t.keywordSet().get("DOPPLER",dpl); 479 MDoppler::Types dtype; 480 MDoppler::getType(dtype, dpl); // Can't fail 399 400 // Get SpectralCoordinate, set reference frame conversion, 401 // velocity conversion, and rest freq state 402 403 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow); 404 // 405 Vector<Double> pixel(nChan()); 406 indgen(pixel); 407 // 408 if (u == Unit("km/s")) { 409 Vector<Double> world; 410 spc.pixelToVelocity(world,pixel); 411 std::vector<double>::iterator it; 412 uInt i = 0; 413 for (it = abc.begin(); it != abc.end(); ++it) { 414 (*it) = world[i]; 415 i++; 416 } 417 } else if (u == Unit("Hz")) { 418 419 // Set world axis units 420 421 Vector<String> wau(1); wau = u.getName(); 422 spc.setWorldAxisUnits(wau); 423 // 424 std::vector<double>::iterator it; 425 Double tmp; 426 uInt i = 0; 427 for (it = abc.begin(); it != abc.end(); ++it) { 428 spc.toWorld(tmp,pixel[i]); 429 (*it) = tmp; 430 i++; 431 } 432 } 433 return abc; 434 } 435 436 std::string SDMemTable::getAbcissaString(Int whichRow) const 437 { 438 ROArrayColumn<uInt> fid(table_, "FREQID"); 439 Table t = table_.keywordSet().asTable("FREQUENCIES"); 440 // 441 String sunit; 442 t.keywordSet().get("UNIT",sunit); 443 if (sunit == "") sunit = "pixel"; 444 Unit u(sunit); 445 // 446 Vector<uInt> v; 447 fid.get(whichRow, v); 448 uInt specidx = v(IFSel_); 449 450 // Get SpectralCoordinate, with frame, velocity, rest freq state set 451 452 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow); 481 453 // 482 454 String s = "Channel"; 483 455 if (u == Unit("km/s")) { 484 spc.setVelocity(u.getName(), dtype);485 456 s = CoordinateUtil::axisLabel(spc,0,True,True,True); 486 457 } else if (u == Unit("Hz")) { 487 458 Vector<String> wau(1);wau = u.getName(); 488 459 spc.setWorldAxisUnits(wau); 489 s = CoordinateUtil::axisLabel(spc); 460 // 461 s = CoordinateUtil::axisLabel(spc,0,True,True,False); 490 462 } 491 463 return s; … … 639 611 Quantum<Double> lon(wpos[0],Unit(String("rad"))); 640 612 Quantum<Double> lat(wpos[1],Unit(String("rad"))); 641 MDirection direct(lon, lat, mdr); 642 return direct; 643 } 644 645 SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const 613 return MDirection(lon, lat, mdr); 614 } 615 616 MEpoch SDMemTable::getEpoch (Int whichRow) const 617 { 618 MEpoch::Types met = getTimeReference(); 619 // 620 ROScalarColumn<Double> tme(table_, "TIME"); 621 Double obstime; 622 tme.get(whichRow,obstime); 623 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d")))); 624 return MEpoch(tm2, met); 625 } 626 627 MPosition SDMemTable::getAntennaPosition () const 628 { 629 Vector<Double> antpos; 630 table_.keywordSet().get("AntennaPosition", antpos); 631 MVPosition mvpos(antpos(0),antpos(1),antpos(2)); 632 return MPosition(mvpos); 633 } 634 635 636 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx) const 646 637 { 647 638 648 639 Table t = table_.keywordSet().asTable("FREQUENCIES"); 649 640 if (whichIdx > t.nrow() ) { 650 throw(AipsError("SDMemTable::get Coordinate - whichIdx out of range"));641 throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range")); 651 642 } 652 643 653 644 Double rp,rv,inc; 654 645 String rf; 655 Vector<Double> vec;656 646 ROScalarColumn<Double> rpc(t, "REFPIX"); 657 647 ROScalarColumn<Double> rvc(t, "REFVAL"); 658 648 ROScalarColumn<Double> incc(t, "INCREMENT"); 659 t.keywordSet().get("RESTFREQS",vec);660 649 t.keywordSet().get("BASEREFFRAME",rf); 650 651 // Create SpectralCoordinate (units Hz) 661 652 662 653 MFrequency::Types mft; … … 668 659 rvc.get(whichIdx, rv); 669 660 incc.get(whichIdx, inc); 661 // 670 662 SpectralCoordinate spec(mft,rv,inc,rp); 671 if (vec.nelements() > 0) 663 // 664 return spec; 665 } 666 667 668 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx, uInt whichRow) const 669 { 670 // Create basic SC 671 672 SpectralCoordinate spec = getSpectralCoordinate (whichIdx); 673 // 674 Table t = table_.keywordSet().asTable("FREQUENCIES"); 675 676 // Set rest frequencies 677 678 Vector<Double> vec; 679 t.keywordSet().get("RESTFREQS",vec); 680 if (vec.nelements() > 0) { 672 681 spec.setRestFrequencies(vec); 682 683 // Select rest freq 684 685 if (vec.nelements() >= nIF()) { 686 spec.selectRestFrequency(uInt(IFSel_)); 687 } 688 } 689 690 // Set up frame conversion layer 691 692 String frm; 693 t.keywordSet().get("REFFRAME",frm); 694 if (frm == "") frm = "TOPO"; 695 MFrequency::Types mtype; 696 if (!MFrequency::getType(mtype, frm)) { 697 cout << "Frequency type unknown assuming TOPO" << endl; // SHould never happen 698 mtype = MFrequency::TOPO; 699 } 700 701 // Set reference frame conversion (requires row) 702 703 MDirection direct = getDirection(whichRow); 704 MEpoch epoch = getEpoch(whichRow); 705 MPosition pos = getAntennaPosition(); 706 if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) { 707 throw(AipsError("Couldn't convert frequency frame.")); 708 } 709 710 // Now velocity conversion if appropriate 711 712 String unitStr; 713 t.keywordSet().get("UNIT",unitStr); 714 // 715 String dpl; 716 t.keywordSet().get("DOPPLER",dpl); 717 MDoppler::Types dtype; 718 MDoppler::getType(dtype, dpl); 719 720 // Only set velocity unit if non-blank and non-Hz 721 722 if (!unitStr.empty()) { 723 Unit unitU(unitStr); 724 if (unitU==Unit("Hz")) { 725 } else { 726 spec.setVelocity(unitStr, dtype); 727 } 728 } 729 // 673 730 return spec; 674 731 } 732 675 733 676 734 Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, -
trunk/src/SDMemTable.h
r281 r286 97 97 std::string getTime(casa::Int whichRow=0, 98 98 casa::Bool showDate=casa::False) const ; 99 casa::MEpoch getEpoch(casa::Int whichRow=0) const; 100 casa::MDirection getDirection(casa::Int whichRow=0, 101 casa::Bool refBeam=casa::False) const; 102 // 99 103 std::string getSourceName(casa::Int whichRow=0) const; 100 104 double getInterval(casa::Int whichRow=0) const; … … 164 168 casa::False) const; 165 169 166 casa::SpectralCoordinate getCoordinate(casa::uInt whichIdx) const; 170 // Return SC, setting only the basic construction state (i.e. 171 // no conversion or velocity or rest frequency state) 172 casa::SpectralCoordinate getSpectralCoordinate(casa::uInt whichIdx) const; 173 174 // Return SC. Set velocity conversion state (unit,doppler), 175 // set rest frequencies. If row number given (>-0), also set 176 // frame conversion layer (needs direction & time which require row) 177 casa::SpectralCoordinate getSpectralCoordinate(casa::uInt whichIdx, casa::uInt row) const; 178 179 // Set just the reference value, pixel and increment into the table 180 // No other state is extracted. 167 181 casa::Bool setCoordinate(const casa::SpectralCoordinate& speccord, 168 182 casa::uInt whichIdx); … … 170 184 casa::Int nCoordinates() const; 171 185 172 173 186 std::vector<double> getAbcissa(int whichRow=0) const; 174 187 std::string getAbcissaString(casa::Int whichRow=0) const; 175 188 176 // Get MDirection for this row 177 casa::MDirection getDirection(casa::Int whichRow=0, 178 casa::Bool refBeam=casa::False) const; 179 180 // Get gloabl Direction reference 189 // Get global reference types 181 190 casa::MDirection::Types getDirectionReference() const; 182 183 // Get global Time reference184 191 casa::MEpoch::Types getTimeReference() const; 192 193 // Get global antenna position 194 casa::MPosition getAntennaPosition() const; 185 195 186 196 // Helper function to check instrument (antenna) name and give enum
Note:
See TracChangeset
for help on using the changeset viewer.