Index: trunk/psModules/src/objects/pmPSFtryModel.c
===================================================================
--- trunk/psModules/src/objects/pmPSFtryModel.c	(revision 25819)
+++ trunk/psModules/src/objects/pmPSFtryModel.c	(revision 26260)
@@ -72,9 +72,5 @@
     }
 
-    // XXX set the min number of needed source more carefully (depends on psfTrendMode?)
-    int orderMax = PS_MAX (options->psfTrendNx, options->psfTrendNy);
-    if ((sources->n < 15) && (orderMax >= 3)) orderMax = 2;
-    if ((sources->n < 11) && (orderMax >= 2)) orderMax = 1;
-    if ((sources->n <  8) && (orderMax >= 1)) orderMax = 0;
+    // hard limit on minimum number of stars
     if ((sources->n <  3)) {
         psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
@@ -82,11 +78,23 @@
     }
 
-    int orderMin;
+    // this is a bit tricky, because we have two cases (MAP vs POLY), and they have a different 
+    // definition for 'order' (order_MAP = order_POLY + 1).  in addition, we have a 
+    // user-specified MAX order, which we should respect, regardless of the mode
+
+    // set the max order (0 = constant) which the number of psf stars can support:
+    // rule of thumb: require 3 stars per 'cell' (order+1)^2
+    int MaxOrderForStars = 0;
+    if (sources->n >= 12) MaxOrderForStars = 1; // 4 cells
+    if (sources->n >= 27) MaxOrderForStars = 2; // 9 cells
+    if (sources->n >= 48) MaxOrderForStars = 3; // 16 cells
+    if (sources->n >  75) MaxOrderForStars = 4; // 25 cells
+
+    int orderMax = PS_MAX (options->psfTrendNx, options->psfTrendNy);
+    int orderMin = 0;
     if (options->psfTrendMode == PM_TREND_MAP) {
-        orderMin = 1;
-        orderMax = PS_MAX(orderMax, 1);
-    } else {
-        orderMin = 0;
-    }
+	MaxOrderForStars ++;
+	orderMin ++;
+    }
+    orderMax = PS_MIN (orderMax, MaxOrderForStars);
 
     // save the raw source mask (generated by pmPSFtryFitEXT)
