Changeset 17239
- Timestamp:
- Mar 30, 2008, 8:44:57 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080324/psphot/src/psphotSourceSize.c
r17153 r17239 1 1 # include "psphotInternal.h" 2 2 # include <gsl/gsl_sf_gamma.h> 3 4 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro); 3 5 4 6 // we need to call this function after sources have been fitted to the PSF model and … … 14 16 psTimerStart ("psphot"); 15 17 16 float CR_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.CRNSIGMA.LIMIT"); 18 float CR_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.CR.NSIGMA.LIMIT"); 19 assert (status); 20 21 float EXT_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.EXT.NSIGMA.LIMIT"); 17 22 assert (status); 18 23 … … 25 30 26 31 source->crNsigma = -1.0; 27 source->extNsigma = -1.0;32 source->extNsigma = 0.0; 28 33 29 34 // source must have been subtracted … … 31 36 if (!(source->mode & PM_SOURCE_MODE_SUBTRACTED)) continue; 32 37 33 psF32 **resid = source->pixels->data.F32;38 psF32 **resid = source->pixels->data.F32; 34 39 psF32 **weight = source->weight->data.F32; 35 psU8 **mask = source->maskObj->data.U8;40 psU8 **mask = source->maskObj->data.U8; 36 41 37 42 int xPeak = source->peak->xf - source->pixels->col0 + 0.5; … … 56 61 57 62 // measure the flux at the 1 sigma contour 58 psVector *contour = psphotModelContour (source->pixels, source->maskObj, source->modelPSF, 1.0); 59 60 // XXX for now, just skip any masked pixels 61 extSum = 0.0; 62 bool keep = true; 63 for (int iy = -1; (iy <= +1) && keep; iy++) { 64 for (int ix = -1; (ix <= +1) && keep; ix++) { 65 if (mask[yPeak+iy][xPeak+ix]) { keep &= false; } 66 } 67 } 68 if (!keep) continue; 63 // XXX prevent a source from being both CR and EXT? 64 source->extNsigma = psphotModelContour (source->pixels, source->weight, source->maskObj, source->modelPSF, 1.0); 65 66 if (source->extNsigma > EXT_NSIGMA_LIMIT) { 67 source->mode |= PM_SOURCE_MODE_EXT_LIMIT; 68 } 69 69 70 70 // XXX need to deal with edge peaks... and mask … … 126 126 } 127 127 source->crNsigma = (nCR > 0) ? fCR / nCR : 0.0; 128 source->extNsigma = (nEXT > 0) ? fabs(fEXT) / nEXT : 0.0;129 128 // NOTE: abs needed to make the Nsigma value positive 130 129 … … 135 134 136 135 if (source->crNsigma > CR_NSIGMA_LIMIT) { 137 source->mode |= PM_SOURCE_MODE_CR LIMIT;136 source->mode |= PM_SOURCE_MODE_CR_LIMIT; 138 137 } 139 138 } … … 183 182 184 183 185 // given the PSF ellipse parameters, navigate around the 1sigma contour 186 // XXX return the Nsigma total deviation? 187 // XXX return just the sum around the contour? 188 // this is measure on the residual image - should we ignore negative deviations? 189 psVector *psphotModelContour (psImage *image, psImage *mask, pmModel *model, float Ro) { 184 // given the PSF ellipse parameters, navigate around the 1sigma contour, return the total 185 // deviation in sigmas. This is measure on the residual image - should we ignore negative 186 // deviations? 187 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro) { 190 188 191 189 psF32 *PAR = model->params->data.F32; 192 psVector *contour = psVectorAllocEmpty (50, PS_TYPE_F32);193 int nPts = 0;194 190 195 191 // Ro = (x / SXX)^2 + (y / SYY)^2 + x y SXY; … … 201 197 // solve this for x2: 202 198 float Q = Ro * PS_SQR(PAR[PM_PAR_SXX]) / (1.0 - PS_SQR(PAR[PM_PAR_SXX]*PAR[PM_PAR_SYY]*PAR[PM_PAR_SXY]) / 4.0); 203 if (Q < 0.0) return contour; // ellipse is imaginary199 if (Q < 0.0) return NAN; // ellipse is imaginary 204 200 205 201 int xMax = sqrt(Q); 206 202 int xMin = -1.0*xMax; 207 203 208 for (int x = MIN; x <= MAX; x++) { 204 int nPts = 0; 205 float nSigma = 0.0; 206 207 for (int x = xMin; x <= xMax; x++) { 209 208 float A = PS_SQR (1.0 / PAR[PM_PAR_SYY]); 210 209 float B = x * PAR[PM_PAR_SXY]; … … 217 216 float yM = (-B - sqrt (T)) / (2.0 * A); 218 217 219 int xPix = x + PAR[PM_PAR_X 0] - source->pixels->col0 + 0.5;220 int yPixM = yM + PAR[PM_PAR_Y 0] - source->pixels->row0 + 0.5;221 int yPixP = yP + PAR[PM_PAR_Y 0] - source->pixels->row0 + 0.5;218 int xPix = x + PAR[PM_PAR_XPOS] - image->col0 + 0.5; 219 int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5; 220 int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5; 222 221 223 222 if (xPix < 0) continue; 224 if (xPix >= source->pixels->numCols) continue;225 226 if ((yPixM >= 0) && (yPixM < source->pixels->numRows)) {227 if (!mask || !mask->data.U8[ xPix][yPixM]) {228 contour->data.F32[nPts] = image->data.F32[xPix][yPixM];229 psVectorExtend (contour, 100, 1);230 nPts ++;223 if (xPix >= image->numCols) continue; 224 225 if ((yPixM >= 0) && (yPixM < image->numRows)) { 226 if (!mask || !mask->data.U8[yPixM][xPix]) { 227 float dSigma = image->data.F32[yPixM][xPix] / sqrt (weight->data.F32[yPixM][xPix]); 228 nSigma += dSigma; 229 nPts ++; 231 230 } 232 231 } … … 234 233 if (yPixM == yPixP) continue; 235 234 236 if ((yPixP >= 0) && (yPixP < source->pixels->numRows)) {237 if (!mask || !mask->data.U8[ xPix][yPixP]) {238 contour->data.F32[nPts] = image->data.F32[xPix][yPixP];239 psVectorExtend (contour, 100, 1);240 nPts ++;235 if ((yPixP >= 0) && (yPixP < image->numRows)) { 236 if (!mask || !mask->data.U8[yPixP][xPix]) { 237 float dSigma = image->data.F32[yPixP][xPix] / sqrt (weight->data.F32[yPixP][xPix]); 238 nSigma += dSigma; 239 nPts ++; 241 240 } 242 241 } 243 242 } 244 245 return contour;243 nSigma /= nPts; 244 return nSigma; 246 245 }
Note:
See TracChangeset
for help on using the changeset viewer.
