Index: trunk/pstamp/src/ppstampMakeStamp.c
===================================================================
--- trunk/pstamp/src/ppstampMakeStamp.c	(revision 25077)
+++ trunk/pstamp/src/ppstampMakeStamp.c	(revision 25136)
@@ -17,4 +17,5 @@
 
 static void skyToChip(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
+static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
 
 // convert the input chip's transforms to the output
@@ -325,4 +326,12 @@
             break;
         }
+        if (readout->variance) {
+            outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
+            if (!outReadout->variance) {
+                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
+                status = false;
+                break;
+            }
+        }
         if (readout->mask) {
             outReadout->mask = extractStamp(readout->mask, extractRegion,  0);
@@ -332,11 +341,9 @@
                 break;
             }
-        }
-        if (readout->variance) {
-            outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
-            if (!outReadout->variance) {
-                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
-                status = false;
-                break;
+
+            if (!setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) {
+                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
+                 status = false;
+                 break;
             }
         }
@@ -668,2 +675,48 @@
 
 
+static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance)
+{
+    bool status;
+    psMetadata *masks = psMetadataLookupMetadata(&status, config->recipes, "MASKS");
+    if (!status) {
+        psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n");
+        return false;
+    }
+    // we set anything masked to NAN except if CONV.POOR is the only bit set
+    // First check the old value
+    psU32 convPoor = psMetadataLookupU32(&status, masks, "POOR.WARP");
+    if (!status) {
+        convPoor = psMetadataLookupU32(&status, masks, "CONV.POOR");
+        if (!status) {
+            psError(PM_ERR_CONFIG, false, "failed to lookup mask value for CONV.POOR in recipes\n");
+            return false;
+        }
+    }
+    psU32 maskMask = ~convPoor;
+
+    double exciseValue;
+    if (image->type.type == PS_TYPE_U16) {
+        exciseValue = 0xffff;
+    } else if (image->type.type == PS_TYPE_F32) {
+        exciseValue = NAN;
+    } else {
+         psError(PS_ERR_PROGRAMMING, true, "unexpected image type: %d\n", image->type.type);
+        return false;
+    }
+    long numExcised = 0;
+    for (int y=0; y<image->numRows; y++) {
+        for (int x=0; x<image->numCols; x++) {
+            psU16 maskVal = psImageGet(mask, x, y);
+            if (maskVal & maskMask) {
+                numExcised++;
+                psImageSet(image, x, y, exciseValue);
+                if (variance) {
+                    psImageSet(variance, x, y, exciseValue);
+                }
+            }
+        }
+    }
+    fprintf(stderr, "excised %ld masked pixels\n", numExcised);
+
+    return true;
+}
