Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 24229)
+++ trunk/ppImage/src/ppImage.h	(revision 24485)
@@ -31,4 +31,5 @@
     bool doNonLin;                      // Non-linearity correction
     bool doOverscan;                    // Overscan subtraction
+    bool doNoiseMap;                    // Bias subtraction
     bool doBias;                        // Bias subtraction
     bool doDark;                        // Dark subtraction
Index: trunk/ppImage/src/ppImageArguments.c
===================================================================
--- trunk/ppImage/src/ppImageArguments.c	(revision 24229)
+++ trunk/ppImage/src/ppImageArguments.c	(revision 24485)
@@ -17,4 +17,5 @@
     fprintf(stderr, "\n");
     fprintf(stderr, "Input options (single file / file list):\n");
+    fprintf(stderr, "\t-noisemap/-noisemaplist: Noise Map image.\n");
     fprintf(stderr, "\t-bias/-biaslist: Bias image.\n");
     fprintf(stderr, "\t-dark/-darklist: Dark image.\n");
@@ -112,4 +113,5 @@
     // if these command-line options are supplied, load the file name lists into config->arguments
     // override any configuration-specified source for these files
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "NOISEMAP", "-noisemap", "-noisemaplist");
     pmConfigFileSetsMD (config->arguments, &argc, argv, "BIAS", "-bias", "-biaslist");
     pmConfigFileSetsMD (config->arguments, &argc, argv, "DARK", "-dark", "-darklist");
Index: trunk/ppImage/src/ppImageDetrendFree.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendFree.c	(revision 24229)
+++ trunk/ppImage/src/ppImageDetrendFree.c	(revision 24485)
@@ -8,4 +8,5 @@
 static char *detrendTypes[] = {
     "PPIMAGE.MASK",
+    "PPIMAGE.NOISEMAP",
     "PPIMAGE.BIAS",
     "PPIMAGE.DARK",
Index: trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendReadout.c	(revision 24229)
+++ trunk/ppImage/src/ppImageDetrendReadout.c	(revision 24485)
@@ -64,5 +64,27 @@
     if (options->doVarianceBuild) {
         // create the target mask and variance images
-        pmReadoutGenerateVariance(input, true);
+	psImage *noiseImage = NULL;
+	if (options->doNoiseMap) {
+	    // XXX convert the noiseMap image to a binned image
+	    pmReadout *noiseMap = NULL;
+	    noiseMap = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.NOISEMAP");
+	    noiseImage = psImageCopy (NULL, input->image, PS_TYPE_F32);
+	    psImageInit (noiseImage, 0.0);
+
+	    // XXX this works, but is not really quite right: the model shoud include the
+	    // offset information, we are not really getting exactly the right mapping from the
+	    // original file.
+	    psImageBinning *binning = psImageBinningAlloc();
+	    binning->nXruff = noiseMap->image->numCols;
+	    binning->nYruff = noiseMap->image->numRows;
+	    binning->nXfine = input->image->numCols;
+	    binning->nYfine = input->image->numRows;
+	    psImageBinningSetScale(binning, PS_IMAGE_BINNING_LEFT);
+
+	    psImageUnbin (noiseImage, noiseMap->image, binning);
+	    psFree (binning);
+	}
+        pmReadoutGenerateVariance(input, noiseImage, true);
+	psFree (noiseImage);
     }
 
Index: trunk/ppImage/src/ppImageDetrendRecord.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendRecord.c	(revision 24229)
+++ trunk/ppImage/src/ppImageDetrendRecord.c	(revision 24485)
@@ -67,12 +67,11 @@
     psMetadataAddMetadata(cell->analysis, PS_LIST_TAIL, "DETREND", 0, "Detrend information", detrend);
 
-    detrendRecord(options->doMask, detrend, config, view, "PPIMAGE.MASK", "DETREND.MASK", "Mask filename");
-    detrendRecord(options->doBias, detrend, config, view, "PPIMAGE.BIAS", "DETREND.BIAS", "Bias filename");
-    detrendRecord(options->doDark, detrend, config, view, "PPIMAGE.DARK", "DETREND.DARK", "Dark filename");
-    detrendRecord(options->doShutter, detrend, config, view, "PPIMAGE.SHUTTER", "DETREND.SHUTTER",
-                  "Shutter correction filename");
-    detrendRecord(options->doFlat, detrend, config, view, "PPIMAGE.FLAT", "DETREND.FLAT", "Flat filename");
-    detrendRecord(options->doFringe, detrend, config, view, "PPIMAGE.FRINGE", "DETREND.FRINGE",
-                  "Fringe filename");
+    detrendRecord(options->doMask,     detrend, config, view, "PPIMAGE.MASK", 	  "DETREND.MASK",     "Mask filename");
+    detrendRecord(options->doNoiseMap, detrend, config, view, "PPIMAGE.NOISEMAP", "DETREND.NOISEMAP", "Noise Map filename");
+    detrendRecord(options->doBias,     detrend, config, view, "PPIMAGE.BIAS", 	  "DETREND.BIAS",     "Bias filename");
+    detrendRecord(options->doDark,     detrend, config, view, "PPIMAGE.DARK", 	  "DETREND.DARK",     "Dark filename");
+    detrendRecord(options->doShutter,  detrend, config, view, "PPIMAGE.SHUTTER",  "DETREND.SHUTTER",  "Shutter correction filename");
+    detrendRecord(options->doFlat,     detrend, config, view, "PPIMAGE.FLAT",     "DETREND.FLAT",     "Flat filename");
+    detrendRecord(options->doFringe,   detrend, config, view, "PPIMAGE.FRINGE",   "DETREND.FRINGE",   "Fringe filename");
 
     psFree (detrend);
Index: trunk/ppImage/src/ppImageOptions.c
===================================================================
--- trunk/ppImage/src/ppImageOptions.c	(revision 24229)
+++ trunk/ppImage/src/ppImageOptions.c	(revision 24485)
@@ -25,4 +25,5 @@
     options->doNonLin        = false;   // Non-linearity correction
     options->doOverscan      = false;   // Overscan subtraction
+    options->doNoiseMap      = false;   // Apply Read Noise Map
     options->doBias          = false;   // Bias subtraction
     options->doDark          = false;   // Dark subtraction
@@ -217,4 +218,5 @@
     options->doCrosstalkCorrect = psMetadataLookupBool(NULL, recipe, "CROSSTALK.CORRECT");
 
+    options->doNoiseMap = psMetadataLookupBool(NULL, recipe, "NOISEMAP");
     options->doBias = psMetadataLookupBool(NULL, recipe, "BIAS");
     options->doDark = psMetadataLookupBool(NULL, recipe, "DARK");
@@ -278,5 +280,5 @@
 
     // even if not requested explicitly, if any of these are set, build an internal mask and variance:
-    if (options->doBias || options->doOverscan || options->doDark || options->doShutter || options->doFlat ||
+    if (options->doNoiseMap || options->doBias || options->doOverscan || options->doDark || options->doShutter || options->doFlat ||
         options->doPhotom) {
         options->doMaskBuild = true;
Index: trunk/ppImage/src/ppImageParseCamera.c
===================================================================
--- trunk/ppImage/src/ppImageParseCamera.c	(revision 24229)
+++ trunk/ppImage/src/ppImageParseCamera.c	(revision 24485)
@@ -25,4 +25,12 @@
     // otherwise they revert to the config information
     // not all input or output images are used in a given recipe
+    if (options->doNoiseMap) {
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.NOISEMAP", "NOISEMAP",
+                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS /* NOISEMAP */)) {
+            psError(PS_ERR_IO, false, "Can't find a noise map image source");
+            psFree(options);
+            return NULL;
+        }
+    }
     if (options->doBias) {
         if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.BIAS", "BIAS",
@@ -48,30 +56,4 @@
             return NULL;
         }
-
-#if 0
-        // I think this is now done automatically in the pmFPAfileDefine and pmFPAfileIOChecks -- PAP.
-
-        // XXX have ppImageDefineFile return the pmFPAfile?
-        pmFPAfile *mask = psMetadataLookupPtr(&status, config->files, "PPIMAGE.MASK");
-        psAssert(mask, "Just defined the mask!");
-
-        // Need to read the names of bit masks from the mask header and set them in the
-        // recipe.  If we are loading this from the detrend db, this action will happen
-        // when the file is resolved.
-        if (!mask->detrend) {
-            // XXX need to load the mask bit names from one of the headers
-            // this grabs the first available hdu : no guarantee that it will be valid, though
-            pmHDU *hdu = pmHDUGetFirst(mask->fpa);
-            if (!hdu) {
-                psError(PS_ERR_IO, true, "no valid HDU for PPIMAGE.INPUT.MASK");
-                return NULL;
-            }
-            // XXX is this consistent with the pmConfigMaskReadHeader call above?
-            if (!pmConfigMaskReadHeader(config, hdu->header)) {
-                psError(PS_ERR_IO, false, "error in mask bits");
-                return NULL;
-            }
-        }
-#endif
     }
     if (options->doShutter) {
