Index: trunk/psphot/src/psphotMagnitudes.c
===================================================================
--- trunk/psphot/src/psphotMagnitudes.c	(revision 19912)
+++ trunk/psphot/src/psphotMagnitudes.c	(revision 19913)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotMagnitudes(psArray *sources, psMetadata *recipe, pmPSF *psf, pmReadout *background) {
+bool psphotMagnitudes(pmConfig *config, const pmFPAview *view, psArray *sources, psMetadata *recipe, pmPSF *psf) {
 
     bool status = false;
@@ -7,4 +7,12 @@
 
     psTimerStart ("psphot");
+
+    pmReadout *backModel = psphotSelectBackground (config, view);
+    pmReadout *backStdev = psphotSelectBackgroundStdev (config, view);
+
+    // XXX require that we have a background model, or
+    // allow it to be missing, setting local sky to 0.0?
+    PS_ASSERT (backModel, false);
+    PS_ASSERT (backStdev, false);
 
     // bit-masks to test for good/bad pixels
@@ -20,8 +28,4 @@
 
     pmSourceMagnitudesInit (recipe);
-
-    // XXX require that we have a background model, or
-    // allow it to be missing, setting local sky to 0.0?
-    PS_ASSERT (background, false);
 
     // the binning details are saved on the analysis metadata
@@ -41,6 +45,13 @@
         if (status) Nap ++;
 
-        source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, background->image, binning);
+        source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning);
         if (isnan(source->sky) && false) {
+          psError(PSPHOT_ERR_SKY, false, "Setting pmSource.sky");
+          psErrorStackPrint(NULL, " ");
+          psErrorClear();
+        }
+
+        source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning);
+        if (isnan(source->skyErr) && false) {
           psError(PSPHOT_ERR_SKY, false, "Setting pmSource.sky");
           psErrorStackPrint(NULL, " ");
