Changeset 1393 for branches/alma/external/atnf/PKSIO/PKSMS2reader.cc
- Timestamp:
- 08/01/07 02:54:51 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/external/atnf/PKSIO/PKSMS2reader.cc
r1325 r1393 26 26 //# Charlottesville, VA 22903-2475 USA 27 27 //# 28 //# $Id : PKSMS2reader.cc,v 19.11 2006/07/05 04:59:20 mcalabre Exp$28 //# $Id$ 29 29 //#--------------------------------------------------------------------------- 30 30 //# Original: 2000/08/03, Mark Calabretta, ATNF … … 38 38 #include <ms/MeasurementSets/MSColumns.h> 39 39 #include <tables/Tables.h> 40 #include <casa/Quanta/MVTime.h> 41 #include <casa/Quanta/MVAngle.h> 42 #include <casa/BasicMath/Math.h> 43 #include <measures/Measures/MeasConvert.h> 44 #include <measures/Measures/MEpoch.h> 45 #include <measures/Measures/MeasRef.h> 46 40 47 41 48 // Parkes includes. … … 84 91 85 92 cPKSMS = MeasurementSet(msName); 93 // taql access to the syscal table 94 String tmpcalName = msName; 95 tmpcalName.append("/SYSCAL"); 96 cSysCalTab = Table(tmpcalName); 97 86 98 cIdx = 0; 99 lastmjd = 0.0; 87 100 cNRow = cPKSMS.nrow(); 88 101 cMSopen = True; … … 111 124 cFieldIdCol.reference(msCols.fieldId()); 112 125 cFieldNameCol.reference(fieldCols.name()); 126 cFieldDelayDirCol.reference(fieldCols.delayDir()); 113 127 114 128 cSrcIdCol.reference(fieldCols.sourceId()); 129 cSrcId2Col.reference(sourceCols.sourceId()); 115 130 cSrcNameCol.reference(sourceCols.name()); 116 131 cSrcDirCol.reference(sourceCols.direction()); … … 120 135 cStateIdCol.reference(msCols.stateId()); 121 136 cObsModeCol.reference(stateCols.obsMode()); 122 137 cCalCol.reference(stateCols.cal()); 138 cSigStateCol.reference(stateCols.sig()); 139 cRefStateCol.reference(stateCols.ref()); 123 140 cDataDescIdCol.reference(msCols.dataDescId()); 141 cSpWinIdCol.reference(dataDescCols.spectralWindowId()); 124 142 cChanFreqCol.reference(spWinCols.chanFreq()); 125 143 … … 142 160 cTsysCol.attach(cPKSMS.sysCal(), "TSYS"); 143 161 } 162 163 if ((cHaveTcal = cPKSMS.sysCal().tableDesc().isColumn("TCAL"))) { 164 cTcalCol.attach(cPKSMS.sysCal(), "TCAL"); 165 } 144 166 145 167 if ((cHaveCalFctr = cPKSMS.tableDesc().isColumn("CALFCTR"))) { … … 157 179 cFlagCol.reference(msCols.flag()); 158 180 181 159 182 if ((cGetXPol = cPKSMS.isColumn(MSMainEnums::DATA))) { 160 183 if ((cHaveXCalFctr = cPKSMS.tableDesc().isColumn("XCALFCTR"))) { … … 177 200 178 201 // Number of IFs. 179 uInt nIF = dataDescCols.nrow(); 202 //uInt nIF = dataDescCols.nrow(); 203 uInt nIF =spWinCols.nrow(); 180 204 IFs.resize(nIF); 181 205 IFs = True; … … 253 277 Double &mjd, 254 278 Double &refFreq, 255 Double &bandwidth) 279 Double &bandwidth, 280 String &fluxunit) 256 281 { 257 282 if (!cMSopen) { … … 277 302 } 278 303 304 fluxunit = ""; 305 const TableRecord& keywordSet 306 = cFloatDataCol.columnDesc().keywordSet(); 307 if(keywordSet.isDefined("UNIT")) { 308 fluxunit = keywordSet.asString("UNIT"); 309 } 279 310 280 311 // Coordinate equinox. … … 538 569 Int ibeam; 539 570 Int iIF; 571 Int iDataDesc; 572 540 573 while (True) { 541 574 ibeam = cBeamNoCol(cIdx); 542 iIF = cDataDescIdCol(cIdx); 575 iDataDesc = cDataDescIdCol(cIdx); 576 iIF =cSpWinIdCol(iDataDesc); 543 577 if (cBeams(ibeam) && cIFs(iIF)) { 544 578 break; … … 552 586 553 587 // Renumerate scan no. Here still is 1-based 554 scanNo = cScanNoCol(cIdx) - cScanNoCol(0) + 1; 555 588 //scanNo = cScanNoCol(cIdx) - cScanNoCol(0) + 1; 589 scanNo = cScanNoCol(cIdx); 590 556 591 if (scanNo != cScanNo) { 557 592 // Start of new scan. … … 576 611 577 612 Int srcId = cSrcIdCol(fieldId); 578 srcName = cSrcNameCol(srcId); 613 //For source with multiple spectral window setting, this is not 614 // correct. Source name of srcId may not be at 'srcId'th row of SrcNameCol 615 //srcName = cSrcNameCol(srcId); 616 for (uInt irow = 0; irow < cSrcId2Col.nrow(); irow++) { 617 if (cSrcId2Col(irow) == srcId) { 618 srcName = cSrcNameCol(irow); 619 } 620 } 621 579 622 srcDir = cSrcDirCol(srcId); 580 623 srcPM = cSrcPMCol(srcId); … … 587 630 } 588 631 632 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 633 String telescope = antennaCols.name()(0); 634 Bool cGBT = telescope.contains("GBT"); 589 635 // Observation type. 590 636 Int stateId = cStateIdCol(cIdx); 591 obsMode = cObsModeCol(stateId); 637 if (stateId == -1) { 638 //obsMode = " "; 639 } else { 640 obsMode = cObsModeCol(stateId); 641 Bool sigState =cSigStateCol(stateId); 642 Bool refState =cRefStateCol(stateId); 643 //DEBUG 644 //cerr <<"stateid="<<stateId<<" obsmode="<<obsMode<<endl; 645 if (cGBT) { 646 // split the obsMode string and append a proper label 647 // (these are GBT specific) 648 int epos = obsMode.find_first_of(':'); 649 int nextpos = obsMode.find_first_of(':',epos+1); 650 string obsMode1 = obsMode.substr(0,epos); 651 string obsMode2 = obsMode.substr(epos+1,nextpos-epos-1); 652 653 //cerr <<"obsMode2= "<<obsMode2<<endl; 654 if (!srcName.contains("_ps") 655 &&!srcName.contains("_psr") 656 &&!srcName.contains("_nod") 657 &&!srcName.contains("_fs") 658 &&!srcName.contains("_fsr")) { 659 // if Nod mode observation , append '_nod' 660 if (obsMode1 == "Nod") { 661 srcName.append("_nod"); 662 } else if (obsMode1 == "OffOn") { 663 // for GBT position switch observations (OffOn or OnOff) 664 if (obsMode2 == "PSWITCHON") srcName.append("_ps"); 665 if (obsMode2 == "PSWITCHOFF") srcName.append("_psr"); 666 } else { 667 if (obsMode2 == "FSWITCH") { 668 // for GBT frequency switch mode 669 if (sigState) srcName.append("_fs"); 670 if (refState) srcName.append("_fsr"); 671 } 672 } 673 } 674 } 675 } 676 // CAL state 677 // this should be apply just for GBT data? 678 Double Cal; 679 if (stateId==-1) { 680 Cal = 0; 681 } else { 682 Cal = cCalCol(stateId); 683 } 684 if (cGBT) { 685 if (Cal > 0 && !srcName.contains("_calon")) { 686 srcName.append("_calon"); 687 } 688 } 592 689 593 690 IFno = iIF + 1; 594 691 Int nChan = abs(cEndChan(iIF) - cStartChan(iIF)) + 1; 595 692 596 693 // Minimal handling on continuum data. 597 694 Vector<Double> chanFreq = cChanFreqCol(iIF); … … 607 704 freqInc = chanFreq(0) - chanFreq(1); 608 705 } 609 610 706 refFreq = chanFreq(cRefChan(iIF)-1); 611 707 restFreq = cSrcRestFrqCol(srcId)(IPosition(1,0)); … … 616 712 tcal = 0.0f; 617 713 tcalTime = ""; 618 azimuth = 0.0f;619 elevation = 0.0f;714 //azimuth = 0.0f; 715 //elevation = 0.0f; 620 716 parAngle = 0.0f; 621 717 focusAxi = 0.0f; … … 649 745 beamNo = ibeam + 1; 650 746 651 Matrix<Double> pointingDir = cPointingCol(fieldId); 652 direction = pointingDir.column(0); 653 uInt ncols = pointingDir.ncolumn(); 747 //Matrix<Double> pointingDir = cPointingCol(fieldId); 748 //pointingDir = cPointingCol(fieldId); 749 //direction = pointingDir.column(0); 750 //uInt ncols = pointingDir.ncolumn(); 751 //if (ncols == 1) { 752 // scanRate = 0.0f; 753 //} else { 754 // scanRate = pointingDir.column(1); 755 //} 756 757 // Get direction from FIELD table 758 // here, assume direction to be the field direction not pointing 759 Matrix<Double> delayDir = cFieldDelayDirCol(fieldId); 760 direction = delayDir.column(0); 761 uInt ncols = delayDir.ncolumn(); 654 762 if (ncols == 1) { 655 763 scanRate = 0.0f; 656 764 } else { 657 scanRate = pointingDir.column(1); 658 } 765 scanRate = delayDir.column(1); 766 } 767 768 // caluculate azimuth and elevation 769 // first, get the reference frame 770 MVPosition mvpos(antennaCols.position()(0)); 771 MPosition mp(mvpos); 772 Quantum<Double> qt(time,"s"); 773 MVEpoch mvt(qt); 774 MEpoch me(mvt); 775 MeasFrame frame(mp, me); 776 // 777 ROMSFieldColumns fldCols(cPKSMS.field()); 778 Vector<MDirection> vmd(1); 779 MDirection md; 780 fldCols.delayDirMeasCol().get(fieldId,vmd); 781 md = vmd[0]; 782 //Vector<Double> dircheck = md.getAngle("rad").getValue(); 783 //cerr<<"dircheck="<<dircheck<<endl; 784 785 Vector<Double> azel = 786 MDirection::Convert(md, MDirection::Ref(MDirection::AZEL, 787 frame) 788 )().getAngle("rad").getValue(); 789 //cerr<<"azel="<<azel<<endl; 790 azimuth = azel[0]; 791 elevation = azel[1]; 659 792 660 793 // Get Tsys assuming that entries in the SYSCAL table match the main table. … … 675 808 cSigmaCol.get(cIdx, sigma, True); 676 809 810 //get Tcal if available 811 if (cHaveTcal) { 812 Int nTcalColRow = cTcalCol.nrow(); 813 uInt nBeam = cBeams.nelements(); 814 uInt nIF = cIFs.nelements(); 815 uInt nrws = nBeam * nIF; 816 if (nTcalColRow > 0) { 817 // find tcal match with the data with the data time stamp 818 Double mjds = mjd*(24*3600); 819 Double dtcalTime; 820 if ( mjd > lastmjd || cIdx==0 ) { 821 //Table tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds)); 822 tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds), nrws); 823 //DEBUG 824 //if (cIdx == 0) { 825 // cerr<<"inital table retrieved"<<endl; 826 //} 827 828 } 829 830 if (nBeam == 1) { 831 tmptab2 = tmptab( tmptab.col("SPECTRAL_WINDOW_ID") == iIF, 1); 832 } else { 833 tmptab2 = tmptab( tmptab.col("SPECTRAL_WINDOW_ID") == iIF && 834 tmptab.col("FEED_ID") == ibeam , 1); 835 } 836 //cerr<<"first subtab rows="<<tmptab.nrow()<<endl; 837 int syscalrow = tmptab2.nrow(); 838 ROArrayColumn<Float> tcalCol(tmptab2, "TCAL"); 839 ROScalarColumn<Double> tcalTimeCol(tmptab2, "TIME"); 840 if (syscalrow==0) { 841 cerr<<"Cannot find any matching Tcal at/near the data timestamp." 842 << " Set Tcal=0.0"<<endl; 843 } else { 844 tcalCol.get(0, tcal); 845 tcalTimeCol.get(0,dtcalTime); 846 tcalTime = MVTime(dtcalTime/(24*3600)).string(MVTime::YMD); 847 //DEBUG 848 //cerr<<"cIdx:"<<cIdx<<" tcal="<<tcal<<" tcalTime="<<tcalTime<<endl; 849 tmptab.markForDelete(); 850 tmptab2.markForDelete(); 851 } 852 } 853 lastmjd = mjd; 854 } 855 677 856 // Calibration factors (if available). 678 857 calFctr.resize(cNPol(iIF)); … … 695 874 baseSub.resize(0,0); 696 875 } 697 698 876 699 877 // Get spectral data. … … 780 958 Int ibeam; 781 959 Int iIF; 960 Int iDataDesc; 782 961 while (True) { 783 962 ibeam = cBeamNoCol(cIdx); 784 iIF = cDataDescIdCol(cIdx); 963 //iIF = cDataDescIdCol(cIdx); 964 iDataDesc = cDataDescIdCol(cIdx); 965 iIF = cSpWinIdCol(iDataDesc); 785 966 if (cBeams(ibeam) && cIFs(iIF)) { 786 967 break; … … 794 975 795 976 IFno = iIF + 1; 796 797 977 // Get Tsys assuming that entries in the SYSCAL table match the main table. 798 978 cTsysCol.get(cIdx, tsys, True);
Note: See TracChangeset
for help on using the changeset viewer.