Index: trunk/ppImage/src/ppImageReplaceBackground.c
===================================================================
--- trunk/ppImage/src/ppImageReplaceBackground.c	(revision 15944)
+++ trunk/ppImage/src/ppImageReplaceBackground.c	(revision 15945)
@@ -28,7 +28,9 @@
     psMaskType maskVal  = options->satMask | options->badMask | options->flatMask | options->blankMask;
 
+    float meanValue = psMetadataLookupF32 (&status, recipe, "SKY_MEAN");
+
     // iterate over the cells and readout for this chip
     while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
-	psLogMsg ("ppImagePhotom", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+	psLogMsg ("ppImagePhotom", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
 	if (! cell->process || ! cell->file_exists) { continue; }
 
@@ -46,8 +48,12 @@
 	    }
 	    if (!modelReadout) {
-		psphotImageMedian (config, view, maskVal);
+		psphotModelBackground (config, view, "PPIMAGE.CHIP", maskVal);
 		modelFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.BACKMDL");
 		assert (modelFile);
-		modelReadout = pmFPAviewThisReadout (view, modelFile->fpa);
+		if (modelFile->mode == PM_FPA_MODE_INTERNAL) {
+		  modelReadout = modelFile->readout;
+		} else {
+		  modelReadout = pmFPAviewThisReadout (view, modelFile->fpa);
+		}
 		assert (modelReadout);
 	    }
@@ -62,9 +68,15 @@
 		for (int ix = 0; ix < image->numCols; ix++) {
 		    if (!(mask->data.U8[iy][ix] && maskVal)) continue;
-		    image->data.F32[iy][ix] = psImageUnbinPixel_V2(ix, iy, model, binning);
+		    if (1) {
+			image->data.F32[iy][ix] = meanValue;
+		    } else {
+			image->data.F32[iy][ix] = psImageUnbinPixel_V2(ix, iy, model, binning);
+		    }
 		}
 	    }
 	}
     }
+    pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
+    pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
     return true;
 }
