Index: branches/pap/psModules/src/objects/pmSource.c
===================================================================
--- branches/pap/psModules/src/objects/pmSource.c	(revision 23948)
+++ branches/pap/psModules/src/objects/pmSource.c	(revision 25027)
@@ -242,5 +242,4 @@
     extend |= (mySource->maskView == NULL);
 
-    // extend = true;
     if (extend) {
         // re-create the subimage
@@ -250,5 +249,5 @@
 
         mySource->pixels   = psImageSubset(readout->image,  newRegion);
-        mySource->variance   = psImageSubset(readout->variance, newRegion);
+        mySource->variance = psImageSubset(readout->variance, newRegion);
         mySource->maskView = psImageSubset(readout->mask,   newRegion);
         mySource->region   = newRegion;
@@ -291,7 +290,7 @@
 
     bool status = true;                 // Status of MD lookup
-    float PSF_CLUMP_SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_CLUMP_SN_LIM");
+    float PSF_SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_SN_LIM");
     if (!status) {
-        PSF_CLUMP_SN_LIM = 0;
+        PSF_SN_LIM = 0;
     }
     float PSF_CLUMP_GRID_SCALE = psMetadataLookupF32(&status, recipe, "PSF_CLUMP_GRID_SCALE");
@@ -342,5 +341,5 @@
             }
 
-            if (src->moments->SN < PSF_CLUMP_SN_LIM) {
+            if (src->moments->SN < PSF_SN_LIM) {
                 psTrace("psModules.objects", 10, "Rejecting source from clump because of low S/N (%f)\n",
                         src->moments->SN);
@@ -450,5 +449,5 @@
             if (tmpSrc->moments == NULL)
                 continue;
-            if (tmpSrc->moments->SN < PSF_CLUMP_SN_LIM)
+            if (tmpSrc->moments->SN < PSF_SN_LIM)
                 continue;
 
@@ -479,9 +478,15 @@
         stats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
 
-        psVectorStats (stats, tmpSx, NULL, NULL, 0);
+        if (!psVectorStats (stats, tmpSx, NULL, NULL, 0)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to measure Sx stats");
+            return (emptyClump);
+        }
         psfClump.X  = stats->clippedMean;
         psfClump.dX = stats->clippedStdev;
 
-        psVectorStats (stats, tmpSy, NULL, NULL, 0);
+        if (!psVectorStats (stats, tmpSy, NULL, NULL, 0)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to measure Sy stats");
+            return (emptyClump);
+        }
         psfClump.Y  = stats->clippedMean;
         psfClump.dY = stats->clippedStdev;
@@ -528,10 +533,9 @@
     bool status;
     float PSF_SN_LIM = psMetadataLookupF32 (&status, recipe, "PSF_SN_LIM");
-    if (!status)
-        PSF_SN_LIM = 20.0;
+    if (!status) PSF_SN_LIM = 20.0;
     float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");
-    if (!status)
-        PSF_CLUMP_NSIGMA = 1.5;
-    float INNER_RADIUS = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
+    if (!status) PSF_CLUMP_NSIGMA = 1.5;
+
+    // float INNER_RADIUS = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
 
     pmSourceMode noMoments = PM_SOURCE_MODE_MOMENTS_FAILURE | PM_SOURCE_MODE_SKYVAR_FAILURE | PM_SOURCE_MODE_SKY_FAILURE | PM_SOURCE_MODE_BELOW_MOMENTS_SN;
@@ -543,12 +547,12 @@
         pmSource *source = (pmSource *) sources->data[i];
 
-	// psf clumps are found for image subregions:
-	// skip sources not in this region 
+        // psf clumps are found for image subregions:
+        // skip sources not in this region
         if (source->peak->x <  region->x0) continue;
         if (source->peak->x >= region->x1) continue;
         if (source->peak->y <  region->y0) continue;
-	if (source->peak->y >= region->y1) continue;
-
-	// should be set by pmSourceAlloc
+        if (source->peak->y >= region->y1) continue;
+
+        // should be set by pmSourceAlloc
         psAssert (source->type == PM_SOURCE_TYPE_UNKNOWN, "source type was not init-ed?");
 
@@ -556,5 +560,5 @@
         if (!source->moments) {
             source->type = PM_SOURCE_TYPE_STAR;
-	    psAssert (source->mode & noMoments, "why is this source missing moments?");
+            psAssert (source->mode & noMoments, "why is this source missing moments?");
             Nstar++;
             continue;
@@ -576,6 +580,7 @@
             source->type = PM_SOURCE_TYPE_STAR;
             source->mode |= PM_SOURCE_MODE_SATSTAR;
-            // recalculate moments here with larger box?
-            pmSourceMoments (source, INNER_RADIUS);
+            // why do we recalculate moments here?
+	    // we already attempt to do this in psphotSourceStats
+            // pmSourceMoments (source, INNER_RADIUS);
             Nsatstar ++;
             continue;
@@ -590,36 +595,38 @@
         }
 
-        // likely defect (too small to be stellar) (push out to 3 sigma)
-        // low S/N objects which are small are probably stellar
-        // only set candidate defects if
-        // XXX these limits are quite arbitrary
-        if ((sigX < 0.05) || (sigY < 0.05)) {
-            source->type = PM_SOURCE_TYPE_DEFECT;
-            source->mode |= PM_SOURCE_MODE_DEFECT;
-            Ncr ++;
-            continue;
-        }
-
-        // likely unsaturated extended source (too large to be stellar)
-        if ((sigX > (clump.X + 3*clump.dX)) || (sigY > (clump.Y + 3*clump.dY))) {
-            source->type = PM_SOURCE_TYPE_EXTENDED;
-            Next ++;
-            continue;
-        }
-
-        // the rest are probable stellar objects
-        starsn_moments->data.F32[starsn_moments->n] = source->moments->SN;
-        starsn_moments->n ++;
-        starsn_peaks->data.F32[starsn_peaks->n] = source->peak->SN;
-        starsn_peaks->n ++;
-        Nstar ++;
-
-        // PSF star (within 1.5 sigma of clump center, S/N > limit)
-        psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY);
-        if ((source->moments->SN > PSF_SN_LIM) && (radius < PSF_CLUMP_NSIGMA)) {
-            source->type = PM_SOURCE_TYPE_STAR;
-            source->mode |= PM_SOURCE_MODE_PSFSTAR;
-            Npsf ++;
-            continue;
+        // The following determinations require the use of moments
+        if (!(source->mode & noMoments)) {
+            // likely defect (too small to be stellar) (push out to 3 sigma)
+            // low S/N objects which are small are probably stellar
+            // XXX these limits are quite arbitrary
+            if (sigX < 0.05 || sigY < 0.05) {
+                source->type = PM_SOURCE_TYPE_DEFECT;
+                source->mode |= PM_SOURCE_MODE_DEFECT;
+                Ncr ++;
+                continue;
+            }
+
+            // likely unsaturated extended source (too large to be stellar)
+            if (sigX > clump.X + 3*clump.dX || sigY > clump.Y + 3*clump.dY) {
+                source->type = PM_SOURCE_TYPE_EXTENDED;
+                Next ++;
+                continue;
+            }
+
+            // the rest are probable stellar objects
+            starsn_moments->data.F32[starsn_moments->n] = source->moments->SN;
+            starsn_moments->n ++;
+            starsn_peaks->data.F32[starsn_peaks->n] = source->peak->SN;
+            starsn_peaks->n ++;
+            Nstar ++;
+
+            // PSF star (within 1.5 sigma of clump center, S/N > limit)
+            psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY);
+            if ((source->moments->SN > PSF_SN_LIM) && (radius < PSF_CLUMP_NSIGMA)) {
+                source->type = PM_SOURCE_TYPE_STAR;
+                source->mode |= PM_SOURCE_MODE_PSFSTAR;
+                Npsf ++;
+                continue;
+            }
         }
 
@@ -636,6 +643,8 @@
 
         if (!psVectorStats (stats, starsn_moments, NULL, NULL, 0)) {
-            // Don't care about this error
-            psErrorClear();
+            psError(PS_ERR_UNKNOWN, false, "failed to measure SN / moments stats");
+            psFree (stats);
+            psFree (starsn_peaks);
+            return false;
         }
         psLogMsg ("pmObjects", 3, "SN range (moments): %f - %f\n", stats->min, stats->max);
@@ -648,6 +657,8 @@
         stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX);
         if (!psVectorStats (stats, starsn_peaks, NULL, NULL, 0)) {
-            // Don't care about this error
-            psErrorClear();
+            psError(PS_ERR_UNKNOWN, false, "failed to measure SN / moments stats");
+            psFree (stats);
+            psFree (starsn_peaks);
+            return false;
         }
         psLogMsg ("psModules.objects", 3, "SN range (peaks)  : %f - %f (%ld)\n",
