- Timestamp:
- Apr 24, 2011, 10:09:38 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110404/psModules/src/objects/pmSourcePhotometry.c
r31340 r31361 82 82 - apMag : only if S/N > AP_MIN_SN 83 83 : is optionally corrected for curve-of-growth if: 84 - the source is a STAR (PSF)85 84 - the option is selected (mode & PM_SOURCE_PHOT_GROWTH) 86 85 - psfMag : all sources with non-NULL modelPSF 87 86 : is optionally corrected for aperture residual if: 88 - the source is a STAR (PSF)89 87 - the option is selected (mode & PM_SOURCE_PHOT_APCORR) 90 91 88 - extMag : all sources with non-NULL modelEXT 92 89 **/ … … 100 97 101 98 int status = false; 102 bool isPSF;103 99 float x, y; 104 100 float SN; 105 pmModel *model;106 101 107 102 source->psfMag = NAN; 108 103 source->extMag = NAN; 109 source-> errMag= NAN;104 source->psfMagErr = NAN; 110 105 source->apMag = NAN; 111 106 source->apMagRaw = NAN; … … 113 108 source->apFluxErr = NAN; 114 109 115 // we must have a valid model 116 // XXX allow aperture magnitudes for sources without a model 117 model = pmSourceGetModel (&isPSF, source); 118 if (model == NULL) { 119 psTrace ("psModules.objects", 3, "fail mag : no valid model"); 110 // XXXXXX review: 111 // Select the 'best' model -- this is used for PSF_QF,_PERFECT & ???. isPSF is true if this 112 // object is a PSF (not extended). We must have a valid model. XXX NOTE: allow aperture 113 // magnitudes for sources without a model 114 115 // select the psf model 116 pmModel *modelPSF = source->modelPSF; 117 if (modelPSF == NULL) { 118 psTrace ("psModules.objects", 3, "fail mag : no valid PSF model"); 120 119 return false; 121 120 } 122 121 123 // XXX handle negative flux, low-significance124 if (model ->dparams->data.F32[PM_PAR_I0] > 0) {125 SN = fabs(model ->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0]);126 source-> errMag= 1.0 / SN;122 // get the error on the PSF model magnitude 123 if (modelPSF->dparams->data.F32[PM_PAR_I0] > 0) { 124 SN = fabs(modelPSF->params->data.F32[PM_PAR_I0] / modelPSF->dparams->data.F32[PM_PAR_I0]); 125 source->psfMagErr = 1.0 / SN; 127 126 } else { 128 127 SN = NAN; 129 source->errMag = NAN; 130 } 131 x = model->params->data.F32[PM_PAR_XPOS]; 132 y = model->params->data.F32[PM_PAR_YPOS]; 128 source->psfMagErr = NAN; 129 } 130 // the source position is used to recenter the aperture for ap photometry 131 x = modelPSF->params->data.F32[PM_PAR_XPOS]; 132 y = modelPSF->params->data.F32[PM_PAR_YPOS]; 133 133 134 134 // measure PSF model photometry 135 // XXX TEST: do not use flux scale 136 // XXX NOTE: turn this back on? 137 if (0 && psf->FluxScale) { 138 // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center 139 double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y); 140 psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y); 141 psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y); 142 source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0]; 143 source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0]; 144 source->psfMag = -2.5*log10(source->psfFlux); 145 } else { 146 status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF); 147 source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]); 148 } 135 status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, modelPSF); 136 source->psfFluxErr = source->psfFlux * source->psfMagErr; 137 138 # if (0) 139 // XXX NOTE: old code to use the flux scale. test & turn this back on? if so, need to save with psf model 140 // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center 141 double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y); 142 psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y); 143 psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y); 144 source->psfFlux = fluxScale * modelPSF->params->data.F32[PM_PAR_I0]; 145 source->psfFluxErr = fluxScale * modelPSF->dparams->data.F32[PM_PAR_I0]; 146 source->psfMag = -2.5*log10(source->psfFlux); 147 # endif 149 148 150 149 if (mode == PM_SOURCE_PHOT_PSFONLY) { … … 152 151 } 153 152 153 // get the EXT model photometry (all EXT models) 154 154 // if we have a collection of model fits, check if one of them is a pointer to modelEXT 155 155 if (source->modelFits) { … … 172 172 } 173 173 174 // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS 175 // XXX add a flag for "ap_mag is corrected?" 176 if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf && psf->ApTrend) { 174 // Correct psfMag to match aperture magnitude system (NOTE : Growth curve is already applied to ApTrend) 175 if ((mode & PM_SOURCE_PHOT_APCORR) && psf && psf->ApTrend) { 177 176 // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center 178 177 double apTrend = pmTrend2DEval (psf->ApTrend, (float)source->peak->x, (float)source->peak->y); … … 182 181 } 183 182 184 // measure the contribution of included pixels 183 // measure the contribution of included pixels to the PSF model fit 185 184 if (mode & PM_SOURCE_PHOT_WEIGHT) { 186 pmSourcePixelWeight (source, model , source->maskObj, maskVal, radius);185 pmSourcePixelWeight (source, modelPSF, source->maskObj, maskVal, radius); 187 186 } 188 187 … … 218 217 y += dy; 219 218 220 if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, 221 NAN, 0xff, PS_INTERPOLATE_BIQUADRATIC)) { 219 // if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_LANCZOS2)) { 220 // if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_BIQUADRATIC)) { 221 if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_BILINEAR)) { 222 222 // Not much we can do about it 223 223 psErrorClear(); … … 233 233 234 234 // measure object aperture photometry 235 status = pmSourcePhotometryAperSource (source, model , flux, variance, mask, maskVal);235 status = pmSourcePhotometryAperSource (source, modelPSF, flux, variance, mask, maskVal); 236 236 if (!status) { 237 237 psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag"); … … 242 242 // detection limits (esp near bright neighbors) 243 243 source->apMag = source->apMagRaw; 244 if (isfinite (source->apMag) && isPSF &&psf) {244 if (isfinite (source->apMag) && psf) { 245 245 if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) { 246 source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius); 247 // XXX correct the apFlux? 246 float apOffset = pmGrowthCurveCorrect (psf->growth, source->apRadius); 247 source->apMag = source->apMagRaw + apOffset; 248 source->apFlux *= pow(10.0, -0.4*apOffset); 249 source->apFluxErr *= pow(10.0, -0.4*apOffset); 248 250 } 249 251 }
Note:
See TracChangeset
for help on using the changeset viewer.
