Index: trunk/psModules/src/objects/pmPSFtry.c
===================================================================
--- trunk/psModules/src/objects/pmPSFtry.c	(revision 15834)
+++ trunk/psModules/src/objects/pmPSFtry.c	(revision 15842)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-11-28 00:43:27 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-12-15 01:23:18 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -221,16 +221,18 @@
 
     // use 3hi/3lo sigma clipping on the chisq fit
-    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
-    stats->clipSigma = 3.0;
-    stats->clipIter = 3;
+    psStats *stats = options->stats;
 
     // linear clipped fit of chisq trend vs flux
-    bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, stats, mask, 0xff, chisq, NULL, flux);
-    psLogMsg ("pmPSFtry", 4, "chisq vs flux fit: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
-
-    psFree (flux);
-    psFree (stats);
-    psFree (mask);
-    psFree (chisq);
+    bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, options->stats, mask,
+                                              0xff, chisq, NULL, flux);
+    psStatsOptions meanStat = psStatsMeanOption(options->stats->options); // Statistic for mean
+    psStatsOptions stdevStat = psStatsStdevOption(options->stats->options); // Statistic for stdev
+
+    psLogMsg ("pmPSFtry", 4, "chisq vs flux fit: %f +/- %f\n",
+              psStatsGetValue(stats, meanStat), psStatsGetValue(stats, stdevStat));
+
+    psFree(flux);
+    psFree(mask);
+    psFree(chisq);
 
     if (!result) {
@@ -247,5 +249,5 @@
 
     // XXX this function wants aperture radius for pmSourcePhotometry
-    if (!pmPSFtryMetric (psfTry, options->radius)) {
+    if (!pmPSFtryMetric (psfTry, options)) {
         psError(PS_ERR_UNKNOWN, false, "Attempt to fit PSF with model %s failed.", modelName);
         return NULL;
@@ -258,8 +260,11 @@
 }
 
-bool pmPSFtryMetric (pmPSFtry *psfTry, float RADIUS)
+bool pmPSFtryMetric (pmPSFtry *psfTry, pmPSFOptions *options)
 {
     PS_ASSERT_PTR_NON_NULL(psfTry, false);
+    PS_ASSERT_PTR_NON_NULL(options, false);
     PS_ASSERT_PTR_NON_NULL(psfTry->sources, false);
+
+    float RADIUS = options->radius;
 
     // the measured (aperture - fit) magnitudes (dA == psfTry->metric)
@@ -286,9 +291,4 @@
     // linear, constant-error fitting.  Do not reject outliers with excessive vigor here.
 
-    // use 3hi/1lo sigma clipping on the r2rflux vs metric fit
-    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
-    stats->clipSigma = 3.0;
-    stats->clipIter = 3;
-
     // fit ApTrend only to r2rflux, ignore x,y,flux variations for now
     // linear clipped fit of ApResid to r2rflux
@@ -297,5 +297,6 @@
 
     // XXX replace this with a psVectorStats call?  since we are not fitting the trend
-    bool result = psVectorClipFitPolynomial1D (poly, stats, psfTry->mask, PSFTRY_MASK_ALL, psfTry->metric, psfTry->metricErr, r2rflux);
+    bool result = psVectorClipFitPolynomial1D(poly, options->stats, psfTry->mask, PSFTRY_MASK_ALL,
+                                              psfTry->metric, psfTry->metricErr, r2rflux);
     if (!result) {
         psError(PS_ERR_UNKNOWN, false, "Failed to fit clipped poly");
@@ -303,9 +304,12 @@
         psFree(poly);
         psFree(r2rflux);
-        psFree(stats);
 
         return false;
     }
-    psLogMsg ("pmPSFtryMetric", 4, "apresid: %f +/- %f; keeping %ld of %ld psf stars\n", poly->coeff[0], stats->robustStdev, stats->clippedNvalues, psfTry->sources->n);
+    psStatsOptions stdevStat = psStatsStdevOption(options->stats->options); // Statistic for stdev
+    psLogMsg ("pmPSFtryMetric", 4, "apresid: %f +/- %f; from statistics of %ld psf stars\n", poly->coeff[0],
+              psStatsGetValue(options->stats, stdevStat), psfTry->sources->n);
+
+
 
     // XXX test dump of fitted model (dump when tracing?)
@@ -335,9 +339,8 @@
     psfTry->psf->skyBias  = poly->coeff[1];
     psfTry->psf->ApResid  = poly->coeff[0];
-    psfTry->psf->dApResid = stats->robustStdev;
+    psfTry->psf->dApResid = psStatsGetValue(options->stats, stdevStat);
 
     psFree (r2rflux);
     psFree (poly);
-    psFree (stats);
 
     return true;
@@ -720,5 +723,6 @@
     // XXX this is a bit arbitrary, but it forces ~3 stars from the bright bin per spatial bin
     int nGroup = PS_MAX (3*Nx*Ny, 10);
-    pmPSFShapeParamsErrors (errorFloor, mag, e0res, e1res, e2res, mask, nGroup);
+    pmPSFShapeParamsErrors (errorFloor, mag, e0res, e1res, e2res, mask, nGroup,
+                            psStatsStdevOption(psf->psfTrendStats->options));
 
     *errorTotal = sqrt(PS_SQR(*errorFloor) + mapErrorSum);
@@ -739,7 +743,9 @@
 
 // calculate the minimum scatter of the parameters
-bool pmPSFShapeParamsErrors (float *errorFloor, psVector *mag, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, int nGroup) {
-
-    psStats *statsS = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
+bool pmPSFShapeParamsErrors(float *errorFloor, psVector *mag, psVector *e0res, psVector *e1res,
+                            psVector *e2res, psVector *mask, int nGroup, psStatsOptions stdevOpt)
+{
+
+    psStats *statsS = psStatsAlloc(stdevOpt);
 
     // measure the trend in bins with 10 values each; if < 10 total, use them all
@@ -778,13 +784,13 @@
         psStatsInit (statsS);
         psVectorStats (statsS, dE0subset, NULL, mkSubset, 0xff);
-        dEsquare += PS_SQR(statsS->robustStdev);
+        dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
 
         psStatsInit (statsS);
         psVectorStats (statsS, dE1subset, NULL, mkSubset, 0xff);
-        dEsquare += PS_SQR(statsS->robustStdev);
+        dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
 
         psStatsInit (statsS);
         psVectorStats (statsS, dE2subset, NULL, mkSubset, 0xff);
-        dEsquare += PS_SQR(statsS->robustStdev);
+        dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
 
         dSo->data.F32[i] = sqrt(dEsquare);
@@ -795,12 +801,10 @@
     psFree (mkSubset);
 
-    psStats *stats = psStatsAlloc (PS_STAT_MIN);
-    psVectorStats (stats, dSo, NULL, NULL, 0);
-
-    *errorFloor = stats->min;
-
-    psFree (stats);
-    psFree (index);
-
+    psStats *minStats = psStatsAlloc(PS_STAT_MIN);
+    psVectorStats(minStats, dSo, NULL, NULL, 0);
+    *errorFloor = minStats->min;
+    psFree(minStats);
+
+    psFree(index);
     psFree (dSo);
 
Index: trunk/psModules/src/objects/pmPSFtry.h
===================================================================
--- trunk/psModules/src/objects/pmPSFtry.h	(revision 15834)
+++ trunk/psModules/src/objects/pmPSFtry.h	(revision 15842)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-11-27 03:14:57 $
+ * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-12-15 01:23:18 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -99,5 +99,5 @@
 bool pmPSFtryMetric(
     pmPSFtry *psfTry,                  ///< Add comment.
-    float RADIUS                       ///< Add comment.
+    pmPSFOptions *options              ///< PSF fitting options
 );
 
@@ -129,5 +129,5 @@
 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
 bool pmPSFFitShapeParamsMap (pmPSF *psf, int scale, float *errorFloor, float *errorTotal, psVector *mask, psVector *x, psVector *y, psVector *mag, psVector *e0obs, psVector *e1obs, psVector *e2obs, psVector *dz);
-bool pmPSFShapeParamsErrors (float *errorFloor, psVector *mag, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, int nGroup);
+bool pmPSFShapeParamsErrors (float *errorFloor, psVector *mag, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, int nGroup, psStatsOptions stdevOpt);
 
 /// @}
Index: trunk/psModules/src/objects/pmTrend2D.h
===================================================================
--- trunk/psModules/src/objects/pmTrend2D.h	(revision 15834)
+++ trunk/psModules/src/objects/pmTrend2D.h	(revision 15842)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-11-27 03:08:38 $
+ * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-12-15 01:23:18 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -12,4 +12,6 @@
 # ifndef PM_TREND_2D_H
 # define PM_TREND_2D_H
+
+#include <pslib.h>
 
 /// @addtogroup Objects Object Detection / Analysis Functions
@@ -26,5 +28,6 @@
     psPolynomial2D *poly;
     psImageMap *map;
-    psStats *stats;
+    psStats *stats;                     // Statistics for clipped fitting
+    psStatsOptions singleMean, singleStdev; // Staistics for mean and stdev when there's a single pixel
     pmTrend2DMode mode; // POLY_ORD, POLY_CHEB, MAP
 } pmTrend2D;
