Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r175 r177 42 42 #include <casa/Arrays/MaskArrMath.h> 43 43 #include <casa/Arrays/MaskArrLogi.h> 44 #include <casa/Utilities/Assert.h> 44 45 #include <casa/Exceptions.h> 46 47 #include <scimath/Mathematics/VectorKernel.h> 48 #include <scimath/Mathematics/Convolver.h> 45 49 46 50 #include <tables/Tables/Table.h> … … 84 88 85 89 CountedPtr<SDMemTable> SDMath::average (const Block<CountedPtr<SDMemTable> >& in, 86 const Vector<Bool>& mask, bool scanAv,90 const Vector<Bool>& mask, Bool scanAv, 87 91 const std::string& weightStr) 88 92 // … … 391 395 392 396 393 SDMemTable* SDMath::hanning(const SDMemTable& in, Bool doAll)394 //395 // Hanning smooth each row396 // Should Tsys be smoothed ?397 //398 {399 400 // New Table401 402 SDMemTable* pTabOut = new SDMemTable(in,True);403 404 // Get cursor location405 406 IPosition start, end;407 getCursorLocation (start, end, in);408 //409 const uInt chanAxis = 3; // Spectrum axis410 IPosition shapeOut(4,1);411 412 // Loop over rows in Table413 414 for (uInt ri=0; ri < in.nRow(); ++ri) {415 416 // Get copy of data417 418 const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri));419 Array<Float> valuesIn = dataIn.getArray();420 Array<Bool> maskIn = dataIn.getMask();421 422 // Smooth along the channels axis423 424 Vector<Float> outValues;425 Vector<Bool> outMask;426 if (doAll) {427 uInt axis = 3;428 VectorIterator<Float> itValues(valuesIn, axis);429 VectorIterator<Bool> itMask(maskIn, axis);430 while (!itValues.pastEnd()) {431 mathutil::hanning(outValues, outMask, itValues.vector(), itMask.vector());432 itValues.vector() = outValues;433 itMask.vector() = outMask;434 //435 itValues.next();436 itMask.next();437 }438 } else {439 440 // Set multi-dim Vector shape441 442 shapeOut(chanAxis) = valuesIn.shape()(chanAxis);443 444 // Stuff about with shapes so that we don't have conformance run-time errors445 446 Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate();447 Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate();448 mathutil::hanning(outValues, outMask, valuesIn2, maskIn2);449 450 // Write back451 452 valuesIn(start,end) = outValues.reform(shapeOut);453 maskIn(start,end) = outMask.reform(shapeOut);454 }455 456 // Create and put back457 458 SDContainer sc = in.getSDContainer(ri);459 putDataInSDC (sc, valuesIn, maskIn);460 //461 pTabOut->putSDContainer(sc);462 }463 //464 return pTabOut;465 }466 467 468 469 470 397 std::vector<float> SDMath::statistic (const CountedPtr<SDMemTable>& in, 471 472 const std::string& which)398 const std::vector<bool>& mask, 399 const String& which) 473 400 // 474 401 // Perhaps iteration over pol/beam/if should be in here … … 779 706 return pTabOut; 780 707 } 708 709 710 SDMemTable* SDMath::smooth (const SDMemTable& in, const casa::String& kernelType, 711 casa::Float width, Bool doAll) 712 { 713 714 // Number of channels 715 716 const uInt chanAxis = 3; // Spectral axis 717 SDHeader sh = in.getSDHeader(); 718 const uInt nChan = sh.nchan; 719 720 // Generate Kernel 721 722 VectorKernel::KernelTypes type = VectorKernel::toKernelType (kernelType); 723 Vector<Float> kernel = VectorKernel::make(type, width, nChan, True, False); 724 725 // Generate Convolver 726 727 IPosition shape(1,nChan); 728 Convolver<Float> conv(kernel, shape); 729 730 // New Table 731 732 SDMemTable* pTabOut = new SDMemTable(in,True); 733 734 // Get cursor location 735 736 IPosition start, end; 737 getCursorLocation (start, end, in); 738 // 739 IPosition shapeOut(4,1); 740 741 // Output Vectors 742 743 Vector<Float> valuesOut(nChan); 744 Vector<Bool> maskOut(nChan); 745 746 // Loop over rows in Table 747 748 for (uInt ri=0; ri < in.nRow(); ++ri) { 749 750 // Get copy of data 751 752 const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri)); 753 AlwaysAssert(dataIn.shape()(chanAxis)==nChan, AipsError); 754 // 755 Array<Float> valuesIn = dataIn.getArray(); 756 Array<Bool> maskIn = dataIn.getMask(); 757 758 // Branch depending on whether we smooth all locations or just 759 // those pointed at by the current selection cursor 760 761 if (doAll) { 762 uInt axis = 3; 763 VectorIterator<Float> itValues(valuesIn, axis); 764 VectorIterator<Bool> itMask(maskIn, axis); 765 while (!itValues.pastEnd()) { 766 767 // Smooth 768 if (kernelType==VectorKernel::HANNING) { 769 mathutil::hanning(valuesOut, maskOut, itValues.vector(), itMask.vector()); 770 itMask.vector() = maskOut; 771 } else { 772 mathutil::replaceMaskByZero(itValues.vector(), itMask.vector()); 773 conv.linearConv(valuesOut, itValues.vector()); 774 } 775 // 776 itValues.vector() = valuesOut; 777 // 778 itValues.next(); 779 itMask.next(); 780 } 781 } else { 782 783 // Set multi-dim Vector shape 784 785 shapeOut(chanAxis) = valuesIn.shape()(chanAxis); 786 787 // Stuff about with shapes so that we don't have conformance run-time errors 788 789 Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate(); 790 Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate(); 791 792 // Smooth 793 794 if (kernelType==VectorKernel::HANNING) { 795 mathutil::hanning(valuesOut, maskOut, valuesIn2, maskIn2); 796 maskIn(start,end) = maskOut.reform(shapeOut); 797 } else { 798 mathutil::replaceMaskByZero(valuesIn2, maskIn2); 799 conv.linearConv(valuesOut, valuesIn2); 800 } 801 // 802 valuesIn(start,end) = valuesOut.reform(shapeOut); 803 } 804 805 // Create and put back 806 807 SDContainer sc = in.getSDContainer(ri); 808 putDataInSDC (sc, valuesIn, maskIn); 809 // 810 pTabOut->putSDContainer(sc); 811 } 812 // 813 return pTabOut; 814 } 815 781 816 782 817 … … 967 1002 sc.putFlags(outflags); 968 1003 } 969 970 -
trunk/src/SDMath.h
r175 r177 61 61 casa::CountedPtr<SDMemTable> average(const casa::Block<casa::CountedPtr<SDMemTable> >& in, 62 62 const casa::Vector<casa::Bool>& mask, 63 bool scanAverage, const std::string& weightStr);63 casa::Bool scanAverage, const std::string& weightStr); 64 64 65 65 // Statistics 66 66 std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in, 67 const std::vector<bool>& mask, const std::string& which); 68 69 // Hanning 70 SDMemTable* hanning(const SDMemTable& in, casa::Bool doAll); 67 const std::vector<bool>& mask, const casa::String& which); 71 68 72 69 // Bin up spectra 73 70 SDMemTable* bin(const SDMemTable& in, casa::Int width); 71 72 // Smooth 73 SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel, 74 casa::Float width, casa::Bool doAll); 74 75 75 76 // Simple mathematical operations. what=0 (mul) or 1 (add) … … 124 125 125 126 void convertWeightString (WeightType& wt, const std::string& weightStr); 126 127 127 }; 128 128
Note:
See TracChangeset
for help on using the changeset viewer.