Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r414 r434 522 522 523 523 IPosition start, end; 524 getCursorLocation(start, end, *in); 524 Bool doAll = False; 525 setCursorSlice (start, end, doAll, *in); 525 526 526 527 // Loop over rows … … 540 541 // Get row and deconstruct 541 542 542 MaskedArray<Float> marr(in->rowAsMaskedArray(ii));543 Array<Float> arr = marr.getArray();544 Array<Bool> barr = marr.getMask();543 MaskedArray<Float> dataIn = (in->rowAsMaskedArray(ii))(start,end); 544 Array<Float> v = dataIn.getArray().nonDegenerate(); 545 Array<Bool> m = dataIn.getMask().nonDegenerate(); 545 546 546 547 // Access desired piece of data 547 548 548 Array<Float> v((arr(start,end)).nonDegenerate());549 Array<Bool> m((barr(start,end)).nonDegenerate());549 // Array<Float> v((arr(start,end)).nonDegenerate()); 550 // Array<Bool> m((barr(start,end)).nonDegenerate()); 550 551 551 552 // Apply OTF mask … … 752 753 ArrayColumn<Float> tSysCol(tOut,"TSYS"); 753 754 Array<Float> tSysArr; 754 // 755 if (doAll) { 756 for (uInt i=0; i < tOut.nrow(); i++) { 755 756 // Get data slice bounds 757 758 IPosition start, end; 759 setCursorSlice (start, end, doAll, in); 760 // 761 for (uInt i=0; i<tOut.nrow(); i++) { 757 762 758 763 // Modify data 759 764 760 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); 765 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); 766 MaskedArray<Float> dataIn2 = dataIn(start,end); // Reference 767 if (what==0) { 768 dataIn2 *= val; 769 } else if (what==1) { 770 dataIn2 += val; 771 } 772 specCol.put(i, dataIn.getArray()); 773 774 // Modify Tsys 775 776 if (doTSys) { 777 tSysCol.get(i, tSysArr); 778 Array<Float> tSysArr2 = tSysArr(start,end); // Reference 761 779 if (what==0) { 762 dataIn*= val;780 tSysArr2 *= val; 763 781 } else if (what==1) { 764 dataIn+= val;782 tSysArr2 += val; 765 783 } 766 specCol.put(i, dataIn.getArray()); 767 768 // Modify Tsys 769 770 if (doTSys) { 771 tSysCol.get(i, tSysArr); 772 if (what==0) { 773 tSysArr *= val; 774 } else if (what==1) { 775 tSysArr += val; 776 } 777 tSysCol.put(i, tSysArr); 778 } 779 } 780 } else { 781 782 // Get cursor location 783 784 IPosition start, end; 785 getCursorLocation(start, end, in); 786 // 787 for (uInt i=0; i < tOut.nrow(); i++) { 788 789 // Modify data 790 791 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); 792 MaskedArray<Float> dataIn2 = dataIn(start,end); // Reference 793 if (what==0) { 794 dataIn2 *= val; 795 } else if (what==1) { 796 dataIn2 += val; 797 } 798 specCol.put(i, dataIn.getArray()); 799 800 // Modify Tsys 801 802 if (doTSys) { 803 tSysCol.get(i, tSysArr); 804 Array<Float> tSysArr2 = tSysArr(start,end); // Reference 805 if (what==0) { 806 tSysArr2 *= val; 807 } else if (what==1) { 808 tSysArr2 += val; 809 } 810 tSysCol.put(i, tSysArr); 811 } 784 tSysCol.put(i, tSysArr); 812 785 } 813 786 } … … 967 940 // Number of channels 968 941 969 SDHeader sh = in.getSDHeader(); 970 const uInt nChan = sh.nchan; 942 const uInt nChan = in.nChan(); 971 943 972 944 // Generate Kernel … … 984 956 SDMemTable* pTabOut = new SDMemTable(in,True); 985 957 986 // Get cursor location987 988 IPosition start, end;989 getCursorLocation(start, end, in);990 //991 IPosition shapeOut(4,1);992 993 958 // Output Vectors 994 959 995 Vector<Float> valuesOut(nChan); 996 Vector<Bool> maskOut(nChan); 960 Vector<Float> valuesOut(nChan); 961 Vector<Bool> maskOut(nChan); 962 963 // Get data slice bounds 964 965 IPosition start, end; 966 setCursorSlice (start, end, doAll, in); 997 967 998 968 // Loop over rows in Table 999 969 1000 for (uInt ri=0; ri < in.nRow(); ++ri) { 1001 1002 // Get copy of data 1003 1004 const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri)); 1005 AlwaysAssert(dataIn.shape()(asap::ChanAxis)==nChan, AipsError); 1006 // 1007 Array<Float> valuesIn = dataIn.getArray(); 1008 Array<Bool> maskIn = dataIn.getMask(); 1009 1010 // Branch depending on whether we smooth all locations or just 1011 // those pointed at by the current selection cursor 1012 1013 if (doAll) { 1014 VectorIterator<Float> itValues(valuesIn, asap::ChanAxis); 1015 VectorIterator<Bool> itMask(maskIn, asap::ChanAxis); 1016 while (!itValues.pastEnd()) { 1017 970 for (uInt ri=0; ri < in.nRow(); ++ri) { 971 972 // Get slice of data 973 974 MaskedArray<Float> dataIn = in.rowAsMaskedArray(ri); 975 976 // Deconstruct and get slices which reference these arrays 977 978 Array<Float> valuesIn = dataIn.getArray(); 979 Array<Bool> maskIn = dataIn.getMask(); 980 // 981 Array<Float> valuesIn2 = valuesIn(start,end); // ref to valuesIn 982 Array<Bool> maskIn2 = maskIn(start,end); 983 984 // Iterate through by spectra 985 986 VectorIterator<Float> itValues(valuesIn2, asap::ChanAxis); 987 VectorIterator<Bool> itMask(maskIn2, asap::ChanAxis); 988 while (!itValues.pastEnd()) { 989 1018 990 // Smooth 1019 if (kernelType==VectorKernel::HANNING) { 1020 mathutil::hanning(valuesOut, maskOut, itValues.vector(), itMask.vector()); 1021 itMask.vector() = maskOut; 1022 } else { 1023 mathutil::replaceMaskByZero(itValues.vector(), itMask.vector()); 1024 conv.linearConv(valuesOut, itValues.vector()); 1025 } 1026 // 1027 itValues.vector() = valuesOut; 1028 // 1029 itValues.next(); 1030 itMask.next(); 1031 } 1032 } else { 1033 1034 // Set multi-dim Vector shape 1035 1036 shapeOut(asap::ChanAxis) = valuesIn.shape()(asap::ChanAxis); 1037 1038 // Stuff about with shapes so that we don't have conformance run-time errors 1039 1040 Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate(); 1041 Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate(); 1042 1043 // Smooth 1044 1045 if (kernelType==VectorKernel::HANNING) { 1046 mathutil::hanning(valuesOut, maskOut, valuesIn2, maskIn2); 1047 maskIn(start,end) = maskOut.reform(shapeOut); 1048 } else { 1049 mathutil::replaceMaskByZero(valuesIn2, maskIn2); 1050 conv.linearConv(valuesOut, valuesIn2); 1051 } 1052 // 1053 valuesIn(start,end) = valuesOut.reform(shapeOut); 1054 } 991 992 if (kernelType==VectorKernel::HANNING) { 993 mathutil::hanning(valuesOut, maskOut, itValues.vector(), itMask.vector()); 994 itMask.vector() = maskOut; 995 } else { 996 mathutil::replaceMaskByZero(itValues.vector(), itMask.vector()); 997 conv.linearConv(valuesOut, itValues.vector()); 998 } 999 // 1000 itValues.vector() = valuesOut; 1001 // 1002 itValues.next(); 1003 itMask.next(); 1004 } 1055 1005 1056 1006 // Create and put back 1057 1007 1058 SDContainer sc = in.getSDContainer(ri);1059 putDataInSDC(sc, valuesIn, maskIn);1060 // 1061 pTabOut->putSDContainer(sc);1062 }1008 SDContainer sc = in.getSDContainer(ri); 1009 putDataInSDC(sc, valuesIn, maskIn); 1010 // 1011 pTabOut->putSDContainer(sc); 1012 } 1063 1013 // 1064 1014 return pTabOut; … … 1305 1255 if (toKelvin) factors = Float(1.0) / factors; 1306 1256 1307 // For operations only on specified cursor location1257 // Get data slice bounds 1308 1258 1309 1259 IPosition start, end; 1310 getCursorLocation(start, end, in);1260 setCursorSlice (start, end, doAll, in); 1311 1261 const uInt ifAxis = in.getIF(); 1312 1262 … … 1328 1278 // Get data 1329 1279 1330 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i)); 1331 Array<Float>& values = dataIn.getRWArray(); 1280 MaskedArray<Float> dataIn = in.rowAsMaskedArray(i); 1281 Array<Float>& values = dataIn.getRWArray(); // Ref to dataIn 1282 Array<Float> values2 = values(start,end); // Ref to values to dataIn 1332 1283 1333 1284 // Get SDCOntainer … … 1343 1294 // us BEAM/POL/CHAN cubes 1344 1295 1345 if (doAll) { 1346 ArrayIterator<Float> itIn(values, axes); 1347 uInt ax = 0; 1348 while (!itIn.pastEnd()) { 1349 itIn.array() *= factors(freqIDs(ax)); // Writes back to dataIn 1350 itIn.next(); 1351 } 1352 } else { 1353 MaskedArray<Float> dataIn2 = dataIn(start,end); // reference 1354 dataIn2 *= factors(freqIDs(ifAxis)); 1296 ArrayIterator<Float> itIn(values2, axes); 1297 uInt ax = 0; 1298 while (!itIn.pastEnd()) { 1299 itIn.array() *= factors(freqIDs(ax)); // Writes back to dataIn 1300 itIn.next(); 1355 1301 } 1356 1302 … … 1714 1660 1715 1661 1716 1717 1718 void SDMath::getCursorLocation(IPosition& start, IPosition& end, 1719 const SDMemTable& in) const 1720 { 1721 const uInt nDim = 4; 1722 const uInt i = in.getBeam(); 1723 const uInt j = in.getIF(); 1724 const uInt k = in.getPol(); 1725 const uInt n = in.nChan(); 1662 void SDMath::setCursorSlice (IPosition& start, IPosition& end, Bool doAll, const SDMemTable& in) const 1663 { 1664 const uInt nDim = asap::nAxes; 1665 DebugAssert(nDim==4,AipsError); 1726 1666 // 1727 1667 start.resize(nDim); 1728 start(0) = i;1729 start(1) = j;1730 start(2) = k;1731 start(3) = 0;1732 //1733 1668 end.resize(nDim); 1734 end(0) = i; 1735 end(1) = j; 1736 end(2) = k; 1737 end(3) = n-1; 1669 if (doAll) { 1670 start = 0; 1671 end(0) = in.nBeam()-1; 1672 end(1) = in.nIF()-1; 1673 end(2) = in.nPol()-1; 1674 end(3) = in.nChan()-1; 1675 } else { 1676 start(0) = in.getBeam(); 1677 end(0) = start(0); 1678 // 1679 start(1) = in.getIF(); 1680 end(1) = start(1); 1681 // 1682 start(2) = in.getPol(); 1683 end(2) = start(2); 1684 // 1685 start(3) = 0; 1686 end(3) = in.nChan()-1; 1687 } 1738 1688 } 1739 1689 … … 1843 1793 { 1844 1794 1845 // For operations only on specified cursor location1795 // Set up data slice 1846 1796 1847 1797 IPosition start, end; 1848 getCursorLocation(start, end, in);1798 setCursorSlice (start, end, doAll, in); 1849 1799 1850 1800 // Loop over rows and apply correction factor … … 1855 1805 // Get data 1856 1806 1857 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i)); 1807 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i)); 1808 MaskedArray<Float> dataIn2 = dataIn(start,end); // reference to dataIn 1858 1809 1859 1810 // Apply factor 1860 1811 1861 if (doAll) { 1862 dataIn *= factor[i]; 1863 } else { 1864 MaskedArray<Float> dataIn2 = dataIn(start,end); // reference 1865 dataIn2 *= factor[i]; 1866 } 1812 dataIn2 *= factor[i]; 1867 1813 1868 1814 // Write out 1869 1815 1870 SDContainer sc = in.getSDContainer(i);1871 putDataInSDC(sc, dataIn.getArray(), dataIn.getMask());1872 // 1873 pTabOut->putSDContainer(sc);1816 SDContainer sc = in.getSDContainer(i); 1817 putDataInSDC(sc, dataIn.getArray(), dataIn.getMask()); 1818 // 1819 pTabOut->putSDContainer(sc); 1874 1820 } 1875 1821 } -
trunk/src/SDMath.h
r397 r434 211 211 casa::Bool perFreqID) const; 212 212 213 // Function to get the current cursor location214 void getCursorLocation (casa::IPosition& start, casa::IPosition& end,215 213 // Set slice to cursor or all axes 214 void setCursorSlice (casa::IPosition& start, casa::IPosition& end, 215 casa::Bool doAll, const SDMemTable& in) const; 216 216 217 217 // Function to normalize data when averaging in time
Note:
See TracChangeset
for help on using the changeset viewer.