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/psphotReadout.c

    r13804 r13900  
    1212    }
    1313
     14    // Interpret the mask values
     15    const char *maskValStr = psMetadataLookupStr(NULL, recipe, "MASKVAL"); // String with mask names
     16    if (!maskValStr) {
     17        psError(PSPHOT_ERR_CONFIG, false, "Missing recipe item: MASKVAL(STR)");
     18        return false;
     19    }
     20    psMaskType maskVal = pmConfigMask(maskValStr, config); // Mask values to mask against
     21    psMaskType maskMark = pmConfigMask("MARK", config); // Mask value for marking
     22    psMaskType maskSat = pmConfigMask("SAT", config); // Mask value for saturated pixels
     23    psMaskType maskBad = pmConfigMask("BAD", config); // Mask value for bad pixels
     24
    1425    // find the currently selected readout
    1526    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
     
    2435
    2536    // generate mask & weight images if they don't already exit
    26     psMaskType satMask = pmConfigMask("SAT", config);
    27     psMaskType badMask = pmConfigMask("BAD", config);
    2837    if (!readout->mask) {
    29         if (!pmReadoutGenerateMask(readout, satMask, badMask)) {
    30             psError (PSPHOT_ERR_CONFIG, false, "trouble creating mask");
    31             return false;
    32         }
     38        if (!pmReadoutGenerateMask(readout, maskSat, maskBad)) {
     39            psError (PSPHOT_ERR_CONFIG, false, "trouble creating mask");
     40            return false;
     41        }
    3342    }
    3443    if (!readout->weight) {
    35         if (!pmReadoutGenerateWeight(readout, true)) {
    36             psError (PSPHOT_ERR_CONFIG, false, "trouble creating weight");
    37             return false;
    38         }
     44        if (!pmReadoutGenerateWeight(readout, true)) {
     45            psError (PSPHOT_ERR_CONFIG, false, "trouble creating weight");
     46            return false;
     47        }
    3948    }
    4049
     
    4655
    4756    // I have a valid mask, now mask in the analysis region of interest
    48     psphotMaskReadout (readout, recipe, config);
     57    psphotMaskReadout (readout, recipe, maskBad);
    4958
    5059    // run a single-model test if desired
    51     psphotModelTest (readout, recipe);
     60    psphotModelTest (readout, recipe, maskVal, maskMark);
    5261
    5362    if (psTraceGetLevel("psphot") >= 5) {
     
    6271
    6372    // generate a background model (median, smoothed image)
    64     if (!psphotImageMedian (config, view)) {
     73    if (!psphotImageMedian (config, view, maskVal)) {
    6574        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL);
    6675    }
     
    7483    psArray *footprints = NULL;
    7584    if (useFootprints) {
    76        footprints = psphotFindPeaks (readout, recipe, useFootprints, 1);
     85       footprints = psphotFindPeaks (readout, recipe, useFootprints, 1, maskVal);
    7786       int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS");
    7887       if (growRadius > 0) {
     
    8594       peaks = pmFootprintArrayToPeaks(footprints);
    8695    } else {
    87        peaks = psphotFindPeaks (readout, recipe, useFootprints, 1);
     96       peaks = psphotFindPeaks (readout, recipe, useFootprints, 1, maskVal);
    8897    }
    8998
     
    97106
    98107    // construct sources and measure basic stats
    99     psArray *sources = psphotSourceStats (readout, recipe, peaks);
     108    psArray *sources = psphotSourceStats (readout, recipe, peaks, maskVal, maskMark);
    100109    if (!sources) return false;
    101110    psFree (peaks);
     
    114123
    115124    // classify sources based on moments, brightness
    116     if (!psphotRoughClass (sources, recipe, true)) {
     125    if (!psphotRoughClass (sources, recipe, true, maskSat)) {
    117126        psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    118127        return psphotReadoutCleanup (config, readout, recipe, NULL, sources);
     
    126135    if (!psf) {
    127136        // use bright stellar objects to measure PSF
    128         psf = psphotChoosePSF (readout, sources, recipe);
     137        psf = psphotChoosePSF (readout, sources, recipe, maskVal, maskMark);
    129138        if (psf == NULL) {
    130139            psLogMsg ("psphot", 3, "failure to construct a psf model");
     
    143152
    144153    // construct an initial model for each object
    145     psphotGuessModels (readout, sources, recipe, psf);
     154    psphotGuessModels (readout, sources, recipe, psf, maskVal);
    146155
    147156    // XXX test output of models
     
    151160
    152161    // linear PSF fit to peaks
    153     psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE);
     162    psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE, maskVal);
    154163    if (dump) psphotSaveImage (NULL, readout->image,  "image.v1.fits");
    155164
     
    162171
    163172    // non-linear PSF and EXT fit to brighter sources
    164     psphotBlendFit (readout, sources, recipe, psf);
     173    psphotBlendFit (readout, sources, recipe, psf, maskVal);
    165174    if (dump) psphotSaveImage (NULL, readout->image,  "image.v2.fits");
    166175
    167176    // replace all sources
    168     psphotReplaceAll (sources);
     177    psphotReplaceAll (sources, maskVal);
    169178    if (dump) psphotSaveImage (NULL, readout->image,  "image.v3.fits");
    170179
    171180    // linear PSF fit to remaining peaks
    172     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     181    psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE, maskVal);
    173182    if (dump) psphotSaveImage (NULL, readout->image,  "image.v4.fits");
    174183    if (!strcasecmp (breakPt, "PASS1")) {
     
    183192
    184193    // add noise for subtracted objects
    185     psphotAddNoise (readout, sources, recipe, true);
     194    psphotAddNoise (readout, sources, recipe, true, maskVal);
    186195
    187196    // find the peaks in the image
    188197    psArray *newPeaks;
    189198    if (useFootprints) {
    190        psArray *newFootprints = psphotFindPeaks (readout, recipe, useFootprints, 2);
     199       psArray *newFootprints = psphotFindPeaks (readout, recipe, useFootprints, 2, maskVal);
    191200
    192201       int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS_2");
     
    209218       psFree(mergedFootprints);
    210219    } else {
    211        newPeaks = psphotFindPeaks(readout, recipe, useFootprints, 2);
     220       newPeaks = psphotFindPeaks(readout, recipe, useFootprints, 2, maskVal);
    212221    }
    213222
    214223    // remove noise for subtracted objects
    215     psphotAddNoise (readout, sources, recipe, false);
     224    psphotAddNoise (readout, sources, recipe, false, maskVal);
    216225
    217226    // define new sources based on the new peaks
    218     psArray *newSources = psphotSourceStats (readout, recipe, newPeaks);
     227    psArray *newSources = psphotSourceStats (readout, recipe, newPeaks, maskVal, maskMark);
    219228    psFree (newPeaks);
    220229
    221230    // set source type
    222     psphotRoughClass (newSources, recipe, false);
     231    psphotRoughClass (newSources, recipe, false, maskSat);
    223232
    224233    // create full input models
    225     psphotGuessModels (readout, newSources, recipe, psf);
     234    psphotGuessModels (readout, newSources, recipe, psf, maskVal);
    226235
    227236    // replace all sources
    228     psphotReplaceAll (sources);
     237    psphotReplaceAll (sources, maskVal);
    229238    if (dump) psphotSaveImage (NULL, readout->image,  "image.v5.fits");
    230239
     
    234243
    235244    // linear PSF fit to remaining peaks
    236     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     245    psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE, maskVal);
    237246    if (dump) psphotSaveImage (NULL, readout->image,  "image.v6.fits");
    238247
     
    243252
    244253    // measure aperture photometry corrections
    245     if (!psphotApResid (readout, sources, recipe, psf)) {
     254    if (!psphotApResid (readout, sources, recipe, psf, maskVal, maskMark)) {
    246255        psTrace ("psphot", 4, "failure on psphotApResid");
    247256        psError(PSPHOT_ERR_PHOTOM, false, "Measure aperture photometry corrections");
     
    251260    // calculate source magnitudes
    252261    pmReadout *background = psphotSelectBackground (config, view, false);
    253     psphotMagnitudes(sources, recipe, psf, background);
     262    psphotMagnitudes(sources, recipe, psf, background, maskVal, maskMark);
    254263
    255264    // replace failed sources?
Note: See TracChangeset for help on using the changeset viewer.