Index: /trunk/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 26916)
+++ /trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 26917)
@@ -152,21 +152,31 @@
         // Test PSF
         {
-            bool goodPSF = true;                                                                // Good PSF?
-            pmModelClassSetLimits(PM_MODEL_LIMITS_IGNORE);
-            pmModel *model = pmModelFromPSFforXY(psf, numCols / 2.0, numRows / 2.0, PEAK_FLUX); // Test model
-            if (!model) {
-                goodPSF = false;
-            } else {
-                model->modelSetLimits(PM_MODEL_LIMITS_MODERATE);
-                for (int j = 0; j < model->params->n && goodPSF; j++) {
-                    if (!model->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) ||
-                        !model->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) {
-                        goodPSF = false;
+            bool goodPSF = false;       // Is there a PSF that we can use?
+            int xNum = PS_MAX(psf->trendNx, 1), yNum = PS_MAX(psf->trendNy, 1); // Number of positions to check
+            for (int j = 0; j < yNum && !goodPSF; j++) {
+                float y = ((float)j + 0.5) / (float)yNum * numRows; // Position on image
+                for (int i = 0; i < xNum && !goodPSF; i++) {
+                    float x = ((float)i + 0.5) / (float)xNum * numCols; // Position on image
+                    pmModelClassSetLimits(PM_MODEL_LIMITS_IGNORE);
+                    pmModel *model = pmModelFromPSFforXY(psf, x, y, PEAK_FLUX); // Test model
+                    if (!model) {
+                        continue;
+                    }
+                    model->modelSetLimits(PM_MODEL_LIMITS_MODERATE);
+                    bool limits = true; // Model within limits?
+                    for (int j = 0; j < model->params->n && limits; j++) {
+                        if (!model->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) ||
+                            !model->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) {
+                            limits = false;
+                        }
+                    }
+                    psFree(model);
+                    if (limits) {
+                        goodPSF = true;
                     }
                 }
-                psFree(model);
             }
             if (!goodPSF) {
-                psWarning("PSF %d is bad --- not including in envelope calculation.", i);
+                psWarning("PSF %d is completely bad --- not including in envelope calculation.", i);
                 continue;
             }
@@ -175,4 +185,5 @@
         pmResiduals *resid = psf->residuals;// PSF residuals
         psf->residuals = NULL;
+        pmModelClassSetLimits(PM_MODEL_LIMITS_MODERATE);
         if (!pmReadoutFakeFromSources(fakeRO, fakeSize, fakeSize, fakes, 0, xOffset, yOffset, psf,
                                       NAN, radius, true, false)) {
@@ -399,5 +410,5 @@
 
     pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, VARIANCE_VAL, true);
-    pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT);
+    pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); // Important for getting a good stack target PSF
 
     pmPSFtry *try = pmPSFtryModel(fakes, modelName, options, 0, 0xff);
