- Timestamp:
- Jul 9, 2010, 10:56:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceMoments.c
r27531 r28643 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) … … 197 211 // Xn = SUM (x - xc)^n * (z - sky) 198 212 213 psF32 RF = 0.0; 214 psF32 RH = 0.0; 215 psF32 RS = 0.0; 199 216 psF32 XX = 0.0; 200 217 psF32 XY = 0.0; … … 244 261 if (r > radius) continue; 245 262 246 psF32 pDiff = *vPix - sky; 263 psF32 fDiff = *vPix - sky; 264 psF32 pDiff = fDiff; 247 265 psF32 wDiff = *vWgt; 248 266 … … 257 275 if (sigma > 0.0) { 258 276 // XXX a lot of extra flops; can we do pre-calculate? 259 psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 277 // XXX we were re-calculating r2 (maybe the compiler caught this?) 278 // psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 279 psF32 z = r2 * rsigma2; 260 280 assert (z >= 0.0); 261 281 psF32 weight = exp(-z); … … 266 286 267 287 Sum += pDiff; 288 289 # if (1) 290 # if (0) 291 if (fDiff < 0) continue; 292 # endif 293 psF32 rf = r * fDiff; 294 psF32 rh = sqrt(r) * fDiff; 295 psF32 rs = fDiff; 296 # else 297 psF32 rf = r * pDiff; 298 psF32 rh = sqrt(r) * pDiff; 299 psF32 rs = pDiff; 300 # endif 268 301 269 302 psF32 x = xDiff * pDiff; … … 284 317 psF32 xyyy = xDiff * yyy / r2; 285 318 psF32 yyyy = yDiff * yyy / r2; 319 320 RF += rf; 321 RH += rh; 322 RS += rs; 286 323 287 324 XX += xx; … … 302 339 } 303 340 341 source->moments->Mrf = RF/RS; 342 source->moments->Mrh = RH/RS; 343 304 344 source->moments->Mxx = XX/Sum; 305 345 source->moments->Mxy = XY/Sum; … … 317 357 source->moments->Myyyy = YYYY/Sum; 318 358 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", 359 // Calculate the Kron magnitude (make this block optional?) 360 // float radKron = 2.5*source->moments->Mrf; 361 float radKinner = 1.0*source->moments->Mrf; 362 float radKron = 2.5*source->moments->Mrf; 363 float radKouter = 4.0*source->moments->Mrf; 364 365 int nKronPix = 0; 366 Sum = Var = 0.0; 367 float SumInner = 0.0; 368 float SumOuter = 0.0; 369 370 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 371 372 psF32 yDiff = row - yCM; 373 if (fabs(yDiff) > radKron) continue; 374 375 psF32 *vPix = source->pixels->data.F32[row]; 376 psF32 *vWgt = source->variance->data.F32[row]; 377 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row]; 378 379 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { 380 if (vMsk) { 381 if (*vMsk & maskVal) { 382 vMsk++; 383 continue; 384 } 385 vMsk++; 386 } 387 if (isnan(*vPix)) continue; 388 389 psF32 xDiff = col - xCM; 390 if (fabs(xDiff) > radKron) continue; 391 392 // radKron is just a function of (xDiff, yDiff) 393 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 394 psF32 r = sqrt(r2); 395 396 psF32 pDiff = *vPix - sky; 397 psF32 wDiff = *vWgt; 398 399 // skip pixels below specified significance level. this is allowed, but should be 400 // avoided -- the over-weights the wings of bright stars compared to those of faint 401 // stars. 402 if (PS_SQR(pDiff) < minSN2*wDiff) continue; 403 404 if (r < radKron) { 405 Sum += pDiff; 406 Var += wDiff; 407 nKronPix ++; 408 // if (beVerbose) fprintf (stderr, "mome: %d %d %f %f %f\n", col, row, sky, *vPix, Sum); 409 } 410 411 if ((r > radKinner) && (r < radKron)) { 412 SumInner += pDiff; 413 } 414 if ((r > radKron) && (r < radKouter)) { 415 SumOuter += pDiff; 416 } 417 } 418 } 419 source->moments->KronFlux = Sum; 420 source->moments->KronFinner = SumInner; 421 source->moments->KronFouter = SumOuter; 422 source->moments->KronFluxErr = sqrt(Var); 423 424 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", 425 source->moments->Mrf, source->moments->KronFlux, 327 426 source->moments->Mxx, source->moments->Mxy, source->moments->Myy, 328 427 source->moments->Mxxx, source->moments->Mxxy, source->moments->Mxyy, source->moments->Myyy,
Note:
See TracChangeset
for help on using the changeset viewer.
