Changeset 29004 for trunk/psModules/src/objects/pmSourceMoments.c
- Timestamp:
- Aug 20, 2010, 1:14:11 PM (16 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/objects/pmSourceMoments.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:mergeinfo deleted
-
trunk/psModules/src/objects/pmSourceMoments.c
r27531 r29004 22 22 #include <strings.h> 23 23 #include <pslib.h> 24 24 25 #include "pmHDU.h" 25 26 #include "pmFPA.h" 26 #include "pmFPAMaskWeight.h" 27 28 #include "pmTrend2D.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 27 31 #include "pmSpan.h" 32 #include "pmFootprintSpans.h" 28 33 #include "pmFootprint.h" 29 34 #include "pmPeaks.h" 30 35 #include "pmMoments.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 33 #include "pmTrend2D.h" 34 #include "pmPSF.h" 36 #include "pmModelFuncs.h" 35 37 #include "pmModel.h" 38 #include "pmModelUtils.h" 39 #include "pmModelClass.h" 40 #include "pmSourceMasks.h" 41 #include "pmSourceExtendedPars.h" 42 #include "pmSourceDiffStats.h" 36 43 #include "pmSource.h" 37 44 … … 54 61 # define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0) 55 62 63 static bool beVerbose = false; 64 void pmSourceMomentsSetVerbose(bool state){ beVerbose = state; } 65 56 66 bool pmSourceMoments(pmSource *source, psF32 radius, psF32 sigma, psF32 minSN, psImageMaskType maskVal) 57 67 { … … 61 71 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false); 62 72 63 // use sky from moments if defined, 0.0 otherwise 73 // use sky from moments if defined, 0.0 otherwise 74 75 // XXX this value comes from the sky model at the source center, and tends to over-estimate 76 // the sky in the vicinity of bright sources. we are better off assuming the model worked 77 // well: 64 78 psF32 sky = 0.0; 65 if (source->moments == NULL) {66 source->moments = pmMomentsAlloc();67 } else {68 sky = source->moments->Sky;69 }79 // XXX if (source->moments == NULL) { 80 // XXX source->moments = pmMomentsAlloc(); 81 // XXX } else { 82 // XXX sky = source->moments->Sky; 83 // XXX } 70 84 71 85 // First Pass: calculate the first moments (these are subtracted from the coordinates below) … … 131 145 psF32 wDiff = *vWgt; 132 146 133 // skip pixels below specified significance level. this is allowed, but should be 134 // avoided -- the over-weights the wings of bright stars compared to those of faint 135 // stars. 136 if (PS_SQR(pDiff) < minSN2*wDiff) continue; 137 // if (pDiff < 0) continue; // XXX : MWV says I should include < 0.0 valued points... 147 // skip pixels below specified significance level. for a PSFs, this 148 // over-weights the wings of bright stars compared to those of faint stars. 149 // for the estimator used for extended source analysis (where the window 150 // function is allowed to be arbitrarily large), we need to clip to avoid 151 // negative second moments. 152 if (PS_SQR(pDiff) < minSN2*wDiff) continue; // 153 if ((minSN > 0.0) && (pDiff < 0)) continue; // 138 154 139 155 // Apply a Gaussian window function. Be careful with the window function. S/N … … 197 213 // Xn = SUM (x - xc)^n * (z - sky) 198 214 215 psF32 RF = 0.0; 216 psF32 RH = 0.0; 217 psF32 RS = 0.0; 199 218 psF32 XX = 0.0; 200 219 psF32 XY = 0.0; … … 244 263 if (r > radius) continue; 245 264 246 psF32 pDiff = *vPix - sky; 265 psF32 fDiff = *vPix - sky; 266 psF32 pDiff = fDiff; 247 267 psF32 wDiff = *vWgt; 248 268 … … 257 277 if (sigma > 0.0) { 258 278 // XXX a lot of extra flops; can we do pre-calculate? 259 psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 279 // XXX we were re-calculating r2 (maybe the compiler caught this?) 280 // psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 281 psF32 z = r2 * rsigma2; 260 282 assert (z >= 0.0); 261 283 psF32 weight = exp(-z); … … 266 288 267 289 Sum += pDiff; 290 291 # if (1) 292 # if (0) 293 if (fDiff < 0) continue; 294 # endif 295 psF32 rf = r * fDiff; 296 psF32 rh = sqrt(r) * fDiff; 297 psF32 rs = fDiff; 298 # else 299 psF32 rf = r * pDiff; 300 psF32 rh = sqrt(r) * pDiff; 301 psF32 rs = pDiff; 302 # endif 268 303 269 304 psF32 x = xDiff * pDiff; … … 284 319 psF32 xyyy = xDiff * yyy / r2; 285 320 psF32 yyyy = yDiff * yyy / r2; 321 322 RF += rf; 323 RH += rh; 324 RS += rs; 286 325 287 326 XX += xx; … … 302 341 } 303 342 343 source->moments->Mrf = RF/RS; 344 source->moments->Mrh = RH/RS; 345 304 346 source->moments->Mxx = XX/Sum; 305 347 source->moments->Mxy = XY/Sum; … … 317 359 source->moments->Myyyy = YYYY/Sum; 318 360 319 // if (source->moments->Mxx < 0) { 320 // fprintf (stderr, "error: neg second moment??\n"); 321 // } 322 // if (source->moments->Myy < 0) { 323 // fprintf (stderr, "error: neg second moment??\n"); 324 // } 325 326 psTrace ("psModules.objects", 4, "Mxx: %f Mxy: %f Myy: %f Mxxx: %f Mxxy: %f Mxyy: %f Myyy: %f Mxxxx: %f Mxxxy: %f Mxxyy: %f Mxyyy: %f Mxyyy: %f\n", 361 // Calculate the Kron magnitude (make this block optional?) 362 // float radKron = 2.5*source->moments->Mrf; 363 float radKinner = 1.0*source->moments->Mrf; 364 float radKron = 2.5*source->moments->Mrf; 365 float radKouter = 4.0*source->moments->Mrf; 366 367 int nKronPix = 0; 368 Sum = Var = 0.0; 369 float SumInner = 0.0; 370 float SumOuter = 0.0; 371 372 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 373 374 psF32 yDiff = row - yCM; 375 if (fabs(yDiff) > radKron) continue; 376 377 psF32 *vPix = source->pixels->data.F32[row]; 378 psF32 *vWgt = source->variance->data.F32[row]; 379 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row]; 380 381 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { 382 if (vMsk) { 383 if (*vMsk & maskVal) { 384 vMsk++; 385 continue; 386 } 387 vMsk++; 388 } 389 if (isnan(*vPix)) continue; 390 391 psF32 xDiff = col - xCM; 392 if (fabs(xDiff) > radKron) continue; 393 394 // radKron is just a function of (xDiff, yDiff) 395 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 396 psF32 r = sqrt(r2); 397 398 psF32 pDiff = *vPix - sky; 399 psF32 wDiff = *vWgt; 400 401 // skip pixels below specified significance level. this is allowed, but should be 402 // avoided -- the over-weights the wings of bright stars compared to those of faint 403 // stars. 404 if (PS_SQR(pDiff) < minSN2*wDiff) continue; 405 406 if (r < radKron) { 407 Sum += pDiff; 408 Var += wDiff; 409 nKronPix ++; 410 // if (beVerbose) fprintf (stderr, "mome: %d %d %f %f %f\n", col, row, sky, *vPix, Sum); 411 } 412 413 if ((r > radKinner) && (r < radKron)) { 414 SumInner += pDiff; 415 } 416 if ((r > radKron) && (r < radKouter)) { 417 SumOuter += pDiff; 418 } 419 } 420 } 421 source->moments->KronFlux = Sum; 422 source->moments->KronFinner = SumInner; 423 source->moments->KronFouter = SumOuter; 424 source->moments->KronFluxErr = sqrt(Var); 425 426 psTrace ("psModules.objects", 4, "Mrf: %f KronFlux: %f Mxx: %f Mxy: %f Myy: %f Mxxx: %f Mxxy: %f Mxyy: %f Myyy: %f Mxxxx: %f Mxxxy: %f Mxxyy: %f Mxyyy: %f Mxyyy: %f\n", 427 source->moments->Mrf, source->moments->KronFlux, 327 428 source->moments->Mxx, source->moments->Mxy, source->moments->Myy, 328 429 source->moments->Mxxx, source->moments->Mxxy, source->moments->Mxyy, source->moments->Myyy,
Note:
See TracChangeset
for help on using the changeset viewer.
