- 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/pmSourcePhotometry.c
r28517 r29060 22 22 #include "pmFPA.h" 23 23 #include "pmFPAMaskWeight.h" 24 25 #include "pmTrend2D.h" 26 #include "pmResiduals.h" 27 #include "pmGrowthCurve.h" 24 28 #include "pmSpan.h" 29 #include "pmFootprintSpans.h" 25 30 #include "pmFootprint.h" 26 31 #include "pmPeaks.h" 27 32 #include "pmMoments.h" 28 #include "pmGrowthCurve.h" 29 #include "pmResiduals.h" 30 #include "pmTrend2D.h" 33 #include "pmModelFuncs.h" 34 #include "pmModel.h" 35 #include "pmModelUtils.h" 36 #include "pmModelClass.h" 37 #include "pmSourceMasks.h" 38 #include "pmSourceExtendedPars.h" 39 #include "pmSourceDiffStats.h" 40 #include "pmSource.h" 41 #include "pmSourceFitModel.h" 31 42 #include "pmPSF.h" 32 #include "pmModel.h" 33 #include "pmSource.h" 34 #include "pmModelClass.h" 43 #include "pmPSFtry.h" 44 35 45 #include "pmSourcePhotometry.h" 36 46 … … 66 76 67 77 // XXX masked region should be (optionally) elliptical 68 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal )78 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal) 69 79 { 70 80 PS_ASSERT_PTR_NON_NULL(source, false); … … 122 132 for (int i = 0; i < source->modelFits->n; i++) { 123 133 pmModel *model = source->modelFits->data[i]; 134 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 124 135 status = pmSourcePhotometryModel (&model->mag, NULL, model); 125 136 if (model == source->modelEXT) foundEXT = true; … … 145 156 // measure the contribution of included pixels 146 157 if (mode & PM_SOURCE_PHOT_WEIGHT) { 147 pmSourcePixelWeight (&source->pixWeight , model, source->maskObj, maskVal);158 pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal); 148 159 } 149 160 150 161 // measure the contribution of included pixels 151 162 if (mode & PM_SOURCE_PHOT_DIFFSTATS) { 152 pmSourceMeasureDiffStats (source, maskVal );163 pmSourceMeasureDiffStats (source, maskVal, markVal); 153 164 } 154 165 … … 191 202 192 203 // measure object aperture photometry 193 status = pmSourcePhotometryAper (&source->apMag , model, flux, mask, maskVal);204 status = pmSourcePhotometryAper (&source->apMagRaw, model, flux, mask, maskVal); 194 205 if (!status) { 195 206 psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag"); … … 199 210 // if the aper mag is NAN, the flux < 0. this can happen for sources near the 200 211 // detection limits (esp near bright neighbors) 212 source->apMag = source->apMagRaw; 201 213 if (isfinite (source->apMag) && isPSF && psf) { 202 214 if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) { 203 source->apMag +=pmGrowthCurveCorrect (psf->growth, source->apRadius);215 source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius); 204 216 } 205 217 if (mode & PM_SOURCE_PHOT_APCORR) { 206 218 // XXX this should be removed -- we no longer fit for the 'sky bias' 219 // XXX is this happening??? 207 220 rflux = pow (10.0, 0.4*source->psfMag); 221 psAssert (psf->skyBias == 0.0, "sky bias not 0"); 222 psAssert (psf->skySat == 0.0, "sky sat not 0"); 208 223 source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux; 209 224 } … … 257 272 PS_ASSERT_PTR_NON_NULL(image, false); 258 273 PS_ASSERT_PTR_NON_NULL(mask, false); 259 PS_ASSERT_PTR_NON_NULL(model, false); 274 275 if (DO_SKY) { 276 PS_ASSERT_PTR_NON_NULL(model, false); 277 } 260 278 261 279 float apSum = 0; … … 271 289 psF32 **imData = image->data.F32; 272 290 psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA; 291 int nAperPix = 0; 273 292 274 293 // measure apMag 275 for (int i x = 0; ix < image->numCols; ix++) {276 for (int iy = 0; iy < image->numRows; iy++) {294 for (int iy = 0; iy < image->numRows; iy++) { 295 for (int ix = 0; ix < image->numCols; ix++) { 277 296 if (mkData[iy][ix] & maskVal) 278 297 continue; 279 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); 280 301 } 281 302 } … … 290 311 291 312 // return source aperture magnitude 292 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal) 293 { 294 PS_ASSERT_PTR_NON_NULL(pixWeight, false); 313 bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal) 314 { 315 PS_ASSERT_PTR_NON_NULL(pixWeightNotBad, false); 316 PS_ASSERT_PTR_NON_NULL(pixWeightNotPoor, false); 295 317 PS_ASSERT_PTR_NON_NULL(mask, false); 296 318 PS_ASSERT_PTR_NON_NULL(model, false); 297 319 298 320 float modelSum = 0; 299 float validSum = 0; 321 float notBadSum = 0; 322 float notPoorSum = 0; 300 323 float sky = 0; 301 324 float value; … … 305 328 int dY, DY, NY; 306 329 307 *pixWeight = 0.0; 330 *pixWeightNotBad = 0.0; 331 *pixWeightNotPoor = 0.0; 308 332 309 333 // we only care about the value of the object model, not the local sky … … 345 369 346 370 // for the full model, add all points 347 value = model->modelFunc (NULL, params, coord) - sky;371 value = fabs(model->modelFunc (NULL, params, coord) - sky); 348 372 modelSum += value; 349 373 350 374 // include count only the unmasked pixels within the image area 351 if (mx < 0) 352 continue; 353 if (my < 0) 354 continue; 355 if (mx >= NX) 356 continue; 357 if (my >= NY) 358 continue; 359 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal) 360 continue; 361 362 validSum += value; 375 if (mx < 0) continue; 376 if (my < 0) continue; 377 if (mx >= NX) continue; 378 if (my >= NY) continue; 379 380 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) { 381 notBadSum += value; 382 } 383 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & ~markVal)) { 384 notPoorSum += value; 385 } 363 386 } 364 387 } 365 388 psFree (coord); 366 389 367 if (validSum <= 0) 368 return false; 369 370 *pixWeight = validSum / modelSum; 390 *pixWeightNotBad = notBadSum / modelSum; 391 *pixWeightNotPoor = notPoorSum / modelSum; 392 371 393 return (true); 372 394 } … … 374 396 # define FLUX_LIMIT 3.0 375 397 376 // return source aperture magnitude377 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal )398 // measure stats that may be using in difference images for distinguishing real sources from bad residuals 399 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) 378 400 { 379 401 PS_ASSERT_PTR_NON_NULL(source, false); … … 399 421 for (int iy = 0; iy < flux->numRows; iy++) { 400 422 for (int ix = 0; ix < flux->numCols; ix++) { 423 // only count up the stats in the unmarked region (ie, the aperture) 424 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & markVal) { 425 continue; 426 } 401 427 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) { 402 428 nMask ++;
Note:
See TracChangeset
for help on using the changeset viewer.
