IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 19, 2007, 4:40:44 PM (19 years ago)
Author:
Paul Price
Message:

Extensive changes to APIs to allow use of a nominated value to mask
against (the maskVal). Previously, the mask values were either
hard-coded (e.g., PM_MASK_SAT) or taken as anything non-zero. The
code is tested with psModules (which has similar changes) and does not
crash, but neither is it successful in marking all bad pixels. For
this reason, I have left the "gutter" pixels (cell gaps) set to 0
instead of NAN in pmFPAMosaic.

File:
1 edited

Legend:

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

    r13430 r13900  
    11# include "psphotInternal.h"
    22
    3 // In this function, we smooth the image, then search for the peaks 
     3// In this function, we smooth the image, then search for the peaks
    44psArray *psphotFindPeaks (pmReadout *readout, psMetadata *recipe,
    5                           bool returnFootprints,
    6                           const int pass) {
     5                          bool returnFootprints,
     6                          const int pass, psMaskType maskVal) {
    77
    88    float SIGMA_SMTH, NSIGMA_SMTH, NSIGMA_PEAK;
     
    1313
    1414    if (pass == 1) {
    15         SIGMA_SMTH  = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_SIGMA");
    16         NSIGMA_SMTH = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_NSIGMA");
     15        SIGMA_SMTH  = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_SIGMA");
     16        NSIGMA_SMTH = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_NSIGMA");
    1717    } else {
    18         bool status_x, status_y;
    19         float FWHM_X = psMetadataLookupF32 (&status_x, recipe, "FWHM_X");
    20         float FWHM_Y = psMetadataLookupF32 (&status_y, recipe, "FWHM_Y");
    21         if (!status_x | !status_y) {
    22             psError(PSPHOT_ERR_CONFIG, false, "FWHM_X or FWHM_Y not defined");
    23             return false;
    24         }
    25         SIGMA_SMTH  = 0.5*(FWHM_X + FWHM_Y) / (2.0*sqrt(2.0*log(2.0)));
    26         NSIGMA_SMTH = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_NSIGMA");
     18        bool status_x, status_y;
     19        float FWHM_X = psMetadataLookupF32 (&status_x, recipe, "FWHM_X");
     20        float FWHM_Y = psMetadataLookupF32 (&status_y, recipe, "FWHM_Y");
     21        if (!status_x | !status_y) {
     22            psError(PSPHOT_ERR_CONFIG, false, "FWHM_X or FWHM_Y not defined");
     23            return false;
     24        }
     25        SIGMA_SMTH  = 0.5*(FWHM_X + FWHM_Y) / (2.0*sqrt(2.0*log(2.0)));
     26        NSIGMA_SMTH = psMetadataLookupF32 (&status, recipe, "PEAKS_SMOOTH_NSIGMA");
    2727    }
    2828
    2929    // smooth the image, applying the mask as we go
    3030    psImage *smooth_im = psImageCopy (NULL, readout->image, PS_TYPE_F32);
    31     psImageSmoothMaskF32 (smooth_im, readout->mask, 0xff, SIGMA_SMTH, NSIGMA_SMTH);
     31    psImageSmoothMaskF32 (smooth_im, readout->mask, maskVal, SIGMA_SMTH, NSIGMA_SMTH);
    3232    psLogMsg ("psphot", PS_LOG_MINUTIA, "smooth image: %f sec\n", psTimerMark ("psphot"));
    3333
    3434    // smooth the weight, applying the mask as we go
    3535    psImage *smooth_wt = psImageCopy (NULL, readout->weight, PS_TYPE_F32);
    36     psImageSmoothMaskF32 (smooth_wt, readout->mask, 0xff, SIGMA_SMTH/sqrt(2), NSIGMA_SMTH);
     36    psImageSmoothMaskF32 (smooth_wt, readout->mask, maskVal, SIGMA_SMTH/sqrt(2), NSIGMA_SMTH);
    3737    psLogMsg ("psphot", PS_LOG_MINUTIA, "smooth weight: %f sec\n", psTimerMark ("psphot"));
    3838
    3939    psImage *mask = readout->mask;
    4040
    41     // optionally save example images under trace 
     41    // optionally save example images under trace
    4242    if (psTraceGetLevel("psphot") > 5) {
    43         char name[64];
    44         sprintf (name, "imsmooth.v%d.fits", pass);
    45         psphotSaveImage (NULL, smooth_im, name);
    46         sprintf (name, "wtsmooth.v%d.fits", pass);
    47         psphotSaveImage (NULL, smooth_wt, name);
     43        char name[64];
     44        sprintf (name, "imsmooth.v%d.fits", pass);
     45        psphotSaveImage (NULL, smooth_im, name);
     46        sprintf (name, "wtsmooth.v%d.fits", pass);
     47        psphotSaveImage (NULL, smooth_wt, name);
    4848    }
    4949
    5050    // build the significance image on top of smooth_im
    5151    for (int j = 0; j < smooth_im->numRows; j++) {
    52         for (int i = 0; i < smooth_im->numCols; i++) {
    53             float value = smooth_im->data.F32[j][i];
    54             if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || mask->data.U8[j][i]) {
    55                 smooth_im->data.F32[j][i] = 0.0;
    56             } else {
    57                 smooth_im->data.F32[j][i] = PS_SQR(value) / smooth_wt->data.F32[j][i];
    58             }
    59         }
     52        for (int i = 0; i < smooth_im->numCols; i++) {
     53            float value = smooth_im->data.F32[j][i];
     54            if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || (mask->data.U8[j][i] & maskVal)) {
     55                smooth_im->data.F32[j][i] = 0.0;
     56            } else {
     57                smooth_im->data.F32[j][i] = PS_SQR(value) / smooth_wt->data.F32[j][i];
     58            }
     59        }
    6060    }
    6161    psLogMsg ("psphot", PS_LOG_INFO, "built smoothed signficance image: %f sec\n", psTimerMark ("psphot"));
    6262
    63     // optionally save example images under trace 
     63    // optionally save example images under trace
    6464    if (psTraceGetLevel("psphot") > 5) {
    65         char name[64];
    66         sprintf (name, "snsmooth.v%d.fits", pass);
    67         psphotSaveImage (NULL, smooth_im, name);
     65        char name[64];
     66        sprintf (name, "snsmooth.v%d.fits", pass);
     67        psphotSaveImage (NULL, smooth_im, name);
    6868    }
    6969
     
    7373    // signal/noise limit for the detected peaks
    7474    if (pass == 1) {
    75         NSIGMA_PEAK = psMetadataLookupF32 (&status, recipe, "PEAKS_NSIGMA_LIMIT");
     75        NSIGMA_PEAK = psMetadataLookupF32 (&status, recipe, "PEAKS_NSIGMA_LIMIT");
    7676    } else {
    77         NSIGMA_PEAK = psMetadataLookupF32 (&status, recipe, "PEAKS_NSIGMA_LIMIT_2");
    78     }   
    79    
     77        NSIGMA_PEAK = psMetadataLookupF32 (&status, recipe, "PEAKS_NSIGMA_LIMIT_2");
     78    }
     79
    8080    // we need to define the threshold based on the value of NSIGMA_PEAK and the applied smoothing
    8181    // gaussian SIGMA.  a peak in the significance image has an effective S/N for faint sources
     
    8787    // terms of smooth_im peak counts Io, for a desired S/N limit corresponds to
    8888    // S/N = sqrt(Io)*4*pi*sigma_sm^2
    89     // thus, the threshold is: 
     89    // thus, the threshold is:
    9090    float effArea = 4.0*M_PI*PS_SQR(SIGMA_SMTH);
    9191    if (effArea < 1) {
    92         effArea = 1;                    // never less than a pixel
     92        effArea = 1;                    // never less than a pixel
    9393    }
    9494    float threshold = PS_SQR(NSIGMA_PEAK) / effArea;
     
    9797    psArray *peaks = pmFindImagePeaks (smooth_im, threshold);
    9898    if (peaks == NULL) {
    99         // XXX this may also be due to a programming or config error
    100         // XXX do we need to set something in the readout->analysis to indicate that
    101         // we tried and failed to find peaks (something in the header data)
    102         psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
    103         return false;
     99        // XXX this may also be due to a programming or config error
     100        // XXX do we need to set something in the readout->analysis to indicate that
     101        // we tried and failed to find peaks (something in the header data)
     102        psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
     103        return false;
    104104    }
    105    
     105
    106106    // correct the peak values to S/N = sqrt(value*effArea)
    107107    // get the peak flux from the unsmoothed image
     
    110110    int col0 = readout->image->col0;
    111111    for (int i = 0; i < peaks->n; i++) {
    112         pmPeak *peak = peaks->data[i];
    113         peak->SN = sqrt(peak->value*effArea);
    114         peak->flux = readout->image->data.F32[peak->y-row0][peak->x-col0];
     112        pmPeak *peak = peaks->data[i];
     113        peak->SN = sqrt(peak->value*effArea);
     114        peak->flux = readout->image->data.F32[peak->y-row0][peak->x-col0];
    115115    }
    116116
    117117    // limit the total number of returned peak as specified
    118118    if (pass == 1) {
    119         psArraySort (peaks, pmPeakSortBySN);
    120         int NMAX = psMetadataLookupS32 (&status, recipe, "PEAKS_NMAX");
    121         if (NMAX && (peaks->n > NMAX)) {
    122             psArray *tmpPeaks = psArrayAllocEmpty (NMAX);
    123             for (int i = 0; i < NMAX; i++) {
    124                 psArrayAdd (tmpPeaks, 100, peaks->data[i]);
    125             }
    126             psFree (peaks);
    127             peaks = tmpPeaks;
    128         }
    129     }   
     119        psArraySort (peaks, pmPeakSortBySN);
     120        int NMAX = psMetadataLookupS32 (&status, recipe, "PEAKS_NMAX");
     121        if (NMAX && (peaks->n > NMAX)) {
     122            psArray *tmpPeaks = psArrayAllocEmpty (NMAX);
     123            for (int i = 0; i < NMAX; i++) {
     124                psArrayAdd (tmpPeaks, 100, peaks->data[i]);
     125            }
     126            psFree (peaks);
     127            peaks = tmpPeaks;
     128        }
     129    }
    130130
    131131    // optional dump of all peak data
    132132    char *output = psMetadataLookupStr (&status, recipe, "PEAKS_OUTPUT_FILE");
    133133    if (status && (output != NULL) && (output[0])) {
    134         pmPeaksWriteText (peaks, output);
     134        pmPeaksWriteText (peaks, output);
    135135    }
    136136    psLogMsg ("psphot", PS_LOG_INFO, "%ld peaks: %f sec\n", peaks->n, psTimerMark ("psphot"));
     
    142142    // want to do that
    143143    //
    144     if (returnFootprints) {     // We want an array of pmFootprint, not pmPeak
    145         int npixMin = psMetadataLookupS32(&status, recipe, "FOOTPRINT_NPIXMIN");
    146         if (!status) {
    147             npixMin = 1;
    148         }
    149         float FOOTPRINT_NSIGMA_LIMIT =
    150             psMetadataLookupS32(&status, recipe,
    151                                 (pass == 1) ? "FOOTPRINT_NSIGMA_LIMIT" : "FOOTPRINT_NSIGMA_LIMIT_2");
    152         if (!status) {
    153             FOOTPRINT_NSIGMA_LIMIT = NSIGMA_PEAK;
    154         }
    155         threshold = PS_SQR(FOOTPRINT_NSIGMA_LIMIT)/effArea;
     144    if (returnFootprints) {     // We want an array of pmFootprint, not pmPeak
     145        int npixMin = psMetadataLookupS32(&status, recipe, "FOOTPRINT_NPIXMIN");
     146        if (!status) {
     147            npixMin = 1;
     148        }
     149        float FOOTPRINT_NSIGMA_LIMIT =
     150            psMetadataLookupS32(&status, recipe,
     151                                (pass == 1) ? "FOOTPRINT_NSIGMA_LIMIT" : "FOOTPRINT_NSIGMA_LIMIT_2");
     152        if (!status) {
     153            FOOTPRINT_NSIGMA_LIMIT = NSIGMA_PEAK;
     154        }
     155        threshold = PS_SQR(FOOTPRINT_NSIGMA_LIMIT)/effArea;
    156156
    157         psArray *footprints = pmFindFootprints(smooth_im, threshold, npixMin);
    158         pmPeaksAssignToFootprints(footprints, peaks);
     157        psArray *footprints = pmFindFootprints(smooth_im, threshold, npixMin);
     158        pmPeaksAssignToFootprints(footprints, peaks);
    159159
    160         psFree(peaks);
    161         peaks = footprints;             // well, you know what I mean
     160        psFree(peaks);
     161        peaks = footprints;             // well, you know what I mean
    162162    }
    163163
     
    174174 */
    175175psErrorCode
    176 psphotCullPeaks(const psImage *image,   // the image wherein lives the footprint
    177                 const psImage *weight,  // corresponding variance image
    178                 const psMetadata *recipe,
    179                 psArray *footprints) {  // array of pmFootprints
     176psphotCullPeaks(const psImage *image,   // the image wherein lives the footprint
     177                const psImage *weight,  // corresponding variance image
     178                const psMetadata *recipe,
     179                psArray *footprints) {  // array of pmFootprints
    180180    bool status = false;
    181181    float nsigma_delta = psMetadataLookupF32(&status, recipe, "FOOTPRINT_CULL_NSIGMA_DELTA");
    182182    if (!status) {
    183         nsigma_delta = 0; // min.
     183        nsigma_delta = 0; // min.
    184184    }
    185185    float nsigma_min = psMetadataLookupF32(&status, recipe, "FOOTPRINT_CULL_NSIGMA_MIN");
    186186    if (!status) {
    187         nsigma_min = 0;
     187        nsigma_min = 0;
    188188    }
    189189    const float skyStdev = psMetadataLookupF32(NULL, recipe, "SKY_STDEV");
    190190
    191191    return pmFootprintArrayCullPeaks(image, weight, footprints,
    192                                      nsigma_delta, nsigma_min*skyStdev);
     192                                     nsigma_delta, nsigma_min*skyStdev);
    193193}
Note: See TracChangeset for help on using the changeset viewer.