- Timestamp:
- Aug 26, 2010, 9:18:39 AM (16 years ago)
- Location:
- branches/sc_branches/trunkTest
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sc_branches/trunkTest
- Property svn:mergeinfo changed
-
branches/sc_branches/trunkTest/psModules
- Property svn:mergeinfo deleted
-
branches/sc_branches/trunkTest/psModules/src/objects/pmSourceMoments.c
r27531 r29060 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 79 if (source->moments == NULL) { 66 source->moments = pmMomentsAlloc(); 67 } else { 68 sky = source->moments->Sky; 69 } 80 source->moments = pmMomentsAlloc(); 81 } 82 // XXX if (source->moments == NULL) { 83 // XXX source->moments = pmMomentsAlloc(); 84 // XXX } else { 85 // XXX sky = source->moments->Sky; 86 // XXX } 70 87 71 88 // First Pass: calculate the first moments (these are subtracted from the coordinates below) … … 131 148 psF32 wDiff = *vWgt; 132 149 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... 150 // skip pixels below specified significance level. for a PSFs, this 151 // over-weights the wings of bright stars compared to those of faint stars. 152 // for the estimator used for extended source analysis (where the window 153 // function is allowed to be arbitrarily large), we need to clip to avoid 154 // negative second moments. 155 if (PS_SQR(pDiff) < minSN2*wDiff) continue; // 156 if ((minSN > 0.0) && (pDiff < 0)) continue; // 138 157 139 158 // Apply a Gaussian window function. Be careful with the window function. S/N … … 197 216 // Xn = SUM (x - xc)^n * (z - sky) 198 217 218 psF32 RF = 0.0; 219 psF32 RH = 0.0; 220 psF32 RS = 0.0; 199 221 psF32 XX = 0.0; 200 222 psF32 XY = 0.0; … … 244 266 if (r > radius) continue; 245 267 246 psF32 pDiff = *vPix - sky; 268 psF32 fDiff = *vPix - sky; 269 psF32 pDiff = fDiff; 247 270 psF32 wDiff = *vWgt; 248 271 … … 257 280 if (sigma > 0.0) { 258 281 // XXX a lot of extra flops; can we do pre-calculate? 259 psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 282 // XXX we were re-calculating r2 (maybe the compiler caught this?) 283 // psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 284 psF32 z = r2 * rsigma2; 260 285 assert (z >= 0.0); 261 286 psF32 weight = exp(-z); … … 266 291 267 292 Sum += pDiff; 293 294 # if (1) 295 # if (0) 296 if (fDiff < 0) continue; 297 # endif 298 psF32 rf = r * fDiff; 299 psF32 rh = sqrt(r) * fDiff; 300 psF32 rs = fDiff; 301 # else 302 psF32 rf = r * pDiff; 303 psF32 rh = sqrt(r) * pDiff; 304 psF32 rs = pDiff; 305 # endif 268 306 269 307 psF32 x = xDiff * pDiff; … … 284 322 psF32 xyyy = xDiff * yyy / r2; 285 323 psF32 yyyy = yDiff * yyy / r2; 324 325 RF += rf; 326 RH += rh; 327 RS += rs; 286 328 287 329 XX += xx; … … 302 344 } 303 345 346 source->moments->Mrf = RF/RS; 347 source->moments->Mrh = RH/RS; 348 304 349 source->moments->Mxx = XX/Sum; 305 350 source->moments->Mxy = XY/Sum; … … 317 362 source->moments->Myyyy = YYYY/Sum; 318 363 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", 364 // Calculate the Kron magnitude (make this block optional?) 365 // float radKron = 2.5*source->moments->Mrf; 366 float radKinner = 1.0*source->moments->Mrf; 367 float radKron = 2.5*source->moments->Mrf; 368 float radKouter = 4.0*source->moments->Mrf; 369 370 int nKronPix = 0; 371 Sum = Var = 0.0; 372 float SumInner = 0.0; 373 float SumOuter = 0.0; 374 375 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 376 377 psF32 yDiff = row - yCM; 378 if (fabs(yDiff) > radKron) continue; 379 380 psF32 *vPix = source->pixels->data.F32[row]; 381 psF32 *vWgt = source->variance->data.F32[row]; 382 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row]; 383 384 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { 385 if (vMsk) { 386 if (*vMsk & maskVal) { 387 vMsk++; 388 continue; 389 } 390 vMsk++; 391 } 392 if (isnan(*vPix)) continue; 393 394 psF32 xDiff = col - xCM; 395 if (fabs(xDiff) > radKron) continue; 396 397 // radKron is just a function of (xDiff, yDiff) 398 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 399 psF32 r = sqrt(r2); 400 401 psF32 pDiff = *vPix - sky; 402 psF32 wDiff = *vWgt; 403 404 // skip pixels below specified significance level. this is allowed, but should be 405 // avoided -- the over-weights the wings of bright stars compared to those of faint 406 // stars. 407 if (PS_SQR(pDiff) < minSN2*wDiff) continue; 408 409 if (r < radKron) { 410 Sum += pDiff; 411 Var += wDiff; 412 nKronPix ++; 413 // if (beVerbose) fprintf (stderr, "mome: %d %d %f %f %f\n", col, row, sky, *vPix, Sum); 414 } 415 416 if ((r > radKinner) && (r < radKron)) { 417 SumInner += pDiff; 418 } 419 if ((r > radKron) && (r < radKouter)) { 420 SumOuter += pDiff; 421 } 422 } 423 } 424 source->moments->KronFlux = Sum; 425 source->moments->KronFinner = SumInner; 426 source->moments->KronFouter = SumOuter; 427 source->moments->KronFluxErr = sqrt(Var); 428 429 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", 430 source->moments->Mrf, source->moments->KronFlux, 327 431 source->moments->Mxx, source->moments->Mxy, source->moments->Myy, 328 432 source->moments->Mxxx, source->moments->Mxxy, source->moments->Mxyy, source->moments->Myyy,
Note:
See TracChangeset
for help on using the changeset viewer.
