Changeset 19915
- Timestamp:
- Oct 6, 2008, 3:16:44 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceSize.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceSize.c
r19286 r19915 2 2 # include <gsl/gsl_sf_gamma.h> 3 3 4 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, p mModel *model, float Ro);4 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, psMaskType maskVal, pmModel *model, float Ro); 5 5 6 6 // we need to call this function after sources have been fitted to the PSF model and … … 51 51 52 52 // check for extendedness: measure the delta flux significance at the 1 sigma contour 53 source->extNsigma = psphotModelContour (source->pixels, source->weight, source->maskObj, source->modelPSF, 1.0);53 source->extNsigma = psphotModelContour (source->pixels, source->weight, source->maskObj, maskVal, source->modelPSF, 1.0); 54 54 55 55 // XXX prevent a source from being both CR and EXT? … … 78 78 if (!keep) continue; 79 79 80 if (mask[yPeak][xPeak] & maskVal) continue; 81 80 82 // XXX need to deal with edge peaks... and mask 81 float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1]; 82 float cY = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak+0] - resid[yPeak+1][xPeak+0]; 83 float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1]; 84 float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1]; 85 86 float dcX = 4*weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1]; 87 float dcY = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak+0] + weight[yPeak+1][xPeak+0]; 88 float dcL = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1]; 89 float dcR = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1]; 90 91 float nX = cX / sqrt(dcX); 92 float nY = cY / sqrt(dcY); 93 float nL = cL / sqrt(dcL); 94 float nR = cR / sqrt(dcR); 83 float nX = 0; 84 float nY = 0; 85 float nL = 0; 86 float nR = 0; 87 88 if (!(mask[yPeak+0][xPeak-1] & maskVal) && !(mask[yPeak+0][xPeak+1] & maskVal)) { 89 float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1]; 90 float dcX = 4*weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1]; 91 nX = cX / sqrt(dcX); 92 } 93 94 if (!(mask[yPeak-1][xPeak+0] & maskVal) && !(mask[yPeak+1][xPeak+0] & maskVal)) { 95 float cY = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak+0] - resid[yPeak+1][xPeak+0]; 96 float dcY = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak+0] + weight[yPeak+1][xPeak+0]; 97 nY = cY / sqrt(dcY); 98 } 99 100 if (!(mask[yPeak-1][xPeak-1] & maskVal) && !(mask[yPeak+1][xPeak+1] & maskVal)) { 101 float dcL = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1]; 102 float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1]; 103 nL = cL / sqrt(dcL); 104 } 105 106 if (!(mask[yPeak+1][xPeak-1] & maskVal) && !(mask[yPeak-1][xPeak+1] & maskVal)) { 107 float dcR = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1]; 108 float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1]; 109 nR = cR / sqrt(dcR); 110 } 95 111 96 112 // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2) … … 100 116 // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq); 101 117 102 // not strictly accurate: overcounts the chisq contribution from the center pixel (by factor of 4) 118 // not strictly accurate: overcounts the chisq contribution from the center pixel (by 119 // factor of 4); also biases a bit low if any pixels are masked 120 // XXX I am not sure I want to keep this value... 103 121 source->psfChisq = PS_SQR (nX) + PS_SQR (nY) + PS_SQR (nX) + PS_SQR (nR); 104 122 105 123 float fCR = 0.0; 106 float fEXT = 0.0;107 124 int nCR = 0; 108 int nEXT = 0;109 125 if (nX > 0.0) { 110 126 fCR += nX; 111 127 nCR ++; 112 } else {113 fEXT += nX;114 nEXT ++;115 128 } 116 129 if (nY > 0.0) { 117 130 fCR += nY; 118 131 nCR ++; 119 } else {120 fEXT += nY;121 nEXT ++;122 132 } 123 133 if (nL > 0.0) { 124 134 fCR += nL; 125 135 nCR ++; 126 } else {127 fEXT += nL;128 nEXT ++;129 136 } 130 137 if (nR > 0.0) { 131 138 fCR += nR; 132 139 nCR ++; 133 } else {134 fEXT += nR;135 nEXT ++;136 140 } 137 141 source->crNsigma = (nCR > 0) ? fCR / nCR : 0.0; 138 // NOTE: abs needed to make the Nsigma value positive 139 140 if (!isfinite(source->crNsigma)) { 141 fprintf (stderr, "."); 142 source->crNsigma = -6.0; 143 } 142 assert (isfinite(source->crNsigma)); 144 143 145 144 // this source is thought to be a cosmic ray. flag the detection and mask the pixels … … 212 211 } 213 212 213 // now that we have masked pixels associated with CRs, we can grow the mask 214 214 if (grow > 0) { 215 215 psImage *newMask = psImageConvolveMask(NULL, readout->mask, crMask, crMask, -grow, grow, -grow, grow); … … 225 225 sources->n - first, psTimerMark ("psphot")); 226 226 227 psphotVisualPlotSourceSize (sources); 228 psphotVisualShowSourceSize (sources); 229 227 230 return true; 228 231 } 229 230 231 // some possible classes:232 // all 4 curvatures are highly negative : CR233 // all 4 curvatures are highly positive : EXT234 235 // at least 2 are significantly negative, none are significantly positive : CR236 // at least 2 are significantly positive, none are significantly negative : EXT237 238 // any are significantly negative, some may be significantly positive : CR239 // any are significantly positive, none may be significantly positive : EXT240 241 /* Nn Np No242 4 0 0 CR_1243 3 1 0 CR_1244 3 0 1 CR_1245 2 2 0 CR_2246 2 1 1 CR_2247 2 0 2 CR_2248 1 3 0 CR_3249 1 2 1 CR_3250 1 1 2 CR_3251 1 0 3 CR_3252 0 4 0 EXT253 0 3 1 EXT254 0 2 2 EXT255 0 1 3 PSF256 0 0 4 PSF257 */258 259 /* Alternatively, write a f(CR) = Sum(nX,etc if >0) */260 261 262 /* I can write the formal probability that the 4 measurements are consistent with a PSF263 * based on how large the error values are (Nsigma -> erf -> P(Nsigma)).264 * I should examine this value as a function of flux and also examine the distribution of265 * the probabilities for the PSF sources.266 */267 268 232 269 233 // given the PSF ellipse parameters, navigate around the 1sigma contour, return the total 270 234 // deviation in sigmas. This is measure on the residual image - should we ignore negative 271 235 // deviations? 272 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro) {236 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, psMaskType maskVal, pmModel *model, float Ro) { 273 237 274 238 psF32 *PAR = model->params->data.F32; … … 309 273 310 274 if ((yPixM >= 0) && (yPixM < image->numRows)) { 311 if (!mask || ! mask->data.U8[yPixM][xPix]) {275 if (!mask || !(mask->data.U8[yPixM][xPix] & maskVal)) { 312 276 float dSigma = image->data.F32[yPixM][xPix] / sqrt (weight->data.F32[yPixM][xPix]); 313 277 nSigma += dSigma; … … 319 283 320 284 if ((yPixP >= 0) && (yPixP < image->numRows)) { 321 if (!mask || ! mask->data.U8[yPixP][xPix]) {285 if (!mask || !(mask->data.U8[yPixP][xPix] & maskVal)) { 322 286 float dSigma = image->data.F32[yPixP][xPix] / sqrt (weight->data.F32[yPixP][xPix]); 323 287 nSigma += dSigma;
Note:
See TracChangeset
for help on using the changeset viewer.
