Changeset 11169
- Timestamp:
- Jan 18, 2007, 6:52:08 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotFindPeaks.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotFindPeaks.c
r10803 r11169 1 1 # include "psphot.h" 2 2 3 // 2006.02.02 : no leaks3 // In this function, we smooth the image, then search for the peaks 4 4 psArray *psphotFindPeaks (pmReadout *readout, psMetadata *recipe) { 5 5 6 6 bool status = false; 7 float NSIGMA;8 float SIGMA;9 float threshold;10 float value;11 7 12 8 // smooth the image and weight map 13 9 psTimerStart ("psphot"); 14 10 15 SIGMA = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_SIGMA");16 NSIGMA = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_NSIGMA");11 float SIGMA = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_SIGMA"); 12 float NSIGMA = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_NSIGMA"); 17 13 18 // XXX we are somewhat doing the wrong thing here with the mask. 19 // it would be better to smooth the image using the mask information 14 // smooth the image, applying the mask as we go 20 15 psImage *smooth_im = psImageCopy (NULL, readout->image, PS_TYPE_F32); 21 psImageSmooth (smooth_im, SIGMA, NSIGMA);16 psImageSmoothMaskF32 (smooth_im, readout->mask, 0xff, SIGMA, NSIGMA); 22 17 psLogMsg ("psphot", PS_LOG_MINUTIA, "smooth image: %f sec\n", psTimerMark ("psphot")); 23 18 19 // smooth the weight, applying the mask as we go 24 20 psImage *smooth_wt = psImageCopy (NULL, readout->weight, PS_TYPE_F32); 25 psImageSmooth (smooth_wt, SIGMA/sqrt(2), NSIGMA); 26 smooth_wt = (psImage*)psBinaryOp(smooth_wt, smooth_wt, "*", 27 psScalarAlloc(1/(4*M_PI*PS_SQR(SIGMA)), PS_TYPE_F32)); 21 psImageSmoothMaskF32 (smooth_wt, readout->mask, 0xff, SIGMA/sqrt(2), NSIGMA); 28 22 psLogMsg ("psphot", PS_LOG_MINUTIA, "smooth weight: %f sec\n", psTimerMark ("psphot")); 29 23 … … 36 30 } 37 31 32 // build the significance image on top of smooth_im 38 33 for (int j = 0; j < smooth_im->numRows; j++) { 39 34 for (int i = 0; i < smooth_im->numCols; i++) { 40 value = smooth_im->data.F32[j][i];35 float value = smooth_im->data.F32[j][i]; 41 36 if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || mask->data.U8[j][i]) { 42 37 smooth_im->data.F32[j][i] = 0.0; … … 46 41 } 47 42 } 48 psLogMsg ("psphot", PS_LOG_INFO, "built smoothed image: %f sec\n", psTimerMark ("psphot")); 43 psLogMsg ("psphot", PS_LOG_INFO, "built smoothed signficance image: %f sec\n", psTimerMark ("psphot")); 44 45 // optionally save example images under trace 46 if (psTraceGetLevel("psphot") > 5) { 47 psphotSaveImage (NULL, smooth_im, "snsmooth.fits"); 48 } 49 49 50 50 psTimerStart ("psphot"); 51 51 // set peak threshold 52 53 // signal/noise limit for the detected peaks 52 54 NSIGMA = psMetadataLookupF32 (&status, recipe, "PEAKS_NSIGMA_LIMIT"); 53 // threshold = NSIGMA*sky->sampleStdev + sky->sampleMean;54 threshold = PS_SQR(NSIGMA);55 psLogMsg ("psphot", PS_LOG_DETAIL, "threshold: %f DN\n", threshold);56 55 57 // find the peaks in the smoothed image 56 // we need to define the threshold based on the value of NSIGMA and the applied smoothing 57 // gaussian SIGMA. a peak in the significance image has an effective S/N for faint sources 58 // of (S = Io*2pi*sigma_eff^2) / sqrt(Var), where sigma_eff^2 = sigma_obs^2 + sigma_sm^2. 59 // the smoothing of the varience map does not affect the faint-source S/N since the noise 60 // is constant under a faint source. 61 62 // if sigma_sm = sigma_obs, then sigma_eff^2 = 2 sigma_sm^2. in this case, the threshold in 63 // terms of smooth_im peak counts Io, for a desired S/N limit corresponds to 64 // S/N = sqrt(Io)*4*pi*sigma_sm^2 65 // thus, the threshold is: 66 float effArea = 4.0*M_PI*PS_SQR(SIGMA); 67 float threshold = PS_SQR(NSIGMA) / effArea; 68 69 // find the peaks in the smoothed image 58 70 psArray *peaks = pmFindImagePeaks (smooth_im, threshold); 59 71 if (peaks == NULL) psAbort ("find peaks", "no peaks found"); 72 73 // correct the peak values to S/N = sqrt(value*effArea) 74 // get the peak flux from the unsmoothed image 75 // the peak pixel coords are guaranteed to be on the image 76 for (int i = 0; i < peaks->n; i++) { 77 pmPeak *peak = peaks->data[i]; 78 peak->SN = sqrt(peak->value*effArea); 79 peak->flux = readout->image->data.F32[peak->y][peak->x]; 80 } 81 60 82 psFree (smooth_im); 61 83 psFree (smooth_wt); … … 71 93 } 72 94 73 // In this function, we smooth the image, then search for the peaks74 // Should we also subtract a super-binned image? (as an option?)75 // XXX : We need to gracefully handle no source detections
Note:
See TracChangeset
for help on using the changeset viewer.
