IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11169


Ignore:
Timestamp:
Jan 18, 2007, 6:52:08 PM (19 years ago)
Author:
eugene
Message:

moved effArea factor to threshold from detection image; added loop to convert detection threshold to SN, retrieve peak flux; include mask in smoothing process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotFindPeaks.c

    r10803 r11169  
    11# include "psphot.h"
    22
    3 // 2006.02.02 : no leaks
     3// In this function, we smooth the image, then search for the peaks
    44psArray *psphotFindPeaks (pmReadout *readout, psMetadata *recipe) {
    55
    66    bool  status = false;
    7     float NSIGMA;
    8     float SIGMA;
    9     float threshold;
    10     float value;
    117
    128    // smooth the image and weight map
    139    psTimerStart ("psphot");
    1410
    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");
    1713
    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
    2015    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);
    2217    psLogMsg ("psphot", PS_LOG_MINUTIA, "smooth image: %f sec\n", psTimerMark ("psphot"));
    2318
     19    // smooth the weight, applying the mask as we go
    2420    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);
    2822    psLogMsg ("psphot", PS_LOG_MINUTIA, "smooth weight: %f sec\n", psTimerMark ("psphot"));
    2923
     
    3630    }
    3731
     32    // build the significance image on top of smooth_im
    3833    for (int j = 0; j < smooth_im->numRows; j++) {
    3934        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];
    4136            if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || mask->data.U8[j][i]) {
    4237                smooth_im->data.F32[j][i] = 0.0;
     
    4641        }
    4742    }
    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    }
    4949
    5050    psTimerStart ("psphot");
    5151    // set peak threshold
     52
     53    // signal/noise limit for the detected peaks
    5254    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);
    5655
    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
    5870    psArray *peaks = pmFindImagePeaks (smooth_im, threshold);
    5971    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
    6082    psFree (smooth_im);
    6183    psFree (smooth_wt);
     
    7193}
    7294
    73 // In this function, we smooth the image, then search for the peaks
    74 // 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.