Changeset 167 for trunk/src/SDMath.cc
- Timestamp:
- 12/27/04 22:14:55 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r165 r167 462 462 } 463 463 464 CountedPtr<SDMemTable> SDMath::bin(const CountedPtr<SDMemTable>& in, 465 Int width) 466 { 467 SDHeader sh = in->getSDHeader(); 468 SDMemTable* sdmt = new SDMemTable(*in,True); 469 470 // Bin up SpectralCoordinates 471 472 IPosition factors(1); 473 factors(0) = width; 474 for (uInt j=0; j<in->nCoordinates(); ++j) { 475 CoordinateSystem cSys; 476 cSys.addCoordinate(in->getCoordinate(j)); 477 CoordinateSystem cSysBin = 478 CoordinateUtil::makeBinnedCoordinateSystem (factors, cSys, False); 479 // 480 SpectralCoordinate sCBin = cSysBin.spectralCoordinate(0); 481 sdmt->setCoordinate(sCBin, j); 482 } 483 484 // Use RebinLattice to find shape 485 486 IPosition shapeIn(1,sh.nchan); 487 IPosition shapeOut = RebinLattice<Float>::rebinShape (shapeIn, factors); 488 sh.nchan = shapeOut(0); 489 sdmt->putSDHeader(sh); 490 491 492 // Loop over rows and bin along channel axis 493 494 const uInt axis = 3; 495 for (uInt i=0; i < in->nRow(); ++i) { 496 SDContainer sc = in->getSDContainer(i); 497 // 498 Array<Float> tSys(sc.getTsys()); // Get it out before sc changes shape 499 500 // Bin up spectrum 501 502 MaskedArray<Float> marr(in->rowAsMaskedArray(i)); 503 MaskedArray<Float> marrout; 504 LatticeUtilities::bin(marrout, marr, axis, width); 505 506 // Put back the binned data and flags 507 508 IPosition ip2 = marrout.shape(); 509 sc.resize(ip2); 510 // 511 putDataInSDC (sc, marrout.getArray(), marrout.getMask()); 512 513 // Bin up Tsys. 514 515 Array<Bool> allGood(tSys.shape(),True); 516 MaskedArray<Float> tSysIn(tSys, allGood, True); 517 // 518 MaskedArray<Float> tSysOut; 519 LatticeUtilities::bin(tSysOut, tSysIn, axis, width); 520 sc.putTsys(tSysOut.getArray()); 521 // 522 sdmt->putSDContainer(sc); 523 } 524 return CountedPtr<SDMemTable>(sdmt); 525 } 464 465 void SDMath::binInSitu (SDMemTable* pIn, int width) 466 { 467 const uInt what = 1; 468 SDMemTable* pOut = localBin (*pIn, Int(width)); 469 *pIn = *pOut; 470 delete pOut; 471 } 472 473 474 CountedPtr<SDMemTable> SDMath::bin (const CountedPtr<SDMemTable>& in, int width) 475 { 476 const uInt what = 1; 477 return CountedPtr<SDMemTable>(localBin(*in, Int(width))); 478 } 479 526 480 527 481 … … 866 820 // 867 821 const Bool useMask = (mask.nelements() == shapeIn(chanAxis)); 868 cerr << "nEl=" << mask.nelements() << endl;869 cerr << "useMask=" << useMask << endl;870 822 871 823 // Loop over rows … … 962 914 return pTabOut; 963 915 } 916 917 SDMemTable* SDMath::localBin (const SDMemTable& in, Int width) 918 { 919 SDHeader sh = in.getSDHeader(); 920 SDMemTable* pTabOut = new SDMemTable(in, True); 921 922 // Bin up SpectralCoordinates 923 924 IPosition factors(1); 925 factors(0) = width; 926 for (uInt j=0; j<in.nCoordinates(); ++j) { 927 CoordinateSystem cSys; 928 cSys.addCoordinate(in.getCoordinate(j)); 929 CoordinateSystem cSysBin = 930 CoordinateUtil::makeBinnedCoordinateSystem (factors, cSys, False); 931 // 932 SpectralCoordinate sCBin = cSysBin.spectralCoordinate(0); 933 pTabOut->setCoordinate(sCBin, j); 934 } 935 936 // Use RebinLattice to find shape 937 938 IPosition shapeIn(1,sh.nchan); 939 IPosition shapeOut = RebinLattice<Float>::rebinShape (shapeIn, factors); 940 sh.nchan = shapeOut(0); 941 pTabOut->putSDHeader(sh); 942 943 944 // Loop over rows and bin along channel axis 945 946 const uInt axis = 3; 947 for (uInt i=0; i < in.nRow(); ++i) { 948 SDContainer sc = in.getSDContainer(i); 949 // 950 Array<Float> tSys(sc.getTsys()); // Get it out before sc changes shape 951 952 // Bin up spectrum 953 954 MaskedArray<Float> marr(in.rowAsMaskedArray(i)); 955 MaskedArray<Float> marrout; 956 LatticeUtilities::bin(marrout, marr, axis, width); 957 958 // Put back the binned data and flags 959 960 IPosition ip2 = marrout.shape(); 961 sc.resize(ip2); 962 // 963 putDataInSDC (sc, marrout.getArray(), marrout.getMask()); 964 965 // Bin up Tsys. 966 967 Array<Bool> allGood(tSys.shape(),True); 968 MaskedArray<Float> tSysIn(tSys, allGood, True); 969 // 970 MaskedArray<Float> tSysOut; 971 LatticeUtilities::bin(tSysOut, tSysIn, axis, width); 972 sc.putTsys(tSysOut.getArray()); 973 // 974 pTabOut->putSDContainer(sc); 975 } 976 return pTabOut; 977 } 978 979
Note: See TracChangeset
for help on using the changeset viewer.