IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 25, 2021, 2:22:11 PM (5 years ago)
Author:
eugene
Message:

allow option to use signal image on first pass for detections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20211108/psphot/src/psphotFindPeaks.c

    r33761 r41968  
    44// image must be constructed to represent (S/N)^2.  If nMax is non-zero, only return a maximum
    55// of nMax peaks
    6 psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax, int *totalPeaks) {
     6psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax, int *totalPeaks, bool firstPass) {
    77
    88    bool status = false;
     
    1010    psTimerStart ("psphot.peaks");
    1111
    12     // find the peaks in the smoothed image
    13     // NOTE : significance->variance actually carries the detection S/N image
    14     psArray *peaks = pmPeaksInImage (significance->variance, threshold);
    15     if (peaks == NULL) {
    16         // we only get a NULL peaks array due to a programming or config error.
    17         // this will result in a failure.
    18         psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
    19         return NULL;
     12    psArray *peaks = NULL;
     13
     14    bool useSignalImage = psMetadataLookupF32 (&status, recipe, "PEAKS_USE_SIGNAL_IMAGE"); PS_ASSERT (status, NULL);
     15
     16    if (firstPass && useSignalImage) {
     17        // find the approximate smoothed signal image that corresponds to the desired threshold
     18
     19        // find all pixels within 25% of the threshold:
     20        float minThresh = threshold * 0.80;
     21        float maxThresh = threshold * 1.25;
     22
     23        psImage *smooth_sn = significance->variance;
     24        psImage *smooth_im = significance->image;
     25
     26        psVector *SNvalues = psVectorAllocEmpty (1000, PS_TYPE_F32);
     27        for (int iy = 0; iy < smooth_im->numRows; iy++) {
     28            for (int ix = 0; ix < smooth_im->numCols; ix++) {
     29                // select all valid pixels within the S/N range
     30                if (!isfinite(smooth_sn->data.F32[iy][ix])) continue;
     31                if (!isfinite(smooth_im->data.F32[iy][ix])) continue;
     32                if (smooth_sn->data.F32[iy][ix] < minThresh) continue;
     33                if (smooth_sn->data.F32[iy][ix] > maxThresh) continue;
     34                psVectorAppend (SNvalues, smooth_im->data.F32[iy][ix]);
     35            }
     36        }
     37
     38        // what is the median of the selected values?
     39        psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     40        if (!psVectorStats(stats, SNvalues, NULL, NULL, 0)) {
     41            // psVectorStats will only fail due to a programming error (e.g., invalid vector type)
     42            psError(PSPHOT_ERR_UNKNOWN, false, "Unable to perform statistics to measure image quality");
     43            return NULL;
     44        }
     45        if (!isfinite(stats->sampleMedian)) {
     46            // could not determine relationship between SN threshold and image values
     47            // XXX fall-back could be the standard analysis above.
     48            psLogMsg ("psphot", PS_LOG_INFO, "failure to map SN to image values");
     49            goto use_significance;
     50        }
     51       
     52        float alt_threshold = stats->sampleMedian;
     53        peaks = pmPeaksInImage (significance->image, alt_threshold);
     54        if (peaks == NULL) {
     55            // we only get a NULL peaks array due to a programming or config error.
     56            // this will result in a failure.
     57            psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
     58            return NULL;
     59        }
    2060    }
     61
     62use_significance:
     63    if (!peaks) {
     64        // peaks is NULL at this point if we did not use signal image (by choice or by failure).
     65        // find the peaks in the smoothed image
     66        // NOTE : significance->variance actually carries the detection S/N image
     67        peaks = pmPeaksInImage (significance->variance, threshold);
     68        if (peaks == NULL) {
     69            // we only get a NULL peaks array due to a programming or config error.
     70            // this will result in a failure.
     71            psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
     72            return NULL;
     73        }
     74    }
     75
    2176    // return the total number of peaks found before the nMax limit is applied
    2277    if (totalPeaks) {
Note: See TracChangeset for help on using the changeset viewer.