IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 15, 2008, 10:29:11 AM (18 years ago)
Author:
eugene
Message:

re-org and cleanup of the mask bits to make it consistent with the pmConfigMaskSetBits concepts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMergeMask.c

    r18365 r18558  
    1818                      psRandom *rng,    // Random number generator
    1919                      psMetadata *stats // Statistics output
    20                       )
     20    )
    2121{
    2222    assert(config);
     
    2828    psStatsOptions meanStat = psMetadataLookupS32(NULL, config->arguments, "MEAN"); // Statistic for mean
    2929    psStatsOptions stdevStat = psMetadataLookupS32(NULL, config->arguments, "STDEV"); // Statistic for stdev
    30     psMaskType maskVal = psMetadataLookupU8(NULL, config->arguments, "MASKVAL"); // Value to mask
    3130    int sample = psMetadataLookupS32(NULL, config->arguments, "SAMPLE"); // Size of sample for statistics
    3231    bool chipStats = psMetadataLookupBool(&mdok, config->arguments, "MASK.CHIPSTATS"); // Statistics on chip?
     
    3534    pmMaskIdentifyMode maskMode = psMetadataLookupS32(NULL, config->arguments, "MASK.MODE"); // Mode for identifying bad pixels
    3635    int maskGrow = psMetadataLookupS32(NULL, config->arguments, "MASK.GROW"); // Radius to grow mask
    37     psMaskType maskGrowVal = psMetadataLookupU8(NULL, config->arguments, "MASK.GROWVAL"); // Value for grown mask
    3836
    3937    bool smoothSuspect = psMetadataLookupBool(&mdok, config->arguments, "MASK.SMOOTH.SUSPECT"); // Radius to grow mask
    4038    float smoothScale = psMetadataLookupF32(&mdok, config->arguments, "MASK.SMOOTH.SCALE"); // Radius to grow mask
    4139
     40    psMaskType markVal;
     41    psMaskType maskValRaw;
     42    if (!pmConfigMaskSetBits (&maskValRaw, &markVal, config)) {
     43        psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
     44        return false;
     45    }
     46
     47    char *maskOutName = psMetadataLookupStr (&mdok, config->arguments, "MASK.SET.VALUE");
     48    psMaskType maskValOut = pmConfigMaskGet (maskOutName, config);
     49    if (!maskValOut) {
     50        psError (PS_ERR_UNKNOWN, true, "Undefined output mask bit value");
     51        return false;
     52    }
     53   
    4254    psStats *statistics = psStatsAlloc(meanStat | stdevStat); // Statistics for background
    4355
     
    137149                int x = pixel % numCols;
    138150                int y = pixel / numCols;
    139                 if ((mask && (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal)) ||
    140                     !isfinite(image->data.F32[y][x]) ||
    141                     (outMask && (outMask->data.PS_TYPE_MASK_DATA[y][x] & maskVal))) {
    142                     continue;
    143                 }
     151                if (mask && (mask->data.PS_TYPE_MASK_DATA[y][x] & maskValRaw)) continue;
     152                if (outMask && (outMask->data.PS_TYPE_MASK_DATA[y][x] & maskValOut)) continue;
     153                if (!isfinite(image->data.F32[y][x])) continue;
    144154
    145155                values->data.F32[valueIndex++] = image->data.F32[y][x];
     
    155165                }
    156166
    157                 if (!pmMaskFlagSuspectPixels(outRO, readout, psStatsGetValue(statistics, meanStat),
    158                                              psStatsGetValue(statistics, stdevStat), maskSuspect, maskVal)) {
     167                float mean = psStatsGetValue(statistics, meanStat);
     168                float stdev = psStatsGetValue(statistics, stdevStat);
     169
     170                // this function increments the count for each suspect pixel in each input plane
     171                // maskValRaw is used to test for valid input pixels
     172                if (!pmMaskFlagSuspectPixels(outRO, readout, mean, stdev, maskSuspect, maskValRaw)) {
    159173                    psError(PS_ERR_UNKNOWN, false, "Unable to find suspect values in file %d", i);
    160174                    psFree(inView);
     
    189203
    190204                pmHDU *hdu = pmHDUFromCell(inCell); // HDU for cell
    191                 if (!hdu || hdu->blankPHU) {
    192                     // No data here
    193                     continue;
    194                 }
     205                if (!hdu || hdu->blankPHU) continue;
     206
    195207                pmReadout *readout = inCell->readouts->data[0]; // Readout of interest
    196208
     
    198210                pmReadout *outRO = pmFPAfileThisReadout(config->files, inView, "PPMERGE.OUTPUT.MASK");
    199211
    200                 if (!pmMaskFlagSuspectPixels(outRO, readout, psStatsGetValue(statistics, meanStat),
    201                                              psStatsGetValue(statistics, stdevStat), maskSuspect, maskVal)) {
     212                float mean = psStatsGetValue(statistics, meanStat);
     213                float stdev = psStatsGetValue(statistics, stdevStat);
     214
     215                if (!pmMaskFlagSuspectPixels(outRO, readout, mean, stdev, maskSuspect, maskValRaw)) {
    202216                    psError(PS_ERR_UNKNOWN, false, "Unable to find suspect values in file %d", i);
    203217                    goto MERGE_MASK_ERROR;
     
    229243    while ((outCell = pmFPAviewNextCell(outView, outFPA, 1))) {
    230244
    231         // skipp inactive cells
     245        // skip inactive cells
    232246        if (!outCell->process) continue;
    233247
    234248        pmHDU *hdu = pmHDUFromCell(outCell); // HDU for cell
    235         if (!hdu || hdu->blankPHU) {
    236             // No data here
    237             continue;
    238         }
     249        if (!hdu || hdu->blankPHU) continue;
    239250
    240251        psTrace("ppMerge", 1, "Getting bad pixels for chip %d cell %d", outView->chip, outView->cell);
     
    250261        }
    251262
    252         if (!pmMaskIdentifyBadPixels(outRO, maskVal, maskBad, maskMode)) {
     263        // set the bad pixels to the value 'maskVal'
     264        if (!pmMaskIdentifyBadPixels(outRO, maskValOut, maskBad, maskMode)) {
    253265            psError(PS_ERR_UNKNOWN, false, "Unable to mask bad pixels");
    254266            goto MERGE_MASK_ERROR;
     
    274286        }
    275287
    276         if (maskGrowVal > 0) {
    277             psImage *grown = psImageGrowMask(NULL, outRO->mask, maskVal, maskGrow, maskGrowVal); // Grown mask
     288        if (maskGrow > 0) {
     289            psImage *grown = psImageGrowMask(NULL, outRO->mask, maskValOut, maskGrow, maskValOut); // Grown mask
    278290            psFree(outRO->mask);
    279291            outRO->mask = grown;
     
    307319            outRO->image = psImageAlloc(outRO->mask->numCols, outRO->mask->numRows, PS_TYPE_F32);
    308320            psImageInit(outRO->image, 1.0);
    309             if (!ppStatsFPA(stats, outRO->parent->parent->parent, outView,
    310                             maskVal | pmConfigMask("BLANK", config), config)) {
     321            if (!ppStatsFPA(stats, outRO->parent->parent->parent, outView, maskValOut, config)) {
    311322                psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate stats for image.");
    312323                psFree(outRO);
     
    337348}
    338349
    339 
    340 
    341 
    342 
    343350bool ppMergeMask(pmConfig *config)
    344351{
     
    381388        goto PPMERGE_MASK_ERROR;
    382389    }
     390
     391    // XXX this function should use pmConfigMaskReadHeader () to get the named values defined
     392    // for the input masks.
    383393
    384394    psString outName = ppMergeOutputFile(config); // Name of output file
     
    414424                psListAdd(inChips, PS_LIST_TAIL, chip);
    415425            }
     426
     427            // XXX I need to call pmConfigMaskWriteHeader for the PHU somewhere, after it is created!
     428
    416429            if (!pmConceptsAverageChips(outChip, inChips, true)) {
    417430                psError(PS_ERR_UNKNOWN, false, "Unable to average Chip concepts.");
Note: See TracChangeset for help on using the changeset viewer.