- Timestamp:
- Sep 24, 2010, 2:49:53 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823/psModules/src/objects/pmSourcePhotometry.c
r29124 r29230 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 … … 88 88 pmModel *model; 89 89 90 source->psfMag = NAN; 91 source->extMag = NAN; 92 source->errMag = NAN; 93 source->apMag = NAN; 90 source->psfMag = NAN; 91 source->extMag = NAN; 92 source->errMag = NAN; 93 source->apMag = NAN; 94 source->apMagRaw = NAN; 95 source->apRadius = NAN; 96 source->apFlux = NAN; 97 source->apFluxErr = NAN; 94 98 95 99 // we must have a valid model … … 182 186 // if we are measuring aperture photometry and applying the growth correction, 183 187 // we need to shift the flux in the selected pixels (but not the mask) 184 psImage *flux = NULL, *mask = NULL; // Star flux and mask images, to photometer 188 psImage *flux = NULL; 189 psImage *variance = NULL; 190 psImage *mask = NULL; // Star flux and mask images, to photometer 185 191 if (mode & PM_SOURCE_PHOT_INTERP) { 186 192 float dx = 0.5 - x + (int)x; … … 199 205 } else { 200 206 flux = source->pixels; 207 variance = source->variance; 201 208 mask = source->maskObj; 202 209 } 203 210 204 211 // measure object aperture photometry 205 status = pmSourcePhotometryAper (&source->apMagRaw, model, flux, mask, maskVal);212 status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal); 206 213 if (!status) { 207 214 psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag"); … … 215 222 if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) { 216 223 source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius); 224 // XXX correct the apFlux? 217 225 } 218 226 if (mode & PM_SOURCE_PHOT_APCORR) { … … 234 242 235 243 /* 236 aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y)237 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)238 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)244 aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y) 245 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y) 246 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y) 239 247 240 248 */ … … 268 276 269 277 // return source aperture magnitude 270 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal) 278 bool pmSourcePhotometryAperSource (pmSource *source, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal) 279 { 280 PS_ASSERT_PTR_NON_NULL(source, false); 281 PS_ASSERT_PTR_NON_NULL(image, false); 282 PS_ASSERT_PTR_NON_NULL(mask, false); 283 284 if (DO_SKY) { 285 PS_ASSERT_PTR_NON_NULL(model, false); 286 } 287 288 bool status; 289 status = pmSourcePhotometryAper(&source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal); 290 291 return status; 292 } 293 294 // return source aperture magnitude 295 bool pmSourcePhotometryAper (float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal) 271 296 { 272 297 PS_ASSERT_PTR_NON_NULL(apMag, false); … … 278 303 } 279 304 280 float apSum = 0;281 305 float sky = 0; 282 *apMag = NAN; 306 float apFlux = 0; 307 float apFluxVar = 0; 283 308 284 309 if (DO_SKY) { 285 310 sky = model->params->data.F32[PM_PAR_SKY]; 286 } else {287 sky = 0;288 311 } 289 312 290 313 psF32 **imData = image->data.F32; 291 314 psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA; 292 int nAperPix = 0; 293 294 // measure apMag 295 // XXX save the apFlux and apFluxErr 315 psF32 **varData = (variance) ? variance->data.F32 : image->data.F32; // if variance is not supplied, assume gain of 1.0, no read noise 316 317 // measure apFlux and apFluxVar, save apMag if not NAN 296 318 // XXX note that these fluxes/mags are uncorrected for masked pixels 297 319 // XXX raise a bit if the aperture has a masked pixel (not marked)? 298 320 for (int iy = 0; iy < image->numRows; iy++) { 299 321 for (int ix = 0; ix < image->numCols; ix++) { 300 if (mkData[iy][ix] & maskVal) 301 continue; 302 apSum += imData[iy][ix] - sky; 303 nAperPix ++; 304 // fprintf (stderr, "aper: %d %d %f %f %f\n", ix, iy, sky, imData[iy][ix], apSum); 305 } 306 } 307 if (apSum <= 0) { 322 if (mkData[iy][ix] & maskVal) continue; 323 apFlux += imData[iy][ix] - sky; 324 apFluxVar += varData[iy][ix]; 325 } 326 } 327 if (apFluxOut) *apFluxOut = apFlux; 328 if (apFluxErr) *apFluxErr = sqrt(apFluxVar); 329 330 if (apFlux <= 0) { 308 331 *apMag = NAN; 309 return true; 310 } 311 312 *apMag = -2.5*log10(apSum); 332 } else { 333 *apMag = -2.5*log10(apFlux); 334 } 313 335 return true; 314 336 } … … 617 639 618 640 switch (term) { 619 case 0:641 case 0: 620 642 factor = 1; 621 643 break; 622 case 1:644 case 1: 623 645 factor = xi + Pi->col0; 624 646 break; 625 case 2:647 case 2: 626 648 factor = yi + Pi->row0; 627 649 break; 628 default:650 default: 629 651 psAbort("invalid term for pmSourceWeight"); 630 652 } … … 695 717 696 718 switch (term) { 697 case 0:719 case 0: 698 720 factor = 1; 699 721 break; 700 case 1:722 case 1: 701 723 factor = xi + Pi->col0; 702 724 break; 703 case 2:725 case 2: 704 726 factor = yi + Pi->row0; 705 727 break; 706 default:728 default: 707 729 psAbort("invalid term for pmSourceWeight"); 708 730 }
Note:
See TracChangeset
for help on using the changeset viewer.
