Changeset 2290


Ignore:
Timestamp:
09/08/11 20:03:01 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-3219/ASAP-247)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs: sdlist unit test (reference data to be updated)

Put in Release Notes: Yes

Module(s): scantable.summary, sdlist

Description:

Output format of scantable summary changed.
Less use of TableIterator? for speed up scantable.summary/sdlist now lists a scantable
with 348,000 records (NRO 45m w/ 25beams x 13,920scans) in ~30sec (was ~7 min previously).


Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r2277 r2290  
    14251425        ssum=self._data._list_header()
    14261426        # Print Observation header to the upper-left corner of plot
    1427         headstr=[ssum[ssum.find('Observer:'):ssum.find('Flux Unit:')]]
    1428         headstr.append(ssum[ssum.find('Beams:'):ssum.find('Observer:')]
    1429                        +ssum[ssum.find('Rest Freqs:'):ssum.find('Abcissa:')])
     1427        headstr=[ssum[0:ssum.find('Obs. Type:')]]
     1428        headstr.append(ssum[ssum.find('Obs. Type:'):ssum.find('Flux Unit:')])
    14301429        if extrastr != '':
    14311430            headstr[0]=extrastr+'\n'+headstr[0]
     
    14501449            asaplog.push("----------------\n  Plot Summary\n----------------")
    14511450            asaplog.push(extrastr)
    1452             asaplog.push(ssum[ssum.find('Beams:'):ssum.find('Selection:')]\
    1453                          #+ selstr + ssum[ssum.find('Scan Source'):])
     1451            asaplog.push(ssum[0:ssum.find('Selection:')]\
    14541452                         + selstr)
    14551453        self._headtext['string'] = headstr
  • trunk/python/scantable.py

    r2286 r2290  
    462462            filename = ""
    463463        Scantable._summary(self, filename)
     464#         info = Scantable._summary(self, filename)
    464465#         return page(info)
    465466
  • trunk/src/Scantable.cpp

    r2286 r2290  
    996996  ostringstream oss;
    997997  oss.flags(std::ios_base::left);
     998  String tmp;
     999  // Project
     1000  table_.keywordSet().get("Project", tmp);
     1001  oss << setw(15) << "Project:" << tmp << endl;
     1002  // Observation date
     1003  oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
     1004  // Observer
     1005  oss << setw(15) << "Observer:"
     1006      << table_.keywordSet().asString("Observer") << endl;
     1007  // Antenna Name
     1008  table_.keywordSet().get("AntennaName", tmp);
     1009  oss << setw(15) << "Antenna Name:" << tmp << endl;
     1010  // Obs type
     1011  table_.keywordSet().get("Obstype", tmp);
     1012  // Records (nrow)
     1013  oss << setw(15) << "Data Records:" << table_.nrow() << " rows" << endl;
     1014  oss << setw(15) << "Obs. Type:" << tmp << endl;
     1015  // Beams, IFs, Polarizations, and Channels
     1016  oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
     1017      << setw(15) << "IFs:" << setw(4) << nif() << endl
     1018      << setw(15) << "Polarisations:" << setw(4) << npol()
     1019      << "(" << getPolType() << ")" << endl
     1020      << setw(15) << "Channels:" << nchan() << endl;
     1021  // Flux unit
     1022  table_.keywordSet().get("FluxUnit", tmp);
     1023  oss << setw(15) << "Flux Unit:" << tmp << endl;
     1024  // Abscissa Unit
     1025  oss << setw(15) << "Abscissa:" << getAbcissaLabel(0) << endl;
     1026  // Selection
     1027  oss << selector_.print() << endl;
     1028
     1029  return String(oss);
     1030}
     1031
     1032void Scantable::summary( const std::string& filename )
     1033{
     1034  ostringstream oss;
     1035  ofstream ofs;
     1036  LogIO ols(LogOrigin("Scantable", "summary", WHERE));
     1037
     1038  if (filename != "")
     1039    ofs.open( filename.c_str(),  ios::out );
     1040
     1041  oss << endl;
     1042  oss << asap::SEPERATOR << endl;
     1043  oss << " Scan Table Summary" << endl;
     1044  oss << asap::SEPERATOR << endl;
     1045
     1046  // Format header info
     1047  oss << headerSummary();
     1048  oss << endl;
     1049
     1050  if (table_.nrow() <= 0){
     1051    oss << asap::SEPERATOR << endl;
     1052    oss << "The MAIN table is empty: there are no data!!!" << endl;
     1053    oss << asap::SEPERATOR << endl;
     1054
     1055    ols << String(oss) << LogIO::POST;
     1056    if (ofs) {
     1057      ofs << String(oss) << flush;
     1058      ofs.close();
     1059    }
     1060    return;
     1061  }
     1062
     1063
     1064
     1065  // main table
     1066  String dirtype = "Position ("
     1067                  + getDirectionRefString()
     1068                  + ")";
     1069  oss.flags(std::ios_base::left);
     1070  oss << setw(5) << "Scan"
     1071      << setw(15) << "Source"
     1072      << setw(35) << "Time range"
     1073      << setw(2) << "" << setw(7) << "Int[s]"
     1074      << setw(7) << "Record"
     1075      << setw(8) << "SrcType"
     1076      << setw(8) << "FreqIDs"
     1077      << setw(7) << "MolIDs" << endl;
     1078  oss << setw(7)<< "" << setw(6) << "Beam"
     1079      << setw(23) << dirtype << endl;
     1080
     1081  oss << asap::SEPERATOR << endl;
     1082
     1083  // Flush summary and clear up the string
     1084  ols << String(oss) << LogIO::POST;
     1085  if (ofs) ofs << String(oss) << flush;
     1086  oss.str("");
     1087  oss.clear();
     1088
     1089
     1090  // Get Freq_ID map
     1091  ROScalarColumn<uInt> ftabIds(frequencies().table(), "ID");
     1092  Int nfid = ftabIds.nrow();
     1093  if (nfid <= 0){
     1094    oss << "FREQUENCIES subtable is empty: there are no data!!!" << endl;
     1095    oss << asap::SEPERATOR << endl;
     1096
     1097    ols << String(oss) << LogIO::POST;
     1098    if (ofs) {
     1099      ofs << String(oss) << flush;
     1100      ofs.close();
     1101    }
     1102    return;
     1103  }
     1104  // Storages of overall IFNO, POLNO, and nchan per FREQ_ID
     1105  // the orders are identical to ID in FREQ subtable
     1106  Block< Vector<uInt> > ifNos(nfid), polNos(nfid);
     1107  Vector<Int> fIdchans(nfid,-1);
     1108  map<uInt, Int> fidMap;  // (FREQ_ID, row # in FREQ subtable) pair
     1109  for (Int i=0; i < nfid; i++){
     1110   // fidMap[freqId] returns row number in FREQ subtable
     1111   fidMap.insert(pair<uInt, Int>(ftabIds(i),i));
     1112   ifNos[i] = Vector<uInt>();
     1113   polNos[i] = Vector<uInt>();
     1114  }
     1115
     1116  TableIterator iter(table_, "SCANNO");
     1117
     1118  // Vars for keeping track of time, freqids, molIds in a SCANNO
     1119  Vector<uInt> freqids;
     1120  Vector<uInt> molids;
     1121  Vector<uInt> beamids(1,0);
     1122  Vector<MDirection> beamDirs;
     1123  Vector<Int> stypeids(1,0);
     1124  Vector<String> stypestrs;
     1125  Int nfreq(1);
     1126  Int nmol(1);
     1127  uInt nbeam(1);
     1128  uInt nstype(1);
     1129
     1130  Double btime(0.0), etime(0.0);
     1131  Double meanIntTim(0.0);
     1132
     1133  uInt currFreqId(0), ftabRow(0);
     1134  Int iflen(0), pollen(0);
     1135
     1136  while (!iter.pastEnd()) {
     1137    Table subt = iter.table();
     1138    uInt snrow = subt.nrow();
     1139    ROTableRow row(subt);
     1140    const TableRecord& rec = row.get(0);
     1141
     1142    // relevant columns
     1143    ROScalarColumn<Double> mjdCol(subt,"TIME");
     1144    ROScalarColumn<Double> intervalCol(subt,"INTERVAL");
     1145    MDirection::ROScalarColumn dirCol(subt,"DIRECTION");
     1146
     1147    ScalarColumn<uInt> freqIdCol(subt,"FREQ_ID");
     1148    ScalarColumn<uInt> molIdCol(subt,"MOLECULE_ID");
     1149    ROScalarColumn<uInt> beamCol(subt,"BEAMNO");
     1150    ROScalarColumn<Int> stypeCol(subt,"SRCTYPE");
     1151
     1152    ROScalarColumn<uInt> ifNoCol(subt,"IFNO");
     1153    ROScalarColumn<uInt> polNoCol(subt,"POLNO");
     1154
     1155
     1156    // Times
     1157    meanIntTim = sum(intervalCol.getColumn()) / (double) snrow;
     1158    minMax(btime, etime, mjdCol.getColumn());
     1159    etime += meanIntTim/C::day;
     1160
     1161    // MOLECULE_ID and FREQ_ID
     1162    molids = getNumbers(molIdCol);
     1163    molids.shape(nmol);
     1164
     1165    freqids = getNumbers(freqIdCol);
     1166    freqids.shape(nfreq);
     1167
     1168    // Add first beamid, and srcNames
     1169    beamids.resize(1,False);
     1170    beamDirs.resize(1,False);
     1171    beamids(0)=beamCol(0);
     1172    beamDirs(0)=dirCol(0);
     1173    nbeam = 1;
     1174
     1175    stypeids.resize(1,False);
     1176    stypeids(0)=stypeCol(0);
     1177    nstype = 1;
     1178
     1179    // Global listings of nchan/IFNO/POLNO per FREQ_ID
     1180    currFreqId=freqIdCol(0);
     1181    ftabRow = fidMap[currFreqId];
     1182    // Assumes an identical number of channels per FREQ_ID
     1183    if (fIdchans(ftabRow) < 0 ) {
     1184      RORecordFieldPtr< Array<Float> > spec(rec, "SPECTRA");
     1185      fIdchans(ftabRow)=(*spec).shape()(0);
     1186    }
     1187    // Should keep ifNos and polNos form the previous SCANNO
     1188    if ( !anyEQ(ifNos[ftabRow],ifNoCol(0)) ) {
     1189      ifNos[ftabRow].shape(iflen);
     1190      iflen++;
     1191      ifNos[ftabRow].resize(iflen,True);
     1192      ifNos[ftabRow](iflen-1) = ifNoCol(0);
     1193    }
     1194    if ( !anyEQ(polNos[ftabRow],polNoCol(0)) ) {
     1195      polNos[ftabRow].shape(pollen);
     1196      pollen++;
     1197      polNos[ftabRow].resize(pollen,True);
     1198      polNos[ftabRow](pollen-1) = polNoCol(0);
     1199    }
     1200
     1201    for (uInt i=1; i < snrow; i++){
     1202      // Need to list BEAMNO and DIRECTION in the same order
     1203      if ( !anyEQ(beamids,beamCol(i)) ) {
     1204        nbeam++;
     1205        beamids.resize(nbeam,True);
     1206        beamids(nbeam-1)=beamCol(i);
     1207        beamDirs.resize(nbeam,True);
     1208        beamDirs(nbeam-1)=dirCol(i);
     1209      }
     1210
     1211      // SRCTYPE is Int (getNumber takes only uInt)
     1212      if ( !anyEQ(stypeids,stypeCol(i)) ) {
     1213        nstype++;
     1214        stypeids.resize(nstype,True);
     1215        stypeids(nstype-1)=stypeCol(i);
     1216      }
     1217
     1218      // Global listings of nchan/IFNO/POLNO per FREQ_ID
     1219      currFreqId=freqIdCol(i);
     1220      ftabRow = fidMap[currFreqId];
     1221      if (fIdchans(ftabRow) < 0 ) {
     1222        const TableRecord& rec = row.get(i);
     1223        RORecordFieldPtr< Array<Float> > spec(rec, "SPECTRA");
     1224        fIdchans(ftabRow) = (*spec).shape()(0);
     1225      }
     1226      if ( !anyEQ(ifNos[ftabRow],ifNoCol(i)) ) {
     1227        ifNos[ftabRow].shape(iflen);
     1228        iflen++;
     1229        ifNos[ftabRow].resize(iflen,True);
     1230        ifNos[ftabRow](iflen-1) = ifNoCol(i);
     1231      }
     1232      if ( !anyEQ(polNos[ftabRow],polNoCol(i)) ) {
     1233        polNos[ftabRow].shape(pollen);
     1234        pollen++;
     1235        polNos[ftabRow].resize(pollen,True);
     1236        polNos[ftabRow](pollen-1) = polNoCol(i);
     1237      }
     1238    } // end of row iteration
     1239
     1240    stypestrs.resize(nstype,False);
     1241    for (uInt j=0; j < nstype; j++)
     1242      stypestrs(j) = SrcType::getName(stypeids(j));
     1243
     1244    // Format Scan summary
     1245    oss << setw(4) << std::right << rec.asuInt("SCANNO")
     1246        << std::left << setw(1) << ""
     1247        << setw(15) << rec.asString("SRCNAME")
     1248        << setw(21) << MVTime(btime).string(MVTime::YMD,7)
     1249        << setw(3) << " - " << MVTime(etime).string(MVTime::TIME,7)
     1250        << setw(3) << "" << setw(6) << meanIntTim << setw(1) << ""
     1251        << std::right << setw(5) << snrow << setw(2) << ""
     1252        << std::left << stypestrs << setw(1) << ""
     1253        << freqids << setw(1) << ""
     1254        << molids  << endl;
     1255    // Format Beam summary
     1256    for (uInt j=0; j < nbeam; j++) {
     1257      oss << setw(7) << "" << setw(6) << beamids(j) << setw(1) << ""
     1258          << formatDirection(beamDirs(j)) << endl;
     1259    }
     1260    // Flush summary every scan and clear up the string
     1261    ols << String(oss) << LogIO::POST;
     1262    if (ofs) ofs << String(oss) << flush;
     1263    oss.str("");
     1264    oss.clear();
     1265
     1266    ++iter;
     1267  } // end of scan iteration
     1268  oss << asap::SEPERATOR << endl;
     1269 
     1270  // List FRECUENCIES Table (using STFrequencies.print may be slow)
     1271  oss << "FREQUENCIES: " << nfreq << endl;
     1272  oss << std::right << setw(5) << "ID" << setw(2) << ""
     1273      << std::left  << setw(5) << "IFNO" << setw(2) << ""
     1274      << setw(8) << "Frame"
     1275      << setw(16) << "RefVal"
     1276      << setw(7) << "RefPix"
     1277      << setw(15) << "Increment"
     1278      << setw(9) << "Channels"
     1279      << setw(6) << "POLNOs" << endl;
     1280  Int tmplen;
     1281  for (Int i=0; i < nfid; i++){
     1282    // List row=i of FREQUENCIES subtable
     1283    ifNos[i].shape(tmplen);
     1284    if (tmplen == 1) {
     1285      oss << std::right << setw(5) << ftabIds(i) << setw(2) << ""
     1286          << setw(3) << ifNos[i](0) << setw(1) << ""
     1287          << std::left << setw(46) << frequencies().print(ftabIds(i))
     1288          << setw(2) << ""
     1289          << std::right << setw(8) << fIdchans[i] << setw(2) << ""
     1290          << std::left << polNos[i] << endl;
     1291    } else if (tmplen > 0 ) {
     1292      // You shouldn't come here
     1293      oss << std::left
     1294          << "Multiple IFNOs in FREQ_ID = " << ftabIds(i)
     1295          << " !!!" << endl;
     1296    }
     1297  }
     1298  oss << asap::SEPERATOR << endl;
     1299
     1300  // List MOLECULES Table (currently lists all rows)
     1301  oss << "MOLECULES: " << endl;
     1302  if (molecules().nrow() <= 0) {
     1303    oss << "   MOLECULES subtable is empty: there are no data" << endl;
     1304  } else {
     1305    ROTableRow row(molecules().table());
     1306    oss << std::right << setw(5) << "ID"
     1307        << std::left << setw(3) << ""
     1308        << setw(18) << "RestFreq"
     1309        << setw(15) << "Name" << endl;
     1310    for (Int i=0; i < molecules().nrow(); i++){
     1311      const TableRecord& rec=row.get(i);
     1312      oss << std::right << setw(5) << rec.asuInt("ID")
     1313          << std::left << setw(3) << ""
     1314          << rec.asArrayDouble("RESTFREQUENCY") << setw(1) << ""
     1315          << rec.asArrayString("NAME") << endl;
     1316    }
     1317  }
     1318  oss << asap::SEPERATOR << endl;
     1319  ols << String(oss) << LogIO::POST;
     1320  if (ofs) {
     1321    ofs << String(oss) << flush;
     1322    ofs.close();
     1323  }
     1324  //  return String(oss);
     1325}
     1326
     1327
     1328std::string Scantable::oldheaderSummary()
     1329{
     1330  // Format header info
     1331//   STHeader sdh;
     1332//   sdh = getHeader();
     1333//   sdh.print();
     1334  ostringstream oss;
     1335  oss.flags(std::ios_base::left);
    9981336  oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
    9991337      << setw(15) << "IFs:" << setw(4) << nif() << endl
     
    10131351  table_.keywordSet().get("FluxUnit", tmp);
    10141352  oss << setw(15) << "Flux Unit:" << tmp << endl;
    1015   //Vector<Double> vec(moleculeTable_.getRestFrequencies());
    10161353  int nid = moleculeTable_.nrow();
    10171354  Bool firstline = True;
     
    10411378
    10421379  //std::string Scantable::summary( const std::string& filename )
    1043 void Scantable::summary( const std::string& filename )
     1380void Scantable::oldsummary( const std::string& filename )
    10441381{
    10451382  ostringstream oss;
     
    10561393
    10571394  // Format header info
    1058   oss << headerSummary();
     1395  oss << oldheaderSummary();
    10591396  oss << endl;
    10601397
     
    10811418  oss.clear();
    10821419
    1083 //   TableIterator iter(table_, "SCANNO");
    1084 //   while (!iter.pastEnd()) {
    1085 //     Table subt = iter.table();
    1086 //     ROTableRow row(subt);
    1087 //     MEpoch::ROScalarColumn timeCol(subt,"TIME");
    1088 //     const TableRecord& rec = row.get(0);
    1089 //     oss << setw(4) << std::right << rec.asuInt("SCANNO")
    1090 //         << std::left << setw(1) << ""
    1091 //         << setw(15) << rec.asString("SRCNAME")
    1092 //         << setw(10) << formatTime(timeCol(0), false);
    1093 //     // count the cycles in the scan
    1094 //     TableIterator cyciter(subt, "CYCLENO");
    1095 //     int nint = 0;
    1096 //     while (!cyciter.pastEnd()) {
    1097 //       ++nint;
    1098 //       ++cyciter;
    1099 //     }
    1100 //     oss << setw(3) << std::right << nint  << setw(3) << " x " << std::left
    1101 //         << setw(11) <<  formatSec(rec.asFloat("INTERVAL")) << setw(1) << ""
    1102 //      << setw(15) << SrcType::getName(rec.asInt("SRCTYPE")) << endl;
    1103 
    1104 //     TableIterator biter(subt, "BEAMNO");
    1105 //     while (!biter.pastEnd()) {
    1106 //       Table bsubt = biter.table();
    1107 //       ROTableRow brow(bsubt);
    1108 //       const TableRecord& brec = brow.get(0);
    1109 //       uInt row0 = bsubt.rowNumbers(table_)[0];
    1110 //       oss << setw(5) << "" <<  setw(4) << std::right << brec.asuInt("BEAMNO")<< std::left;
    1111 //       oss  << setw(4) << ""  << formatDirection(getDirection(row0)) << endl;
    1112 //       TableIterator iiter(bsubt, "IFNO");
    1113 //       while (!iiter.pastEnd()) {
    1114 //         Table isubt = iiter.table();
    1115 //         ROTableRow irow(isubt);
    1116 //         const TableRecord& irec = irow.get(0);
    1117 //         oss << setw(9) << "";
    1118 //         oss << setw(3) << std::right << irec.asuInt("IFNO") << std::left
    1119 //             << setw(1) << "" << frequencies().print(irec.asuInt("FREQ_ID"))
    1120 //             << setw(3) << "" << nchan(irec.asuInt("IFNO"))
    1121 //             << endl;
    1122 
    1123 //         ++iiter;
    1124 //       }
    1125 //       ++biter;
    1126 //     }
    1127 //     ++iter;
    1128 //   }
    11291420  TableIterator iter(table_, "SCANNO");
    11301421  while (!iter.pastEnd()) {
     
    11821473  ols << String(oss) << LogIO::POST;
    11831474  if (ofs) {
    1184     //ofs << String(oss) << flush;
     1475    ofs << String(oss) << flush;
    11851476    ofs.close();
    11861477  }
  • trunk/src/Scantable.h

    r2286 r2290  
    375375
    376376  std::string headerSummary();
     377  void summary(const std::string& filename="");
     378  std::string oldheaderSummary();
    377379  //  std::string summary();
    378   void summary(const std::string& filename="");
     380  void oldsummary(const std::string& filename="");
     381
    379382  //std::string getTime(int whichrow=-1, bool showdate=true) const;
    380383  std::string getTime(int whichrow=-1, bool showdate=true, casa::uInt prec=0) const;
  • trunk/src/ScantableWrapper.h

    r2286 r2290  
    221221  //  }
    222222  void summary(const std::string& filename="") {
    223     return table_->summary(filename);
     223    //std::string summary(const std::string& filename="") const {
     224    table_->summary(filename);
    224225  }
    225226
Note: See TracChangeset for help on using the changeset viewer.