- Timestamp:
- 10/04/16 18:20:50 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/external-alma/components/SpectralComponents/Spectral2Estimate.tcc
r2980 r3106 18 18 //# 19 19 //# Correspondence concerning AIPS++ should be addressed as follows: 20 //# Internet email: aips2-request@nrao.edu.20 //# casacore::Internet email: aips2-request@nrao.edu. 21 21 //# Postal address: AIPS++ Project Office 22 22 //# National Radio Astronomy Observatory … … 40 40 //# Member templates 41 41 template <class MT> 42 const SpectralList &SpectralEstimate::estimate(const Vector<MT> &prof,43 Vector<MT> *der) {42 const SpectralList &SpectralEstimate::estimate(const casacore::Vector<MT> &prof, 43 casacore::Vector<MT> *der) { 44 44 if (prof.nelements() != lprof_p) { 45 45 delete [] deriv_p; deriv_p = 0; lprof_p = 0; 46 46 lprof_p = prof.nelements(); 47 deriv_p = new Double[lprof_p];47 deriv_p = new casacore::Double[lprof_p]; 48 48 }; 49 49 // Check if signal in window 50 50 if (!window(prof)) return slist_p; 51 51 // Limit window 52 windowEnd_p = min(windowEnd_p+q_p , Int(lprof_p));52 windowEnd_p = min(windowEnd_p+q_p , casacore::Int(lprof_p)); 53 53 windowLow_p = max(windowLow_p-q_p , 0 ); 54 54 // Get the second derivatives … … 56 56 // Next for debugging 57 57 if (der) { 58 for ( uInt i=0; i<lprof_p; i++) (*der)[i] = deriv_p[i];58 for (casacore::uInt i=0; i<lprof_p; i++) (*der)[i] = deriv_p[i]; 59 59 }; 60 60 // Find the estimates (sorted) … … 65 65 66 66 template <class MT> 67 const SpectralList& SpectralEstimate::estimate(const Vector<MT>& x,68 const Vector<MT>& y)67 const SpectralList& SpectralEstimate::estimate(const casacore::Vector<MT>& x, 68 const casacore::Vector<MT>& y) 69 69 { 70 70 if (x.nelements() != y.nelements()) { … … 77 77 estimate(y); 78 78 // Convert 79 for ( uInt i=0; i<slist_p.nelements(); i++) {79 for (casacore::uInt i=0; i<slist_p.nelements(); i++) { 80 80 if (slist_p[i]->getType() != SpectralElement::GAUSSIAN) { 81 81 throw AipsError("Non-gaussian spectral types cannot be estimated"); … … 90 90 91 91 template <class MT> 92 uInt SpectralEstimate::window(constVector<MT> &prof) {92 casacore::uInt SpectralEstimate::window(const casacore::Vector<MT> &prof) { 93 93 windowLow_p =0; 94 94 windowEnd_p = 0; 95 95 if (!useWindow_p || rms_p <= 0.0 || lprof_p == 0) { 96 96 if (regionEnd_p) { 97 windowLow_p = min(max(0,regionLow_p), Int(lprof_p));98 windowEnd_p = min(regionEnd_p, Int(lprof_p));97 windowLow_p = min(max(0,regionLow_p),casacore::Int(lprof_p)); 98 windowEnd_p = min(regionEnd_p, casacore::Int(lprof_p)); 99 99 } else windowEnd_p = lprof_p; 100 100 return windowEnd_p-windowLow_p; 101 101 }; 102 102 // Total flux in profile and max position 103 Double flux(0.0);104 Double pmax(prof(0));105 uInt imax(0);106 for ( Int i=windowLow_p; i<windowEnd_p; i++) {103 casacore::Double flux(0.0); 104 casacore::Double pmax(prof(0)); 105 casacore::uInt imax(0); 106 for (casacore::Int i=windowLow_p; i<windowEnd_p; i++) { 107 107 if (prof(i)>pmax) { 108 108 pmax = prof(i); … … 114 114 if (pmax < cutoff_p) return 0; 115 115 // Window boundaries; new/old base and centre; width 116 Int width(-1);117 Int nw(0);118 Double bnew(flux), bold;119 Double cnew(imax), cold;116 casacore::Int width(-1); 117 casacore::Int nw(0); 118 casacore::Double bnew(flux), bold; 119 casacore::Double cnew(imax), cold; 120 120 do { 121 121 width++; 122 122 cold = cnew; 123 123 bold = bnew; 124 windowLow_p = max(0, Int(cold-width+0.5));125 windowEnd_p = min( Int(lprof_p),Int(cold+width+1.5));124 windowLow_p = max(0, casacore::Int(cold-width+0.5)); 125 windowEnd_p = min(casacore::Int(lprof_p), casacore::Int(cold+width+1.5)); 126 126 // flux and first moment in window 127 Double s(0);128 Double c(0);129 for ( Int i=windowLow_p; i<windowEnd_p; i++) {127 casacore::Double s(0); 128 casacore::Double c(0); 129 for (casacore::Int i=windowLow_p; i<windowEnd_p; i++) { 130 130 s += prof(i); 131 131 c += i*prof(i); … … 142 142 143 143 template <class MT> 144 void SpectralEstimate::findc2(const Vector<MT> &prof) {145 for ( Int i=windowLow_p; i<windowEnd_p; i++) {144 void SpectralEstimate::findc2(const casacore::Vector<MT> &prof) { 145 for (casacore::Int i=windowLow_p; i<windowEnd_p; i++) { 146 146 // Moments 147 Double m0(0.0);148 Double m2(0.0);149 for ( Int j = -q_p; j <= q_p; j++) {150 Int k = i+j;151 if (k >= 0 && k< Int(lprof_p)) {147 casacore::Double m0(0.0); 148 casacore::Double m2(0.0); 149 for (casacore::Int j = -q_p; j <= q_p; j++) { 150 casacore::Int k = i+j; 151 if (k >= 0 && k<casacore::Int(lprof_p)) { 152 152 // add to moments 153 153 m0 += prof(k); … … 161 161 162 162 template <class MT> 163 void SpectralEstimate::findga(const Vector<MT> &prof) {164 Int i(windowLow_p-1);163 void SpectralEstimate::findga(const casacore::Vector<MT> &prof) { 164 casacore::Int i(windowLow_p-1); 165 165 // Window on Gaussian 166 Int iclo(windowLow_p);167 Int ichi(windowLow_p);166 casacore::Int iclo(windowLow_p); 167 casacore::Int ichi(windowLow_p); 168 168 // Peak counter 169 Int nmax = 0;169 casacore::Int nmax = 0; 170 170 GaussianSpectralElement tspel; 171 171 while (++i < windowEnd_p) { … … 187 187 case 2: { 188 188 // Some moments 189 Double m0m(0);190 Double m0(0);191 Double m1(0);192 Double m2(0);189 casacore::Double m0m(0); 190 casacore::Double m0(0); 191 casacore::Double m1(0); 192 casacore::Double m2(0); 193 193 ichi = i; 194 194 // Do Schwarz' calculation 195 Double b = deriv_p[iclo];196 Double a = (deriv_p[ichi] - b) / (ichi-iclo);197 for ( Int ic=iclo; ic<=ichi; ic++) {195 casacore::Double b = deriv_p[iclo]; 196 casacore::Double a = (deriv_p[ichi] - b) / (ichi-iclo); 197 for (casacore::Int ic=iclo; ic<=ichi; ic++) { 198 198 m0m += min(deriv_p[ic], 0.0); 199 Double wi = deriv_p[ic] - a*(ic-iclo) - b;199 casacore::Double wi = deriv_p[ic] - a*(ic-iclo) - b; 200 200 m0 += wi; 201 201 m1 += wi*ic; … … 203 203 }; 204 204 // determinant 205 Double det = m2*m0 - m1*m1;205 casacore::Double det = m2*m0 - m1*m1; 206 206 if (det > 0.0 && fabs(m0m) > FLT_EPSILON) { 207 Double xm = m1/m0;208 Double sg = 1.69*sqrt(det) / fabs(m0);207 casacore::Double xm = m1/m0; 208 casacore::Double sg = 1.69*sqrt(det) / fabs(m0); 209 209 // Width above critical? 210 210 if (sg > sigmin_p) { 211 Int is =Int(1.73*sg+0.5);212 Int im =Int(xm+0.5);213 Double yl(0);211 casacore::Int is = casacore::Int(1.73*sg+0.5); 212 casacore::Int im = casacore::Int(xm+0.5); 213 casacore::Double yl(0); 214 214 if ((im-is) >= 0) yl = prof(im-is); 215 Double yh(0);216 if ((im + is) <= Int(lprof_p-1)) yh = prof(im+is);217 Double ym = prof(im);215 casacore::Double yh(0); 216 if ((im + is) <= casacore::Int(lprof_p-1)) yh = prof(im+is); 217 casacore::Double ym = prof(im); 218 218 // modified by dmehringer 2012apr03 to deal with 0 denominator 219 219 // 0.0/0.0 produces NaN on Linux but 0 on OSX 220 Double pg = (ym-0.5*(yh+yl));220 casacore::Double pg = (ym-0.5*(yh+yl)); 221 221 if (pg != 0) { 222 Double denom = (1.0-exp(-0.5*(is*is)/sg/sg));222 casacore::Double denom = (1.0-exp(-0.5*(is*is)/sg/sg)); 223 223 if (denom == 0) { 224 224 throw AipsError("Bailing because division by zero is undefined"); … … 252 252 253 253 template <class MT> 254 GaussianSpectralElement SpectralEstimate::convertElement (const Vector<MT>& x,254 GaussianSpectralElement SpectralEstimate::convertElement (const casacore::Vector<MT>& x, 255 255 const GaussianSpectralElement& el) const 256 256 { 257 257 GaussianSpectralElement elOut = el; 258 const Int& idxMax = x.nelements()-1;258 const casacore::Int& idxMax = x.nelements()-1; 259 259 260 260 // Get current (pars are amp, center, width as the SpectralElement 261 261 // will always be a Gaussian) 262 262 263 Vector<Double> par, err;263 casacore::Vector<casacore::Double> par, err; 264 264 el.get(par); 265 265 el.getError(err); … … 267 267 // Center 268 268 269 Int cenIdx =Int(par[1]);269 casacore::Int cenIdx = casacore::Int(par[1]); 270 270 271 271 // Get the x-increment, local to the center, as best we can from … … 273 273 // vector is monotonic 274 274 275 Double incX;275 casacore::Double incX; 276 276 if (cenIdx-1<0) { 277 277 incX = x[1] - x[0]; … … 287 287 par[1] = incX*(par[1]-idxMax) + x[idxMax]; // Extrapolate from x[idxMax] 288 288 } else { 289 Double dIdx = par[1] - cenIdx;290 par[1] = x[cenIdx] + dIdx*incX; // Interpolate289 casacore::Double dIdx = par[1] - cenIdx; 290 par[1] = x[cenIdx] + dIdx*incX; // casacore::Interpolate 291 291 } 292 292 err[1] = abs(err[1] * incX);
Note: See TracChangeset
for help on using the changeset viewer.