- Timestamp:
- 12/27/04 22:14:55 (20 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapmath.py
r166 r167 89 89 return 90 90 91 def bin(scan, binwidth=5):91 def bin(scan, width=5, insitu=False): 92 92 """ 93 Return a scan where all spectra have been binned up 94 width The bin width (default=5) in pixels 95 insitu: if False (default) a new scantable is returned. 96 Otherwise, the addition is done in-situ 93 97 """ 94 from asap._asap import bin as _bin 95 return scantable(_bin(scan, binwidth)) 98 if not insitu: 99 from asap._asap import bin as _bin 100 return scantable(_bin(scan, width)) 101 else: 102 from asap._asap import bin_insitu as _bin 103 _bin(scan, width) 104 return 96 105 97 106 def average_pol(scan, mask=None, insitu=False): -
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 -
trunk/src/SDMath.h
r165 r167 66 66 // Bin up 67 67 68 casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in,69 68 void binInSitu (SDMemTable* in, casa::Int width); 69 casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in, casa::Int width); 70 70 71 71 // Average in time … … 144 144 145 145 SDMemTable* localAveragePol(const SDMemTable& in, const casa::Vector<casa::Bool>& mask); 146 147 // Function to bin up spectra 148 149 SDMemTable* localBin (const SDMemTable& in, casa::Int width); 146 150 }; 147 151 -
trunk/src/SDMathWrapper.h
r165 r167 56 56 void scaleInSitu(SDMemTableWrapper& in, casa::Float factor, casa::Bool all) 57 57 { 58 SDMemTable* sdmt = in.getPtr();59 58 SDMath::multiplyInSitu(in.getPtr(),factor, all); 60 59 } … … 69 68 void addInSitu(SDMemTableWrapper& in, casa::Float offset, casa::Bool all) 70 69 { 71 SDMemTable* sdmt = in.getPtr();72 70 SDMath::addInSitu(in.getPtr(), offset, all); 73 71 } … … 85 83 // Bin up 86 84 87 SDMemTableWrapper bin(const SDMemTableWrapper& in, 88 int width) { 89 return SDMath::bin(in.getCP(), width); 85 void binInSitu (SDMemTableWrapper& in, int width) 86 { 87 SDMath::binInSitu (in.getPtr(), width); 88 } 89 SDMemTableWrapper bin(const SDMemTableWrapper& in, int width) 90 { 91 return SDMemTableWrapper(SDMath::bin(in.getCP(), width)); 90 92 } 91 93 -
trunk/src/python_SDMath.cc
r165 r167 62 62 void python_SDMath() { 63 63 def("quotient", &SDMathWrapper::quotient); 64 // 64 65 def("scale", &SDMathWrapper::scale); 65 66 def("scale_insitu", &SDMathWrapper::scaleInSitu); 67 // 66 68 def("add", &SDMathWrapper::add); 67 69 def("add_insitu", &SDMathWrapper::addInSitu); 70 // 68 71 def("hanning", &SDMathWrapper::hanning); 72 // 69 73 def("average", &SDMathWrapper::average); 74 // 70 75 def("averagepol", &SDMathWrapper::averagePol); 71 76 def("averagepol_insitu", &SDMathWrapper::averagePolInSitu); 77 // 72 78 def("bin", &SDMathWrapper::bin); 79 def("bin_insitu", &SDMathWrapper::binInSitu); 80 // 73 81 def("stats", &SDMathWrapper::statistic); 74 82 };
Note:
See TracChangeset
for help on using the changeset viewer.