Changeset 152
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r146 r152 380 380 } 381 381 382 383 384 void SDMath::multiplyInSitu(SDMemTable* pIn, Float factor) 385 { 386 SDMemTable* pOut = localMultiply (*pIn, factor); 382 void SDMath::multiplyInSitu(SDMemTable* pIn, Float factor, Bool doAll) 383 { 384 const uInt what = 0; 385 SDMemTable* pOut = localOperate (*pIn, factor, doAll, what); 387 386 *pIn = *pOut; 388 387 delete pOut; … … 391 390 392 391 CountedPtr<SDMemTable> 393 SDMath::multiply(const CountedPtr<SDMemTable>& in, Float factor) 394 { 395 return CountedPtr<SDMemTable>(localMultiply(*in,factor)); 396 } 392 SDMath::multiply(const CountedPtr<SDMemTable>& in, Float factor, Bool doAll) 393 { 394 const uInt what = 0; 395 return CountedPtr<SDMemTable>(localOperate (*in, factor, doAll, what)); 396 } 397 398 399 void SDMath::addInSitu (SDMemTable* pIn, Float offset, Bool doAll) 400 { 401 const uInt what = 1; 402 SDMemTable* pOut = localOperate (*pIn, offset, doAll, what); 403 *pIn = *pOut; 404 delete pOut; 405 } 406 397 407 398 408 CountedPtr<SDMemTable> 399 SDMath::add(const CountedPtr<SDMemTable>& in, Float offset) 400 // 401 // Add offset to values 402 // 403 { 404 SDMemTable* sdmt = new SDMemTable(*in,False); 405 Table t = sdmt->table(); 406 ArrayColumn<Float> spec(t,"SPECTRA"); 407 408 for (uInt i=0; i < t.nrow(); i++) { 409 MaskedArray<Float> marr(sdmt->rowAsMaskedArray(i)); 410 marr += offset; 411 spec.put(i, marr.getArray()); 412 } 413 return CountedPtr<SDMemTable>(sdmt); 409 SDMath::add(const CountedPtr<SDMemTable>& in, Float offset, Bool doAll) 410 { 411 const uInt what = 1; 412 return CountedPtr<SDMemTable>(localOperate(*in, offset, doAll, what)); 414 413 } 415 414 … … 657 656 // Specify cursor location 658 657 659 uInt i = in->getBeam(); 660 uInt j = in->getIF(); 661 uInt k = in->getPol(); 662 IPosition start(4,i,j,k,0); 663 IPosition end(4,i,j,k,in->nChan()-1); 658 IPosition start, end; 659 getCursorLocation (start, end, *in); 664 660 665 661 // Loop over rows … … 831 827 } 832 828 833 SDMemTable* SDMath::localMultiply (const SDMemTable& in, Float factor) 834 { 835 SDMemTable* pOut = new SDMemTable(in,False); 836 const Table& tOut = pOut->table(); 837 ArrayColumn<Float> spec(tOut,"SPECTRA"); 838 // 839 for (uInt i=0; i < tOut.nrow(); i++) { 840 MaskedArray<Float> marr(pOut->rowAsMaskedArray(i)); 841 marr *= factor; 842 spec.put(i, marr.getArray()); 843 } 829 SDMemTable* SDMath::localOperate (const SDMemTable& in, Float val, Bool doAll, 830 uInt what) 831 // 832 // what = 0 Multiply 833 // 1 Add 834 { 835 SDMemTable* pOut = new SDMemTable(in,False); 836 const Table& tOut = pOut->table(); 837 ArrayColumn<Float> spec(tOut,"SPECTRA"); 838 // 839 if (doAll) { 840 for (uInt i=0; i < tOut.nrow(); i++) { 841 842 // Get 843 844 MaskedArray<Float> marr(pOut->rowAsMaskedArray(i)); 845 846 // Operate 847 848 if (what==0) { 849 marr *= val; 850 } else if (what==1) { 851 marr += val; 852 } 853 854 // Put 855 856 spec.put(i, marr.getArray()); 857 } 858 } else { 859 860 // Get cursor location 861 862 IPosition start, end; 863 getCursorLocation (start, end, in); 864 // 865 for (uInt i=0; i < tOut.nrow(); i++) { 866 867 // Get 868 869 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); 870 871 // Modify. More work than we would like to deal with the mask 872 873 Array<Float>& values = dataIn.getRWArray(); 874 Array<Bool> mask(dataIn.getMask()); 875 // 876 Array<Float> values2 = values(start,end); 877 Array<Bool> mask2 = mask(start,end); 878 MaskedArray<Float> t(values2,mask2); 879 if (what==0) { 880 t *= val; 881 } else if (what==1) { 882 t += val; 883 } 884 values(start, end) = t.getArray(); // Write back into 'dataIn' 885 886 // Put 887 spec.put(i, dataIn.getArray()); 888 } 889 } 890 // 844 891 return pOut; 845 892 } 846 893 847 894 895 896 void SDMath::getCursorLocation (IPosition& start, IPosition& end, 897 const SDMemTable& in) 898 { 899 const uInt nDim = 4; 900 const uInt i = in.getBeam(); 901 const uInt j = in.getIF(); 902 const uInt k = in.getPol(); 903 const uInt n = in.nChan(); 904 // 905 IPosition s(nDim,i,j,k,0); 906 IPosition e(nDim,i,j,k,n-1); 907 // 908 start.resize(nDim); 909 start = s; 910 end.resize(nDim); 911 end = e; 912 } -
trunk/src/SDMath.h
r146 r152 42 42 43 43 namespace SDMath { 44 //public: 44 45 // Quotient 46 45 47 casa::CountedPtr<SDMemTable> quotient(const casa::CountedPtr<SDMemTable>& on, 46 48 const casa::CountedPtr<SDMemTable>& off); 47 // 48 void multiplyInSitu(SDMemTable* in, casa::Float factor); 49 50 // Multiply 51 52 void multiplyInSitu(SDMemTable* in, casa::Float factor, casa::Bool all); 49 53 casa::CountedPtr<SDMemTable> multiply(const casa::CountedPtr<SDMemTable>& in, 50 casa::Float factor); 51 // 54 casa::Float factor, casa::Bool all); 55 56 // Addition 57 58 void addInSitu (SDMemTable* in, casa::Float offset, casa::Bool all); 52 59 casa::CountedPtr<SDMemTable> add(const casa::CountedPtr<SDMemTable>& in, 53 casa::Float offset); 54 60 casa::Float offset, casa::Bool all); 61 62 // Hanning 63 55 64 casa::CountedPtr<SDMemTable> hanning(const casa::CountedPtr<SDMemTable>& in); 65 66 // Bin up 67 68 casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in, 69 casa::Int width); 70 71 // Average in time 56 72 57 73 casa::CountedPtr<SDMemTable> … … 60 76 bool scanAverage, const std::string& weightStr); 61 77 78 // Average polarizations 79 62 80 casa::CountedPtr<SDMemTable> 63 81 averagePol(const casa::CountedPtr<SDMemTable>& in, const casa::Vector<casa::Bool>& mask); 64 82 83 // Statistics 84 65 85 std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in, 66 86 const std::vector<bool>& mask, const std::string& which); 67 68 casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in,69 casa::Int width);70 87 71 88 // private (not actually...) 72 89 90 // Weighting type for time averaging 91 73 92 enum weightType {NONE,VAR,TSYS}; 93 94 // Function to use accumulate data during time averaging 74 95 75 96 void accumulate (casa::Double& timeSum, casa::Double& intSum, casa::Int& nAccum, … … 82 103 casa::Bool useMask, weightType wtType); 83 104 105 // Function to fill Scan Container when averaging in time 106 84 107 void fillSDC (SDContainer& sc, const casa::Array<casa::Bool>& mask, 85 108 const casa::Array<casa::Float>& data, … … 89 112 const casa::Vector<casa::uInt>& freqID); 90 113 91 SDMemTable* localMultiply (const SDMemTable& in, casa::Float factor); 114 // Function to normalize data when averaging in time 92 115 93 116 void normalize (casa::MaskedArray<casa::Float>& data, … … 95 118 const casa::Array<casa::Float>& nPts, 96 119 weightType wtType, casa::Int axis, casa::Int nAxes); 120 121 // Functions for simple mathematical operations. what=0 (mul) or 1 (add) 122 123 SDMemTable* localOperate (const SDMemTable& in, casa::Float offset, 124 casa::Bool doAll, casa::uInt what); 125 126 // Function to get the current cursor location 127 void getCursorLocation (casa::IPosition& start, casa::IPosition& end, 128 const SDMemTable& in); 97 129 }; 98 130
Note:
See TracChangeset
for help on using the changeset viewer.