Changeset 21366 for trunk/psphot/src/psphotSourceSize.c
- Timestamp:
- Feb 5, 2009, 5:03:33 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceSize.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceSize.c
r21183 r21366 2 2 # include <gsl/gsl_sf_gamma.h> 3 3 4 static float psphotModelContour(const psImage *image, const psImage * weight, const psImage *mask,4 static float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask, 5 5 psImageMaskType maskVal, const pmModel *model, float Ro); 6 6 … … 62 62 63 63 psF32 **resid = source->pixels->data.F32; 64 psF32 ** weight = source->weight->data.F32;64 psF32 **variance = source->variance->data.F32; 65 65 psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA; 66 66 67 67 // check for extendedness: measure the delta flux significance at the 1 sigma contour 68 source->extNsigma = psphotModelContour(source->pixels, source-> weight, source->maskObj, maskVal,68 source->extNsigma = psphotModelContour(source->pixels, source->variance, source->maskObj, maskVal, 69 69 source->modelPSF, 1.0); 70 70 … … 103 103 // Compare the central pixel with those on either side, for the four possible lines through it. 104 104 105 // Soften weights (add systematic error)106 float softening = soft * PS_SQR(source->peak->flux); // Softening for weights105 // Soften variances (add systematic error) 106 float softening = soft * PS_SQR(source->peak->flux); // Softening for variances 107 107 108 108 // Across the middle: y = 0 109 109 float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1]; 110 float dcX = 4* weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1];110 float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1]; 111 111 float nX = cX / sqrtf(dcX + softening); 112 112 113 113 // Up the centre: x = 0 114 114 float cY = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak+0] - resid[yPeak+1][xPeak+0]; 115 float dcY = 4* weight[yPeak][xPeak] + weight[yPeak-1][xPeak+0] + weight[yPeak+1][xPeak+0];115 float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0]; 116 116 float nY = cY / sqrtf(dcY + softening); 117 117 118 118 // Diagonal: x = y 119 119 float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1]; 120 float dcL = 4* weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1];120 float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1]; 121 121 float nL = cL / sqrtf(dcL + softening); 122 122 123 123 // Diagonal: x = - y 124 124 float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1]; 125 float dcR = 4* weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1];125 float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1]; 126 126 float nR = cR / sqrtf(dcR + softening); 127 127 … … 160 160 // this source is thought to be a cosmic ray. flag the detection and mask the pixels 161 161 if (source->crNsigma > CR_NSIGMA_LIMIT) { 162 // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask);163 psphotMaskCosmicRay_Old (source, maskVal, crMask);162 // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask); 163 psphotMaskCosmicRay_Old (source, maskVal, crMask); 164 164 } 165 165 } … … 190 190 // deviation in sigmas. This is measured on the residual image - should we ignore negative 191 191 // deviations? 192 static float psphotModelContour(const psImage *image, const psImage * weight, const psImage *mask,192 static float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask, 193 193 psImageMaskType maskVal, const pmModel *model, float Ro) 194 194 { … … 240 240 if (yPixM >= 0 && yPixM < image->numRows && 241 241 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) { 242 float dSigma = image->data.F32[yPixM][xPix] / sqrtf( weight->data.F32[yPixM][xPix]);242 float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]); 243 243 nSigma += dSigma; 244 244 nPts++; … … 251 251 if (yPixP >= 0 && yPixP < image->numRows && 252 252 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) { 253 float dSigma = image->data.F32[yPixP][xPix] / sqrtf( weight->data.F32[yPixP][xPix]);253 float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]); 254 254 nSigma += dSigma; 255 255 nPts++; … … 274 274 pmFootprint *footprint = peak->footprint; 275 275 if (!footprint) { 276 // if we have not footprint, use the old code to mask by isophot277 psphotMaskCosmicRay_Old (source, maskVal, crMask);278 return true;276 // if we have not footprint, use the old code to mask by isophot 277 psphotMaskCosmicRay_Old (source, maskVal, crMask); 278 return true; 279 279 } 280 280 281 281 if (!footprint->spans) { 282 // if we have not footprint, use the old code to mask by isophot283 psphotMaskCosmicRay_Old (source, maskVal, crMask);284 return true;282 // if we have not footprint, use the old code to mask by isophot 283 psphotMaskCosmicRay_Old (source, maskVal, crMask); 284 return true; 285 285 } 286 286 287 287 // mask all of the pixels covered by the spans of the footprint 288 288 for (int j = 1; j < footprint->spans->n; j++) { 289 pmSpan *span1 = footprint->spans->data[j];290 291 int iy = span1->y;292 int xs = span1->x0;293 int xe = span1->x1;294 295 for (int ix = xs; ix < xe; ix++) {296 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;297 }289 pmSpan *span1 = footprint->spans->data[j]; 290 291 int iy = span1->y; 292 int xs = span1->x0; 293 int xe = span1->x1; 294 295 for (int ix = xs; ix < xe; ix++) { 296 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 297 } 298 298 } 299 299 return true; … … 308 308 psImage *mask = source->maskView; 309 309 psImage *pixels = source->pixels; 310 psImage * weight = source->weight;310 psImage *variance = source->variance; 311 311 312 312 // XXX This should be a recipe variable … … 318 318 // mark the pixels in this row to the left, then the right 319 319 for (int ix = xo; ix >= 0; ix--) { 320 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);321 if (SN > SN_LIMIT) {322 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;323 }320 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]); 321 if (SN > SN_LIMIT) { 322 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask; 323 } 324 324 } 325 325 for (int ix = xo + 1; ix < pixels->numCols; ix++) { 326 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);327 if (SN > SN_LIMIT) {328 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;329 }326 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]); 327 if (SN > SN_LIMIT) { 328 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask; 329 } 330 330 } 331 331 … … 333 333 // first go up: 334 334 for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) { 335 // mark the pixels in this row to the left, then the right336 for (int ix = 0; ix < pixels->numCols; ix++) {337 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);338 if (SN < SN_LIMIT) continue;339 340 bool valid = false;341 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);342 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;343 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;344 345 if (!valid) continue;346 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;347 }335 // mark the pixels in this row to the left, then the right 336 for (int ix = 0; ix < pixels->numCols; ix++) { 337 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 338 if (SN < SN_LIMIT) continue; 339 340 bool valid = false; 341 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask); 342 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0; 343 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0; 344 345 if (!valid) continue; 346 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 347 } 348 348 } 349 349 // next go down: 350 350 for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) { 351 // mark the pixels in this row to the left, then the right352 for (int ix = 0; ix < pixels->numCols; ix++) {353 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);354 if (SN < SN_LIMIT) continue;355 356 bool valid = false;357 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);358 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;359 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;360 361 if (!valid) continue;362 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;363 }351 // mark the pixels in this row to the left, then the right 352 for (int ix = 0; ix < pixels->numCols; ix++) { 353 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 354 if (SN < SN_LIMIT) continue; 355 356 bool valid = false; 357 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask); 358 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0; 359 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0; 360 361 if (!valid) continue; 362 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 363 } 364 364 } 365 365 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
