Index: branches/eam_branches/ipp-20100823/psphot/doc/notes.20100715.txt
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/doc/notes.20100715.txt	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/doc/notes.20100715.txt	(revision 29124)
@@ -1,2 +1,18 @@
+
+2010.08.24
+
+  Remaining work to be done:
+
+  * test and turn on CR masking
+  * double-check source size analysis:
+    * are we doing the right thing with sources flagged as bad in 'rough'?
+    * are we doing the right thing for SAT, CR, EXT, PSF after SourceSize?
+  * convert CR_SIGMA and EXT_SIGMA to probabilities
+  * example results of model fits vs fake inputs
+  * what is the right solution for the stack PSF photometry?
+    * Nigel sees 4-6%
+    * we see 1.9% at the worst
+    * non-poisson errors are clearly better -- check on the chisq values
+    * why is QGAUSS so good for the one example (better for poisson, if trendy)
 
 2010.08.12
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotBlendFit.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotBlendFit.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotBlendFit.c	(revision 29124)
@@ -66,8 +66,15 @@
 
     float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance
-    assert (status && isfinite(fitMinTol) && fitMinTol > 0);
+    if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
+	fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance
+	if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
+	    psAbort("PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive");
+	}
+    }
 
     float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance
-    assert (status && isfinite(fitMaxTol) && fitMaxTol > 0);
+    if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) {
+	fitMaxTol = 1.0;
+    }
 
     bool poisson = psMetadataLookupBool(&status, recipe, "POISSON.ERRORS.PHOT.LMM"); // Poisson errors?
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotExtendedSourceAnalysis.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotExtendedSourceAnalysis.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotExtendedSourceAnalysis.c	(revision 29124)
@@ -121,4 +121,6 @@
 	if (source->peak->y > AnalysisRegion.y1) continue;
 
+	// fprintf (stderr, "xsrc: %f, %f : %f\n", source->peak->xf, source->peak->yf, source->peak->SN); 
+
 	// replace object in image
 	if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
@@ -178,4 +180,6 @@
     }
 
+    // fprintf (stderr, "xsrc : tried %ld objects\n", sources->n);
+
     return true;
 }
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotExtendedSourceFits.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotExtendedSourceFits.c	(revision 29124)
@@ -200,5 +200,5 @@
             }
             psFree(job);
-            }
+	}
     }
     psFree (cellGroups);
@@ -270,4 +270,5 @@
 	// set the radius based on the footprint (also sets the mask pixels)
 	if (!psphotSetRadiusFootprint(&radius, readout, source, markVal, 1.0)) {
+	    fprintf (stderr, "skipping (1) %f, %f\n", source->peak->xf, source->peak->yf);
 	    psFree (fitOptions)
 	    return false;
@@ -280,4 +281,5 @@
 	// XXX save the psf-based moments for output
 	if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) {
+	    fprintf (stderr, "skipping (2) %f, %f\n", source->peak->xf, source->peak->yf);
 	    // subtract the best fit from the object, leave local sky
 	    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
@@ -289,8 +291,13 @@
         psImage *modelFluxStart = psMemIncrRefCounter (source->modelFlux);
 	if (!modelFluxStart) {
-	  // XXX raise an error of some kind?
-	  continue;
+	    pmSourceCacheModel (source, maskVal);
+	    modelFluxStart = psMemIncrRefCounter (source->modelFlux);
+	    if (!modelFluxStart) {
+		fprintf (stderr, "skipping (3) %f, %f\n", source->peak->xf, source->peak->yf);
+		// XXX raise an error of some kind?
+		continue;
+	    }
 	}
-
+	
         if (savePics) {
           psphotSaveImage (NULL, readout->image, "image.xp.fits");
@@ -317,4 +324,6 @@
           float SNlim = psMetadataLookupF32 (&status, model, "SNLIM_VALUE");
           assert (status);
+
+	  // fprintf (stderr, "xfit: %f, %f : %f\n", source->peak->xf, source->peak->yf, source->peak->SN); 
 
           // limit selection to some SN limit
@@ -449,4 +458,6 @@
     psFree (fitOptions);
 
+    // fprintf (stderr, "xfit : tried %ld objects\n", sources->n);
+
     // change the value of a scalar on the array (wrap this and put it in psArray.h)
     scalar = job->args->data[7];
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotSourceFits.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotSourceFits.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotSourceFits.c	(revision 29124)
@@ -506,5 +506,5 @@
     // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
     pmSourceFitModel (source, model, &options, maskVal);
-    fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
+    // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
 
     // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
@@ -570,5 +570,5 @@
     // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
     pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
-    fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
+    // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
 
     // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
@@ -613,5 +613,5 @@
 	
 	pmSourceFitModel (source, model, &options, maskVal);
-	fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
+	// fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
 
 	chiSquare[i] = model->chisqNorm;
@@ -681,5 +681,5 @@
 	pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
 # endif
-	fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
+	// fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
 
 	chiSquare[i] = model->chisq;
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotSourceSize.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotSourceSize.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotSourceSize.c	(revision 29124)
@@ -366,7 +366,7 @@
         float nSigmaMYY = (Myy - psfClump->Y) / hypot(psfClump->dY, psfClump->Y*psfClump->Y*source->errMag);
 
-	fprintf (stderr, "%f %f : Mxx: %f, Myy: %f, dx: %f, dy: %f, psfMag: %f, apMag: %f, dMag: %f, errMag: %f, nSigmaMag: %f, nSigmaMxx: %f, nSigmaMyy: %f\n", 
-		 source->peak->xf, source->peak->yf, Mxx, Myy, source->peak->xf - source->moments->Mx, source->peak->yf - source->moments->My, 
-		 source->psfMag, apMag, dMag, source->errMag, nSigmaMAG, nSigmaMXX, nSigmaMYY);
+	// fprintf (stderr, "%f %f : Mxx: %f, Myy: %f, dx: %f, dy: %f, psfMag: %f, apMag: %f, dMag: %f, errMag: %f, nSigmaMag: %f, nSigmaMxx: %f, nSigmaMyy: %f\n", 
+	// source->peak->xf, source->peak->yf, Mxx, Myy, source->peak->xf - source->moments->Mx, source->peak->yf - source->moments->My, 
+	// source->psfMag, apMag, dMag, source->errMag, nSigmaMAG, nSigmaMXX, nSigmaMYY);
 
         // XXX double check on ths stuff!! partially-masked sources are more likely to be mis-measured PSFs
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotStackMatchPSFs.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotStackMatchPSFs.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotStackMatchPSFs.c	(revision 29124)
@@ -106,5 +106,5 @@
     rescaleData(readoutOut, config, options, index);
 
-    dumpImage(readoutOut, readoutSrc, index, "convolved");
+    // dumpImage(readoutOut, readoutSrc, index, "convolved");
 
     return true;
Index: branches/eam_branches/ipp-20100823/psphot/src/psphotStackMatchPSFsUtils.c
===================================================================
--- branches/eam_branches/ipp-20100823/psphot/src/psphotStackMatchPSFsUtils.c	(revision 29016)
+++ branches/eam_branches/ipp-20100823/psphot/src/psphotStackMatchPSFsUtils.c	(revision 29124)
@@ -346,6 +346,6 @@
     if (!fake) goto escape;
 
-    dumpImage(fake, readoutSrc, index, "fake");
-    dumpImage(readoutSrc,  readoutSrc, index, "real");
+    // dumpImage(fake, readoutSrc, index, "fake");
+    // dumpImage(readoutSrc,  readoutSrc, index, "real");
 
     if (threads) pmSubtractionThreadsInit();
@@ -380,6 +380,6 @@
     }
 
-    dumpImage(readoutOut, readoutSrc, index, "conv");
-    dumpImageDiff(readoutOut, fake, readoutSrc, index, "diff");
+    // dumpImage(readoutOut, readoutSrc, index, "conv");
+    // dumpImageDiff(readoutOut, fake, readoutSrc, index, "diff");
 
     psFree(fake);
