Changeset 29546 for trunk/psModules/src/objects/pmSourcePhotometry.c
- Timestamp:
- Oct 25, 2010, 2:54:22 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmSourcePhotometry.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourcePhotometry.c
r29004 r29546 62 62 63 63 /** 64 this function is used to calculate the three defined source magnitudes:65 - apMag : only if S/N > AP_MIN_SN66 : is optionally corrected for curve-of-growth if:67 - the source is a STAR (PSF)68 - the option is selected (mode & PM_SOURCE_PHOT_GROWTH)69 - psfMag : all sources with non-NULL modelPSF70 : is optionally corrected for aperture residual if:71 - the source is a STAR (PSF)72 - the option is selected (mode & PM_SOURCE_PHOT_APCORR)73 74 - extMag : all sources with non-NULL modelEXT64 this function is used to calculate the three defined source magnitudes: 65 - apMag : only if S/N > AP_MIN_SN 66 : is optionally corrected for curve-of-growth if: 67 - the source is a STAR (PSF) 68 - the option is selected (mode & PM_SOURCE_PHOT_GROWTH) 69 - psfMag : all sources with non-NULL modelPSF 70 : is optionally corrected for aperture residual if: 71 - the source is a STAR (PSF) 72 - the option is selected (mode & PM_SOURCE_PHOT_APCORR) 73 74 - extMag : all sources with non-NULL modelEXT 75 75 **/ 76 76 77 77 // XXX masked region should be (optionally) elliptical 78 // if mode is PM_SOURCE_PHOT_PSFONLY, we skip all other magnitudes 78 79 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal) 79 80 { … … 88 89 pmModel *model; 89 90 90 source->psfMag = NAN; 91 source->extMag = NAN; 92 source->errMag = NAN; 93 source->apMag = NAN; 91 source->psfMag = NAN; 92 source->extMag = NAN; 93 source->errMag = NAN; 94 source->apMag = NAN; 95 source->apMagRaw = NAN; 96 source->apFlux = NAN; 97 source->apFluxErr = NAN; 94 98 95 99 // we must have a valid model … … 114 118 // measure PSF model photometry 115 119 // XXX TEST: do not use flux scale 120 // XXX NOTE: turn this back on? 116 121 if (0 && psf->FluxScale) { 117 122 // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center … … 127 132 } 128 133 134 if (mode == PM_SOURCE_PHOT_PSFONLY) { 135 return true; 136 } 137 129 138 // if we have a collection of model fits, check if one of them is a pointer to modelEXT 130 139 if (source->modelFits) { … … 148 157 149 158 // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS 159 // XXX add a flag for "ap_mag is corrected?" 150 160 if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf && psf->ApTrend) { 151 161 // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center … … 181 191 // if we are measuring aperture photometry and applying the growth correction, 182 192 // we need to shift the flux in the selected pixels (but not the mask) 183 psImage *flux = NULL, *mask = NULL; // Star flux and mask images, to photometer 193 psImage *flux = NULL; 194 psImage *variance = NULL; 195 psImage *mask = NULL; // Star flux and mask images, to photometer 184 196 if (mode & PM_SOURCE_PHOT_INTERP) { 185 197 float dx = 0.5 - x + (int)x; … … 198 210 } else { 199 211 flux = source->pixels; 212 variance = source->variance; 200 213 mask = source->maskObj; 201 214 } 202 215 203 216 // measure object aperture photometry 204 status = pmSourcePhotometryAper (&source->apMagRaw, model, flux, mask, maskVal);217 status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal); 205 218 if (!status) { 206 219 psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag"); … … 214 227 if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) { 215 228 source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius); 229 // XXX correct the apFlux? 216 230 } 217 231 if (mode & PM_SOURCE_PHOT_APCORR) { … … 233 247 234 248 /* 235 aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y)236 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)237 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)249 aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y) 250 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y) 251 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y) 238 252 239 253 */ … … 267 281 268 282 // return source aperture magnitude 269 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal) 283 bool pmSourcePhotometryAperSource (pmSource *source, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal) 284 { 285 PS_ASSERT_PTR_NON_NULL(source, false); 286 PS_ASSERT_PTR_NON_NULL(image, false); 287 PS_ASSERT_PTR_NON_NULL(mask, false); 288 289 if (DO_SKY) { 290 PS_ASSERT_PTR_NON_NULL(model, false); 291 } 292 293 bool status; 294 status = pmSourcePhotometryAper(&source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal); 295 296 return status; 297 } 298 299 // return source aperture magnitude 300 bool pmSourcePhotometryAper (float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal) 270 301 { 271 302 PS_ASSERT_PTR_NON_NULL(apMag, false); … … 277 308 } 278 309 279 float apSum = 0;280 310 float sky = 0; 281 *apMag = NAN; 311 float apFlux = 0; 312 float apFluxVar = 0; 282 313 283 314 if (DO_SKY) { 284 315 sky = model->params->data.F32[PM_PAR_SKY]; 285 } else {286 sky = 0;287 316 } 288 317 289 318 psF32 **imData = image->data.F32; 290 319 psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA; 291 int nAperPix = 0; 292 293 // measure apMag 320 psF32 **varData = (variance) ? variance->data.F32 : image->data.F32; // if variance is not supplied, assume gain of 1.0, no read noise 321 322 // measure apFlux and apFluxVar, save apMag if not NAN 323 // XXX note that these fluxes/mags are uncorrected for masked pixels 324 // XXX raise a bit if the aperture has a masked pixel (not marked)? 294 325 for (int iy = 0; iy < image->numRows; iy++) { 295 326 for (int ix = 0; ix < image->numCols; ix++) { 296 if (mkData[iy][ix] & maskVal) 297 continue; 298 apSum += imData[iy][ix] - sky; 299 nAperPix ++; 300 // fprintf (stderr, "aper: %d %d %f %f %f\n", ix, iy, sky, imData[iy][ix], apSum); 301 } 302 } 303 if (apSum <= 0) { 327 if (mkData[iy][ix] & maskVal) continue; 328 apFlux += imData[iy][ix] - sky; 329 apFluxVar += varData[iy][ix]; 330 } 331 } 332 if (apFluxOut) *apFluxOut = apFlux; 333 if (apFluxErr) *apFluxErr = sqrt(apFluxVar); 334 335 if (apFlux <= 0) { 304 336 *apMag = NAN; 305 return true; 306 } 307 308 *apMag = -2.5*log10(apSum); 337 } else { 338 *apMag = -2.5*log10(apFlux); 339 } 309 340 return true; 310 341 } … … 419 450 } 420 451 452 // NOTE: until 2010.10.01, these measurements included a 3sigma-per-pixel significance 453 // this followed what we understood as the definition given to us 454 // by Armin, but it always seemed a poor idea -- a faint source is unlikely to have any 3sigma pixels. 455 // changed to remove the per-pixel filter. 456 421 457 for (int iy = 0; iy < flux->numRows; iy++) { 422 458 for (int ix = 0; ix < flux->numCols; ix++) { 423 459 // only count up the stats in the unmarked region (ie, the aperture) 460 // skip the marked pixels; these are not relevant 424 461 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & markVal) { 425 462 continue; … … 430 467 } 431 468 432 float SN = flux->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);433 434 if ( SN > +FLUX_LIMIT) {469 float value = flux->data.F32[iy][ix]; 470 471 if (value > 0.0) { 435 472 nGood ++; 436 fGood += fabs(flux->data.F32[iy][ix]); 437 } 438 439 if (SN < -FLUX_LIMIT) { 473 fGood += fabs(value); 474 } else { 440 475 nBad ++; 441 fBad += fabs( flux->data.F32[iy][ix]);476 fBad += fabs(value); 442 477 } 443 478 } … … 613 648 614 649 switch (term) { 615 case 0:650 case 0: 616 651 factor = 1; 617 652 break; 618 case 1:653 case 1: 619 654 factor = xi + Pi->col0; 620 655 break; 621 case 2:656 case 2: 622 657 factor = yi + Pi->row0; 623 658 break; 624 default:659 default: 625 660 psAbort("invalid term for pmSourceWeight"); 626 661 } … … 691 726 692 727 switch (term) { 693 case 0:728 case 0: 694 729 factor = 1; 695 730 break; 696 case 1:731 case 1: 697 732 factor = xi + Pi->col0; 698 733 break; 699 case 2:734 case 2: 700 735 factor = yi + Pi->row0; 701 736 break; 702 default:737 default: 703 738 psAbort("invalid term for pmSourceWeight"); 704 739 }
Note:
See TracChangeset
for help on using the changeset viewer.
