Changeset 1757 for branches/alma/src/STMath.cpp
- Timestamp:
- 06/09/10 19:03:06 (14 years ago)
- Location:
- branches/alma
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma
-
Property
svn:ignore
set to
.sconf_temp
.sconsign.dblite
-
Property
svn:mergeinfo
set to
/branches/asap-3.x merged eligible
-
Property
svn:ignore
set to
-
branches/alma/src/STMath.cpp
r1719 r1757 52 52 #include "RowAccumulator.h" 53 53 #include "STAttr.h" 54 #include "STSelector.h" 55 54 56 #include "STMath.h" 55 #include "STSelector.h"56 57 57 using namespace casa; 58 58 … … 740 740 } 741 741 742 CountedPtr<Scantable> STMath::binaryOperate(const CountedPtr<Scantable>& left, 743 const CountedPtr<Scantable>& right, 742 CountedPtr<Scantable> STMath::binaryOperate(const CountedPtr<Scantable>& left, 743 const CountedPtr<Scantable>& right, 744 744 const std::string& mode) 745 745 { … … 1379 1379 { 1380 1380 1381 1381 1382 1382 STSelector sel; 1383 1383 CountedPtr< Scantable > ws = getScantable(s, false); … … 1518 1518 // for each row 1519 1519 // assume that the data order are same between sig and ref 1520 RowAccumulator acc( asap:: TINTSYS ) ;1520 RowAccumulator acc( asap::W_TINTSYS ) ; 1521 1521 for ( int i = 0 ; i < sig->nrow() ; i++ ) { 1522 1522 // get values … … 1952 1952 // initialize the lookup table if necessary 1953 1953 if ( lookup.empty() ) { 1954 lookup["NONE"] = asap:: NONE;1955 lookup["TINT"] = asap:: TINT;1956 lookup["TINTSYS"] = asap:: TINTSYS;1957 lookup["TSYS"] = asap:: TSYS;1958 lookup["VAR"] = asap:: VAR;1954 lookup["NONE"] = asap::W_NONE; 1955 lookup["TINT"] = asap::W_TINT; 1956 lookup["TINTSYS"] = asap::W_TINTSYS; 1957 lookup["TSYS"] = asap::W_TSYS; 1958 lookup["VAR"] = asap::W_VAR; 1959 1959 } 1960 1960 … … 2000 2000 String msg; 2001 2001 if ( nc > 0 ) { 2002 ppoly = new Polynomial<Float>(nc );2002 ppoly = new Polynomial<Float>(nc-1); 2003 2003 coeff = coeffs; 2004 2004 msg = String("user"); … … 2006 2006 STAttr sdAttr; 2007 2007 coeff = sdAttr.gainElevationPoly(inst); 2008 ppoly = new Polynomial<Float>( 3);2008 ppoly = new Polynomial<Float>(coeff.nelements()-1); 2009 2009 msg = String("built in"); 2010 2010 } … … 2144 2144 if (d < 0) { 2145 2145 Instrument inst = 2146 STAttr::convertInstrument(tab.keywordSet().asString("AntennaName"), 2146 STAttr::convertInstrument(tab.keywordSet().asString("AntennaName"), 2147 2147 True); 2148 2148 STAttr sda; … … 2207 2207 2208 2208 CountedPtr< Scantable > STMath::opacity( const CountedPtr< Scantable > & in, 2209 floattau )2209 const std::vector<float>& tau ) 2210 2210 { 2211 2211 CountedPtr< Scantable > out = getScantable(in, false); 2212 2212 2213 Table tab = out->table(); 2214 ROScalarColumn<Float> elev(tab, "ELEVATION"); 2215 ArrayColumn<Float> specCol(tab, "SPECTRA"); 2216 ArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 2217 ArrayColumn<Float> tsysCol(tab, "TSYS"); 2218 for ( uInt i=0; i<tab.nrow(); ++i) { 2219 Float zdist = Float(C::pi_2) - elev(i); 2220 Float factor = exp(tau/cos(zdist)); 2221 MaskedArray<Float> ma = maskedArray(specCol(i), flagCol(i)); 2222 ma *= factor; 2223 specCol.put(i, ma.getArray()); 2224 flagCol.put(i, flagsFromMA(ma)); 2225 Vector<Float> tsys; 2226 tsysCol.get(i, tsys); 2227 tsys *= factor; 2228 tsysCol.put(i, tsys); 2213 Table outtab = out->table(); 2214 2215 const uInt ntau = uInt(tau.size()); 2216 std::vector<float>::const_iterator tauit = tau.begin(); 2217 AlwaysAssert((ntau == 1 || ntau == in->nif() || ntau == in->nif() * in->npol()), 2218 AipsError); 2219 TableIterator iiter(outtab, "IFNO"); 2220 while ( !iiter.pastEnd() ) { 2221 Table itab = iiter.table(); 2222 TableIterator piter(outtab, "POLNO"); 2223 while ( !piter.pastEnd() ) { 2224 Table tab = piter.table(); 2225 ROScalarColumn<Float> elev(tab, "ELEVATION"); 2226 ArrayColumn<Float> specCol(tab, "SPECTRA"); 2227 ArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 2228 ArrayColumn<Float> tsysCol(tab, "TSYS"); 2229 for ( uInt i=0; i<tab.nrow(); ++i) { 2230 Float zdist = Float(C::pi_2) - elev(i); 2231 Float factor = exp(*tauit/cos(zdist)); 2232 MaskedArray<Float> ma = maskedArray(specCol(i), flagCol(i)); 2233 ma *= factor; 2234 specCol.put(i, ma.getArray()); 2235 flagCol.put(i, flagsFromMA(ma)); 2236 Vector<Float> tsys; 2237 tsysCol.get(i, tsys); 2238 tsys *= factor; 2239 tsysCol.put(i, tsys); 2240 } 2241 if (ntau == in->nif()*in->npol() ) { 2242 tauit++; 2243 } 2244 piter++; 2245 } 2246 if (ntau >= in->nif() ) { 2247 tauit++; 2248 } 2249 iiter++; 2229 2250 } 2230 2251 return out; … … 2233 2254 CountedPtr< Scantable > STMath::smoothOther( const CountedPtr< Scantable >& in, 2234 2255 const std::string& kernel, 2235 float width 2256 float width, int order) 2236 2257 { 2237 2258 CountedPtr< Scantable > out = getScantable(in, false); … … 2254 2275 mathutil::runningMedian(specout, maskout, spec , mask, width); 2255 2276 convertArray(flag, maskout); 2277 } else if ( kernel == "poly" ) { 2278 mathutil::polyfit(specout, maskout, spec, !mask, width, order); 2279 convertArray(flag, !maskout); 2256 2280 } 2257 2281 flagCol.put(i, flag); … … 2262 2286 2263 2287 CountedPtr< Scantable > STMath::smooth( const CountedPtr< Scantable >& in, 2264 const std::string& kernel, float width ) 2265 { 2266 if (kernel == "rmedian" || kernel == "hanning") { 2267 return smoothOther(in, kernel, width); 2288 const std::string& kernel, float width, 2289 int order) 2290 { 2291 if (kernel == "rmedian" || kernel == "hanning" || kernel == "poly") { 2292 return smoothOther(in, kernel, width, order); 2268 2293 } 2269 2294 CountedPtr< Scantable > out = getScantable(in, false); … … 2351 2376 id = out->molecules().addEntry(rf, name, fname); 2352 2377 molidcol.put(k, id); 2353 Float f rot,fax,ftan,fhand,fmount,fuser, fxy, fxyp;2354 (*it)->focus().getEntry(f ax, ftan, frot, fhand,2378 Float fpa,frot,fax,ftan,fhand,fmount,fuser, fxy, fxyp; 2379 (*it)->focus().getEntry(fpa, fax, ftan, frot, fhand, 2355 2380 fmount,fuser, fxy, fxyp, 2356 2381 rec.asuInt("FOCUS_ID")); 2357 id = out->focus().addEntry(f ax, ftan, frot, fhand,2382 id = out->focus().addEntry(fpa, fax, ftan, frot, fhand, 2358 2383 fmount,fuser, fxy, fxyp); 2359 2384 focusidcol.put(k, id); … … 2399 2424 cols[3] = String("CYCLENO"); 2400 2425 TableIterator iter(tout, cols); 2401 CountedPtr<STPol> stpol = STPol::getPolClass(out->factories_, 2426 CountedPtr<STPol> stpol = STPol::getPolClass(out->factories_, 2402 2427 out->getPolType() ); 2403 2428 while (!iter.pastEnd()) { … … 2405 2430 ArrayColumn<Float> speccol(t, "SPECTRA"); 2406 2431 ScalarColumn<uInt> focidcol(t, "FOCUS_ID"); 2407 ScalarColumn<Float> parancol(t, "PARANGLE");2408 2432 Matrix<Float> pols(speccol.getColumn()); 2409 2433 try { 2410 2434 stpol->setSpectra(pols); 2411 Float fang,fhand ,parang;2412 fang = in->focusTable_.getTotal FeedAngle(focidcol(0));2435 Float fang,fhand; 2436 fang = in->focusTable_.getTotalAngle(focidcol(0)); 2413 2437 fhand = in->focusTable_.getFeedHand(focidcol(0)); 2414 parang = parancol(0); 2415 /// @todo re-enable this 2416 // disable total feed angle to support paralactifying Caswell style 2417 stpol->setPhaseCorrections(parang, -parang, fhand); 2438 stpol->setPhaseCorrections(fang, fhand); 2418 2439 // use a member function pointer in STPol. This only works on 2419 2440 // the STPol pointer itself, not the Counted Pointer so … … 2681 2702 uInt row = tab.rowNumbers()[0]; 2682 2703 stpol->setSpectra(in->getPolMatrix(row)); 2683 Float fang,fhand ,parang;2684 fang = in->focusTable_.getTotal FeedAngle(in->mfocusidCol_(row));2704 Float fang,fhand; 2705 fang = in->focusTable_.getTotalAngle(in->mfocusidCol_(row)); 2685 2706 fhand = in->focusTable_.getFeedHand(in->mfocusidCol_(row)); 2686 parang = in->paraCol_(row); 2687 /// @todo re-enable this 2688 // disable total feed angle to support paralactifying Caswell style 2689 stpol->setPhaseCorrections(parang, -parang, fhand); 2707 stpol->setPhaseCorrections(fang, fhand); 2690 2708 Int npolout = 0; 2691 2709 for (uInt i=0; i<tab.nrow(); ++i) { … … 2737 2755 CountedPtr< Scantable > 2738 2756 asap::STMath::lagFlag( const CountedPtr< Scantable > & in, 2739 double frequency, double width ) 2757 double start, double end, 2758 const std::string& mode) 2740 2759 { 2741 2760 CountedPtr< Scantable > out = getScantable(in, false); … … 2755 2774 Vector<Float> spec = specCol(i); 2756 2775 Vector<uChar> flag = flagCol(i); 2757 Int lag0 = Int(spec.nelements()*abs(inc)/(frequency+width)+0.5);2758 Int lag1 = Int(spec.nelements()*abs(inc)/(frequency-width)+0.5);2776 int fstart = -1; 2777 int fend = -1; 2759 2778 for (unsigned int k=0; k < flag.nelements(); ++k ) { 2760 2779 if (flag[k] > 0) { 2761 spec[k] = 0.0; 2780 fstart = k; 2781 while (flag[k] > 0 && k < flag.nelements()) { 2782 fend = k; 2783 k++; 2784 } 2762 2785 } 2786 Float interp = 0.0; 2787 if (fstart-1 > 0 ) { 2788 interp = spec[fstart-1]; 2789 if (fend+1 < spec.nelements()) { 2790 interp = (interp+spec[fend+1])/2.0; 2791 } 2792 } else { 2793 interp = spec[fend+1]; 2794 } 2795 if (fstart > -1 && fend > -1) { 2796 for (int j=fstart;j<=fend;++j) { 2797 spec[j] = interp; 2798 } 2799 } 2800 fstart =-1; 2801 fend = -1; 2763 2802 } 2764 2803 Vector<Complex> lags; 2765 2804 ffts.fft0(lags, spec); 2766 Int start = max(0, lag0); 2767 Int end = min(Int(lags.nelements()-1), lag1); 2768 if (start == end) { 2769 lags[start] = Complex(0.0); 2805 Int lag0(start+0.5); 2806 Int lag1(end+0.5); 2807 if (mode == "frequency") { 2808 lag0 = Int(spec.nelements()*abs(inc)/(start)+0.5); 2809 lag1 = Int(spec.nelements()*abs(inc)/(end)+0.5); 2810 } 2811 Int lstart = max(0, lag0); 2812 Int lend = min(Int(lags.nelements()-1), lag1); 2813 if (lstart == lend) { 2814 lags[lstart] = Complex(0.0); 2770 2815 } else { 2771 for (int j=start; j <=end ;++j) { 2816 if (lstart > lend) { 2817 Int tmp = lend; 2818 lend = lstart; 2819 lstart = tmp; 2820 } 2821 for (int j=lstart; j <=lend ;++j) { 2772 2822 lags[j] = Complex(0.0); 2773 2823 }
Note: See TracChangeset
for help on using the changeset viewer.