Index: trunk/magic/remove/src/streaksremove.c
===================================================================
--- trunk/magic/remove/src/streaksremove.c	(revision 20580)
+++ trunk/magic/remove/src/streaksremove.c	(revision 20671)
@@ -23,4 +23,10 @@
     psFree(sfile);
 }
+
+// TODO: get these by reading the recipe
+#define MASK_STREAK   0x20
+#define MASK_BAD_WARP 0x10
+
+
 
 // getNebServer()
@@ -498,4 +504,12 @@
         return NULL;
     }
+
+    bool gotReplace = false;
+    if ((argnum = psArgumentGet(argc, argv, "-replace"))) {
+        gotReplace = true;
+        psArgumentRemove(argnum, &argc, argv);
+        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REPLACE", 0, "replace input files",
+            true);
+    }
     
     
@@ -540,6 +554,6 @@
         psArgumentRemove(argnum, &argc, argv);
         bool nebulousTmp = IN_NEBULOUS(argv[argnum]);
-        if (nebulousTmp != nebulousImage) {
-            psError(PS_ERR_UNKNOWN, true, "tmproot must have %snebulous path with %s image path\n",
+        if (gotReplace && (nebulousTmp != nebulousImage)) {
+            psError(PS_ERR_UNKNOWN, true, "tmproot must have %snebulous path with %s image path with -replace\n",
                 nebulousImage ? "" : "non ", nebulousImage ? "nebulous" : "regular");
             return NULL;
@@ -562,11 +576,4 @@
         psError(PS_ERR_UNKNOWN, true, "-recovery is required for -stage raw\n");
         return NULL;
-    }
-    bool gotReplace = false;
-    if ((argnum = psArgumentGet(argc, argv, "-replace"))) {
-        gotReplace = true;
-        psArgumentRemove(argnum, &argc, argv);
-        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REPLACE", 0, "replace input files",
-            true);
     }
     if ((argnum = psArgumentGet(argc, argv, "-remove"))) {
@@ -721,4 +728,6 @@
 
     sf->inImage->image = (psImage*) psMemIncrRefCounter(readout->image);
+    sf->inImage->numCols = readout->image->numCols;
+    sf->inImage->numRows = readout->image->numRows;
 }
 
@@ -921,10 +930,10 @@
 
     // set up the compression parameters
-    copyFitsOptions(sf->outImage, sf->recImage, sf->inImage);
+//    copyFitsOptions(sf->outImage, sf->recImage, sf->inImage);
 
     // XXX: TODO: can we derive these values from the input header?
     // psFitsCompressionGet(sf->inImage->image) gives compression none
     // perhaps we should just use the definition of COMP_IMG in the configuration 
-    psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
+//    psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
     psFitsSetCompression(sf->recImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
 
@@ -1251,5 +1260,16 @@
     double imageValue  = psImageGet (sfiles->inImage->image,  x, y);
     psImageSet (sfiles->recImage->image,  x, y, imageValue);
+
+#define ACTUALLY_MASK_PIXEL
+#ifdef ACTUALLY_MASK_PIXEL
     psImageSet (sfiles->outImage->image,  x, y, NAN);
+#else
+    if (newMaskValue == MASK_BAD_WARP) {
+        psImageSet (sfiles->outImage->image,  x, y, NAN);
+    } else {
+        // as a visualization aid don't mask the pixel, just reduce it in intensity a bit
+        psImageSet (sfiles->outImage->image,  x, y, imageValue - 50);
+    }
+#endif
 
     // TODO:
@@ -1333,4 +1353,52 @@
 }
 
+bool
+streakEndOnComponent(streak *streak, double r_min, double r_max, double d_min, double d_max)
+{
+    if ((streak->ra1  >= r_min) && (streak->ra1  <= r_max) &&
+        (streak->dec1 >= d_min) && (streak->dec1 <= d_max)) {
+        return true;
+    }
+    if ((streak->ra2  >= r_min) && (streak->ra2  <= r_max) &&
+        (streak->dec2 >= d_min) && (streak->dec2 <= d_max)) {
+        return true;
+    }
+    return false;
+}
+
+
+Streaks *
+restrictStreaksToComponent(streakFiles *sfiles, Streaks *streaks)
+{
+    Streaks *out = psAlloc(sizeof(Streaks));
+
+    strkPt ll, ur;
+    cellToSky(&ll, sfiles->astrom, 0, 0);
+    cellToSky(&ur, sfiles->astrom, sfiles->inImage->numCols-1, sfiles->inImage->numRows-1);
+
+    double r_min, r_max, d_min, d_max;
+    if (ll.x < ur.x) {
+        r_min = ll.x; r_max = ur.x;
+    } else {
+        r_min = ur.x; r_max = ll.x;
+    }
+    if (ll.y < ur.y) {
+        d_min = ll.y; d_max = ur.y;
+    } else {
+        d_min = ur.y; d_max = ll.y;
+    }
+
+    out->list = psAlloc(streaks->size * sizeof(streak));
+    int j=0;
+    for (int i=0 ; i<streaks->size; i++) {
+        if (streakEndOnComponent(&streaks->list[i], r_min, r_max, d_min, d_max)) {
+            out->list[j++] = streaks->list[i];
+        }
+            
+    }
+    out->size = j;
+    return out;
+}
+
 int
 main(int argc, char *argv[])
@@ -1359,5 +1427,7 @@
     streakFiles *sfiles = openFiles(config);
 
-    if (CHIP_LEVEL_INPUT(sfiles->stage)) {
+    bool status;
+    bool checkWarpedPixels = ! psMetadataLookupBool(&status, config->arguments, "INCLUDE_NON_WARPED");
+    if (checkWarpedPixels) {
         // From ICD:
         // In the raw and detrended images, the pixels which were not
@@ -1394,6 +1464,25 @@
         // Identify pixels to mask because of streaks
 
+#ifdef notyet
+        Streaks *componentStreaks = NULL;
+        Streaks *streaksToProcess;
+
+        bool only_component_streaks = false; // XXX flesh this out and make it an option
+        if (only_component_streaks) {
+            componentStreaks = restrictStreaksToComponent(sfiles, streaks);
+            streaksToProcess = componentStreaks;
+        } else { 
+            streaksToProcess = streaks;
+        }
+
+        pixels = streak_on_component (streaksToProcess, sfiles->astrom,
+                                      sfiles->inImage->numCols, sfiles->inImage->numRows);
+        if (componentStreaks) {
+            psFree(componentStreaks);
+        }
+#else
         pixels = streak_on_component (streaks, sfiles->astrom,
                                       sfiles->inImage->numCols, sfiles->inImage->numRows);
+#endif
         // XXX: 
         // 
@@ -1401,8 +1490,8 @@
         // in a config somewhere?  Not sure how to properly set the maskValue.
         // WES just pick some numbers
-#define MASK_STREAK     42
-#define MASK_NOT_WARPED 51
-
-        exciseNonWarpedPixels(sfiles, MASK_NOT_WARPED);
+
+        if (checkWarpedPixels) {
+            exciseNonWarpedPixels(sfiles, MASK_BAD_WARP);
+        }
 
         if (sfiles->inImage->image) {
@@ -1410,5 +1499,5 @@
                 pixelPos = psArrayGet (pixels, i);
 
-                if (warpedPixel(sfiles, pixelPos)) {
+                if (!checkWarpedPixels || warpedPixel(sfiles, pixelPos)) {
 
                     excisePixel(sfiles, pixelPos->x, pixelPos->y, MASK_STREAK);
@@ -1443,5 +1532,4 @@
     }
 
-    bool status;
     if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {
         //     swap the instances for the input and output
