Changeset 1779 for branches/mergetest/src/Scantable.cpp
- Timestamp:
- 07/29/10 19:13:46 (14 years ago)
- Location:
- branches/mergetest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mergetest
- Property svn:mergeinfo changed
-
branches/mergetest/src/Scantable.cpp
r1743 r1779 11 11 // 12 12 #include <map> 13 #include <fstream> 13 14 14 15 #include <casa/aips.h> … … 24 25 #include <casa/Arrays/Vector.h> 25 26 #include <casa/Arrays/VectorSTLIterator.h> 27 #include <casa/Arrays/Slice.h> 26 28 #include <casa/BasicMath/Math.h> 27 29 #include <casa/BasicSL/Constants.h> … … 29 31 #include <casa/Containers/RecordField.h> 30 32 #include <casa/Utilities/GenSort.h> 33 #include <casa/Logging/LogIO.h> 31 34 32 35 #include <tables/Tables/TableParse.h> … … 106 109 { 107 110 initFactories(); 111 108 112 Table tab(name, Table::Update); 109 113 uInt version = tab.keywordSet().asuInt("VERSION"); … … 121 125 attach(); 122 126 } 127 /* 128 Scantable::Scantable(const std::string& name, Table::TableType ttype) : 129 type_(ttype) 130 { 131 initFactories(); 132 Table tab(name, Table::Update); 133 uInt version = tab.keywordSet().asuInt("VERSION"); 134 if (version != version_) { 135 throw(AipsError("Unsupported version of ASAP file.")); 136 } 137 if ( type_ == Table::Memory ) { 138 table_ = tab.copyToMemoryTable(generateName()); 139 } else { 140 table_ = tab; 141 } 142 143 attachSubtables(); 144 originalTable_ = table_; 145 attach(); 146 } 147 */ 123 148 124 149 Scantable::Scantable( const Scantable& other, bool clear ) … … 201 226 td.addColumn(ScalarColumnDesc<Int>("REFBEAMNO")); 202 227 228 td.addColumn(ScalarColumnDesc<uInt>("FLAGROW")); 229 203 230 td.addColumn(ScalarColumnDesc<Double>("TIME")); 204 231 TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default … … 257 284 originalTable_ = table_; 258 285 } 259 260 286 261 287 void Scantable::attach() … … 285 311 mfocusidCol_.attach(table_, "FOCUS_ID"); 286 312 mmolidCol_.attach(table_, "MOLECULE_ID"); 313 314 //Add auxiliary column for row-based flagging (CAS-1433 Wataru Kawasaki) 315 attachAuxColumnDef(flagrowCol_, "FLAGROW", 0); 316 317 } 318 319 template<class T, class T2> 320 void Scantable::attachAuxColumnDef(ScalarColumn<T>& col, 321 const String& colName, 322 const T2& defValue) 323 { 324 try { 325 col.attach(table_, colName); 326 } catch (TableError& err) { 327 String errMesg = err.getMesg(); 328 if (errMesg == "Table column " + colName + " is unknown") { 329 table_.addColumn(ScalarColumnDesc<T>(colName)); 330 col.attach(table_, colName); 331 col.fillColumn(static_cast<T>(defValue)); 332 } else { 333 throw; 334 } 335 } catch (...) { 336 throw; 337 } 338 } 339 340 template<class T, class T2> 341 void Scantable::attachAuxColumnDef(ArrayColumn<T>& col, 342 const String& colName, 343 const Array<T2>& defValue) 344 { 345 try { 346 col.attach(table_, colName); 347 } catch (TableError& err) { 348 String errMesg = err.getMesg(); 349 if (errMesg == "Table column " + colName + " is unknown") { 350 table_.addColumn(ArrayColumnDesc<T>(colName)); 351 col.attach(table_, colName); 352 353 int size = 0; 354 ArrayIterator<T2>& it = defValue.begin(); 355 while (it != defValue.end()) { 356 ++size; 357 ++it; 358 } 359 IPosition ip(1, size); 360 Array<T>& arr(ip); 361 for (int i = 0; i < size; ++i) 362 arr[i] = static_cast<T>(defValue[i]); 363 364 col.fillColumn(arr); 365 } else { 366 throw; 367 } 368 } catch (...) { 369 throw; 370 } 287 371 } 288 372 … … 627 711 } 628 712 713 void Scantable::clip(const Float uthres, const Float dthres, bool clipoutside, bool unflag) 714 { 715 for (uInt i=0; i<table_.nrow(); ++i) { 716 Vector<uChar> flgs = flagsCol_(i); 717 srchChannelsToClip(i, uthres, dthres, clipoutside, unflag, flgs); 718 flagsCol_.put(i, flgs); 719 } 720 } 721 722 std::vector<bool> Scantable::getClipMask(int whichrow, const Float uthres, const Float dthres, bool clipoutside, bool unflag) 723 { 724 Vector<uChar> flags; 725 flagsCol_.get(uInt(whichrow), flags); 726 srchChannelsToClip(uInt(whichrow), uthres, dthres, clipoutside, unflag, flags); 727 Vector<Bool> bflag(flags.shape()); 728 convertArray(bflag, flags); 729 //bflag = !bflag; 730 731 std::vector<bool> mask; 732 bflag.tovector(mask); 733 return mask; 734 } 735 736 void Scantable::srchChannelsToClip(uInt whichrow, const Float uthres, const Float dthres, bool clipoutside, bool unflag, 737 Vector<uChar> flgs) 738 { 739 Vector<Float> spcs = specCol_(whichrow); 740 uInt nchannel = nchan(); 741 if (spcs.nelements() != nchannel) { 742 throw(AipsError("Data has incorrect number of channels")); 743 } 744 uChar userflag = 1 << 7; 745 if (unflag) { 746 userflag = 0 << 7; 747 } 748 if (clipoutside) { 749 for (uInt j = 0; j < nchannel; ++j) { 750 Float spc = spcs(j); 751 if ((spc >= uthres) || (spc <= dthres)) { 752 flgs(j) = userflag; 753 } 754 } 755 } else { 756 for (uInt j = 0; j < nchannel; ++j) { 757 Float spc = spcs(j); 758 if ((spc < uthres) && (spc > dthres)) { 759 flgs(j) = userflag; 760 } 761 } 762 } 763 } 764 629 765 void Scantable::flag(const std::vector<bool>& msk, bool unflag) 630 766 { … … 673 809 flagsCol_.put(i, flgs); 674 810 } 811 } 812 813 void Scantable::flagRow(const std::vector<uInt>& rows, bool unflag) 814 { 815 if ( selector_.empty() && (rows.size() == table_.nrow()) ) 816 throw(AipsError("Trying to flag whole scantable.")); 817 818 uInt rowflag = (unflag ? 0 : 1); 819 std::vector<uInt>::const_iterator it; 820 for (it = rows.begin(); it != rows.end(); ++it) 821 flagrowCol_.put(*it, rowflag); 675 822 } 676 823 … … 793 940 table_.keywordSet().get("FluxUnit", tmp); 794 941 oss << setw(15) << "Flux Unit:" << tmp << endl; 795 Vector<Double> vec(moleculeTable_.getRestFrequencies()); 942 //Vector<Double> vec(moleculeTable_.getRestFrequencies()); 943 int nid = moleculeTable_.nrow(); 944 Bool firstline = True; 796 945 oss << setw(15) << "Rest Freqs:"; 797 if (vec.nelements() > 0) { 798 oss << setprecision(10) << vec << " [Hz]" << endl; 799 } else { 800 oss << "none" << endl; 946 for (int i=0; i<nid; i++) { 947 Table t = table_(table_.col("MOLECULE_ID") == i); 948 if (t.nrow() > 0) { 949 Vector<Double> vec(moleculeTable_.getRestFrequency(i)); 950 if (vec.nelements() > 0) { 951 if (firstline) { 952 oss << setprecision(10) << vec << " [Hz]" << endl; 953 firstline=False; 954 } 955 else{ 956 oss << setw(15)<<" " << setprecision(10) << vec << " [Hz]" << endl; 957 } 958 } else { 959 oss << "none" << endl; 960 } 961 } 801 962 } 802 963 … … 901 1062 const MDirection& md = getDirection(whichrow); 902 1063 const MEpoch& me = timeCol_(whichrow); 903 Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 1064 //Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 1065 Vector<Double> rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 904 1066 return freqTable_.getSpectralCoordinate(md, mp, me, rf, 905 1067 mfreqidCol_(whichrow)); … … 975 1137 const MDirection& md = getDirection(whichrow); 976 1138 const MEpoch& me = timeCol_(whichrow); 977 const Double& rf = mmolidCol_(whichrow); 1139 //const Double& rf = mmolidCol_(whichrow); 1140 const Vector<Double> rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 978 1141 SpectralCoordinate spc = 979 1142 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow)); … … 992 1155 } 993 1156 994 void Scantable::setRestFrequencies( double rf, const std::string& name, 1157 /** 1158 void asap::Scantable::setRestFrequencies( double rf, const std::string& name, 995 1159 const std::string& unit ) 1160 **/ 1161 void Scantable::setRestFrequencies( vector<double> rf, const vector<std::string>& name, 1162 const std::string& unit ) 1163 996 1164 { 997 1165 ///@todo lookup in line table to fill in name and formattedname 998 1166 Unit u(unit); 999 Quantum<Double> urf(rf, u); 1000 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), name, ""); 1167 //Quantum<Double> urf(rf, u); 1168 Quantum<Vector<Double> >urf(rf, u); 1169 Vector<String> formattedname(0); 1170 //cerr<<"Scantable::setRestFrequnecies="<<urf<<endl; 1171 1172 //uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), name, ""); 1173 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), mathutil::toVectorString(name), formattedname); 1001 1174 TableVector<uInt> tabvec(table_, "MOLECULE_ID"); 1002 1175 tabvec = id; 1003 1176 } 1004 1177 1005 void Scantable::setRestFrequencies( const std::string& name ) 1178 /** 1179 void asap::Scantable::setRestFrequencies( const std::string& name ) 1006 1180 { 1007 1181 throw(AipsError("setRestFrequencies( const std::string& name ) NYI")); 1182 ///@todo implement 1183 } 1184 **/ 1185 void Scantable::setRestFrequencies( const vector<std::string>& name ) 1186 { 1187 throw(AipsError("setRestFrequencies( const vector<std::string>& name ) NYI")); 1008 1188 ///@todo implement 1009 1189 } … … 1044 1224 void Scantable::addFit( const STFitEntry& fit, int row ) 1045 1225 { 1046 cout << mfitidCol_(uInt(row)) << endl; 1226 //cout << mfitidCol_(uInt(row)) << endl; 1227 LogIO os( LogOrigin( "Scantable", "addFit()", WHERE ) ) ; 1228 os << mfitidCol_(uInt(row)) << LogIO::POST ; 1047 1229 uInt id = fitTable_.addEntry(fit, mfitidCol_(uInt(row))); 1048 1230 mfitidCol_.put(uInt(row), id); … … 1078 1260 Table subt = t( t.col("SCAN") == scanlist[i]+1 ); 1079 1261 if (subt.nrow()==0) { 1080 cerr <<"Scan "<<scanlist[i]<<" cannot be found in the scantable."<<endl; 1262 //cerr <<"Scan "<<scanlist[i]<<" cannot be found in the scantable."<<endl; 1263 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1264 os <<LogIO::WARN<<"Scan "<<scanlist[i]<<" cannot be found in the scantable."<<LogIO::POST; 1081 1265 ret = 1; 1082 1266 break; … … 1090 1274 Table subt2 = t( t.col("SCAN") == scanlist[i+1]+1 ); 1091 1275 if ( subt2.nrow() == 0) { 1092 cerr<<"Scan "<<scanlist[i+1]<<" cannot be found in the scantable."<<endl; 1276 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1277 1278 //cerr<<"Scan "<<scanlist[i+1]<<" cannot be found in the scantable."<<endl; 1279 os<<LogIO::WARN<<"Scan "<<scanlist[i+1]<<" cannot be found in the scantable."<<LogIO::POST; 1093 1280 ret = 1; 1094 1281 break; … … 1100 1287 if (scan1seqn == 1 && scan2seqn == 2) { 1101 1288 if (laston1 == laston2) { 1102 cerr<<"A valid scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<endl; 1289 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1290 //cerr<<"A valid scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<endl; 1291 os<<"A valid scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<LogIO::POST; 1103 1292 i +=1; 1104 1293 } 1105 1294 else { 1106 cerr<<"Incorrect scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<endl; 1295 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1296 //cerr<<"Incorrect scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<endl; 1297 os<<LogIO::WARN<<"Incorrect scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<LogIO::POST; 1107 1298 } 1108 1299 } 1109 1300 else if (scan1seqn==2 && scan2seqn == 1) { 1110 1301 if (laston1 == laston2) { 1111 cerr<<"["<<scanlist[i]<<","<<scanlist[i+1]<<"] is a valid scan pair but in incorrect order."<<endl; 1302 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1303 //cerr<<"["<<scanlist[i]<<","<<scanlist[i+1]<<"] is a valid scan pair but in incorrect order."<<endl; 1304 os<<LogIO::WARN<<"["<<scanlist[i]<<","<<scanlist[i+1]<<"] is a valid scan pair but in incorrect order."<<LogIO::POST; 1112 1305 ret = 1; 1113 1306 break; … … 1115 1308 } 1116 1309 else { 1117 cerr<<"The other scan for "<<scanlist[i]<<" appears to be missing. Check the input scan numbers."<<endl; 1310 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1311 //cerr<<"The other scan for "<<scanlist[i]<<" appears to be missing. Check the input scan numbers."<<endl; 1312 os<<LogIO::WARN<<"The other scan for "<<scanlist[i]<<" appears to be missing. Check the input scan numbers."<<LogIO::POST; 1118 1313 ret = 1; 1119 1314 break; … … 1122 1317 } 1123 1318 else { 1124 cerr<<"The scan does not appear to be standard obsevation."<<endl; 1319 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1320 //cerr<<"The scan does not appear to be standard obsevation."<<endl; 1321 os<<LogIO::WARN<<"The scan does not appear to be standard obsevation."<<LogIO::POST; 1125 1322 } 1126 1323 //if ( i >= nscan ) break; … … 1128 1325 } 1129 1326 else { 1130 cerr<<"No reference to GBT_GO table."<<endl; 1327 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ; 1328 //cerr<<"No reference to GBT_GO table."<<endl; 1329 os<<LogIO::WARN<<"No reference to GBT_GO table."<<LogIO::POST; 1131 1330 ret = 1; 1132 1331 } … … 1142 1341 } 1143 1342 1343 void asap::Scantable::reshapeSpectrum( int nmin, int nmax ) 1344 throw( casa::AipsError ) 1345 { 1346 // assumed that all rows have same nChan 1347 Vector<Float> arr = specCol_( 0 ) ; 1348 int nChan = arr.nelements() ; 1349 1350 // if nmin < 0 or nmax < 0, nothing to do 1351 if ( nmin < 0 ) { 1352 throw( casa::indexError<int>( nmin, "asap::Scantable::reshapeSpectrum: Invalid range. Negative index is specified." ) ) ; 1353 } 1354 if ( nmax < 0 ) { 1355 throw( casa::indexError<int>( nmax, "asap::Scantable::reshapeSpectrum: Invalid range. Negative index is specified." ) ) ; 1356 } 1357 1358 // if nmin > nmax, exchange values 1359 if ( nmin > nmax ) { 1360 int tmp = nmax ; 1361 nmax = nmin ; 1362 nmin = tmp ; 1363 LogIO os( LogOrigin( "Scantable", "reshapeSpectrum()", WHERE ) ) ; 1364 os << "Swap values. Applied range is [" 1365 << nmin << ", " << nmax << "]" << LogIO::POST ; 1366 } 1367 1368 // if nmin exceeds nChan, nothing to do 1369 if ( nmin >= nChan ) { 1370 throw( casa::indexError<int>( nmin, "asap::Scantable::reshapeSpectrum: Invalid range. Specified minimum exceeds nChan." ) ) ; 1371 } 1372 1373 // if nmax exceeds nChan, reset nmax to nChan 1374 if ( nmax >= nChan ) { 1375 if ( nmin == 0 ) { 1376 // nothing to do 1377 LogIO os( LogOrigin( "Scantable", "reshapeSpectrum()", WHERE ) ) ; 1378 os << "Whole range is selected. Nothing to do." << LogIO::POST ; 1379 return ; 1380 } 1381 else { 1382 LogIO os( LogOrigin( "Scantable", "reshapeSpectrum()", WHERE ) ) ; 1383 os << "Specified maximum exceeds nChan. Applied range is [" 1384 << nmin << ", " << nChan-1 << "]." << LogIO::POST ; 1385 nmax = nChan - 1 ; 1386 } 1387 } 1388 1389 // reshape specCol_ and flagCol_ 1390 for ( int irow = 0 ; irow < nrow() ; irow++ ) { 1391 reshapeSpectrum( nmin, nmax, irow ) ; 1392 } 1393 1394 // update FREQUENCIES subtable 1395 Double refpix ; 1396 Double refval ; 1397 Double increment ; 1398 int freqnrow = freqTable_.table().nrow() ; 1399 Vector<uInt> oldId( freqnrow ) ; 1400 Vector<uInt> newId( freqnrow ) ; 1401 for ( int irow = 0 ; irow < freqnrow ; irow++ ) { 1402 freqTable_.getEntry( refpix, refval, increment, irow ) ; 1403 /*** 1404 * need to shift refpix to nmin 1405 * note that channel nmin in old index will be channel 0 in new one 1406 ***/ 1407 refval = refval - ( refpix - nmin ) * increment ; 1408 refpix = 0 ; 1409 freqTable_.setEntry( refpix, refval, increment, irow ) ; 1410 } 1411 1412 // update nchan 1413 int newsize = nmax - nmin + 1 ; 1414 table_.rwKeywordSet().define( "nChan", newsize ) ; 1415 1416 // update bandwidth 1417 // assumed all spectra in the scantable have same bandwidth 1418 table_.rwKeywordSet().define( "Bandwidth", increment * newsize ) ; 1419 1420 return ; 1421 } 1422 1423 void asap::Scantable::reshapeSpectrum( int nmin, int nmax, int irow ) 1424 { 1425 // reshape specCol_ and flagCol_ 1426 Vector<Float> oldspec = specCol_( irow ) ; 1427 Vector<uChar> oldflag = flagsCol_( irow ) ; 1428 uInt newsize = nmax - nmin + 1 ; 1429 specCol_.put( irow, oldspec( Slice( nmin, newsize, 1 ) ) ) ; 1430 flagsCol_.put( irow, oldflag( Slice( nmin, newsize, 1 ) ) ) ; 1431 1432 return ; 1433 } 1434 1435 void asap::Scantable::regridChannel( int nChan, double dnu ) 1436 { 1437 LogIO os( LogOrigin( "Scantable", "regridChannel()", WHERE ) ) ; 1438 os << "Regrid abcissa with channel number " << nChan << " and spectral resoultion " << dnu << "Hz." << LogIO::POST ; 1439 // assumed that all rows have same nChan 1440 Vector<Float> arr = specCol_( 0 ) ; 1441 int oldsize = arr.nelements() ; 1442 1443 // if oldsize == nChan, nothing to do 1444 if ( oldsize == nChan ) { 1445 os << "Specified channel number is same as current one. Nothing to do." << LogIO::POST ; 1446 return ; 1447 } 1448 1449 // if oldChan < nChan, unphysical operation 1450 if ( oldsize < nChan ) { 1451 os << "Unphysical operation. Nothing to do." << LogIO::POST ; 1452 return ; 1453 } 1454 1455 // change channel number for specCol_ and flagCol_ 1456 Vector<Float> newspec( nChan, 0 ) ; 1457 Vector<uChar> newflag( nChan, false ) ; 1458 vector<string> coordinfo = getCoordInfo() ; 1459 string oldinfo = coordinfo[0] ; 1460 coordinfo[0] = "Hz" ; 1461 setCoordInfo( coordinfo ) ; 1462 for ( int irow = 0 ; irow < nrow() ; irow++ ) { 1463 regridChannel( nChan, dnu, irow ) ; 1464 } 1465 coordinfo[0] = oldinfo ; 1466 setCoordInfo( coordinfo ) ; 1467 1468 1469 // NOTE: this method does not update metadata such as 1470 // FREQUENCIES subtable, nChan, Bandwidth, etc. 1471 1472 return ; 1473 } 1474 1475 void asap::Scantable::regridChannel( int nChan, double dnu, int irow ) 1476 { 1477 // logging 1478 //ofstream ofs( "average.log", std::ios::out | std::ios::app ) ; 1479 //ofs << "IFNO = " << getIF( irow ) << " irow = " << irow << endl ; 1480 1481 Vector<Float> oldspec = specCol_( irow ) ; 1482 Vector<uChar> oldflag = flagsCol_( irow ) ; 1483 Vector<Float> newspec( nChan, 0 ) ; 1484 Vector<uChar> newflag( nChan, false ) ; 1485 1486 // regrid 1487 vector<double> abcissa = getAbcissa( irow ) ; 1488 int oldsize = abcissa.size() ; 1489 double olddnu = abcissa[1] - abcissa[0] ; 1490 //int refChan = 0 ; 1491 //double frac = 0.0 ; 1492 //double wedge = 0.0 ; 1493 //double pile = 0.0 ; 1494 int ichan = 0 ; 1495 double wsum = 0.0 ; 1496 Vector<Float> z( nChan ) ; 1497 z[0] = abcissa[0] - 0.5 * olddnu + 0.5 * dnu ; 1498 for ( int ii = 1 ; ii < nChan ; ii++ ) 1499 z[ii] = z[ii-1] + dnu ; 1500 Vector<Float> zi( nChan+1 ) ; 1501 Vector<Float> yi( oldsize + 1 ) ; 1502 zi[0] = z[0] - 0.5 * dnu ; 1503 zi[1] = z[0] + 0.5 * dnu ; 1504 for ( int ii = 2 ; ii < nChan ; ii++ ) 1505 zi[ii] = zi[ii-1] + dnu ; 1506 zi[nChan] = z[nChan-1] + 0.5 * dnu ; 1507 yi[0] = abcissa[0] - 0.5 * olddnu ; 1508 yi[1] = abcissa[1] + 0.5 * olddnu ; 1509 for ( int ii = 2 ; ii < oldsize ; ii++ ) 1510 yi[ii] = abcissa[ii-1] + olddnu ; 1511 yi[oldsize] = abcissa[oldsize-1] + 0.5 * olddnu ; 1512 if ( dnu > 0.0 ) { 1513 for ( int ii = 0 ; ii < nChan ; ii++ ) { 1514 double zl = zi[ii] ; 1515 double zr = zi[ii+1] ; 1516 for ( int j = ichan ; j < oldsize ; j++ ) { 1517 double yl = yi[j] ; 1518 double yr = yi[j+1] ; 1519 if ( yl <= zl ) { 1520 if ( yr <= zl ) { 1521 continue ; 1522 } 1523 else if ( yr <= zr ) { 1524 newspec[ii] += oldspec[j] * ( yr - zl ) ; 1525 newflag[ii] = newflag[ii] || oldflag[j] ; 1526 wsum += ( yr - zl ) ; 1527 } 1528 else { 1529 newspec[ii] += oldspec[j] * dnu ; 1530 newflag[ii] = newflag[ii] || oldflag[j] ; 1531 wsum += dnu ; 1532 ichan = j ; 1533 break ; 1534 } 1535 } 1536 else if ( yl < zr ) { 1537 if ( yr <= zr ) { 1538 newspec[ii] += oldspec[j] * ( yr - yl ) ; 1539 newflag[ii] = newflag[ii] || oldflag[j] ; 1540 wsum += ( yr - yl ) ; 1541 } 1542 else { 1543 newspec[ii] += oldspec[j] * ( zr - yl ) ; 1544 newflag[ii] = newflag[ii] || oldflag[j] ; 1545 wsum += ( zr - yl ) ; 1546 ichan = j ; 1547 break ; 1548 } 1549 } 1550 else { 1551 ichan = j - 1 ; 1552 break ; 1553 } 1554 } 1555 newspec[ii] /= wsum ; 1556 wsum = 0.0 ; 1557 } 1558 } 1559 else if ( dnu < 0.0 ) { 1560 for ( int ii = 0 ; ii < nChan ; ii++ ) { 1561 double zl = zi[ii] ; 1562 double zr = zi[ii+1] ; 1563 for ( int j = ichan ; j < oldsize ; j++ ) { 1564 double yl = yi[j] ; 1565 double yr = yi[j+1] ; 1566 if ( yl >= zl ) { 1567 if ( yr >= zl ) { 1568 continue ; 1569 } 1570 else if ( yr >= zr ) { 1571 newspec[ii] += oldspec[j] * abs( yr - zl ) ; 1572 newflag[ii] = newflag[ii] || oldflag[j] ; 1573 wsum += abs( yr - zl ) ; 1574 } 1575 else { 1576 newspec[ii] += oldspec[j] * abs( dnu ) ; 1577 newflag[ii] = newflag[ii] || oldflag[j] ; 1578 wsum += abs( dnu ) ; 1579 ichan = j ; 1580 break ; 1581 } 1582 } 1583 else if ( yl > zr ) { 1584 if ( yr >= zr ) { 1585 newspec[ii] += oldspec[j] * abs( yr - yl ) ; 1586 newflag[ii] = newflag[ii] || oldflag[j] ; 1587 wsum += abs( yr - yl ) ; 1588 } 1589 else { 1590 newspec[ii] += oldspec[j] * abs( zr - yl ) ; 1591 newflag[ii] = newflag[ii] || oldflag[j] ; 1592 wsum += abs( zr - yl ) ; 1593 ichan = j ; 1594 break ; 1595 } 1596 } 1597 else { 1598 ichan = j - 1 ; 1599 break ; 1600 } 1601 } 1602 newspec[ii] /= wsum ; 1603 wsum = 0.0 ; 1604 } 1605 } 1606 // * ichan = 0 1607 // ***/ 1608 // //ofs << "olddnu = " << olddnu << ", dnu = " << dnu << endl ; 1609 // pile += dnu ; 1610 // wedge = olddnu * ( refChan + 1 ) ; 1611 // while ( wedge < pile ) { 1612 // newspec[0] += olddnu * oldspec[refChan] ; 1613 // newflag[0] = newflag[0] || oldflag[refChan] ; 1614 // //ofs << "channel " << refChan << " is included in new channel 0" << endl ; 1615 // refChan++ ; 1616 // wedge += olddnu ; 1617 // wsum += olddnu ; 1618 // //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ; 1619 // } 1620 // frac = ( wedge - pile ) / olddnu ; 1621 // wsum += ( 1.0 - frac ) * olddnu ; 1622 // newspec[0] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ; 1623 // newflag[0] = newflag[0] || oldflag[refChan] ; 1624 // //ofs << "channel " << refChan << " is partly included in new channel 0" << " with fraction of " << ( 1.0 - frac ) << endl ; 1625 // //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ; 1626 // newspec[0] /= wsum ; 1627 // //ofs << "newspec[0] = " << newspec[0] << endl ; 1628 // //ofs << "wedge = " << wedge << ", pile = " << pile << endl ; 1629 1630 // /*** 1631 // * ichan = 1 - nChan-2 1632 // ***/ 1633 // for ( int ichan = 1 ; ichan < nChan - 1 ; ichan++ ) { 1634 // pile += dnu ; 1635 // newspec[ichan] += frac * olddnu * oldspec[refChan] ; 1636 // newflag[ichan] = newflag[ichan] || oldflag[refChan] ; 1637 // //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << frac << endl ; 1638 // refChan++ ; 1639 // wedge += olddnu ; 1640 // wsum = frac * olddnu ; 1641 // //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ; 1642 // while ( wedge < pile ) { 1643 // newspec[ichan] += olddnu * oldspec[refChan] ; 1644 // newflag[ichan] = newflag[ichan] || oldflag[refChan] ; 1645 // //ofs << "channel " << refChan << " is included in new channel " << ichan << endl ; 1646 // refChan++ ; 1647 // wedge += olddnu ; 1648 // wsum += olddnu ; 1649 // //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ; 1650 // } 1651 // frac = ( wedge - pile ) / olddnu ; 1652 // wsum += ( 1.0 - frac ) * olddnu ; 1653 // newspec[ichan] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ; 1654 // newflag[ichan] = newflag[ichan] || oldflag[refChan] ; 1655 // //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << ( 1.0 - frac ) << endl ; 1656 // //ofs << "wedge = " << wedge << ", pile = " << pile << endl ; 1657 // //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ; 1658 // newspec[ichan] /= wsum ; 1659 // //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << endl ; 1660 // } 1661 1662 // /*** 1663 // * ichan = nChan-1 1664 // ***/ 1665 // // NOTE: Assumed that all spectra have the same bandwidth 1666 // pile += dnu ; 1667 // newspec[nChan-1] += frac * olddnu * oldspec[refChan] ; 1668 // newflag[nChan-1] = newflag[nChan-1] || oldflag[refChan] ; 1669 // //ofs << "channel " << refChan << " is partly included in new channel " << nChan-1 << " with fraction of " << frac << endl ; 1670 // refChan++ ; 1671 // wedge += olddnu ; 1672 // wsum = frac * olddnu ; 1673 // //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ; 1674 // for ( int jchan = refChan ; jchan < oldsize ; jchan++ ) { 1675 // newspec[nChan-1] += olddnu * oldspec[jchan] ; 1676 // newflag[nChan-1] = newflag[nChan-1] || oldflag[jchan] ; 1677 // wsum += olddnu ; 1678 // //ofs << "channel " << jchan << " is included in new channel " << nChan-1 << " with fraction of " << frac << endl ; 1679 // //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ; 1680 // } 1681 // //ofs << "wedge = " << wedge << ", pile = " << pile << endl ; 1682 // //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ; 1683 // newspec[nChan-1] /= wsum ; 1684 // //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << endl ; 1685 1686 // specCol_.put( irow, newspec ) ; 1687 // flagsCol_.put( irow, newflag ) ; 1688 1689 // // ofs.close() ; 1690 1691 1692 return ; 1693 } 1694 1144 1695 std::vector<float> Scantable::getWeather(int whichrow) const 1145 1696 { … … 1154 1705 1155 1706 } 1156 1707 //namespace asap
Note:
See TracChangeset
for help on using the changeset viewer.