Changeset 1757 for branches/alma/external/atnf/PKSIO/PKSMS2reader.cc
- Timestamp:
- 06/09/10 19:03:06 (14 years ago)
- Location:
- branches/alma
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma
-
Property
svn:ignore
set to
.sconf_temp
.sconsign.dblite
-
Property
svn:mergeinfo
set to
/branches/asap-3.x merged eligible
-
Property
svn:ignore
set to
-
branches/alma/external/atnf/PKSIO/PKSMS2reader.cc
r1453 r1757 2 2 //# PKSMS2reader.cc: Class to read Parkes Multibeam data from a v2 MS. 3 3 //#--------------------------------------------------------------------------- 4 //# Copyright (C) 2000-20065 //# Associated Universities, Inc. Washington DC, USA.4 //# livedata - processing pipeline for single-dish, multibeam spectral data. 5 //# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO 6 6 //# 7 //# This library is free software; you can redistribute it and/or modify it 8 //# under the terms of the GNU Library General Public License as published by 9 //# the Free Software Foundation; either version 2 of the License, or (at your 10 //# option) any later version. 7 //# This file is part of livedata. 11 8 //# 12 //# This library is distributed in the hope that it will be useful, but13 //# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY14 //# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public15 //# License for more details.9 //# livedata is free software: you can redistribute it and/or modify it under 10 //# the terms of the GNU General Public License as published by the Free 11 //# Software Foundation, either version 3 of the License, or (at your option) 12 //# any later version. 16 13 //# 17 //# You should have received a copy of the GNU Library General Public License 18 //# along with this library; if not, write to the Free Software Foundation, 19 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 14 //# livedata is distributed in the hope that it will be useful, but WITHOUT 15 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 //# more details. 20 18 //# 21 //# Correspondence concerning AIPS++ should be addressed as follows: 22 //# Internet email: aips2-request@nrao.edu. 23 //# Postal address: AIPS++ Project Office 24 //# National Radio Astronomy Observatory 25 //# 520 Edgemont Road 26 //# Charlottesville, VA 22903-2475 USA 19 //# You should have received a copy of the GNU General Public License along 20 //# with livedata. If not, see <http://www.gnu.org/licenses/>. 27 21 //# 28 //# $Id$ 22 //# Correspondence concerning livedata may be directed to: 23 //# Internet email: mcalabre@atnf.csiro.au 24 //# Postal address: Dr. Mark Calabretta 25 //# Australia Telescope National Facility, CSIRO 26 //# PO Box 76 27 //# Epping NSW 1710 28 //# AUSTRALIA 29 //# 30 //# http://www.atnf.csiro.au/computing/software/livedata.html 31 //# $Id: PKSMS2reader.cc,v 19.23 2009-09-29 07:33:38 cal103 Exp $ 29 32 //#--------------------------------------------------------------------------- 30 33 //# Original: 2000/08/03, Mark Calabretta, ATNF 31 34 //#--------------------------------------------------------------------------- 32 33 35 34 36 // AIPS++ includes. … … 41 43 #include <casa/Quanta/MVAngle.h> 42 44 #include <casa/BasicMath/Math.h> 45 #include <casa/Logging/LogIO.h> 46 #include <casa/Utilities/Sort.h> 43 47 #include <measures/Measures/MeasConvert.h> 44 48 #include <measures/Measures/MEpoch.h> … … 48 52 // Parkes includes. 49 53 #include <atnf/pks/pks_maths.h> 54 #include <atnf/PKSIO/PKSrecord.h> 50 55 #include <atnf/PKSIO/PKSMS2reader.h> 51 56 … … 73 78 Int PKSMS2reader::open( 74 79 const String msName, 80 const String antenna, 75 81 Vector<Bool> &beams, 76 82 Vector<Bool> &IFs, … … 91 97 92 98 cPKSMS = MeasurementSet(msName); 99 100 // data selection by antenna 101 if ( antenna.length() == 0 ) { 102 cAntId.resize( 1 ) ; 103 cAntId[0] = 0 ; 104 } 105 else { 106 setupAntennaList( antenna ) ; 107 if ( cAntId.size() > 1 ) { 108 LogIO os( LogOrigin( "PKSMS2reader", "open()", WHERE ) ) ; 109 os << LogIO::WARN << "PKSMS2reader is not ready for multiple antenna selection. Use first antenna id " << cAntId[0] << "."<< LogIO::POST ; 110 Int tmp = cAntId[0] ; 111 cAntId.resize( 1 ) ; 112 cAntId[0] = tmp ; 113 } 114 stringstream ss ; 115 ss << "SELECT FROM $1 WHERE ANTENNA1 == ANTENNA2 && ANTENNA1 IN [" ; 116 for ( uInt i = 0 ; i < cAntId.size() ; i++ ) { 117 ss << cAntId[i] ; 118 if ( i == cAntId.size()-1 ) { 119 ss << "]" ; 120 } 121 else { 122 ss << "," ; 123 } 124 } 125 string taql = ss.str() ; 126 //cerr << "taql = " << taql << endl ; 127 cPKSMS = MeasurementSet( tableCommand( taql, cPKSMS ) ) ; 128 } 129 93 130 // taql access to the syscal table 94 131 cHaveSysCal = False; … … 97 134 } 98 135 136 // Lock the table for read access. 137 cPKSMS.lock(False); 138 99 139 cIdx = 0; 100 140 lastmjd = 0.0; 101 141 cNRow = cPKSMS.nrow(); 102 142 cMSopen = True; 103 104 // Lock the table for read access.105 cPKSMS.lock(False);106 143 107 144 // Main MS table and subtable column access. … … 140 177 cSigStateCol.reference(stateCols.sig()); 141 178 cRefStateCol.reference(stateCols.ref()); 179 142 180 cDataDescIdCol.reference(msCols.dataDescId()); 143 181 cSpWinIdCol.reference(dataDescCols.spectralWindowId()); 144 182 cChanFreqCol.reference(spWinCols.chanFreq()); 183 cTotBWCol.reference(spWinCols.totalBandwidth()); 145 184 146 185 cWeatherTimeCol.reference(weatherCols.time()); … … 151 190 cBeamNoCol.reference(msCols.feed1()); 152 191 cPointingCol.reference(pointingCols.direction()); 192 cPointingTimeCol.reference(pointingCols.time()); 153 193 cSigmaCol.reference(msCols.sigma()); 154 194 cNumReceptorCol.reference(feedCols.numReceptors()); … … 182 222 cHaveDataCol = False; 183 223 cHaveCorrectedDataCol = False; 184 //String telName = antennaCols.name()(0);185 224 ROMSObservationColumns observationCols(cPKSMS.observation()); 186 String telName = observationCols.telescopeName()(0); 187 //cATF = (telName.contains("DA41") || telName.contains("DV01")); 188 cATF = telName.contains("ATF"); 225 //String telName = observationCols.telescopeName()(0); 226 cTelName = observationCols.telescopeName()(0); 227 //cATF = cTelName.contains("ATF"); 228 //cOSF = cTelName.contains("OSF"); 229 //cALMA = cTelName.contains("ALMA"); 230 cALMA = cTelName.contains("ATF")||cTelName.contains("OSF")|| 231 cTelName.contains("ALMA"); 189 232 190 233 if (cHaveDataCol = cPKSMS.isColumn(MSMainEnums::DATA)) { 191 if (cA TF) {234 if (cALMA) { 192 235 //try to read a single baseline interferometeric data 193 236 //and treat it as single dish data … … 204 247 } 205 248 cFlagCol.reference(msCols.flag()); 206 207 208 if (cGetXPol = (cPKSMS.isColumn(MSMainEnums::DATA) && (!cA TF))) {249 cFlagRowCol.reference(msCols.flagRow()); 250 251 if (cGetXPol = (cPKSMS.isColumn(MSMainEnums::DATA) && (!cALMA))) { 209 252 if ((cHaveXCalFctr = cPKSMS.tableDesc().isColumn("XCALFCTR"))) { 210 253 cXCalFctrCol.attach(cPKSMS, "XCALFCTR"); … … 228 271 //uInt nIF = dataDescCols.nrow(); 229 272 uInt nIF =spWinCols.nrow(); 273 Vector<Int> spWinIds = cSpWinIdCol.getColumn() ; 230 274 IFs.resize(nIF); 231 275 IFs = True; 276 for ( Int ispw = 0 ; ispw < nIF ; ispw++ ) { 277 if ( allNE( ispw, spWinIds ) ) { 278 IFs(ispw) = False ; 279 } 280 } 232 281 233 282 // Number of polarizations and channels in each IF. 234 ROScalarColumn<Int> spWinIdCol(dataDescCols.spectralWindowId());235 283 ROScalarColumn<Int> numChanCol(spWinCols.numChan()); 236 284 … … 241 289 nPol.resize(nIF); 242 290 for (uInt iIF = 0; iIF < nIF; iIF++) { 243 nChan(iIF) = numChanCol(spWinIdCol(iIF)); 244 nPol(iIF) = numPolCol(polIdCol(iIF)); 291 if ( IFs(iIF) ) { 292 nChan(iIF) = numChanCol(cSpWinIdCol(iIF)) ; 293 nPol(iIF) = numPolCol(polIdCol(iIF)) ; 294 } 295 else { 296 nChan(iIF) = 0 ; 297 nPol(iIF) = 0 ; 298 } 245 299 } 246 300 … … 249 303 haveXPol = False; 250 304 251 if (cGetXPol && !(cA TF)) {305 if (cGetXPol && !(cALMA)) { 252 306 for (Int irow = 0; irow < cNRow; irow++) { 253 307 if (cDataCol.isDefined(irow)) { … … 298 352 String &antName, 299 353 Vector<Double> &antPosition, 300 String &obsMode, 354 // before merge... 355 //String &obsMode, 356 String &obsType, 357 String &bunit, 301 358 Float &equinox, 302 359 String &dopplerFrame, 303 360 Double &mjd, 304 361 Double &refFreq, 305 Double &bandwidth, 306 String &fluxunit) 362 Double &bandwidth) 307 363 { 308 364 if (!cMSopen) { … … 317 373 // Antenna name and ITRF coordinates. 318 374 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 319 antName = antennaCols.name()(0); 320 antPosition = antennaCols.position()(0); 375 //antName = antennaCols.name()(0); 376 antName = antennaCols.name()(cAntId[0]); 377 if (cALMA) { 378 antName = cTelName + "-" + antName; 379 } 380 //antPosition = antennaCols.position()(0); 381 antPosition = antennaCols.position()(cAntId[0]); 321 382 322 383 // Observation type. 323 384 if (cObsModeCol.nrow()) { 324 obs Mode = cObsModeCol(0);325 if (obs Mode == "\0") obsMode = "RF";385 obsType = cObsModeCol(0); 386 if (obsType == "\0") obsType = "RF"; 326 387 } else { 327 obs Mode = "RF";328 } 329 330 fluxunit = "";388 obsType = "RF"; 389 } 390 391 bunit = ""; 331 392 if (cHaveDataCol) { 332 393 const TableRecord& keywordSet2 333 394 = cDataCol.columnDesc().keywordSet(); 334 395 if(keywordSet2.isDefined("UNIT")) { 335 fluxunit = keywordSet2.asString("UNIT");396 bunit = keywordSet2.asString("UNIT"); 336 397 } 337 398 } else { … … 339 400 = cFloatDataCol.columnDesc().keywordSet(); 340 401 if(keywordSet.isDefined("UNIT")) { 341 fluxunit = keywordSet.asString("UNIT");402 bunit = keywordSet.asString("UNIT"); 342 403 } 343 404 } … … 354 415 String dirref = pointingCols.direction().keywordSet().asRecord("MEASINFO"). 355 416 asString("Ref"); 417 cDirRef = dirref; 418 if (dirref =="AZELGEO" || dirref == "AZEL") { 419 dirref = "J2000"; 420 } 356 421 sscanf(dirref.chars()+1, "%f", &equinox); 357 422 … … 422 487 const Bool getSpectra, 423 488 const Bool getXPol, 424 const Bool getFeedPos) 489 const Bool getFeedPos, 490 const Bool getPointing, 491 const Int coordSys) 425 492 { 426 493 if (!cMSopen) { … … 504 571 cGetFeedPos = False; 505 572 573 // Get Pointing data (for MS) 574 cGetPointing = getPointing; 575 576 // Coordinate system? (Only equatorial available.) 577 cCoordSys = 0; 578 506 579 return maxNChan; 507 580 } … … 555 628 // Read the next data record. 556 629 630 /** 557 631 Int PKSMS2reader::read( 558 632 Int &scanNo, … … 595 669 Matrix<Float> &spectra, 596 670 Matrix<uChar> &flagged, 671 uInt &flagrow, 597 672 Complex &xCalFctr, 598 673 Vector<Complex> &xPol) 674 **/ 675 Int PKSMS2reader::read(PKSrecord &pksrec) 599 676 { 677 LogIO os( LogOrigin( "PKSMS2reader", "read()", WHERE ) ) ; 678 600 679 if (!cMSopen) { 601 680 return 1; … … 627 706 // Renumerate scan no. Here still is 1-based 628 707 //scanNo = cScanNoCol(cIdx) - cScanNoCol(0) + 1; 629 scanNo = cScanNoCol(cIdx); 630 631 if (scanNo != cScanNo) { 708 //scanNo = cScanNoCol(cIdx); 709 pksrec.scanNo = cScanNoCol(cIdx); 710 711 if (pksrec.scanNo != cScanNo) { 632 712 // Start of new scan. 633 cScanNo = scanNo;713 cScanNo = pksrec.scanNo; 634 714 cCycleNo = 1; 635 715 cTime = cTimeCol(cIdx); … … 637 717 638 718 Double time = cTimeCol(cIdx); 639 mjd = time/86400.0;640 interval = cIntervalCol(cIdx);719 pksrec.mjd = time/86400.0; 720 pksrec.interval = cIntervalCol(cIdx); 641 721 642 722 // Reconstruct the integration cycle number; due to small latencies the 643 723 // integration time is usually slightly less than the time between cycles, 644 724 // resetting cTime will prevent the difference from accumulating. 645 cCycleNo += nint((time - cTime)/ interval);646 cycleNo = cCycleNo;647 cTime 725 cCycleNo += nint((time - cTime)/pksrec.interval); 726 pksrec.cycleNo = cCycleNo; 727 cTime = time; 648 728 649 729 Int fieldId = cFieldIdCol(cIdx); 650 fieldName = cFieldNameCol(fieldId);730 pksrec.fieldName = cFieldNameCol(fieldId); 651 731 652 732 Int srcId = cSrcIdCol(fieldId); … … 656 736 for (uInt irow = 0; irow < cSrcId2Col.nrow(); irow++) { 657 737 if (cSrcId2Col(irow) == srcId) { 658 srcName = cSrcNameCol(irow); 659 } 660 } 661 662 srcDir = cSrcDirCol(srcId); 663 srcPM = cSrcPMCol(srcId); 738 //srcName = cSrcNameCol(irow); 739 pksrec.srcName = cSrcNameCol(irow); 740 } 741 } 742 743 pksrec.srcDir = cSrcDirCol(srcId); 744 pksrec.srcPM = cSrcPMCol(srcId); 664 745 665 746 // Systemic velocity. 666 if (!cHaveSrcVel || cA TF) {667 srcVel = 0.0f;747 if (!cHaveSrcVel || cALMA) { 748 pksrec.srcVel = 0.0f; 668 749 } else { 669 srcVel= cSrcVelCol(srcId)(IPosition(1,0));750 pksrec.srcVel = cSrcVelCol(srcId)(IPosition(1,0)); 670 751 } 671 752 672 753 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 673 String telescope = antennaCols.name()(0); 754 //String telescope = antennaCols.name()(0); 755 String telescope = antennaCols.name()(cAntId[0]); 674 756 Bool cGBT = telescope.contains("GBT"); 757 //Bool cPM = telescope.contains("PM"); // ACA TP antenna 758 //Bool cDV = telescope.contains("DV"); // VERTEX 759 //Bool cCM = telescope.contains("CM"); // ACA 7m antenna 760 //Bool cALMA = cPM || cDV || cCM ; 675 761 // Observation type. 676 762 // check if State Table exist … … 680 766 StateNRow=cObsModeCol.nrow(); 681 767 if (Table::isReadable(cPKSMS.stateTableName())) { 682 obsMode = " ";768 pksrec.obsType = " "; 683 769 if (StateNRow > 0) { 684 770 stateId = cStateIdCol(cIdx); 685 771 if (stateId == -1) { 686 // obsMode = " ";772 //pksrec.obsType = " "; 687 773 } else { 688 obsMode = cObsModeCol(stateId);774 pksrec.obsType = cObsModeCol(stateId); 689 775 Bool sigState =cSigStateCol(stateId); 690 776 Bool refState =cRefStateCol(stateId); 691 777 //DEBUG 692 //cerr <<"stateid="<<stateId<<" obsmode="<< obsMode<<endl;778 //cerr <<"stateid="<<stateId<<" obsmode="<<pksrec.obsType<<endl; 693 779 if (cGBT) { 694 // split the obs Mode string and append a proper label780 // split the obsType string and append a proper label 695 781 // (these are GBT specific) 696 int epos = obsMode.find_first_of(':');697 int nextpos = obsMode.find_first_of(':',epos+1);698 string obsMode1 = obsMode.substr(0,epos);699 string obsMode2 = obsMode.substr(epos+1,nextpos-epos-1);782 int epos = pksrec.obsType.find_first_of(':'); 783 int nextpos = pksrec.obsType.find_first_of(':',epos+1); 784 string obsMode1 = pksrec.obsType.substr(0,epos); 785 string obsMode2 = pksrec.obsType.substr(epos+1,nextpos-epos-1); 700 786 701 787 //cerr <<"obsMode2= "<<obsMode2<<endl; 702 if (! srcName.contains("_ps")703 &&! srcName.contains("_psr")704 &&! srcName.contains("_nod")705 &&! srcName.contains("_fs")706 &&! srcName.contains("_fsr")) {788 if (!pksrec.srcName.contains("_ps") 789 &&!pksrec.srcName.contains("_psr") 790 &&!pksrec.srcName.contains("_nod") 791 &&!pksrec.srcName.contains("_fs") 792 &&!pksrec.srcName.contains("_fsr")) { 707 793 // if Nod mode observation , append '_nod' 708 794 if (obsMode1 == "Nod") { 709 srcName.append("_nod"); 795 //pksrec.srcName.append("_nod"); 796 pksrec.srcType = SrcType::NOD ; 710 797 } else if (obsMode1 == "OffOn") { 711 798 // for GBT position switch observations (OffOn or OnOff) 712 if (obsMode2 == "PSWITCHON") srcName.append("_ps"); 713 if (obsMode2 == "PSWITCHOFF") srcName.append("_psr"); 799 //if (obsMode2 == "PSWITCHON") pksrec.srcName.append("_ps"); 800 //if (obsMode2 == "PSWITCHOFF") pksrec.srcName.append("_psr"); 801 if (obsMode2 == "PSWITCHON") pksrec.srcType = SrcType::PSON ; 802 if (obsMode2 == "PSWITCHOFF") pksrec.srcType = SrcType::PSOFF ; 714 803 } else { 715 804 if (obsMode2 == "FSWITCH") { 716 805 // for GBT frequency switch mode 717 if (sigState) srcName.append("_fs"); 718 if (refState) srcName.append("_fsr"); 806 //if (sigState) pksrec.srcName.append("_fs"); 807 //if (refState) pksrec.srcName.append("_fsr"); 808 if (sigState) pksrec.srcType = SrcType::FSON ; 809 if (refState) pksrec.srcType = SrcType::FSOFF ; 719 810 } 720 811 } 721 812 } 722 813 } 814 else if (cALMA) { 815 // ALMA tag 816 // split the obsType string and append a proper label 817 string substr[1] ; 818 int numSubstr = split( pksrec.obsType, substr, 1, "," ); 819 String obsType = String( substr[0] ); 820 int epos = obsType.find_first_of('.'); 821 int nextpos = obsType.find_first_of('.',epos+1); 822 string obsMode1 = obsType.substr(0,epos); 823 string obsMode2 = obsType.substr(epos+1,nextpos-epos-1); 824 825 //cerr <<"obsMode2= "<<obsMode2<<endl; 826 // Current OBS_MODE format: 827 // 828 // ON: OBSERVE_TARGET.ON_SOURCE 829 // OFF: OBSERVE_TARGET.OFF_SOURCE 830 // 831 if (obsMode1 == "OBSERVE_TARGET") { 832 //if (obsMode2 == "ON_SOURCE") pksrec.srcName.append("_pson"); 833 //if (obsMode2 == "OFF_SOURCE") pksrec.srcName.append("_psoff"); 834 if (obsMode2 == "ON_SOURCE") pksrec.srcType = SrcType::PSON ; 835 if (obsMode2 == "OFF_SOURCE") pksrec.srcType = SrcType::PSOFF ; 836 } 837 } 723 838 } 724 839 } … … 733 848 } 734 849 if (cGBT) { 735 if (Cal > 0 && !srcName.contains("_calon")) { 736 srcName.append("_calon"); 737 } 738 } 739 740 IFno = iIF + 1; 850 if (Cal > 0 && !pksrec.srcName.contains("_calon")) { 851 //pksrec.srcName.append("_calon"); 852 if ( pksrec.srcType == SrcType::NOD ) 853 pksrec.srcType = SrcType::NODCAL ; 854 else if ( pksrec.srcType == SrcType::PSON ) 855 pksrec.srcType = SrcType::PONCAL ; 856 else if ( pksrec.srcType == SrcType::PSOFF ) 857 pksrec.srcType = SrcType::POFFCAL ; 858 else if ( pksrec.srcType == SrcType::FSON ) 859 pksrec.srcType = SrcType::FONCAL ; 860 else if ( pksrec.srcType == SrcType::FSOFF ) 861 pksrec.srcType = SrcType::FOFFCAL ; 862 else 863 pksrec.srcName.append("_calon"); 864 } 865 } 866 867 pksrec.IFno = iIF + 1; 741 868 Int nChan = abs(cEndChan(iIF) - cStartChan(iIF)) + 1; 742 869 743 870 // Minimal handling on continuum data. 744 871 Vector<Double> chanFreq = cChanFreqCol(iIF); 872 pksrec.nchan = nChan; 745 873 if (nChan == 1) { 746 freqInc = chanFreq(0); 747 refFreq = chanFreq(0); 748 restFreq = 0.0f; 874 //pksrec.freqInc = chanFreq(0); 875 pksrec.freqInc = cTotBWCol(iIF); 876 pksrec.refFreq = chanFreq(0); 877 pksrec.restFreq.resize(1); 878 pksrec.restFreq[0] = 0.0f; 749 879 } else { 750 880 751 881 if (cStartChan(iIF) <= cEndChan(iIF)) { 752 freqInc = chanFreq(1) - chanFreq(0);882 pksrec.freqInc = chanFreq(1) - chanFreq(0); 753 883 } else { 754 freqInc = chanFreq(0) - chanFreq(1); 755 } 756 refFreq = chanFreq(cRefChan(iIF)-1); 884 pksrec.freqInc = chanFreq(0) - chanFreq(1); 885 } 886 887 pksrec.refFreq = chanFreq(cRefChan(iIF)-1); 888 757 889 Bool HaveSrcRestFreq= cSrcRestFrqCol.isDefined(srcId); 758 890 if (HaveSrcRestFreq) { 759 891 //restFreq = cSrcRestFrqCol(srcId)(IPosition(1,0)); 760 restFreq = cSrcRestFrqCol(srcId); 892 //restFreq = cSrcRestFrqCol(srcId); 893 pksrec.restFreq = cSrcRestFrqCol(srcId); 761 894 } else { 762 restFreq = 0.0f; 763 } 764 } 765 bandwidth = abs(freqInc * nChan); 766 767 tcal.resize(cNPol(iIF)); 768 tcal = 0.0f; 769 tcalTime = ""; 770 //azimuth = 0.0f; 771 //elevation = 0.0f; 772 parAngle = 0.0f; 773 focusAxi = 0.0f; 774 focusTan = 0.0f; 775 focusRot = 0.0f; 895 pksrec.restFreq.resize(1); 896 pksrec.restFreq[0] = 0.0f; 897 } 898 } 899 //pksrec.bandwidth = abs(pksrec.freqInc * nChan); 900 pksrec.bandwidth = abs(cTotBWCol(0)); 901 902 pksrec.tcal.resize(cNPol(iIF)); 903 pksrec.tcal = 0.0f; 904 pksrec.tcalTime = ""; 905 // pksrec.azimuth = 0.0f; 906 // pksrec.elevation = 0.0f; 907 pksrec.parAngle = 0.0f; 908 909 pksrec.focusAxi = 0.0f; 910 pksrec.focusTan = 0.0f; 911 pksrec.focusRot = 0.0f; 776 912 777 913 // Find the appropriate entry in the WEATHER subtable. … … 787 923 } 788 924 } 925 789 926 if (weatherIdx < 0 || !cHaveWeatherTab) { 790 927 // No appropriate WEATHER entry. 791 p ressure= 0.0f;792 humidity= 0.0f;793 temperature= 0.0f;928 pksrec.temperature = 0.0f; 929 pksrec.pressure = 0.0f; 930 pksrec.humidity = 0.0f; 794 931 } else { 795 pressure = cPressureCol(weatherIdx); 796 humidity = cHumidityCol(weatherIdx); 797 temperature = cTemperatureCol(weatherIdx); 798 } 799 800 windSpeed = 0.0f; 801 windAz = 0.0f; 802 803 refBeam = 0; 804 beamNo = ibeam + 1; 805 806 //Matrix<Double> pointingDir = cPointingCol(fieldId); 807 //pointingDir = cPointingCol(fieldId); 808 //direction = pointingDir.column(0); 809 //uInt ncols = pointingDir.ncolumn(); 810 //if (ncols == 1) { 811 // scanRate = 0.0f; 812 //} else { 813 // scanRate = pointingDir.column(1); 814 //} 815 932 pksrec.temperature = cTemperatureCol(weatherIdx); 933 pksrec.pressure = cPressureCol(weatherIdx); 934 pksrec.humidity = cHumidityCol(weatherIdx); 935 } 936 937 pksrec.windSpeed = 0.0f; 938 pksrec.windAz = 0.0f; 939 940 pksrec.refBeam = 0; 941 pksrec.beamNo = ibeam + 1; 942 943 //pointing/azel 944 MVPosition mvpos(antennaCols.position()(cAntId[0])); 945 MPosition mp(mvpos); 946 Quantum<Double> qt(time,"s"); 947 MVEpoch mvt(qt); 948 MEpoch me(mvt); 949 MeasFrame frame(mp, me); 950 MDirection md; 951 pksrec.pCode = 0; 952 pksrec.rateAge = 0.0f; 953 pksrec.paRate = 0.0f; 954 if (cGetPointing) { 955 //cerr << "get pointing data ...." << endl; 956 ROScalarColumn<Int> pAntIdCol ; 957 ROScalarColumn<Double> psTimeCol ; 958 Table ptTable = cPKSMS.pointing() ; 959 MSPointing selPtTab( ptTable( ptTable.col("ANTENNA_ID") == cAntId[0] ) ) ; 960 pAntIdCol.attach( selPtTab, "ANTENNA_ID" ) ; 961 Vector<Int> antIds = pAntIdCol.getColumn() ; 962 psTimeCol.attach( selPtTab, "TIME" ) ; 963 Vector<Double> pTimes = psTimeCol.getColumn(); 964 Bool doInterp = False ; 965 Int PtIdx=-1; 966 for (PtIdx = pTimes.nelements()-1; PtIdx >= 0; PtIdx--) { 967 if ( pTimes[PtIdx] == time ) { 968 break ; 969 } 970 else if ( pTimes[PtIdx] < time ) { 971 if ( PtIdx != pTimes.nelements()-1 ) { 972 doInterp = True ; 973 } 974 break ; 975 } 976 } 977 if ( PtIdx == -1 ) { 978 PtIdx = 0 ; 979 } 980 //cerr << "got index=" << PtIdx << endl; 981 Matrix<Double> pointingDir = cPointingCol(PtIdx); 982 ROMSPointingColumns PtCols( selPtTab ) ; 983 Vector<Double> pointingDirVec ; 984 if ( doInterp ) { 985 Double dt1 = time - pTimes[PtIdx] ; 986 Double dt2 = pTimes[PtIdx+1] - time ; 987 Vector<Double> dirVec1 = pointingDir.column(0) ; 988 Matrix<Double> pointingDir2 = cPointingCol(PtIdx+1) ; 989 Vector<Double> dirVec2 = pointingDir2.column(0) ; 990 pointingDirVec = (dt1*dirVec2+dt2*dirVec1)/(dt1+dt2) ; 991 Vector<MDirection> vmd1(1) ; 992 Vector<MDirection> vmd2(1) ; 993 PtCols.directionMeasCol().get(PtIdx,vmd1) ; 994 Vector<Double> angle1 = vmd1(0).getAngle().getValue("rad") ; 995 PtCols.directionMeasCol().get(PtIdx+1,vmd2) ; 996 Vector<Double> angle2 = vmd2(0).getAngle().getValue("rad") ; 997 Vector<Double> angle = (dt1*angle2+dt2*angle1)/(dt1+dt2) ; 998 Quantum< Vector<Double> > qangle( angle, "rad" ) ; 999 String typeStr = vmd1(0).getRefString() ; 1000 //cerr << "vmd1.getRefString()=" << typeStr << endl ; 1001 MDirection::Types mdType ; 1002 MDirection::getType( mdType, typeStr ) ; 1003 //cerr << "mdType=" << mdType << endl ; 1004 md = MDirection( qangle, mdType ) ; 1005 //cerr << "md=" << md.getAngle().getValue("rad") << endl ; 1006 } 1007 else { 1008 pointingDirVec = pointingDir.column(0) ; 1009 Vector<MDirection> vmd(1); 1010 PtCols.directionMeasCol().get(PtIdx,vmd); 1011 md = vmd[0]; 1012 } 1013 // put J2000 coordinates in "direction" 1014 if (cDirRef =="J2000") { 1015 pksrec.direction = pointingDirVec ; 1016 } 1017 else { 1018 pksrec.direction = 1019 MDirection::Convert(md, MDirection::Ref(MDirection::J2000, 1020 frame) 1021 )().getAngle("rad").getValue(); 1022 1023 } 1024 uInt ncols = pointingDir.ncolumn(); 1025 pksrec.scanRate.resize(2); 1026 if (ncols == 1) { 1027 pksrec.scanRate = 0.0f; 1028 } else { 1029 pksrec.scanRate(0) = pointingDir.column(1)(0); 1030 pksrec.scanRate(1) = pointingDir.column(1)(1); 1031 } 1032 } 1033 else { 816 1034 // Get direction from FIELD table 817 1035 // here, assume direction to be the field direction not pointing 818 Matrix<Double> delayDir = cFieldDelayDirCol(fieldId); 819 direction = delayDir.column(0); 820 uInt ncols = delayDir.ncolumn(); 821 if (ncols == 1) { 822 scanRate = 0.0f; 823 } else { 824 scanRate = delayDir.column(1); 825 } 826 1036 Matrix<Double> delayDir = cFieldDelayDirCol(fieldId); 1037 pksrec.direction = delayDir.column(0); 1038 uInt ncols = delayDir.ncolumn(); 1039 pksrec.scanRate.resize(2); 1040 if (ncols == 1) { 1041 pksrec.scanRate = 0.0f; 1042 } else { 1043 pksrec.scanRate(0) = delayDir.column(1)(0); 1044 pksrec.scanRate(1) = delayDir.column(1)(1); 1045 } 1046 } 827 1047 // caluculate azimuth and elevation 828 1048 // first, get the reference frame 1049 /** 829 1050 MVPosition mvpos(antennaCols.position()(0)); 830 1051 MPosition mp(mvpos); … … 833 1054 MEpoch me(mvt); 834 1055 MeasFrame frame(mp, me); 1056 **/ 835 1057 // 836 1058 ROMSFieldColumns fldCols(cPKSMS.field()); 837 1059 Vector<MDirection> vmd(1); 838 MDirection md;1060 //MDirection md; 839 1061 fldCols.delayDirMeasCol().get(fieldId,vmd); 840 1062 md = vmd[0]; … … 847 1069 )().getAngle("rad").getValue(); 848 1070 //cerr<<"azel="<<azel<<endl; 849 azimuth = azel[0];850 elevation = azel[1];1071 pksrec.azimuth = azel[0]; 1072 pksrec.elevation = azel[1]; 851 1073 852 1074 // Get Tsys assuming that entries in the SYSCAL table match the main table. … … 858 1080 } 859 1081 if (cHaveTsys) { 860 cTsysCol.get(cIdx, tsys, True);1082 cTsysCol.get(cIdx, pksrec.tsys, True); 861 1083 } else { 862 1084 Int numReceptor; 863 1085 cNumReceptorCol.get(0, numReceptor); 864 tsys.resize(numReceptor);865 tsys = 1.0f;866 } 867 cSigmaCol.get(cIdx, sigma, True);1086 pksrec.tsys.resize(numReceptor); 1087 pksrec.tsys = 1.0f; 1088 } 1089 cSigmaCol.get(cIdx, pksrec.sigma, True); 868 1090 869 1091 //get Tcal if available … … 875 1097 if (nTcalColRow > 0) { 876 1098 // find tcal match with the data with the data time stamp 877 Double mjds = mjd*(24*3600);1099 Double mjds = pksrec.mjd*(24*3600); 878 1100 Double dtcalTime; 879 if ( mjd > lastmjd || cIdx==0 ) {1101 if ( pksrec.mjd > lastmjd || cIdx==0 ) { 880 1102 //Table tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds)); 881 1103 tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds), nrws); … … 898 1120 ROScalarColumn<Double> tcalTimeCol(tmptab2, "TIME"); 899 1121 if (syscalrow==0) { 900 cerr<<"Cannot find any matching Tcal at/near the data timestamp." 901 << " Set Tcal=0.0"<<endl; 1122 os << LogIO::NORMAL 1123 <<"Cannot find any matching Tcal at/near the data timestamp." 1124 << " Set Tcal=0.0" << LogIO::POST ; 902 1125 } else { 903 tcalCol.get(0, tcal);1126 tcalCol.get(0, pksrec.tcal); 904 1127 tcalTimeCol.get(0,dtcalTime); 905 tcalTime = MVTime(dtcalTime/(24*3600)).string(MVTime::YMD);1128 pksrec.tcalTime = MVTime(dtcalTime/(24*3600)).string(MVTime::YMD); 906 1129 //DEBUG 907 1130 //cerr<<"cIdx:"<<cIdx<<" tcal="<<tcal<<" tcalTime="<<tcalTime<<endl; … … 910 1133 } 911 1134 } 912 lastmjd = mjd;1135 lastmjd = pksrec.mjd; 913 1136 } 914 1137 915 1138 // Calibration factors (if available). 916 calFctr.resize(cNPol(iIF));1139 pksrec.calFctr.resize(cNPol(iIF)); 917 1140 if (cHaveCalFctr) { 918 cCalFctrCol.get(cIdx, calFctr);1141 cCalFctrCol.get(cIdx, pksrec.calFctr); 919 1142 } else { 920 calFctr = 0.0f;1143 pksrec.calFctr = 0.0f; 921 1144 } 922 1145 923 1146 // Baseline parameters (if available). 924 1147 if (cHaveBaseLin) { 925 baseLin.resize(2,cNPol(iIF));926 cBaseLinCol.get(cIdx, baseLin);927 928 baseSub.resize(9,cNPol(iIF));929 cBaseSubCol.get(cIdx, baseSub);1148 pksrec.baseLin.resize(2,cNPol(iIF)); 1149 cBaseLinCol.get(cIdx, pksrec.baseLin); 1150 1151 pksrec.baseSub.resize(24,cNPol(iIF)); 1152 cBaseSubCol.get(cIdx, pksrec.baseSub); 930 1153 931 1154 } else { 932 baseLin.resize(0,0); 933 baseSub.resize(0,0); 934 } 1155 pksrec.baseLin.resize(0,0); 1156 pksrec.baseSub.resize(0,0); 1157 } 1158 1159 935 1160 // Get spectral data. 936 1161 if (cGetSpectra) { … … 960 1185 // Transpose spectra. 961 1186 Int nPol = tmpData.nrow(); 962 spectra.resize(nChan, nPol);963 flagged.resize(nChan, nPol);1187 pksrec.spectra.resize(nChan, nPol); 1188 pksrec.flagged.resize(nChan, nPol); 964 1189 if (cEndChan(iIF) >= cStartChan(iIF)) { 965 1190 // Simple transposition. 966 1191 for (Int ipol = 0; ipol < nPol; ipol++) { 967 1192 for (Int ichan = 0; ichan < nChan; ichan++) { 968 spectra(ichan,ipol) = tmpData(ipol,ichan);969 flagged(ichan,ipol) = tmpFlag(ipol,ichan);1193 pksrec.spectra(ichan,ipol) = tmpData(ipol,ichan); 1194 pksrec.flagged(ichan,ipol) = tmpFlag(ipol,ichan); 970 1195 } 971 1196 } … … 976 1201 for (Int ipol = 0; ipol < nPol; ipol++) { 977 1202 for (Int ichan = 0; ichan < nChan; ichan++, jchan--) { 978 spectra(ichan,ipol) = tmpData(ipol,jchan);979 flagged(ichan,ipol) = tmpFlag(ipol,jchan);1203 pksrec.spectra(ichan,ipol) = tmpData(ipol,jchan); 1204 pksrec.flagged(ichan,ipol) = tmpFlag(ipol,jchan); 980 1205 } 981 1206 } 982 1207 } 1208 1209 // Row-based flagging info. (True:1, False:0) 1210 pksrec.flagrow = (cFlagRowCol(cIdx) ? 1 : 0); 983 1211 } 984 1212 … … 989 1217 990 1218 if (cHaveXCalFctr) { 991 cXCalFctrCol.get(cIdx, xCalFctr);1219 cXCalFctrCol.get(cIdx, pksrec.xCalFctr); 992 1220 } else { 993 xCalFctr = Complex(0.0f, 0.0f);994 } 995 996 if(!cA TF) {997 cDataCol.get(cIdx, xPol, True);1221 pksrec.xCalFctr = Complex(0.0f, 0.0f); 1222 } 1223 1224 if(!cALMA) { 1225 cDataCol.get(cIdx, pksrec.xPol, True); 998 1226 999 1227 if (cEndChan(iIF) < cStartChan(iIF)) { … … 1001 1229 Int jchan = nChan - 1; 1002 1230 for (Int ichan = 0; ichan < nChan/2; ichan++, jchan--) { 1003 ctmp = xPol(ichan);1004 xPol(ichan) =xPol(jchan);1005 xPol(jchan) = ctmp;1231 ctmp = pksrec.xPol(ichan); 1232 pksrec.xPol(ichan) = pksrec.xPol(jchan); 1233 pksrec.xPol(jchan) = ctmp; 1006 1234 } 1007 1235 } … … 1097 1325 cBaseLinCol.get(cIdx, baseLin); 1098 1326 1099 baseSub.resize( 9,cNPol(iIF));1327 baseSub.resize(24,cNPol(iIF)); 1100 1328 cBaseSubCol.get(cIdx, baseSub); 1101 1329 … … 1158 1386 cMSopen = False; 1159 1387 } 1388 1389 //-------------------------------------------------------- PKSMS2reader::splitAntenanSelectionString 1390 1391 // split antenna selection string 1392 // delimiter is ',' 1393 1394 Vector<String> PKSMS2reader::splitAntennaSelectionString( const String s ) 1395 { 1396 Char delim = ',' ; 1397 Int n = s.freq( delim ) + 1 ; 1398 Vector<String> antlist ; 1399 string sl[n] ; 1400 Int numSubstr = split( s, sl, n, "," ); 1401 antlist.resize( numSubstr ) ; 1402 for ( Int i = 0 ; i < numSubstr ; i++ ) { 1403 antlist[i] = String( sl[i] ) ; 1404 antlist[i].trim() ; 1405 } 1406 //cerr << "antlist = " << antlist << endl ; 1407 return antlist ; 1408 } 1409 1410 //-------------------------------------------------------- PKSMS2reader::setupAntennaList 1411 1412 // Fill cAntenna and cAntId 1413 1414 void PKSMS2reader::setupAntennaList( const String s ) 1415 { 1416 LogIO os( LogOrigin( "PKSMS2reader", "setupAntennaList()", WHERE ) ) ; 1417 //cerr << "antenna specification: " << s << endl ; 1418 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 1419 ROScalarColumn<String> antNames = antennaCols.name(); 1420 Int nrow = antNames.nrow() ; 1421 Vector<String> antlist = splitAntennaSelectionString( s ) ; 1422 Int len = antlist.size() ; 1423 Vector<Int> AntId( len ) ; 1424 Regex re( "[0-9]+" ) ; 1425 for ( Int i = 0 ; i < len ; i++ ) { 1426 if ( antlist[i].matches( re ) ) { 1427 AntId[i] = atoi( antlist[i].c_str() ) ; 1428 if ( AntId[i] >= nrow ) { 1429 os << LogIO::SEVERE << "Antenna index out of range: " << AntId[i] << LogIO::EXCEPTION ; 1430 } 1431 } 1432 else { 1433 AntId[i] = -1 ; 1434 for ( uInt j = 0 ; j < antNames.nrow() ; j++ ) { 1435 if ( antlist[i] == antNames(j) ) { 1436 AntId[i] = j ; 1437 break ; 1438 } 1439 } 1440 if ( AntId[i] == -1 ) { 1441 os << LogIO::SEVERE << "Specified antenna name not found: " << antlist[i] << LogIO::EXCEPTION ; 1442 } 1443 } 1444 } 1445 //cerr << "AntId = " << AntId << endl ; 1446 vector<Int> uniqId ; 1447 uniqId.push_back( AntId(0) ) ; 1448 for ( uInt i = 1 ; i < AntId.size() ; i++ ) { 1449 if ( count(uniqId.begin(),uniqId.end(),AntId[i]) == 0 ) { 1450 uniqId.push_back( AntId[i] ) ; 1451 } 1452 } 1453 Vector<Int> newAntId( uniqId ) ; 1454 cAntId.assign( newAntId ) ; 1455 //cerr << "cAntId = " << cAntId << endl ; 1456 }
Note: See TracChangeset
for help on using the changeset viewer.