Index: trunk/magic/remove/src/streaksremove.c
===================================================================
--- trunk/magic/remove/src/streaksremove.c	(revision 20817)
+++ trunk/magic/remove/src/streaksremove.c	(revision 20844)
@@ -406,8 +406,10 @@
     if (sf->stage == IPP_STAGE_CHIP) {
         // For the chip level files, copy the WCS from the astrometry file to the header
-        updateAstrometry = true;
-        if (!pmAstromWriteWCS(sf->inImage->header, sf->inAstrom->fpa, sf->chip, 0.001)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to update astrometry for extension %d", sf->extnum);
-            streaksExit("", PS_EXIT_UNKNOWN_ERROR);
+        if (!sf->bilevelAstrometry) {
+            updateAstrometry = true;
+            if (!pmAstromWriteWCS(sf->inImage->header, sf->inAstrom->fpa, sf->chip, 0.001)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to update astrometry for extension %d", sf->extnum);
+                streaksExit("", PS_EXIT_UNKNOWN_ERROR);
+            }
         }
     }
@@ -447,37 +449,44 @@
     if (sf->inMask) {
         readImage(sf->inMask, sf->extnum, sf->stage);
-        if (updateAstrometry) {
-            pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
-        }
         sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
         if (sf->recMask) {
             sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
         }
+        if (updateAstrometry) {
+            pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
+        }
 
         setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll);
 
+#ifdef STREAKS_COMPRESS_OUTPUT
         // XXX: see note above
         copyFitsOptions(sf->outMask, sf->recMask, sf->inMask);
         psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
-        psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
+        if (sf->recMask) {
+            psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
+        }
+#endif
     }
 
     if (sf->inWeight) {
         readImage(sf->inWeight, sf->extnum, sf->stage);
-        if (updateAstrometry) {
-            pmAstromWriteWCS(sf->inWeight->header, sf->inAstrom->fpa, sf->chip, 0.001);
-        }
         sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header);
         if (sf->recWeight) {
             sf->recWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header);
         }
-        setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll);
-
+        if (updateAstrometry) {
+            pmAstromWriteWCS(sf->inWeight->header, sf->inAstrom->fpa, sf->chip, 0.001);
+        }
+        setupImageRefs(sf->outWeight, sf->recWeight, sf->inWeight, sf->extnum, exciseAll);
+
+#ifdef STREAKS_COMPRESS_OUTPUT
         copyFitsOptions(sf->outWeight, sf->recWeight, sf->inWeight);
         // XXX: see note above
         psFitsSetCompression(sf->outWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
-        psFitsSetCompression(sf->recWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
-    }
-
+        if (sf->recWeight) {
+            psFitsSetCompression(sf->recWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
+        }
+#endif
+    }
     // and for raw images, create sub images that represent the actual image
     // area (no overscan)
@@ -611,11 +620,15 @@
 
     if (sfiles->inWeight) {
-        double weightValue = psImageGet (sfiles->inWeight->image, x, y);
-        psImageSet (sfiles->recWeight->image, x, y, weightValue);
+        if (sfiles->recWeight) {
+            double weightValue = psImageGet (sfiles->inWeight->image, x, y);
+            psImageSet (sfiles->recWeight->image, x, y, weightValue);
+        }
         psImageSet (sfiles->outWeight->image, x, y, NAN);
     }
     if (sfiles->inMask) {
-        double maskValue   = psImageGet (sfiles->inMask->image,   x, y);
-        psImageSet (sfiles->recMask->image,   x, y, maskValue);
+        if (sfiles->recMask) {
+            double maskValue   = psImageGet (sfiles->inMask->image,   x, y);
+            psImageSet (sfiles->recMask->image,   x, y, maskValue);
+        }
         psImageSet (sfiles->outMask->image,   x, y, newMaskValue);
     }
