Changeset 31153 for trunk/psModules/src/objects/pmSourcePhotometry.c
- Timestamp:
- Apr 4, 2011, 1:04:41 PM (15 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/objects/pmSourcePhotometry.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:ignore
-
old new 28 28 ChangeLog 29 29 psmodules-*.tar.* 30 a.out.dSYM
-
- Property svn:ignore
-
trunk/psModules/src/objects/pmSourcePhotometry.c
r29935 r31153 23 23 #include "pmFPAMaskWeight.h" 24 24 25 #include "pmConfigMask.h" 25 26 #include "pmTrend2D.h" 26 27 #include "pmResiduals.h" … … 49 50 static float AP_MIN_SN = 0.0; 50 51 51 bool pmSourceMagnitudesInit (psMetadata *config) 52 { 53 PS_ASSERT_PTR_NON_NULL(config, false); 52 // make this a bit more clever and dynamic 53 static psImageMaskType maskSuspect = 0; 54 static psImageMaskType maskSpike = 0; 55 static psImageMaskType maskStarCore = 0; 56 static psImageMaskType maskBurntool = 0; 57 static psImageMaskType maskConvPoor = 0; 58 59 bool pmSourceMagnitudesInit (pmConfig *config, psMetadata *recipe) 60 { 61 PS_ASSERT_PTR_NON_NULL(recipe, false); 54 62 bool status; 55 63 56 float limit = psMetadataLookupF32 (&status, config, "AP_MIN_SN"); 64 // we are going to test specially against these poor values 65 if (config) { 66 maskSpike = pmConfigMaskGet("SPIKE", config); 67 maskStarCore = pmConfigMaskGet("STARCORE", config); 68 maskBurntool = pmConfigMaskGet("BURNTOOL", config); 69 maskConvPoor = pmConfigMaskGet("CONV.POOR", config); 70 maskSuspect = maskSpike | maskStarCore | maskBurntool | maskConvPoor; 71 } 72 73 float limit = psMetadataLookupF32 (&status, recipe, "AP_MIN_SN"); 57 74 if (status) { 58 75 AP_MIN_SN = limit; … … 77 94 // XXX masked region should be (optionally) elliptical 78 95 // if mode is PM_SOURCE_PHOT_PSFONLY, we skip all other magnitudes 79 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal )96 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal, float radius) 80 97 { 81 98 PS_ASSERT_PTR_NON_NULL(source, false); … … 166 183 // measure the contribution of included pixels 167 184 if (mode & PM_SOURCE_PHOT_WEIGHT) { 168 pmSourcePixelWeight ( &source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal);185 pmSourcePixelWeight (source, model, source->maskObj, maskVal, radius); 169 186 } 170 187 … … 342 359 343 360 // return source aperture magnitude 344 bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal) 345 { 346 PS_ASSERT_PTR_NON_NULL(pixWeightNotBad, false); 347 PS_ASSERT_PTR_NON_NULL(pixWeightNotPoor, false); 361 bool pmSourcePixelWeight (pmSource *source, pmModel *model, psImage *mask, psImageMaskType maskVal, float radius) 362 { 363 PS_ASSERT_PTR_NON_NULL(source, false); 364 source->pixWeightNotBad = NAN; 365 source->pixWeightNotPoor = NAN; 366 348 367 PS_ASSERT_PTR_NON_NULL(mask, false); 349 368 PS_ASSERT_PTR_NON_NULL(model, false); … … 355 374 float value; 356 375 376 float spikeSum = 0; 377 float starcoreSum = 0; 378 float burntoolSum = 0; 379 float convpoorSum = 0; 380 357 381 int Xo, Yo, dP; 358 382 int dX, DX, NX; 359 383 int dY, DY, NY; 360 384 361 *pixWeightNotBad = 0.0; 362 *pixWeightNotPoor = 0.0; 385 float radius2 = PS_SQR(radius); 363 386 364 387 // we only care about the value of the object model, not the local sky … … 387 410 NY = mask->numRows; 388 411 412 psImageMaskType maskBad = maskVal; 413 maskBad &= ~maskSuspect; 414 389 415 // measure modelSum and validSum. this function is applied to a sources' subimage. the 390 416 // value of DX is chosen (see above) to cover the full possible size of the subimage if it 391 417 // were not by an edge; ie, if the source is cut in half by an image edge, we correctly 392 418 // count the virtual pixels off the edge in normalizing the value of the pixWeight 419 420 // we skip any pixels [real or virtual] outside of the specified radius (nominally the aperture radius) 393 421 for (int ix = -DX; ix < DX + 1; ix++) { 422 if (ix > radius) continue; 394 423 int mx = ix + dX; 395 424 for (int iy = -DY; iy < DY + 1; iy++) { 425 if (iy > radius) continue; 426 if (ix*ix + iy*iy > radius2) continue; 396 427 int my = iy + dY; 397 428 … … 409 440 if (my >= NY) continue; 410 441 411 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) { 442 // count pixels which are masked only with bad pixels 443 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskBad)) { 412 444 notBadSum += value; 413 445 } 414 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & ~markVal)) { 446 447 // count pixels which are masked with an mask bit (bad or poor) 448 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) { 415 449 notPoorSum += value; 416 450 } 451 452 // count pixels which are masked with an mask bit (bad or poor) 453 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskSpike) { 454 spikeSum += value; 455 } 456 // count pixels which are masked with an mask bit (bad or poor) 457 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskStarCore) { 458 starcoreSum += value; 459 } 460 // count pixels which are masked with an mask bit (bad or poor) 461 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskBurntool) { 462 burntoolSum += value; 463 } 464 // count pixels which are masked with an mask bit (bad or poor) 465 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskConvPoor) { 466 convpoorSum += value; 467 } 417 468 } 418 469 } 419 470 psFree (coord); 420 471 421 *pixWeightNotBad = notBadSum / modelSum; 422 *pixWeightNotPoor = notPoorSum / modelSum; 472 source->pixWeightNotBad = notBadSum / modelSum; 473 source->pixWeightNotPoor = notPoorSum / modelSum; 474 475 if ((spikeSum/modelSum) > 0.25) { 476 source->mode2 |= PM_SOURCE_MODE2_ON_SPIKE; 477 } 478 if ((starcoreSum/modelSum) > 0.25) { 479 source->mode2 |= PM_SOURCE_MODE2_ON_STARCORE; 480 } 481 if ((burntoolSum/modelSum) > 0.25) { 482 source->mode2 |= PM_SOURCE_MODE2_ON_BURNTOOL; 483 } 484 if ((convpoorSum/modelSum) > 0.25) { 485 source->mode2 |= PM_SOURCE_MODE2_ON_CONVPOOR; 486 } 487 488 if (isfinite(source->pixWeightNotBad) && isfinite(source->pixWeightNotPoor)) { 489 psAssert (source->pixWeightNotBad <= source->pixWeightNotPoor, "error: all bad pixels should also be poor"); 490 } 423 491 424 492 return (true); … … 427 495 # define FLUX_LIMIT 3.0 428 496 429 // measure stats that may be us ingin difference images for distinguishing real sources from bad residuals497 // measure stats that may be used in difference images for distinguishing real sources from bad residuals 430 498 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) 431 499 { … … 673 741 # endif 674 742 675 // determine chisq, etc for linear normalization-only fit676 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *variance, psImageMaskType maskVal , const float covarFactor)743 // determine chisq, nPix, nDOF, chisqNorm : model->nPar must be set 744 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *variance, psImageMaskType maskVal) 677 745 { 678 746 PS_ASSERT_PTR_NON_NULL(model, false); … … 689 757 if (variance->data.F32[j][i] <= 0) 690 758 continue; 691 dC += PS_SQR (image->data.F32[j][i]) / (covarFactor * variance->data.F32[j][i]);759 dC += PS_SQR (image->data.F32[j][i]) / variance->data.F32[j][i]; 692 760 Npix ++; 693 761 } 694 762 } 695 763 model->nPix = Npix; 696 model->nDOF = Npix - 1;764 model->nDOF = Npix - model->nPar; 697 765 model->chisq = dC; 766 model->chisqNorm = dC / model->nDOF; 698 767 699 768 return (true); 700 769 } 701 770 771 772 // return source aperture magnitude 773 bool pmSourceChisqUnsubtracted (pmSource *source, pmModel *model, psImageMaskType maskVal) 774 { 775 PS_ASSERT_PTR_NON_NULL(source, false); 776 PS_ASSERT_PTR_NON_NULL(model, false); 777 778 float dC = 0.0; 779 int Npix = 0; 780 781 // the model function returns the source flux at a position 782 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 783 784 psVector *params = model->params; 785 psImage *image = source->pixels; 786 psImage *mask = source->maskObj; 787 psImage *variance = source->variance; 788 789 int dX = image->col0; 790 int dY = image->row0; 791 792 for (int iy = 0; iy < image->numRows; iy++) { 793 for (int ix = 0; ix < image->numCols; ix++) { 794 795 // skip pixels which are masked 796 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue; 797 798 if (variance->data.F32[iy][ix] <= 0) continue; 799 800 coord->data.F32[0] = (psF32) ix + dX + 0.5; 801 coord->data.F32[1] = (psF32) iy + dY + 0.5; 802 803 // for the full model, add all points 804 float value = model->modelFunc (NULL, params, coord); 805 806 // fprintf (stderr, "%d, %d : %f, %f : %f - %f : %f\n", 807 // ix, iy, coord->data.F32[0], coord->data.F32[1], image->data.F32[iy][ix], value, dC); 808 809 dC += PS_SQR (image->data.F32[iy][ix] - value) / variance->data.F32[iy][ix]; 810 Npix ++; 811 } 812 } 813 model->nPix = Npix; 814 model->nDOF = Npix - model->nPar; 815 model->chisq = dC; 816 model->chisqNorm = dC / model->nDOF; 817 818 psFree (coord); 819 return (true); 820 } 702 821 703 822 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
Note:
See TracChangeset
for help on using the changeset viewer.
