Changeset 455
- Timestamp:
- 02/16/05 12:29:26 (20 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMemTable.cc
r447 r455 40 40 #include <casa/Arrays/ArrayLogical.h> 41 41 #include <casa/Arrays/ArrayAccessor.h> 42 #include <casa/Arrays/VectorSTLIterator.h> 42 43 #include <casa/Arrays/Vector.h> 43 44 #include <casa/BasicMath/Math.h> … … 113 114 polSel_(0) 114 115 { 115 cout << exprs << endl;116 116 Table t = tableCommand(exprs,tab); 117 117 if (t.nrow() == 0) … … 160 160 TableDesc td("", "1", TableDesc::Scratch); 161 161 td.comment() = "A SDMemTable"; 162 // 162 163 163 td.addColumn(ScalarColumnDesc<Double>("TIME")); 164 164 td.addColumn(ScalarColumnDesc<String>("SRCNAME")); … … 180 180 td.addColumn(ScalarColumnDesc<Int>("REFBEAM")); 181 181 td.addColumn(ArrayColumnDesc<String>("HISTORY")); 182 td.addColumn(ArrayColumnDesc<Int>("FITID")); 183 182 184 183 185 // Now create Table SetUp from the description. … … 185 187 SetupNewTable aNewTab("dummy", td, Table::New); 186 188 187 // Bind the Stokes Virtual machine to the STOKES column 188 // Because we don't know how many polarizations will 189 // be in the data at this point, we must bind the 190 // Virtual Engine regardless. The STOKES column won't 191 // be accessed if not appropriate (nPol=4) 189 // Bind the Stokes Virtual machine to the STOKES column Because we 190 // don't know how many polarizations will be in the data at this 191 // point, we must bind the Virtual Engine regardless. The STOKES 192 // column won't be accessed if not appropriate (nPol=4) 192 193 193 194 SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA")); 194 195 aNewTab.bindColumn ("STOKES", stokesEngine); 195 196 196 // Create Table 197 197 // Create Table 198 198 table_ = Table(aNewTab, Table::Memory, 0); 199 } 200 199 // add subtable 200 TableDesc tdf("", "1", TableDesc::Scratch); 201 tdf.addColumn(ArrayColumnDesc<String>("FUNCTIONS")); 202 tdf.addColumn(ArrayColumnDesc<Int>("COMPONENTS")); 203 tdf.addColumn(ArrayColumnDesc<Double>("PARAMETERS")); 204 tdf.addColumn(ArrayColumnDesc<Bool>("PARMASK")); 205 SetupNewTable fittab("fits", tdf, Table::New); 206 Table fitTable(fittab, Table::Memory); 207 table_.rwKeywordSet().defineTable("FITS", fitTable); 208 209 210 } 201 211 202 212 void SDMemTable::attach() … … 221 231 rbeamCol_.attach(table_, "REFBEAM"); 222 232 histCol_.attach(table_, "HISTORY"); 233 fitCol_.attach(table_,"FITID"); 223 234 } 224 235 … … 311 322 312 323 std::vector<bool> mask; 313 // 324 314 325 Array<uChar> arr; 315 326 flagsCol_.get(whichRow, arr); 316 // 327 317 328 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); 318 329 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam … … 347 358 Array<Float> arr; 348 359 specCol_.get(whichRow, arr); 349 return getFloatSpectrum 350 } 351 352 std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol, Float paOffset) const353 // 354 // Gets355 // doPol=False : I,Q,U,V356 // doPol=True : I,P,PA,V ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U)357 //360 return getFloatSpectrum(arr); 361 } 362 363 std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol, 364 Float paOffset) const 365 // Gets 366 // doPol=False : I,Q,U,V 367 // doPol=True : I,P,PA,V ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U) 368 // 358 369 { 359 370 AlwaysAssert(asap::nAxes==4,AipsError); … … 363 374 Array<Float> arr; 364 375 stokesCol_.get(whichRow, arr); 365 // 376 366 377 if (doPol && (polSel_==1 || polSel_==2)) { // Q,U --> P, P.A. 367 378 368 // Set current cursor location 369 379 // Set current cursor location 370 380 const IPosition& shape = arr.shape(); 371 381 IPosition start, end; 372 382 setCursorSlice (start, end, shape); 373 383 374 // Get Q and U slices375 376 Array<Float> Q = SDPolUtil::getStokesSlice 377 Array<Float> U = SDPolUtil::getStokesSlice 378 379 // Compute output384 // Get Q and U slices 385 386 Array<Float> Q = SDPolUtil::getStokesSlice(arr,start,end,"Q"); 387 Array<Float> U = SDPolUtil::getStokesSlice(arr,start,end,"U"); 388 389 // Compute output 380 390 381 391 Array<Float> out; … … 386 396 } 387 397 388 // Copy to output398 // Copy to output 389 399 390 400 IPosition vecShape(1,shape(asap::ChanAxis)); 391 401 Vector<Float> outV = out.reform(vecShape); 392 return convertVector(outV); 402 std::vector<float> stlout; 403 outV.tovector(stlout); 404 return stlout; 405 393 406 } else { 394 407 395 // Selects at the cursor location 396 397 return getFloatSpectrum (arr); 398 } 399 } 400 401 std::vector<float> SDMemTable::getCircularSpectrum(Int whichRow, Bool doRR) const 402 // 403 // Gets 404 // RR = I + V 405 // LL = I - V 406 // 408 // Selects at the cursor location 409 return getFloatSpectrum(arr); 410 } 411 } 412 413 std::vector<float> SDMemTable::getCircularSpectrum(Int whichRow, 414 Bool doRR) const 415 // Gets 416 // RR = I + V 417 // LL = I - V 407 418 { 408 419 AlwaysAssert(asap::nAxes==4,AipsError); … … 413 424 stokesCol_.get(whichRow, arr); 414 425 415 // Set current cursor location426 // Set current cursor location 416 427 417 428 const IPosition& shape = arr.shape(); 418 429 IPosition start, end; 419 setCursorSlice 420 421 // Get I and V slices422 423 Array<Float> I = SDPolUtil::getStokesSlice 424 Array<Float> V = SDPolUtil::getStokesSlice 425 426 // Compute output427 428 Array<Float> out = SDPolUtil::circularPolarizationFromStokes 429 430 // Copy to output430 setCursorSlice(start, end, shape); 431 432 // Get I and V slices 433 434 Array<Float> I = SDPolUtil::getStokesSlice(arr,start,end,"I"); 435 Array<Float> V = SDPolUtil::getStokesSlice(arr,start,end,"V"); 436 437 // Compute output 438 439 Array<Float> out = SDPolUtil::circularPolarizationFromStokes(I, V, doRR); 440 441 // Copy to output 431 442 432 443 IPosition vecShape(1,shape(asap::ChanAxis)); 433 444 Vector<Float> outV = out.reform(vecShape); 434 return convertVector(outV); 445 std::vector<float> stlout; 446 outV.tovector(stlout); 447 448 return stlout; 435 449 } 436 450 … … 464 478 dpl = theinfo[2]; // Doppler 465 479 brfrm = theinfo[3]; // Base frame 466 // 480 467 481 Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); 468 // 482 469 483 Vector<Double> rstf; 470 484 t.keywordSet().get("RESTFREQS",rstf); 471 // 485 472 486 Bool canDo = True; 473 487 Unit u1("km/s");Unit u2("Hz"); … … 482 496 } 483 497 t.rwKeywordSet().define("UNIT", un); 484 // 498 485 499 MFrequency::Types mdr; 486 500 if (!MFrequency::getType(mdr, rfrm)) { … … 493 507 t.rwKeywordSet().define("REFFRAME",rfrm); 494 508 } 495 // 509 496 510 MDoppler::Types dtype; 497 511 dpl.upcase(); … … 501 515 t.rwKeywordSet().define("DOPPLER",dpl); 502 516 } 503 // 517 504 518 if (!MFrequency::getType(mdr, brfrm)) { 505 519 Int a,b;const uInt* c; … … 517 531 std::vector<double> abc(nChan()); 518 532 519 // Get header units keyword 520 533 // Get header units keyword 521 534 Table t = table_.keywordSet().asTable("FREQUENCIES"); 522 535 String sunit; … … 525 538 Unit u(sunit); 526 539 527 // Easy if just wanting pixels 528 540 // Easy if just wanting pixels 529 541 if (sunit==String("pixel")) { 530 542 // assume channels/pixels … … 534 546 (*it) = Double(i++); 535 547 } 536 //537 548 return abc; 538 549 } 539 550 540 // Continue with km/s or Hz. Get FreqIDs 541 551 // Continue with km/s or Hz. Get FreqIDs 542 552 Vector<uInt> freqIDs; 543 553 freqidCol_.get(whichRow, freqIDs); … … 546 556 uInt restFreqID = freqIDs(IFSel_); 547 557 548 // Get SpectralCoordinate, set reference frame conversion,549 // velocity conversion, and rest freq state558 // Get SpectralCoordinate, set reference frame conversion, 559 // velocity conversion, and rest freq state 550 560 551 561 SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow); 552 562 Vector<Double> pixel(nChan()); 553 563 indgen(pixel); 554 // 564 555 565 if (u == Unit("km/s")) { 556 566 Vector<Double> world; … … 564 574 } else if (u == Unit("Hz")) { 565 575 566 // Set world axis units 567 576 // Set world axis units 568 577 Vector<String> wau(1); wau = u.getName(); 569 578 spc.setWorldAxisUnits(wau); 570 // 579 571 580 std::vector<double>::iterator it; 572 581 Double tmp; … … 584 593 { 585 594 Table t = table_.keywordSet().asTable("FREQUENCIES"); 586 // 595 587 596 String sunit; 588 597 t.keywordSet().get("UNIT",sunit); 589 598 if (sunit == "") sunit = "pixel"; 590 599 Unit u(sunit); 591 // 600 592 601 Vector<uInt> freqIDs; 593 602 freqidCol_.get(whichRow, freqIDs); … … 596 605 uInt restFreqID = freqIDs(IFSel_); 597 606 598 // Get SpectralCoordinate, with frame, velocity, rest freq state set 599 607 // Get SpectralCoordinate, with frame, velocity, rest freq state set 600 608 SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow); 601 // 609 602 610 String s = "Channel"; 603 611 if (u == Unit("km/s")) { … … 606 614 Vector<String> wau(1);wau = u.getName(); 607 615 spc.setWorldAxisUnits(wau); 608 // 616 609 617 s = CoordinateUtil::axisLabel(spc,0,True,True,False); 610 618 } … … 616 624 Array<Float> arr; 617 625 specCol_.get(whichRow, arr); 618 if (spectrum.size() != arr.shape()( 3)) {626 if (spectrum.size() != arr.shape()(asap::ChanAxis)) { 619 627 throw(AipsError("Attempting to set spectrum with incorrect length.")); 620 628 } 621 629 622 // Setup accessors 623 630 // Setup accessors 624 631 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); 625 632 aa0.reset(aa0.begin(uInt(beamSel_))); // Beam selection … … 629 636 aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection 630 637 631 // Iterate 632 638 // Iterate 633 639 std::vector<float>::iterator it = spectrum.begin(); 634 640 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { … … 644 650 specCol_.get(whichRow, arr); 645 651 646 // Iterate and extract 647 652 // Iterate and extract 648 653 spectrum.resize(arr.shape()(3)); 649 654 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); … … 653 658 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); 654 659 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol 655 // 660 656 661 ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum); 657 662 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { … … 696 701 */ 697 702 698 MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, Bool toStokes) const 699 { 700 701 // Get flags 702 703 MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, 704 Bool toStokes) const 705 { 706 // Get flags 703 707 Array<uChar> farr; 704 708 flagsCol_.get(whichRow, farr); 705 709 706 // Get data and convert mask to Bool 707 710 // Get data and convert mask to Bool 708 711 Array<Float> arr; 709 712 Array<Bool> mask; 710 713 if (toStokes) { 711 714 stokesCol_.get(whichRow, arr); 712 // 715 713 716 Array<Bool> tMask(farr.shape()); 714 717 convertArray(tMask, farr); … … 719 722 convertArray(mask, farr); 720 723 } 721 // 724 722 725 return MaskedArray<Float>(arr,!mask); 723 726 } … … 728 731 tsCol_.get(whichRow, arr); 729 732 Float out; 730 // 733 731 734 IPosition ip(arr.shape()); 732 735 ip(asap::BeamAxis) = beamSel_; … … 734 737 ip(asap::PolAxis) = polSel_; 735 738 ip(asap::ChanAxis)=0; // First channel only 736 // 739 737 740 out = arr(ip); 738 741 return out; … … 762 765 { 763 766 MEpoch::Types met = getTimeReference(); 764 // 767 765 768 Double obstime; 766 769 timeCol_.get(whichRow,obstime); … … 793 796 t.keywordSet().get("BASEREFFRAME",rf); 794 797 795 // Create SpectralCoordinate (units Hz) 796 798 // Create SpectralCoordinate (units Hz) 797 799 MFrequency::Types mft; 798 800 if (!MFrequency::getType(mft, rf)) { … … 803 805 rvc.get(freqID, rv); 804 806 incc.get(freqID, inc); 805 // 807 806 808 SpectralCoordinate spec(mft,rv,inc,rp); 807 //808 809 return spec; 809 810 } 810 811 811 812 812 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, uInt restFreqID, 813 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, 814 uInt restFreqID, 813 815 uInt whichRow) const 814 816 { 815 816 // Create basic SC 817 817 818 // Create basic SC 818 819 SpectralCoordinate spec = getSpectralCoordinate (freqID); 819 // 820 820 821 Table t = table_.keywordSet().asTable("FREQUENCIES"); 821 822 822 // Set rest frequency 823 823 // Set rest frequency 824 824 Vector<Double> restFreqIDs; 825 825 t.keywordSet().get("RESTFREQS",restFreqIDs); 826 if (restFreqID < restFreqIDs.nelements()) { // SHould always be true826 if (restFreqID < restFreqIDs.nelements()) { // Should always be true 827 827 spec.setRestFrequency(restFreqIDs(restFreqID),True); 828 828 } 829 829 830 // Set up frame conversion layer 831 830 // Set up frame conversion layer 832 831 String frm; 833 832 t.keywordSet().get("REFFRAME",frm); … … 835 834 MFrequency::Types mtype; 836 835 if (!MFrequency::getType(mtype, frm)) { 837 cerr << "Frequency type unknown assuming TOPO" << endl; // SHould never happen 836 // Should never happen 837 cerr << "Frequency type unknown assuming TOPO" << endl; 838 838 mtype = MFrequency::TOPO; 839 839 } 840 840 841 // Set reference frame conversion (requires row) 842 841 // Set reference frame conversion (requires row) 843 842 MDirection dir = getDirection(whichRow); 844 843 MEpoch epoch = getEpoch(whichRow); 845 844 MPosition pos = getAntennaPosition(); 846 // 845 847 846 if (!spec.setReferenceConversion(mtype,epoch,pos,dir)) { 848 847 throw(AipsError("Couldn't convert frequency frame.")); 849 848 } 850 849 851 // Now velocity conversion if appropriate 852 850 // Now velocity conversion if appropriate 853 851 String unitStr; 854 852 t.keywordSet().get("UNIT",unitStr); 855 // 853 856 854 String dpl; 857 855 t.keywordSet().get("DOPPLER",dpl); … … 859 857 MDoppler::getType(dtype, dpl); 860 858 861 // Only set velocity unit if non-blank and non-Hz 862 859 // Only set velocity unit if non-blank and non-Hz 863 860 if (!unitStr.empty()) { 864 861 Unit unitU(unitStr); … … 868 865 } 869 866 } 870 // 867 871 868 return spec; 872 869 } … … 937 934 rfvec = q.getValue("Hz"); 938 935 aTable.rwKeywordSet().define("RESTFREQS", rfvec); 939 table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable); 940 return True; 936 table_.rwKeywordSet().defineTable("FREQUENCIES", aTable); 937 return true; 938 } 939 940 bool SDMemTable::putSDFitTable(const SDFitTable& sdft) 941 { 942 TableDesc td("", "1", TableDesc::Scratch); 943 td.addColumn(ArrayColumnDesc<String>("FUNCTIONS")); 944 td.addColumn(ArrayColumnDesc<Int>("COMPONENTS")); 945 td.addColumn(ArrayColumnDesc<Double>("PARAMETERS")); 946 td.addColumn(ArrayColumnDesc<Bool>("PARMASK")); 947 SetupNewTable aNewTab("fits", td, Table::New); 948 Table aTable(aNewTab, Table::Memory); 949 ArrayColumn<String> sc0(aTable, "FUNCTIONS"); 950 ArrayColumn<Int> sc1(aTable, "COMPONENTS"); 951 ArrayColumn<Double> sc2(aTable, "PARAMETERS"); 952 ArrayColumn<Bool> sc3(aTable, "PARMASK"); 953 for (uInt i; i<sdft.length(); ++i) { 954 const Vector<Double>& parms = sdft.getFitParameters(i); 955 const Vector<Bool>& parmask = sdft.getFitParameterMask(i); 956 const Vector<String>& funcs = sdft.getFitFunctions(i); 957 const Vector<Int>& comps = sdft.getFitComponents(i); 958 sc0.put(i,funcs); 959 sc1.put(i,comps); 960 sc3.put(i,parmask); 961 sc2.put(i,parms); 962 } 963 table_.rwKeywordSet().defineTable("FITS", aTable); 964 return true; 965 } 966 967 SDFitTable SDMemTable::getSDFitTable() const 968 { 969 const Table& t = table_.keywordSet().asTable("FITS"); 970 Vector<Double> parms; 971 Vector<Bool> parmask; 972 Vector<String> funcs; 973 Vector<Int> comps; 974 ROArrayColumn<Double> parmsCol(t, "PARAMETERS"); 975 ROArrayColumn<Bool> parmaskCol(t, "PARMASK"); 976 ROArrayColumn<Int> compsCol(t, "COMPONENTS"); 977 ROArrayColumn<String> funcsCol(t, "FUNCTIONS"); 978 uInt n = t.nrow(); 979 SDFitTable sdft(n); 980 for (uInt i=0; i<n; ++i) { 981 parmaskCol.get(i, parmask); 982 sdft.putFitParameterMask(i, parmask); 983 parmsCol.get(i, parms); 984 sdft.putFitParameters(i, parms); 985 funcsCol.get(i, funcs); 986 sdft.putFitFunctions(i, funcs); 987 compsCol.get(i, comps); 988 sdft.putFitComponents(i, comps); 989 } 990 return sdft; 991 } 992 993 994 void SDMemTable::addFit(uInt whichRow, 995 const Vector<Double>& p, const Vector<Bool>& m, 996 const Vector<String>& f, const Vector<Int>& c) 997 { 998 if (whichRow >= nRow()) { 999 throw(AipsError("Specified row out of range")); 1000 } 1001 Table t = table_.keywordSet().asTable("FITS"); 1002 uInt nrow = t.nrow(); 1003 t.addRow(); 1004 ArrayColumn<Double> parmsCol(t, "PARAMETERS"); 1005 ArrayColumn<Bool> parmaskCol(t, "PARMASK"); 1006 ArrayColumn<Int> compsCol(t, "COMPONENTS"); 1007 ArrayColumn<String> funcsCol(t, "FUNCTIONS"); 1008 parmsCol.put(nrow, p); 1009 parmaskCol.put(nrow, m); 1010 compsCol.put(nrow, c); 1011 funcsCol.put(nrow, f); 1012 1013 Array<Int> fitarr; 1014 fitCol_.get(whichRow, fitarr); 1015 1016 Array<Int> newarr; // The new Array containing the fitid 1017 Int pos =-1; // The fitid position in the array 1018 if ( fitarr.nelements() == 0 ) { // no fits at all in this row 1019 Array<Int> arr(IPosition(4,nBeam(),nIF(),nPol(),1)); 1020 arr = -1; 1021 newarr.reference(arr); 1022 pos = 0; 1023 } else { 1024 IPosition shp = fitarr.shape(); 1025 IPosition start(4, beamSel_, IFSel_, polSel_,0); 1026 IPosition end(4, beamSel_, IFSel_, polSel_, shp[3]-1); 1027 // reform the output array slice to be of dim=1 1028 Array<Int> tmp = (fitarr(start, end)).reform(IPosition(1,shp[3])); 1029 const Vector<Int>& fits = tmp; 1030 VectorSTLIterator<Int> it(fits); 1031 Int i = 0; 1032 while (it != fits.end()) { 1033 if (*it == -1) { 1034 pos = i; 1035 break; 1036 } 1037 ++i; 1038 ++it; 1039 }; 1040 } 1041 if (pos == -1) { 1042 mathutil::extendLastArrayAxis(newarr,fitarr, -1); 1043 pos = fitarr.shape()[3]; // the new element position 1044 } else { 1045 if (fitarr.nelements() > 0) 1046 newarr = fitarr; 1047 } 1048 newarr(IPosition(4, beamSel_, IFSel_, polSel_, pos)) = Int(nrow); 1049 fitCol_.put(whichRow, newarr); 1050 941 1051 } 942 1052 … … 946 1056 SDFrequencyTable sdft; 947 1057 948 // Add refpix/refval/incr. What are the units ? Hz I suppose 949 // but it's nowhere described... 950 1058 // Add refpix/refval/incr. What are the units ? Hz I suppose 1059 // but it's nowhere described... 951 1060 Vector<Double> refPix, refVal, incr; 952 1061 ScalarColumn<Double> refPixCol(t, "REFPIX"); … … 956 1065 refVal = refValCol.getColumn(); 957 1066 incr = incrCol.getColumn(); 958 // 1067 959 1068 uInt n = refPix.nelements(); 960 1069 for (uInt i=0; i<n; i++) { … … 962 1071 } 963 1072 964 // Frequency reference frame. I don't know if this 965 // is the correct frame. It might be 'REFFRAME' 966 // rather than 'BASEREFFRAME' ? 967 1073 // Frequency reference frame. I don't know if this 1074 // is the correct frame. It might be 'REFFRAME' 1075 // rather than 'BASEREFFRAME' ? 968 1076 String baseFrame; 969 1077 t.keywordSet().get("BASEREFFRAME",baseFrame); 970 1078 sdft.setRefFrame(baseFrame); 971 1079 972 // Equinox 973 1080 // Equinox 974 1081 Float equinox; 975 1082 t.keywordSet().get("EQUINOX", equinox); 976 1083 sdft.setEquinox(equinox); 977 1084 978 // Rest Frequency 979 1085 // Rest Frequency 980 1086 Vector<Double> restFreqs; 981 1087 t.keywordSet().get("RESTFREQS", restFreqs); … … 984 1090 } 985 1091 sdft.setRestFrequencyUnit(String("Hz")); 986 // 1092 987 1093 return sdft; 988 1094 } … … 992 1098 uInt rno = table_.nrow(); 993 1099 table_.addRow(); 994 // 1100 995 1101 timeCol_.put(rno, sdc.timestamp); 996 1102 srcnCol_.put(rno, sdc.sourcename); … … 1011 1117 paraCol_.put(rno, sdc.parangle); 1012 1118 histCol_.put(rno, sdc.getHistory()); 1013 // 1119 fitCol_.put(rno, sdc.getFitMap()); 1120 1014 1121 return true; 1015 1122 } … … 1031 1138 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1]; 1032 1139 tcaltCol_.get(whichRow, sdc.tcaltime); 1033 // 1140 1034 1141 Array<Float> spectrum; 1035 1142 Array<Float> tsys; … … 1038 1145 Array<Double> direction; 1039 1146 Vector<String> histo; 1040 // 1147 Array<Int> fits; 1148 1041 1149 specCol_.get(whichRow, spectrum); 1042 1150 sdc.putSpectrum(spectrum); … … 1053 1161 histCol_.get(whichRow, histo); 1054 1162 sdc.putHistory(histo); 1163 fitCol_.get(whichRow, fits); 1164 sdc.putFitMap(fits); 1055 1165 return sdc; 1056 1166 } … … 1168 1278 { 1169 1279 Bool throwIt = True; 1170 Instrument ins = convertInstrument 1280 Instrument ins = convertInstrument(name, throwIt); 1171 1281 String nameU(name); 1172 1282 nameU.upcase(); … … 1176 1286 std::string SDMemTable::summary(bool verbose) const { 1177 1287 1178 // Format header info 1179 1288 // Format header info 1180 1289 ostringstream oss; 1181 1290 oss << endl; … … 1214 1323 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl; 1215 1324 oss << endl; 1216 // 1325 1217 1326 String dirtype ="Position ("+ MDirection::showType(getDirectionReference()) + ")"; 1218 1327 oss << setw(5) << "Scan" … … 1224 1333 oss << "--------------------------------------------------------------------------------" << endl; 1225 1334 1226 // Generate list of scan start and end integrations 1227 1335 // Generate list of scan start and end integrations 1228 1336 Vector<Int> scanIDs = scanCol_.getColumn(); 1229 1337 Vector<uInt> startInt, endInt; 1230 1338 mathutil::scanBoundaries(startInt, endInt, scanIDs); 1231 // 1339 1232 1340 const uInt nScans = startInt.nelements(); 1233 1341 String name; 1234 1342 Vector<uInt> freqIDs, listFQ; 1235 1343 uInt nInt; 1236 // 1344 1237 1345 for (uInt i=0; i<nScans; i++) { 1238 1239 // Get things from first integration of scan 1240 1241 String time = getTime(startInt(i),False); 1242 String tInt = formatSec(Double(getInterval(startInt(i)))); 1243 String posit = formatDirection(getDirection(startInt(i),True)); 1244 srcnCol_.getScalar(startInt(i),name); 1245 1246 // Find all the FreqIDs in this scan 1247 1248 listFQ.resize(0); 1249 for (uInt j=startInt(i); j<endInt(i)+1; j++) { 1250 freqidCol_.get(j, freqIDs); 1251 for (uInt k=0; k<freqIDs.nelements(); k++) { 1252 mathutil::addEntry(listFQ, freqIDs(k)); 1253 } 1346 // Get things from first integration of scan 1347 String time = getTime(startInt(i),False); 1348 String tInt = formatSec(Double(getInterval(startInt(i)))); 1349 String posit = formatDirection(getDirection(startInt(i),True)); 1350 srcnCol_.getScalar(startInt(i),name); 1351 1352 // Find all the FreqIDs in this scan 1353 listFQ.resize(0); 1354 for (uInt j=startInt(i); j<endInt(i)+1; j++) { 1355 freqidCol_.get(j, freqIDs); 1356 for (uInt k=0; k<freqIDs.nelements(); k++) { 1357 mathutil::addEntry(listFQ, freqIDs(k)); 1254 1358 } 1255 // 1256 nInt = endInt(i) - startInt(i) + 1; 1257 oss << setw(3) << std::right << i << std::left << setw(2) << " " 1258 << setw(15) << name 1259 << setw(24) << posit 1260 << setw(10) << time 1261 << setw(3) << std::right << nInt << setw(3) << " x " << std::left 1262 << setw(6) << tInt 1263 << " " << listFQ << endl; 1359 } 1360 1361 nInt = endInt(i) - startInt(i) + 1; 1362 oss << setw(3) << std::right << i << std::left << setw(2) << " " 1363 << setw(15) << name 1364 << setw(24) << posit 1365 << setw(10) << time 1366 << setw(3) << std::right << nInt << setw(3) << " x " << std::left 1367 << setw(6) << tInt 1368 << " " << listFQ << endl; 1264 1369 } 1265 1370 oss << endl; 1266 oss << "Table contains " << table_.nrow() << " integration(s) in " << nScans << " scan(s)." << endl;1267 1268 // Frequency Table 1269 1371 oss << "Table contains " << table_.nrow() << " integration(s) in " 1372 << nScans << " scan(s)." << endl; 1373 1374 // Frequency Table 1270 1375 if (verbose) { 1271 1376 std::vector<string> info = getCoordInfo(); … … 1292 1397 return n; 1293 1398 } 1399 1294 1400 Int SDMemTable::nIF() const { 1295 1401 Int n; … … 1297 1403 return n; 1298 1404 } 1405 1299 1406 Int SDMemTable::nPol() const { 1300 1407 Int n; … … 1302 1409 return n; 1303 1410 } 1411 1304 1412 Int SDMemTable::nChan() const { 1305 1413 Int n; … … 1307 1415 return n; 1308 1416 } 1417 1309 1418 bool SDMemTable::appendHistory(const std::string& hist, int whichRow) 1310 1419 { … … 1378 1487 cerr << "Unknown equinox using J2000" << endl; 1379 1488 } 1380 // 1489 1381 1490 return mdr; 1382 1491 } … … 1391 1500 met = MEpoch::UTC; 1392 1501 } 1393 // 1502 1394 1503 return met; 1395 1504 } … … 1402 1511 t.upcase(); 1403 1512 1404 // The strings are what SDReader returns, after cunning interrogation 1405 // of station names... :-( 1406 1513 // The strings are what SDReader returns, after cunning interrogation 1514 // of station names... :-( 1407 1515 Instrument inst = asap::UNKNOWN; 1408 1516 if (t==String("DSS-43")) { … … 1426 1534 } 1427 1535 1428 Bool SDMemTable::setRestFreqs 1429 1430 1431 1432 1536 Bool SDMemTable::setRestFreqs(const Vector<Double>& restFreqsIn, 1537 const String& sUnit, 1538 const vector<string>& lines, 1539 const String& source, 1540 Int whichIF) 1433 1541 { 1434 1542 const Int nIFs = nIF(); … … 1437 1545 } 1438 1546 1439 // FInd vector of restfrequencies 1440 // Double takes precedence over String 1441 1547 // Find vector of restfrequencies 1548 // Double takes precedence over String 1442 1549 Unit unit; 1443 1550 Vector<Double> restFreqs; … … 1457 1564 restFreqs[i] = lineFreq.getValue().getValue(); // Hz 1458 1565 } else { 1459 String s = String(lines[i]) + String(" is an unrecognized spectral line"); 1566 String s = String(lines[i]) + 1567 String(" is an unrecognized spectral line"); 1460 1568 throw(AipsError(s)); 1461 1569 } … … 1465 1573 } 1466 1574 1467 // If multiple restfreqs, must be length nIF. In this 1468 // case we will just replace the rest frequencies 1469 // 1470 1575 // If multiple restfreqs, must be length nIF. In this 1576 // case we will just replace the rest frequencies 1471 1577 const uInt nRestFreqs = restFreqs.nelements(); 1472 1578 Int idx = -1; … … 1474 1580 1475 1581 if (nRestFreqs>1) { 1476 1477 // Replace restFreqs, one per IF 1478 1582 // Replace restFreqs, one per IF 1479 1583 if (nRestFreqs != nIFs) { 1480 1584 throw (AipsError("Number of rest frequencies must be equal to the number of IFs")); 1481 1585 } 1482 1586 cout << "Replacing rest frequencies with given list, one per IF" << endl; 1483 //1484 1587 sdft.deleteRestFrequencies(); 1485 1588 for (uInt i=0; i<nRestFreqs; i++) { … … 1489 1592 } else { 1490 1593 1491 // Add new rest freq 1492 1594 // Add new rest freq 1493 1595 Quantum<Double> rf(restFreqs[0], unit); 1494 1596 idx = sdft.addRestFrequency(rf.getValue("Hz")); 1495 1597 cout << "Selecting given rest frequency" << endl; 1496 1598 } 1497 1498 // Replace 1499 1599 1600 // Replace 1500 1601 Bool empty = source.empty(); 1501 1602 Bool ok = False; … … 1507 1608 srcnCol_.get(i, srcName); 1508 1609 restfreqidCol_.get(i,restFreqIDs); 1509 // 1610 1510 1611 if (idx==-1) { 1511 1512 // Replace vector of restFreqs; one per IF. 1513 // No selection possible 1514 1612 // Replace vector of restFreqs; one per IF. 1613 // No selection possible 1515 1614 for (uInt i=0; i<nIFs; i++) restFreqIDs[i] = i; 1516 1615 } else { 1517 1518 // Set RestFreqID for selected data 1519 1616 // Set RestFreqID for selected data 1520 1617 if (empty || source==srcName) { 1521 1618 if (whichIF<0) { … … 1526 1623 } 1527 1624 } 1528 //1529 1625 restfreqidCol_.put(i,restFreqIDs); 1530 1626 } 1531 1627 ok = True; 1532 1628 } else { 1533 1629 ok = False; 1534 1630 } 1535 // 1631 1536 1632 return ok; 1537 1633 } … … 1542 1638 MFrequency lineFreq; 1543 1639 Double freq; 1544 // 1640 1545 1641 cout.flags(std::ios_base::left); 1546 1642 cout << "Line Frequency (Hz)" << endl; … … 1549 1645 MeasTable::Line(lineFreq, lines[i]); 1550 1646 freq = lineFreq.getValue().getValue(); // Hz 1551 //1552 1647 cout << setw(11) << lines[i] << setprecision(10) << freq << endl; 1553 1648 } … … 1577 1672 1578 1673 void SDMemTable::rotateXYPhase (Float value, Bool doAll) 1579 // 1580 // phase in degrees 1581 // Applies to all Beams and IFs 1582 // Might want to optionally select on Beam/IF 1583 // 1584 { 1585 if (nPol() != 4) { 1586 throw(AipsError("You must have 4 polarizations to run this function")); 1587 } 1588 // 1589 IPosition start(asap::nAxes,0); 1590 IPosition end(asap::nAxes); 1591 // 1592 uInt nRow = specCol_.nrow(); 1593 Array<Float> data; 1594 for (uInt i=0; i<nRow;++i) { 1595 specCol_.get(i,data); 1596 IPosition shape = data.shape(); 1597 1598 // Set slice 1599 1600 if (!doAll) { 1601 setCursorSlice (start, end, shape); 1602 } else { 1603 end = shape-1; 1604 } 1605 1606 // Get polarization slice references 1607 1608 start(asap::PolAxis) = 2; 1609 end(asap::PolAxis) = 2; 1610 Array<Float> C3 = data(start,end); 1611 // 1612 start(asap::PolAxis) = 3; 1613 end(asap::PolAxis) = 3; 1614 Array<Float> C4 = data(start,end); 1615 1616 // Rotate 1617 1618 SDPolUtil::rotateXYPhase(C3, C4, value); 1619 1620 // Put 1621 1622 specCol_.put(i,data); 1623 } 1624 } 1625 1626 1627 void SDMemTable::setCursorSlice (IPosition& start, IPosition& end, 1628 const IPosition& shape) const 1629 { 1630 const uInt nDim = shape.nelements(); 1631 start.resize(nDim); 1632 end.resize(nDim); 1633 // 1634 start(asap::BeamAxis) = beamSel_; 1635 end(asap::BeamAxis) = beamSel_; 1636 // 1637 start(asap::IFAxis) = IFSel_; 1638 end(asap::IFAxis) = IFSel_; 1639 // 1640 start(asap::PolAxis) = polSel_; 1641 end(asap::PolAxis) = polSel_; 1642 // 1643 start(asap::ChanAxis) = 0; 1644 end(asap::ChanAxis) = shape(asap::ChanAxis) - 1; 1645 } 1646 1647 1648 std::vector<float> SDMemTable::convertVector (const Vector<Float>& in) const 1649 { 1650 std::vector<float> out(in.nelements()); 1651 for (uInt i=0; i<in.nelements(); i++) { 1652 out[i] = in[i]; 1653 } 1654 return out; 1655 } 1656 1657 1658 std::vector<float> SDMemTable::getFloatSpectrum (const Array<Float>& arr) const 1659 // 1660 // Get spectrum at cursor location 1661 // 1662 { 1663 1664 // Setup accessors 1665 1674 // phase in degrees 1675 // Applies to all Beams and IFs 1676 // Might want to optionally select on Beam/IF 1677 { 1678 if (nPol() != 4) { 1679 throw(AipsError("You must have 4 polarizations to run this function")); 1680 } 1681 1682 IPosition start(asap::nAxes,0); 1683 IPosition end(asap::nAxes); 1684 1685 uInt nRow = specCol_.nrow(); 1686 Array<Float> data; 1687 for (uInt i=0; i<nRow;++i) { 1688 specCol_.get(i,data); 1689 IPosition shape = data.shape(); 1690 1691 // Set slice 1692 if (!doAll) { 1693 setCursorSlice (start, end, shape); 1694 } else { 1695 end = shape-1; 1696 } 1697 1698 // Get polarization slice references 1699 start(asap::PolAxis) = 2; 1700 end(asap::PolAxis) = 2; 1701 Array<Float> C3 = data(start,end); 1702 1703 start(asap::PolAxis) = 3; 1704 end(asap::PolAxis) = 3; 1705 Array<Float> C4 = data(start,end); 1706 1707 // Rotate 1708 SDPolUtil::rotateXYPhase(C3, C4, value); 1709 1710 // Put 1711 specCol_.put(i,data); 1712 } 1713 } 1714 1715 void SDMemTable::setCursorSlice(IPosition& start, IPosition& end, 1716 const IPosition& shape) const 1717 { 1718 const uInt nDim = shape.nelements(); 1719 start.resize(nDim); 1720 end.resize(nDim); 1721 1722 start(asap::BeamAxis) = beamSel_; 1723 end(asap::BeamAxis) = beamSel_; 1724 start(asap::IFAxis) = IFSel_; 1725 end(asap::IFAxis) = IFSel_; 1726 1727 start(asap::PolAxis) = polSel_; 1728 end(asap::PolAxis) = polSel_; 1729 1730 start(asap::ChanAxis) = 0; 1731 end(asap::ChanAxis) = shape(asap::ChanAxis) - 1; 1732 } 1733 1734 1735 std::vector<float> SDMemTable::getFloatSpectrum(const Array<Float>& arr) const 1736 // Get spectrum at cursor location 1737 { 1738 1739 // Setup accessors 1666 1740 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); 1667 1741 aa0.reset(aa0.begin(uInt(beamSel_))); // Beam selection … … 1672 1746 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); 1673 1747 aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection 1674 // 1748 1675 1749 std::vector<float> spectrum; 1676 1750 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { -
trunk/src/SDMemTable.h
r447 r455 36 36 #include <vector> 37 37 // AIPS++ 38 38 #include <casa/aips.h> 39 39 #include <casa/Arrays/MaskedArray.h> 40 40 #include <casa/BasicSL/String.h> … … 49 49 50 50 namespace asap { 51 51 52 52 class SDContainer; 53 53 class SDHeader; 54 54 class SDFrequencyTable; 55 55 class SDFitTable; 56 56 57 57 … … 95 95 virtual std::vector<bool> getMask(casa::Int whichRow=0) const; 96 96 97 98 97 // When we can handle input correlations being either circular or 99 // linear, we should probably have functions; getLinear, getCircular, getStokes 100 // since one can inter-convert between all three regardless of the input 101 // provided there are 4 polarizations. For now, we are assuming, if 102 // there are 4 polarizations, that we have linears. getSpectrum 103 // is then 'getLinear', getStokesSpectrum is 'getStokes' and getCircularSpectrum 104 // is 'getCircular' 105 106 107 // Get Stokes at cursor location. One of either I,Q,U,V or I,P,PA,V (doPol=True) 108 // If the latter, you can add a PA offset (degrees) 98 // linear, we should probably have functions; getLinear, 99 // getCircular, getStokes since one can inter-convert between all 100 // three regardless of the input provided there are 4 101 // polarizations. For now, we are assuming, if there are 4 102 // polarizations, that we have linears. getSpectrum is then 103 // 'getLinear', getStokesSpectrum is 'getStokes' and 104 // getCircularSpectrum is 'getCircular' 105 106 107 // Get Stokes at cursor location. One of either I,Q,U,V or I,P,PA,V 108 // (doPol=True) If the latter, you can add a PA offset (degrees) 109 109 virtual std::vector<float> getStokesSpectrum(casa::Int whichRow=0, 110 110 casa::Bool doPol=casa::False, … … 130 130 casa::MDirection getDirection(casa::Int whichRow=0, 131 131 casa::Bool refBeam=casa::False) const; 132 // 132 133 133 std::string getSourceName(casa::Int whichRow=0) const; 134 134 double getInterval(casa::Int whichRow=0) const; … … 137 137 virtual void setCoordInfo(std::vector<string> theinfo); 138 138 139 // Set RestFreqID. source="" and IF=-1 means select all140 virtual casa::Bool setRestFreqs 141 142 143 144 145 146 // List lines147 148 149 // Get/Set flux unit139 // Set RestFreqID. source="" and IF=-1 means select all 140 virtual casa::Bool setRestFreqs(const casa::Vector<casa::Double>& restFreqs, 141 const casa::String& unit, 142 const std::vector<std::string>& lines, 143 const casa::String& source, 144 casa::Int whichIF=-1); 145 146 // List lines 147 void spectralLines() const; 148 149 // Get/Set flux unit 150 150 std::string getFluxUnit() const; 151 151 void setFluxUnit (const std::string& unit); 152 153 // Set Instrument152 153 // Set Instrument 154 154 void setInstrument (const std::string& instrument); 155 155 … … 243 243 static Instrument convertInstrument(const casa::String& instrument, 244 244 casa::Bool throwIt); 245 245 246 bool putSDFitTable(const SDFitTable& sdft); 247 SDFitTable getSDFitTable() const; 248 249 void addFit(casa::uInt whichRow, 250 const casa::Vector<casa::Double>& p, 251 const casa::Vector<casa::Bool>& m, 252 const casa::Vector<casa::String>& f, 253 const casa::Vector<casa::Int>& c); 254 246 255 private: 247 256 // utility func for nice printout 248 257 casa::String formatSec(casa::Double x) const; 249 258 casa::String formatDirection(const casa::MDirection& md) const; 250 std::vector<float> getFloatSpectrum 259 std::vector<float> getFloatSpectrum(const casa::Array<casa::Float>& arr) const; 251 260 void setup(); 252 261 void attach(); … … 254 263 255 264 // Generate start and end for shape and current cursor selection 256 void setCursorSlice(casa::IPosition& start, casa::IPosition& end, const casa::IPosition& shape) const; 257 258 // Convert Vector to vector 259 std::vector<float> convertVector (const casa::Vector<casa::Float>& in) const; 260 265 void setCursorSlice(casa::IPosition& start, casa::IPosition& end, 266 const casa::IPosition& shape) const; 261 267 262 268 // the current cursor into the array … … 266 272 casa::Table table_; 267 273 268 // Cached Columns to avoid reconstructing them for each row get/put274 // Cached Columns to avoid reconstructing them for each row get/put 269 275 casa::ScalarColumn<casa::Double> timeCol_, integrCol_; 270 276 casa::ScalarColumn<casa::Float> azCol_, elCol_, paraCol_; … … 276 282 casa::ArrayColumn<casa::uInt> freqidCol_, restfreqidCol_; 277 283 casa::ArrayColumn<casa::String> histCol_; 284 casa::ArrayColumn<casa::Int> fitCol_; 278 285 casa::ROArrayColumn<casa::Float> stokesCol_; 279 286 }; -
trunk/src/SDMemTableWrapper.h
r433 r455 81 81 } 82 82 83 std::vector<float> getStokesSpectrum(int whichRow=0, bool doPol=false, float paOff=0.0) const { 83 std::vector<float> getStokesSpectrum(int whichRow=0, bool doPol=false, 84 float paOff=0.0) const { 84 85 return table_->getStokesSpectrum(whichRow, doPol, paOff); 85 86 } 86 87 87 std::vector<float> getCircularSpectrum(int whichRow=0, bool doRR=true) const { 88 std::vector<float> getCircularSpectrum(int whichRow=0, 89 bool doRR=true) const { 88 90 return table_->getCircularSpectrum(whichRow, doRR); 89 91 } … … 187 189 } 188 190 191 void addFit(int whichRow, const std::vector<double>& p, 192 const std::vector<bool>& m, const std::vector<string>& f, 193 const std::vector<int>& c) { 194 195 casa::Vector<casa::Double> p2(p); 196 casa::Vector<casa::Bool> m2(m); 197 casa::Vector<casa::String> f2(f.size()); 198 casa::uInt i=0; 199 std::vector<std::string>::const_iterator it; 200 for (it=f.begin();it != f.end();++it) { 201 f2[i] = casa::String(*it); 202 } 203 casa::Vector<casa::Int> c2(c); 204 table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2); 205 } 206 189 207 void rotateXYPhase (float value, bool doAll) { 190 208 table_->rotateXYPhase(value, doAll);
Note:
See TracChangeset
for help on using the changeset viewer.