Changeset 745 for trunk/src/SDMemTable.cc
- Timestamp:
- 11/28/05 15:25:18 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMemTable.cc
r717 r745 75 75 IFSel_(0), 76 76 beamSel_(0), 77 polSel_(0) 77 polSel_(0) 78 78 { 79 79 setup(); … … 105 105 beamSel_= 0; 106 106 polSel_= 0; 107 chanMask_.resize(0);108 107 } else { 109 108 IFSel_= other.IFSel_; 110 109 beamSel_= other.beamSel_; 111 110 polSel_= other.polSel_; 112 chanMask_.resize(0);113 chanMask_ = other.chanMask_;114 111 } 115 112 … … 148 145 beamSel_= other.beamSel_; 149 146 polSel_= other.polSel_; 150 chanMask_.resize(0);151 chanMask_ = other.chanMask_;152 147 table_ = other.table_.copyToMemoryTable(String("dummy")); 153 148 attach(); … … 199 194 SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA")); 200 195 aNewTab.bindColumn("STOKES", stokesEngine); 201 196 202 197 // Create Table 203 table_ = Table(aNewTab, Table::Memory, 0); 204 // add subtable 198 table_ = Table(aNewTab, Table::Memory, 0); 199 // add subtable 205 200 TableDesc tdf("", "1", TableDesc::Scratch); 206 201 tdf.addColumn(ArrayColumnDesc<String>("FUNCTIONS")); … … 262 257 if (showDate) 263 258 mvt.setFormat(MVTime::YMD); 264 else 259 else 265 260 mvt.setFormat(MVTime::TIME); 266 261 ostringstream oss; … … 303 298 } 304 299 305 void SDMemTable::resetCursor() 300 void SDMemTable::resetCursor() 306 301 { 307 302 polSel_ = 0; … … 310 305 } 311 306 312 bool SDMemTable::setMask(std::vector<int> whichChans) 313 { 314 std::vector<int>::iterator it; 315 uInt n = flagsCol_.shape(0)(3); 316 if (whichChans.empty()) { 317 chanMask_ = std::vector<bool>(n,true); 318 return true; 319 } 320 chanMask_.resize(n,true); 321 for (it = whichChans.begin(); it != whichChans.end(); ++it) { 322 if (*it < n) { 323 chanMask_[*it] = false; 324 } 325 } 326 return true; 327 } 328 329 std::vector<bool> SDMemTable::getMask(Int whichRow) const 307 std::vector<bool> SDMemTable::getMask(Int whichRow) const 330 308 { 331 309 … … 342 320 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol 343 321 344 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );345 346 std::vector<bool> tmp;347 tmp = chanMask_; // WHY the fxxx do I have to make a copy here348 std::vector<bool>::iterator miter;349 miter = tmp.begin();350 351 322 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { 352 323 bool out =!static_cast<bool>(*i); 353 if (useUserMask) {354 out = out && (*miter);355 miter++;356 }357 324 mask.push_back(out); 358 325 } … … 362 329 363 330 364 std::vector<float> SDMemTable::getSpectrum(Int whichRow) const 331 std::vector<float> SDMemTable::getSpectrum(Int whichRow) const 365 332 { 366 333 Array<Float> arr; … … 376 343 377 344 378 std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, 379 345 std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, 346 Bool doPol) const 380 347 // 381 348 // Gets one STokes parameter depending on cursor polSel location … … 388 355 throw (AipsError("You must have 1,2 or 4 polarizations to get the Stokes parameters")); 389 356 } 390 357 391 358 // For full conversion we are only supporting linears at the moment 392 359 393 360 if (nPol() > 2) { 394 361 String antName; … … 403 370 Array<Float> arr; 404 371 stokesCol_.get(whichRow, arr); 405 372 406 373 if (doPol && (polSel_==1 || polSel_==2)) { // Q,U --> P, P.A. 407 374 408 375 // Set current cursor location 409 376 410 377 const IPosition& shape = arr.shape(); 411 378 IPosition start, end; 412 379 getCursorSlice(start, end, shape); 413 380 414 381 // Get Q and U slices 415 382 416 383 Array<Float> Q = SDPolUtil::getStokesSlice(arr,start,end,"Q"); 417 384 Array<Float> U = SDPolUtil::getStokesSlice(arr,start,end,"U"); 418 419 // Compute output 420 385 386 // Compute output 387 421 388 Array<Float> out; 422 389 if (polSel_==1) { // P … … 425 392 out = SDPolUtil::positionAngle(Q,U); 426 393 } 427 394 428 395 // Copy to output 429 396 430 397 IPosition vecShape(1,shape(asap::ChanAxis)); 431 398 Vector<Float> outV = out.reform(vecShape); … … 433 400 outV.tovector(stlout); 434 401 return stlout; 435 436 } else { 402 403 } else { 437 404 // Selects at the cursor location 438 405 return getFloatSpectrum(arr); … … 440 407 } 441 408 442 std::string SDMemTable::getPolarizationLabel(Bool linear, Bool stokes, 443 444 { 445 uInt idx = polSel_; 409 std::string SDMemTable::getPolarizationLabel(Bool linear, Bool stokes, 410 Bool linPol, Int polIdx) const 411 { 412 uInt idx = polSel_; 446 413 if (polIdx >=0) idx = polIdx; 447 414 return SDPolUtil::polarizationLabel(idx, linear, stokes, linPol); … … 450 417 451 418 452 std::vector<float> SDMemTable::stokesToPolSpectrum(Int whichRow, 453 Bool toLinear, 454 419 std::vector<float> SDMemTable::stokesToPolSpectrum(Int whichRow, 420 Bool toLinear, 421 Int polIdx) const 455 422 // 456 423 // polIdx … … 489 456 throw(AipsError("Only conversion to RR & LL is currently supported")); 490 457 } 491 492 // Get I and V slices 458 459 // Get I and V slices 493 460 Array<Float> I = SDPolUtil::getStokesSlice(arr,start,end,"I"); 494 461 Array<Float> V = SDPolUtil::getStokesSlice(arr,start,end,"V"); 495 496 // Compute output 462 463 // Compute output 497 464 out = SDPolUtil::circularPolarizationFromStokes(I, V, doRR); 498 465 } 499 466 500 467 // Copy to output 501 468 IPosition vecShape(1,shape(asap::ChanAxis)); … … 521 488 522 489 const IPosition& shape = arr.shape(); 523 IPosition start(shape.nelements(),0); 490 IPosition start(shape.nelements(),0); 524 491 IPosition end(shape-1); 525 492 if (iBeam!=-1) { … … 587 554 MFrequency::Types mdr; 588 555 if (!MFrequency::getType(mdr, rfrm)) { 589 556 590 557 Int a,b;const uInt* c; 591 558 const String* valid = MFrequency::allMyTypes(a, b, c); … … 662 629 } else if (u == Unit("Hz")) { 663 630 664 // Set world axis units 631 // Set world axis units 665 632 Vector<String> wau(1); wau = u.getName(); 666 633 spc.setWorldAxisUnits(wau); … … 689 656 Vector<uInt> freqIDs; 690 657 freqidCol_.get(whichRow, freqIDs); 691 uInt freqID = freqIDs(IFSel_); 658 uInt freqID = freqIDs(IFSel_); 692 659 restfreqidCol_.get(whichRow, freqIDs); 693 660 uInt restFreqID = freqIDs(IFSel_); … … 697 664 698 665 String s = "Channel"; 699 if (u == Unit("km/s")) { 666 if (u == Unit("km/s")) { 700 667 s = CoordinateUtil::axisLabel(spc,0,True,True,True); 701 668 } else if (u == Unit("Hz")) { … … 789 756 */ 790 757 791 MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, 792 Bool toStokes) const 758 MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, 759 Bool toStokes) const 793 760 { 794 761 // Get flags … … 871 838 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID) const 872 839 { 873 840 874 841 Table t = table_.keywordSet().asTable("FREQUENCIES"); 875 842 if (freqID> t.nrow() ) { … … 900 867 901 868 902 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, 903 869 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, 870 uInt restFreqID, 904 871 uInt whichRow) const 905 872 { 906 873 907 874 // Create basic SC 908 875 SpectralCoordinate spec = getSpectralCoordinate (freqID); … … 989 956 std::vector<double> stlout; 990 957 tvec.tovector(stlout); 991 return stlout; 958 return stlout; 992 959 } 993 960 … … 1065 1032 Vector<String> funcs; 1066 1033 Vector<String> finfo; 1067 Vector<Int> comps; 1034 Vector<Int> comps; 1068 1035 ROArrayColumn<Double> parmsCol(t, "PARAMETERS"); 1069 1036 ROArrayColumn<Bool> parmaskCol(t, "PARMASK"); … … 1102 1069 Vector<String> funcs; 1103 1070 Vector<String> finfo; 1104 Vector<Int> comps; 1071 Vector<Int> comps; 1105 1072 ROArrayColumn<Double> parmsCol(t, "PARAMETERS"); 1106 1073 ROArrayColumn<Bool> parmaskCol(t, "PARMASK"); … … 1130 1097 1131 1098 void SDMemTable::addFit(uInt whichRow, 1132 1133 1099 const Vector<Double>& p, const Vector<Bool>& m, 1100 const Vector<String>& f, const Vector<Int>& c) 1134 1101 { 1135 1102 if (whichRow >= nRow()) { … … 1137 1104 } 1138 1105 Table t = table_.keywordSet().asTable("FITS"); 1139 uInt nrow = t.nrow(); 1106 uInt nrow = t.nrow(); 1140 1107 t.addRow(); 1141 1108 ArrayColumn<Double> parmsCol(t, "PARAMETERS"); … … 1154 1121 fitCol_.get(whichRow, fitarr); 1155 1122 1156 Array<Int> newarr; // The new Array containing the fitid 1157 Int pos =-1; // The fitid position in the array 1123 Array<Int> newarr; // The new Array containing the fitid 1124 Int pos =-1; // The fitid position in the array 1158 1125 if ( fitarr.nelements() == 0 ) { // no fits at all in this row 1159 1126 Array<Int> arr(IPosition(4,nBeam(),nIF(),nPol(),1)); 1160 1127 arr = -1; 1161 1128 newarr.reference(arr); 1162 pos = 0; 1129 pos = 0; 1163 1130 } else { 1164 1131 IPosition shp = fitarr.shape(); … … 1172 1139 while (it != fits.end()) { 1173 1140 if (*it == -1) { 1174 1175 1141 pos = i; 1142 break; 1176 1143 } 1177 1144 ++i; … … 1186 1153 newarr = fitarr; 1187 1154 } 1188 newarr(IPosition(4, beamSel_, IFSel_, polSel_, pos)) = Int(nrow); 1155 newarr(IPosition(4, beamSel_, IFSel_, polSel_, pos)) = Int(nrow); 1189 1156 fitCol_.put(whichRow, newarr); 1190 1157 … … 1218 1185 sdft.setRefFrame(baseFrame); 1219 1186 1220 // Equinox 1187 // Equinox 1221 1188 Float equinox; 1222 1189 t.keywordSet().get("EQUINOX", equinox); … … 1283 1250 Array<Double> direction; 1284 1251 Array<Int> fits; 1285 1252 1286 1253 specCol_.get(whichRow, spectrum); 1287 1254 sdc.putSpectrum(spectrum); … … 1344 1311 } 1345 1312 void SDMemTable::makePersistent(const std::string& filename) 1346 { 1313 { 1347 1314 table_.deepCopy(filename,Table::New); 1348 1315 … … 1369 1336 if (x < 59.95) 1370 1337 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s"; 1371 else if (x < 3599.95) 1338 else if (x < 3599.95) 1372 1339 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" "; 1373 1340 else { … … 1376 1343 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " "; 1377 1344 return String(oss); 1378 } 1345 } 1379 1346 }; 1380 1347 … … 1465 1432 << setw(24) << dirtype 1466 1433 << setw(10) << "Time" 1467 << setw(18) << "Integration" 1434 << setw(18) << "Integration" 1468 1435 << setw(7) << "FreqIDs" << endl; 1469 1436 oss << "--------------------------------------------------------------------------------" << endl; 1470 1437 1471 1438 // Generate list of scan start and end integrations 1472 1439 Vector<Int> scanIDs = scanCol_.getColumn(); … … 1488 1455 1489 1456 // Find all the FreqIDs in this scan 1490 listFQ.resize(0); 1491 listRestFQ.resize(0); 1457 listFQ.resize(0); 1458 listRestFQ.resize(0); 1492 1459 for (uInt j=startInt(i); j<endInt(i)+1; j++) { 1493 1460 freqidCol_.get(j, freqIDs); 1494 1461 for (uInt k=0; k<freqIDs.nelements(); k++) { 1495 1462 mathutil::addEntry(listFQ, freqIDs(k)); 1496 1463 } 1497 1464 // 1498 1465 restfreqidCol_.get(j, restFreqIDs); 1499 1466 for (uInt k=0; k<restFreqIDs.nelements(); k++) { 1500 1467 mathutil::addEntry(listRestFQ, restFreqIDs(k)); 1501 1468 } 1502 1469 } … … 1504 1471 nInt = endInt(i) - startInt(i) + 1; 1505 1472 oss << setw(3) << std::right << i << std::left << setw(2) << " " 1506 1507 1508 << setw(10) << time 1509 1510 1511 1473 << setw(15) << name 1474 << setw(24) << posit 1475 << setw(10) << time 1476 << setw(3) << std::right << nInt << setw(3) << " x " << std::left 1477 << setw(6) << tInt 1478 << " " << listFQ << " " << listRestFQ << endl; 1512 1479 } 1513 1480 oss << endl; 1514 oss << "Table contains " << table_.nrow() << " integration(s) in " 1481 oss << "Table contains " << table_.nrow() << " integration(s) in " 1515 1482 << nScans << " scan(s)." << endl; 1516 1483 … … 1524 1491 for (uInt i=0; i<sdft.length(); i++) { 1525 1492 oss << setw(8) << i << setw(8) 1526 1527 1528 1529 1493 << info[3] << setw(16) << setprecision(8) 1494 << sdft.referenceValue(i) << setw(10) 1495 << sdft.referencePixel(i) << setw(12) 1496 << sdft.increment(i) << endl; 1530 1497 } 1531 1498 oss << "--------------------------------------------------------------------------------" << endl; … … 1586 1553 { 1587 1554 Table t = table_.rwKeywordSet().asTable("HISTORY"); 1588 uInt nrow = t.nrow(); 1555 uInt nrow = t.nrow(); 1589 1556 t.addRow(); 1590 1557 ScalarColumn<String> itemCol(t, "ITEM"); … … 1596 1563 Vector<String> history; 1597 1564 const Table& t = table_.keywordSet().asTable("HISTORY"); 1598 uInt nrow = t.nrow(); 1565 uInt nrow = t.nrow(); 1599 1566 ROScalarColumn<String> itemCol(t, "ITEM"); 1600 1567 std::vector<std::string> stlout; … … 1647 1614 1648 1615 MDirection::Types SDMemTable::getDirectionReference() const 1649 { 1616 { 1650 1617 Float eq; 1651 1618 table_.keywordSet().get("Equinox",eq); … … 1654 1621 mp[1950.0] = "B1950"; 1655 1622 MDirection::Types mdr; 1656 if (!MDirection::getType(mdr, mp[eq])) { 1623 if (!MDirection::getType(mdr, mp[eq])) { 1657 1624 mdr = MDirection::J2000; 1658 1625 pushLog("WARNING: Unknown equinox using J2000"); 1659 1626 1660 1627 } 1661 1628 … … 1677 1644 1678 1645 1679 Bool SDMemTable::setRestFreqs(const Vector<Double>& restFreqsIn, 1680 1681 1682 1683 1646 Bool SDMemTable::setRestFreqs(const Vector<Double>& restFreqsIn, 1647 const String& sUnit, 1648 const vector<string>& lines, 1649 const String& source, 1650 Int whichIF) 1684 1651 { 1685 1652 const Int nIFs = nIF(); … … 1707 1674 restFreqs[i] = lineFreq.getValue().getValue(); // Hz 1708 1675 } else { 1709 String s = String(lines[i]) + 1710 1676 String s = String(lines[i]) + 1677 String(" is an unrecognized spectral line"); 1711 1678 throw(AipsError(s)); 1712 1679 } … … 1757 1724 for (uInt i=0; i<nRow; i++) { 1758 1725 srcnCol_.get(i, srcName); 1759 restfreqidCol_.get(i,restFreqIDs); 1726 restfreqidCol_.get(i,restFreqIDs); 1760 1727 if (idx==-1) { 1761 1762 1728 // Replace vector of restFreqs; one per IF. 1729 // No selection possible 1763 1730 for (uInt i=0; i<nIFs; i++) restFreqIDs[i] = i; 1764 1731 } else { 1765 1732 // Set RestFreqID for selected data 1766 1733 if (empty || source==srcName) { 1767 1734 if (whichIF<0) { 1768 1735 restFreqIDs = idx; 1769 } else { 1736 } else { 1770 1737 restFreqIDs[whichIF] = idx; 1771 1738 } 1772 1739 } 1773 1740 } 1774 restfreqidCol_.put(i,restFreqIDs); 1741 restfreqidCol_.put(i,restFreqIDs); 1775 1742 } 1776 1743 ok = True; … … 1813 1780 // renumber 1814 1781 scanCol_.put(i,newscanid); 1815 } else { 1782 } else { 1816 1783 ++newscanid; 1817 1784 pIdx = cIdx; // store scanid … … 1823 1790 1824 1791 void SDMemTable::getCursorSlice(IPosition& start, IPosition& end, 1825 1792 const IPosition& shape) const 1826 1793 { 1827 1794 const uInt nDim = shape.nelements(); 1828 1795 start.resize(nDim); 1829 1796 end.resize(nDim); 1830 1797 1831 1798 start(asap::BeamAxis) = beamSel_; 1832 1799 end(asap::BeamAxis) = beamSel_; … … 1855 1822 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); 1856 1823 aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection 1857 1824 1858 1825 std::vector<float> spectrum; 1859 1826 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
Note: See TracChangeset
for help on using the changeset viewer.