Index: branches/eam_branches/20090522/ppImage/notes.txt
===================================================================
--- branches/eam_branches/20090522/ppImage/notes.txt	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/notes.txt	(revision 24557)
@@ -1,23 +1,15 @@
 
-ppImage pmFPAfiles:
+20090611 : adjusting things to allow the readnoise to be an image map for each cell
 
-    pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");
-    pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.MASK", "INPUT.MASK");
-    pmFPAfile *inputWeight = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.WEIGHT", "INPUT.WEIGHT");
-    pmFPAfile *output = pmFPAfileDefineOutput(config, input->fpa, "PPIMAGE.OUTPUT");
-    pmFPAfile *outMask = pmFPAfileDefineOutput(config, input->fpa, "PPIMAGE.OUTPUT.MASK");
-    pmFPAfile *outWeight = pmFPAfileDefineOutput(config, input->fpa, "PPIMAGE.OUTPUT.WEIGHT");
-    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPIMAGE.CHIP");
-    pmFPAfile *chipMask = pmFPAfileDefineOutput(config, chipImage->fpa, "PPIMAGE.CHIP.MASK");
-    pmFPAfile *chipWeight = pmFPAfileDefineOutput(config, chipImage->fpa, "PPIMAGE.CHIP.WEIGHT");
-    pmFPAfile *byFPA1 = pmFPAfileDefineFPAMosaic(config, input->fpa, "PPIMAGE.OUTPUT.FPA1");
-    pmFPAfile *byFPA2 = pmFPAfileDefineFPAMosaic(config, input->fpa, "PPIMAGE.OUTPUT.FPA2");
+  * pmReadoutSetVaraince : when variance is created, we are suppling a single CELL.READNOISE value -- change this to an optional image (carried through concepts?)
 
-        pmFPAfile *psphotInput = pmFPAfileDefineFromFPA (config, chipImage->fpa, 1, 1, "PSPHOT.INPUT");
-        pmFPAfile *psphotOutput = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
-        pmFPAfile *psastroInput = pmFPAfileDefineInput (config, psphotOutput->fpa, "PSASTRO.INPUT");
+  I need to:
 
-    pmFPAfile *bin1 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin1, options->yBin1, "PPIMAGE.BIN1");
-    pmFPAfile *bin2 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin2, options->yBin2, "PPIMAGE.BIN2");
-    pmFPAfile *jpg1 = pmFPAfileDefineOutput (config, byFPA1->fpa, "PPIMAGE.JPEG1");
-    pmFPAfile *jpg2 = pmFPAfileDefineOutput (config, byFPA2->fpa, "PPIMAGE.JPEG2");
+  * define a format for the readnoise map (image map in SPLIT/MEF format?)
+  * load the readnoise map
+
+  * supply the map for each cell to the pmReadoutSetVariance (pointer to ppImageMap?)
+    pmReadoutSetVariance -> add psImageMap to API (also pmReadoutGenerateVariance)
+
+  * add recipe information to define the source of the READNOISE info.
+
Index: branches/eam_branches/20090522/ppImage/src/ppImage.h
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImage.h	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImage.h	(revision 24557)
@@ -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: branches/eam_branches/20090522/ppImage/src/ppImageArguments.c
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImageArguments.c	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImageArguments.c	(revision 24557)
@@ -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: branches/eam_branches/20090522/ppImage/src/ppImageDetrendFree.c
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImageDetrendFree.c	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImageDetrendFree.c	(revision 24557)
@@ -8,4 +8,5 @@
 static char *detrendTypes[] = {
     "PPIMAGE.MASK",
+    "PPIMAGE.NOISEMAP",
     "PPIMAGE.BIAS",
     "PPIMAGE.DARK",
Index: branches/eam_branches/20090522/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImageDetrendReadout.c	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImageDetrendReadout.c	(revision 24557)
@@ -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: branches/eam_branches/20090522/ppImage/src/ppImageDetrendRecord.c
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImageDetrendRecord.c	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImageDetrendRecord.c	(revision 24557)
@@ -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: branches/eam_branches/20090522/ppImage/src/ppImageOptions.c
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImageOptions.c	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImageOptions.c	(revision 24557)
@@ -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: branches/eam_branches/20090522/ppImage/src/ppImageParseCamera.c
===================================================================
--- branches/eam_branches/20090522/ppImage/src/ppImageParseCamera.c	(revision 24238)
+++ branches/eam_branches/20090522/ppImage/src/ppImageParseCamera.c	(revision 24557)
@@ -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_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) {
