Changeset 221
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r209 r221 42 42 #include <casa/Arrays/MaskArrMath.h> 43 43 #include <casa/Arrays/MaskArrLogi.h> 44 #include <casa/Containers/Block.h> 45 #include <casa/Quanta/QC.h> 44 46 #include <casa/Utilities/Assert.h> 45 47 #include <casa/Exceptions.h> … … 57 59 #include <coordinates/Coordinates/CoordinateSystem.h> 58 60 #include <coordinates/Coordinates/CoordinateUtil.h> 61 #include <coordinates/Coordinates/VelocityAligner.h> 59 62 60 63 #include "MathUtils.h" … … 94 97 const Vector<Bool>& mask, Bool scanAv, 95 98 const std::string& weightStr) 99 //Bool alignVelocity) 96 100 // 97 101 // Weighted averaging of spectra from one or more Tables. 98 102 // 99 103 { 104 Bool alignVelocity = False; 100 105 101 106 // Convert weight type … … 110 115 // Setup 111 116 112 const uInt axis = asap::ChanAxis; // Spectral axis113 117 IPosition shp = in[0]->rowAsMaskedArray(0).shape(); // Must not change 114 118 Array<Float> arr(shp); 115 119 Array<Bool> barr(shp); 116 const Bool useMask = (mask.nelements() == shp(a xis));120 const Bool useMask = (mask.nelements() == shp(asap::ChanAxis)); 117 121 118 122 // Columns from Tables … … 149 153 IPosition shp2(nAxesSub); 150 154 for (uInt i=0,j=0; i<(nAxesSub+1); i++) { 151 if (i!=a xis) {155 if (i!=asap::ChanAxis) { 152 156 shp2(j) = shp(i); 153 157 j++; … … 192 196 Vector<uInt> freqID, freqIDStart, oldFreqID; 193 197 198 // Velocity Aligner. We need an aligner for each Direction and FreqID 199 // combination. I don't think there is anyway to know how many 200 // directions there are. 201 // For now, assume all Tables have the same Frequency Table 202 203 /* 204 { 205 MEpoch::Ref timeRef(MEpoch::UTC); // Should be in header 206 MDirection::Types dirRef(MDirection::J2000); // Should be in header 207 // 208 SDHeader sh = in[0].getSDHeader(); 209 const uInt nChan = sh.nchan; 210 // 211 const SDFrequencyTable freqTab = in[0]->getSDFreqTable(); 212 const uInt nFreqID = freqTab.length(); 213 PtrBlock<const VelocityAligner<Float>* > vA(nFreqID); 214 215 // Get first time from first table 216 217 const Table& tabIn0 = in[0]->table(); 218 mjdCol.attach(tabIn0, "TIME"); 219 Double dTmp; 220 mjdCol.get(0, dTmp); 221 MVEpoch tmp2(Quantum<Double>(dTmp, Unit(String("d")))); 222 MEpoch epoch(tmp2, timeRef); 223 // 224 for (uInt freqID=0; freqID<nFreqID; freqID++) { 225 SpectralCoordinate sC = in[0]->getCoordinate(freqID); 226 vA[freqID] = new VelocityAligner<Float>(sC, nChan, epoch, const MDirection& dir, 227 const MPosition& pos, const String& velUnit, 228 MDoppler::Types velType, MFrequency::Types velFreqSystem) 229 } 230 } 231 */ 232 194 233 // Loop over tables 195 234 … … 197 236 const uInt nTables = in.nelements(); 198 237 for (uInt iTab=0; iTab<nTables; iTab++) { 238 239 // Should check that the frequency tables don't change if doing VelocityAlignment 199 240 200 241 // Attach columns to Table … … 252 293 // Normalize data in 'sum' accumulation array according to weighting scheme 253 294 254 normalize(sum, sumSq, nPts, wtType, a xis, nAxesSub);295 normalize(sum, sumSq, nPts, wtType, asap::ChanAxis, nAxesSub); 255 296 256 297 // Fill scan container. The source and freqID come from the … … 275 316 timeSum = 0.0; 276 317 intSum = 0.0; 277 nPts = 0.0; // reset this too!!!318 nPts = 0.0; 278 319 279 320 // Increment … … 292 333 293 334 accumulate(timeSum, intSum, nAccum, sum, sumSq, nPts, tSysSum, 294 tSys, nInc, mask, time, interval, in, iTab, iRow, a xis,335 tSys, nInc, mask, time, interval, in, iTab, iRow, asap::ChanAxis, 295 336 nAxesSub, useMask, wtType); 296 337 // … … 306 347 // 307 348 // Normalize data in 'sum' accumulation array according to weighting scheme 308 normalize(sum, sumSq, nPts, wtType, a xis, nAxesSub);349 normalize(sum, sumSq, nPts, wtType, asap::ChanAxis, nAxesSub); 309 350 310 351 // Create and fill container. The container we clone will be from … … 316 357 fillSDC(sc, sum.getMask(), sum.getArray(), tSysSum/nR, outScanID, 317 358 timeSum/nR, intSum, sourceNameStart, freqIDStart); 318 //319 359 pTabOut->putSDContainer(sc); 320 /* 321 cout << endl; 322 cout << "Last accumulation for output scan ID " << outScanID << endl; 323 cout << " The first row in this accumulation is " << rowStart << endl; 324 cout << " The number of rows accumulated is " << nAccum << endl; 325 cout << " The first table in this accumulation is " << tableStart << endl; 326 cout << " The first source in this accumulation is " << sourceNameStart << endl; 327 cout << " The first freqID in this accumulation is " << freqIDStart << endl; 328 cout << " Average time stamp = " << timeSum/nR << endl; 329 cout << " Integrated time = " << intSum << endl; 330 */ 360 // 331 361 return CountedPtr<SDMemTable>(pTabOut); 332 362 } … … 480 510 // Loop over rows and bin along channel axis 481 511 482 const uInt axis = asap::ChanAxis;483 512 for (uInt i=0; i < in.nRow(); ++i) { 484 513 SDContainer sc = in.getSDContainer(i); … … 490 519 MaskedArray<Float> marr(in.rowAsMaskedArray(i)); 491 520 MaskedArray<Float> marrout; 492 LatticeUtilities::bin(marrout, marr, a xis, width);521 LatticeUtilities::bin(marrout, marr, asap::ChanAxis, width); 493 522 494 523 // Put back the binned data and flags … … 505 534 // 506 535 MaskedArray<Float> tSysOut; 507 LatticeUtilities::bin(tSysOut, tSysIn, a xis, width);536 LatticeUtilities::bin(tSysOut, tSysIn, asap::ChanAxis, width); 508 537 sc.putTsys(tSysOut.getArray()); 509 538 // … … 766 795 767 796 if (doAll) { 768 uInt axis = 3;797 uInt axis = asap::ChanAxis; 769 798 VectorIterator<Float> itValues(valuesIn, axis); 770 799 VectorIterator<Bool> itMask(maskIn, axis); … … 821 850 822 851 852 SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float a, Float eta, Bool doAll) 853 // 854 // As it is, this function could be implemented with 'simpleOperate' 855 // However, I anticipate that eventually we will look the conversion 856 // values up in a Table and apply them in a frequency dependent way, 857 // so I have implemented it fully here 858 // 859 { 860 SDHeader sh = in.getSDHeader(); 861 SDMemTable* pTabOut = new SDMemTable(in, True); 862 863 // FInd out how to convert values into Jy and K (e.g. units might be mJy or mK) 864 // Also automatically find out what we are converting to according to the 865 // flux unit 866 867 Unit fluxUnit(sh.fluxunit); 868 Unit K(String("K")); 869 Unit JY(String("Jy")); 870 // 871 Bool toKelvin = True; 872 Double inFac = 1.0; 873 if (fluxUnit==JY) { 874 cerr << "Converting to K" << endl; 875 // 876 Quantum<Double> t(1.0,fluxUnit); 877 Quantum<Double> t2 = t.get(JY); 878 inFac = (t2 / t).getValue(); 879 // 880 toKelvin = True; 881 sh.fluxunit = "K"; 882 } else if (fluxUnit==K) { 883 cerr << "Converting to Jy" << endl; 884 // 885 Quantum<Double> t(1.0,fluxUnit); 886 Quantum<Double> t2 = t.get(K); 887 inFac = (t2 / t).getValue(); 888 // 889 toKelvin = False; 890 sh.fluxunit = "Jy"; 891 } else { 892 throw AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K"); 893 } 894 pTabOut->putSDHeader(sh); 895 896 // Compute conversion factor. 'a' and 'eta' are really frequency, time and 897 // telescope dependent and should be looked// up in a table 898 899 Float factor = 2.0 * inFac * 1.0e-7 * 1.0e26 * QC::k.getValue(Unit(String("erg/K"))) / a / eta; 900 if (toKelvin) { 901 factor = 1.0 / factor; 902 } 903 cerr << "Applying conversion factor = " << factor << endl; 904 905 // For operations only on specified cursor location 906 907 IPosition start, end; 908 getCursorLocation(start, end, in); 909 910 // Loop over rows and apply factor to spectra 911 912 const uInt axis = asap::ChanAxis; 913 for (uInt i=0; i < in.nRow(); ++i) { 914 915 // Get data 916 917 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i)); 918 Array<Float>& valuesIn = dataIn.getRWArray(); // writable reference 919 const Array<Bool>& maskIn = dataIn.getMask(); 920 921 // Need to apply correct conversion factor (frequency and time dependent) 922 // which should be sourced from a Table. For now we just apply the given 923 // factor to everything 924 925 if (doAll) { 926 VectorIterator<Float> itValues(valuesIn, asap::ChanAxis); 927 while (!itValues.pastEnd()) { 928 itValues.vector() *= factor; // Writes back into dataIn 929 // 930 itValues.next(); 931 } 932 } else { 933 Array<Float> valuesIn2 = valuesIn(start,end); 934 valuesIn2 *= factor; 935 valuesIn(start,end) = valuesIn2; 936 } 937 938 // Write out 939 940 SDContainer sc = in.getSDContainer(i); 941 putDataInSDC(sc, valuesIn, maskIn); 942 // 943 pTabOut->putSDContainer(sc); 944 } 945 return pTabOut; 946 } 823 947 824 948 -
trunk/src/SDMath.h
r183 r221 65 65 const casa::Vector<casa::Bool>& mask, 66 66 casa::Bool scanAverage, const std::string& weightStr); 67 // casa::Bool alignVelocity); 67 68 68 69 // Statistics … … 76 77 SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel, 77 78 casa::Float width, casa::Bool doAll); 79 80 // Flux conversion between Jansky and Kelvin 81 SDMemTable* convertFlux (const SDMemTable& in, casa::Float area, 82 casa::Float eta, casa::Bool doAll); 78 83 79 84 // Simple mathematical operations. what=0 (mul) or 1 (add)
Note:
See TracChangeset
for help on using the changeset viewer.