Index: /trunk/psphot/src/psphotEnsemblePSF.c
===================================================================
--- /trunk/psphot/src/psphotEnsemblePSF.c	(revision 9833)
+++ /trunk/psphot/src/psphotEnsemblePSF.c	(revision 9834)
@@ -141,4 +141,5 @@
     psSparse *sparse = psSparseAlloc (models->n, 100);
     psVector *weight = psVectorAlloc (models->n, PS_TYPE_F32);
+    psVector *errors = psVectorAlloc (models->n, PS_TYPE_F32);
 
     for (int i = 0; i < models->n; i++) {
@@ -150,4 +151,12 @@
         r = pmSourceCrossProduct (Mi, Mi, CONSTANT_PHOTOMETRIC_WEIGHTS);
         weight->data.F32[i] = r;
+
+	// the formal error depends on the weighting scheme
+	if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
+	    float var = pmSourceCrossProduct (Mi, Mi, false);
+	    errors->data.F32[i] = 1.0 / sqrt(var);
+	} else {
+	    errors->data.F32[i] = 1.0 / sqrt(r);
+	}
 
         psSparseMatrixElement (sparse, i, i, 1.0);
@@ -200,6 +209,8 @@
         }
         Fi->modelPSF->params->data.F32[PM_PAR_I0] = norm->data.F32[i];
-        Fi->modelPSF->dparams->data.F32[PM_PAR_I0] = sqrt(sqrt(2) * norm->data.F32[i] / (sparse->Bfj->data.F32[i] * weight->data.F32[i]));
+	// XXX I was using this before, but it is not strictly accurate
         // XXX EAM : this factor of sqrt(2) makes the errors consistent, but I don't understand it
+        // Fi->modelPSF->dparams->data.F32[PM_PAR_I0] = sqrt(sqrt(2) * norm->data.F32[i] / (sparse->Bfj->data.F32[i] * weight->data.F32[i]));
+        Fi->modelPSF->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i];
 
         // subtract object
@@ -228,4 +239,5 @@
     psFree (norm);
     psFree (weight);
+    psFree (errors);
 
     psLogMsg ("psphot.emsemble", 3, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot"));
Index: /trunk/psphot/src/psphotFindPeaks.c
===================================================================
--- /trunk/psphot/src/psphotFindPeaks.c	(revision 9833)
+++ /trunk/psphot/src/psphotFindPeaks.c	(revision 9834)
@@ -29,6 +29,8 @@
 
     // XXX make this a user-option?
-    // psphotSaveImage (NULL, smooth_im, "imsmooth.fits");
-    // psphotSaveImage (NULL, smooth_wt, "wtsmooth.fits");
+    if (psTraceGetLevel("psphot") > 5) {
+	psphotSaveImage (NULL, smooth_im, "imsmooth.fits");
+	psphotSaveImage (NULL, smooth_wt, "wtsmooth.fits");
+    }
 
     psTimerStart ("psphot");
