IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25136


Ignore:
Timestamp:
Aug 19, 2009, 3:53:07 PM (17 years ago)
Author:
bills
Message:

set masked pixels to NAN

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/ppstampMakeStamp.c

    r21403 r25136  
    1717
    1818static void skyToChip(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
     19static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
    1920
    2021// convert the input chip's transforms to the output
     
    325326            break;
    326327        }
     328        if (readout->variance) {
     329            outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
     330            if (!outReadout->variance) {
     331                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
     332                status = false;
     333                break;
     334            }
     335        }
    327336        if (readout->mask) {
    328337            outReadout->mask = extractStamp(readout->mask, extractRegion,  0);
     
    332341                break;
    333342            }
    334         }
    335         if (readout->variance) {
    336             outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
    337             if (!outReadout->variance) {
    338                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
    339                 status = false;
    340                 break;
     343
     344            if (!setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) {
     345                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
     346                 status = false;
     347                 break;
    341348            }
    342349        }
     
    668675
    669676
     677static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance)
     678{
     679    bool status;
     680    psMetadata *masks = psMetadataLookupMetadata(&status, config->recipes, "MASKS");
     681    if (!status) {
     682        psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n");
     683        return false;
     684    }
     685    // we set anything masked to NAN except if CONV.POOR is the only bit set
     686    // First check the old value
     687    psU32 convPoor = psMetadataLookupU32(&status, masks, "POOR.WARP");
     688    if (!status) {
     689        convPoor = psMetadataLookupU32(&status, masks, "CONV.POOR");
     690        if (!status) {
     691            psError(PM_ERR_CONFIG, false, "failed to lookup mask value for CONV.POOR in recipes\n");
     692            return false;
     693        }
     694    }
     695    psU32 maskMask = ~convPoor;
     696
     697    double exciseValue;
     698    if (image->type.type == PS_TYPE_U16) {
     699        exciseValue = 0xffff;
     700    } else if (image->type.type == PS_TYPE_F32) {
     701        exciseValue = NAN;
     702    } else {
     703         psError(PS_ERR_PROGRAMMING, true, "unexpected image type: %d\n", image->type.type);
     704        return false;
     705    }
     706    long numExcised = 0;
     707    for (int y=0; y<image->numRows; y++) {
     708        for (int x=0; x<image->numCols; x++) {
     709            psU16 maskVal = psImageGet(mask, x, y);
     710            if (maskVal & maskMask) {
     711                numExcised++;
     712                psImageSet(image, x, y, exciseValue);
     713                if (variance) {
     714                    psImageSet(variance, x, y, exciseValue);
     715                }
     716            }
     717        }
     718    }
     719    fprintf(stderr, "excised %ld masked pixels\n", numExcised);
     720
     721    return true;
     722}
Note: See TracChangeset for help on using the changeset viewer.