Index: branches/simmosaic_branches/psphot/src/psphotFindFootprints.c
===================================================================
--- branches/simmosaic_branches/psphot/src/psphotFindFootprints.c	(revision 24860)
+++ branches/simmosaic_branches/psphot/src/psphotFindFootprints.c	(revision 27839)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const int pass, psImageMaskType maskVal) {
+bool psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int pass, psImageMaskType maskVal) {
 
     bool status;
@@ -9,17 +9,4 @@
     int npixMin = psMetadataLookupS32(&status, recipe, "FOOTPRINT_NPIXMIN");
     PS_ASSERT (status, false);
-
-    float FOOTPRINT_NSIGMA_LIMIT;
-    if (pass == 1) {
-        FOOTPRINT_NSIGMA_LIMIT = psMetadataLookupS32(&status, recipe, "FOOTPRINT_NSIGMA_LIMIT");
-    } else {
-        FOOTPRINT_NSIGMA_LIMIT = psMetadataLookupS32(&status, recipe, "FOOTPRINT_NSIGMA_LIMIT_2");
-    }
-    PS_ASSERT (status, false);
-
-    // XXX do we need to use the same threshold here as for peaks?  does it make sense for
-    // these to be different?
-
-    float threshold = PS_SQR(FOOTPRINT_NSIGMA_LIMIT);
 
     int growRadius = 0;
@@ -54,7 +41,5 @@
     if (pass == 2) {
         // merge in old peaks;
-        const int includePeaks = 0x0 | 0x2; // i.e. just from newFootprints
-
-        // XXX EAM : still not sure I understand this: are we double-couning or undercounting peaks
+        const int includePeaks = 0x1 | 0x2; // i.e. both new and old footprints
 
         psArray *mergedFootprints = pmFootprintArraysMerge(detections->footprints, footprints, includePeaks);
@@ -63,4 +48,6 @@
         psFree(footprints);
         psFree(detections->footprints);
+
+	// replace the merged footprints on the detection structure
         detections->footprints = mergedFootprints;
     } else {
@@ -68,5 +55,5 @@
     }
 
-    psphotCullPeaks(readout->image, readout->variance, recipe, detections->footprints);
+    psphotCullPeaks(readout, recipe, detections->footprints);
     detections->peaks = pmFootprintArrayToPeaks(detections->footprints);
     psLogMsg ("psphot", PS_LOG_INFO, "%ld peaks, %ld total footprints: %f sec\n", detections->peaks->n, detections->footprints->n, psTimerMark ("psphot.footprints"));
@@ -74,2 +61,17 @@
     return detections;
 }
+
+bool psphotCheckFootprints (pmDetections *detections) {
+
+    // check for messed up footprints in the old peaks
+    for (int i = 0; i < detections->oldPeaks->n; i++) {
+	pmPeak *peak = detections->oldPeaks->data[i];
+	pmFootprint *footprint = peak->footprint;
+	if (!footprint) continue;
+	for (int j = 0; j < footprint->spans->n; j++) {
+	    pmSpan *sp = footprint->spans->data[j];
+	    psAssert (sp, "missing span");
+	}
+    }
+    return true;
+}
