Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30752)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30753)
@@ -335,4 +335,7 @@
         return NULL;
     }
+
+    // XXX does this work here?
+    psphotVisualShowPSFStars (recipe, try->psf, try->sources);
 
     // build the flux-to-magnitude conversion information
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotGuessModels.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotGuessModels.c	(revision 30752)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotGuessModels.c	(revision 30753)
@@ -160,4 +160,8 @@
         pmSource *source = sources->data[i];
 
+        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) {
+	    fprintf (stderr, "moment failure\n");
+	}
+
         // this is used to mark sources for which the model is measured. We check later that
         // all are used.
@@ -187,5 +191,5 @@
         useMoments = (useMoments && source->moments);          // can't if there are no moments
         useMoments = (useMoments && source->moments->nPixels); // can't if the moments were not measured
-        useMoments = (useMoments && !(source->mode && PM_SOURCE_MODE_MOMENTS_FAILURE)); // can't if the moments failed...
+        useMoments = (useMoments && !(source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE)); // can't if the moments failed...
 
         float Xo, Yo;
@@ -198,4 +202,11 @@
         }
 
+	if (source->mode & PM_SOURCE_MODE_SATSTAR) {
+	    fprintf (stderr, "satstar: %f,%f vs %f,%f : %c\n", 
+		     source->moments->Mx, source->moments->My, 
+		     source->peak->xf, source->peak->yf,
+		     (useMoments ? 'T' : 'F'));
+	}
+
         // set PSF parameters for this model (apply 2D shape model to coordinates Xo, Yo)
         pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c	(revision 30752)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c	(revision 30753)
@@ -122,4 +122,8 @@
         // allocate space for moments
         source->moments = pmMomentsAlloc();
+
+        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) {
+	    fprintf (stderr, "moment failure\n");
+	}
 
         // allocate image, weight, mask arrays for each peak (square of radius OUTER)
@@ -361,5 +365,4 @@
 
     bool status = false;
-    float BIG_RADIUS;
     psScalar *scalar = NULL;
 
@@ -415,4 +418,8 @@
             continue;
         }
+
+	if (source->mode & PM_SOURCE_MODE_SATSTAR) {
+	    fprintf (stderr, "satstar: %f,%f\n", source->peak->xf, source->peak->yf);
+	}
 
         // measure basic source moments (no S/N clipping on input pixels)
@@ -431,14 +438,30 @@
 	    psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
 	}	    
-        if (status) {
+        if (status && (source->moments->Mrf < 2.0*SIGMA)) {
             Nmoments ++;
             continue;
         }
 
-        // if no valid pixels, or massive swing, likely saturated source,
+        // if no valid pixels, massive swing or very large Mrf, likely saturated source,
         // try a much larger box
-        BIG_RADIUS = PS_MIN (INNER, 3*RADIUS);
+        float BIG_RADIUS = 3.0*RADIUS;
+        float BIG_SIGMA  = 3.0*SIGMA;
+
+	{ 
+	    // NOTE this is slightly sleazy, but only slightly: pmSourceRedefinePixels uses the readout
+	    // to pass the pointers to the parent image data.  I guess the API could be simplified:
+	    // we could recover this from the source in the function
+
+	    pmReadout tmpReadout;
+	    tmpReadout.image    = (psImage *)source->pixels->parent;
+	    tmpReadout.mask     = (psImage *)source->maskView->parent;
+	    tmpReadout.variance = (psImage *)source->variance->parent;
+
+	    // re-allocate image, weight, mask arrays for each peak (square of radius OUTER)
+	    pmSourceRedefinePixels (source, &tmpReadout, source->peak->x, source->peak->y, BIG_RADIUS + 2);
+	}
+
         psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
-        status = pmSourceMoments (source, BIG_RADIUS, 3.0*SIGMA, 0.0, maskVal);
+        status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, maskVal);
         if (status) {
             source->mode |= PM_SOURCE_MODE_BIG_RADIUS;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c	(revision 30752)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c	(revision 30753)
@@ -218,5 +218,5 @@
 }
 
-bool psphotVisualScaleImage (int kapaFD, psImage *inImage, psImage *inMask, const char *name, int channel) {
+bool psphotVisualScaleImage (int kapaFD, psImage *inImage, psImage *inMask, const char *name, float factor, int channel) {
 
     KiiImage image;
@@ -239,6 +239,8 @@
     strcpy (data.name, name);
     strcpy (data.file, name);
-    data.zero = stats->robustMedian - stats->robustStdev;
-    data.range = 5*stats->robustStdev;
+    data.zero = stats->robustMedian - factor*stats->robustStdev;
+
+    // XXX I we have a smoothed image, this make a much-too-tight display range
+    data.range = 5*factor*stats->robustStdev;
     data.logflux = 0;
 
@@ -283,7 +285,12 @@
     if (kapa == -1) return false;
 
+    float factor = 1.0;
+    if (readout->covariance) {
+	factor = psImageCovarianceFactorForAperture(readout->covariance, 10.0);
+    }
+
     psphotVisualShowMask (kapa, readout->mask, "mask", 2);
-    psphotVisualScaleImage (kapa, readout->variance, readout->mask, "variance", 1);
-    psphotVisualScaleImage (kapa, readout->image, readout->mask, "image", 0);
+    psphotVisualScaleImage (kapa, readout->variance, readout->mask, "variance", 1.0, 1);
+    psphotVisualScaleImage (kapa, readout->image, readout->mask, "image", sqrt(factor), 0);
 
     pmVisualAskUser(NULL);
@@ -303,6 +310,11 @@
     pmReadout *backgnd = READOUT_OR_INTERNAL(view, file);
 
-    psphotVisualScaleImage (kapa, backgnd->image, readout->mask, "backgnd", 2);
-    psphotVisualScaleImage (kapa, readout->image, readout->mask, "backsub", 0);
+    float factor = 1.0;
+    if (readout->covariance) {
+	factor = psImageCovarianceFactorForAperture(readout->covariance, 10.0);
+    }
+
+    psphotVisualScaleImage (kapa, backgnd->image, readout->mask, "backgnd", 1.0, 2);
+    psphotVisualScaleImage (kapa, readout->image, readout->mask, "backsub", sqrt(factor), 0);
 
     pmVisualAskUser(NULL);
@@ -1221,5 +1233,5 @@
     }
 
-    psphotVisualScaleImage (myKapa, outsat, NULL, "satstar", 2);
+    psphotVisualScaleImage (myKapa, outsat, NULL, "satstar", 1.0, 2);
 
     pmVisualAskUser(NULL);
@@ -2490,9 +2502,14 @@
     if (myKapa == -1) return false;
 
+    float factor = 1.0;
+    if (readout->covariance) {
+	factor = psImageCovarianceFactorForAperture(readout->covariance, 10.0);
+    }
+
     if (reshow) {
 	psphotVisualShowMask (myKapa, readout->mask, "mask", 2);
-	psphotVisualScaleImage (myKapa, readout->variance, readout->mask, "variance", 1);
-    }
-    psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", 0);
+	psphotVisualScaleImage (myKapa, readout->variance, readout->mask, "variance", 1.0, 1);
+    }
+    psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", sqrt(factor), 0);
 
     pmVisualAskUser(NULL);
