Index: /branches/eam_branches/ipp-20110213/psphot/src/models/pmModel_STRAIL.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/models/pmModel_STRAIL.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/models/pmModel_STRAIL.c	(revision 30975)
@@ -496,5 +496,5 @@
 
     params[PM_PAR_SKY]  = Smoments->Sky;
-    params[PM_PAR_I0]   = peak->flux;
+    params[PM_PAR_I0]   = peak->rawFlux;
     params[PM_PAR_XPOS] = peak->xf;
     params[PM_PAR_YPOS] = peak->yf;
Index: /branches/eam_branches/ipp-20110213/psphot/src/models/pmModel_TEST1.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/models/pmModel_TEST1.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/models/pmModel_TEST1.c	(revision 30975)
@@ -139,5 +139,5 @@
 
     PAR[PM_PAR_SKY] = moments->Sky;
-    PAR[PM_PAR_I0]   = peak->flux;
+    PAR[PM_PAR_I0]   = peak->rawFlux;
     PAR[PM_PAR_XPOS] = peak->xf;
     PAR[PM_PAR_YPOS] = peak->yf;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphot.h
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphot.h	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphot.h	(revision 30975)
@@ -182,5 +182,5 @@
 // used by psphotFindDetections
 pmReadout      *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, psImageMaskType maskVal);
-psArray        *psphotFindPeaks (psImage *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax);
+psArray        *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax);
 bool            psphotFindFootprints (pmDetections *detections, pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int pass, psImageMaskType maskVal);
 psErrorCode     psphotCullPeaks(const pmReadout *readout, const pmReadout *signifRO, const psMetadata *recipe, psArray *footprints);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotBasicDeblend.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotBasicDeblend.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotBasicDeblend.c	(revision 30975)
@@ -63,5 +63,5 @@
     for (int i = 0; i < SN->n; i++) {
         source = sources->data[i];
-        SN->data.F32[i] = source->peak->SN;
+        SN->data.F32[i] = source->peak->rawFlux;
     }
     psVector *index = psVectorSortIndex (NULL, SN);
@@ -115,5 +115,5 @@
         // threshold is fraction of the source peak flux
         // image is background subtracted; source->moments->Sky should always be 0.0
-        threshold = FRACTION * source->peak->SN;
+        threshold = FRACTION * sqrt(source->peak->detValue);
         // threshold is no less than NSIGMA
         threshold = PS_MAX (threshold, NSIGMA);
@@ -138,5 +138,5 @@
             testSource = overlap->data[k];
 	    if (testSource->mode & PM_SOURCE_MODE_BLEND) continue;
-            if (testSource->peak->value > source->peak->value) continue;
+            if (testSource->peak->rawFlux > source->peak->rawFlux) continue;
             for (int j = 0; j < xv->n; j+=2) {
                 if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotBlendFit.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotBlendFit.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotBlendFit.c	(revision 30975)
@@ -104,5 +104,5 @@
 
     // source analysis is done in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
     if (!sources->n) {
         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
@@ -243,5 +243,5 @@
 
         // limit selection to some SN limit
-        if (source->peak->SN < FIT_SN_LIM) continue;
+        if (sqrt(source->peak->detValue) < FIT_SN_LIM) continue;
 
         // exclude sources outside optional analysis region
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30975)
@@ -70,5 +70,5 @@
 
     // examine PSF sources in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // structure to store user options defining the psf
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotCullPeaks.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotCullPeaks.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotCullPeaks.c	(revision 30975)
@@ -1,5 +1,3 @@
 # include "psphotInternal.h"
-
-# define CULL_WITH_SMOOTHED_IMAGE 1
 
 /*
@@ -63,5 +61,5 @@
     float SAT_THRESHOLD  = 0.05*SATURATION;
 
-# if (CULL_WITH_SMOOTHED_IMAGE)
+# if (PM_PEAKS_CULL_WITH_SMOOTHED_IMAGE)
     psLogMsg ("psphot", PS_LOG_INFO, "Culling peaks from footprints using the smoothed image");
 # else
@@ -81,26 +79,19 @@
 	pmPeak *brightPeak = fp->peaks->data[0];
 	float max_threshold = SAT_TEST_LEVEL;
-	if (brightPeak->flux > SAT_TEST_LEVEL) {
+	if (brightPeak->rawFlux > SAT_TEST_LEVEL) {
 	    max_threshold = SAT_THRESHOLD;
 	    brightPeak->type = PM_PEAK_SUSPECT_SATURATION;
 	}
 
-# if (CULL_WITH_SMOOTHED_IMAGE)
+# if (PM_PEAKS_CULL_WITH_SMOOTHED_IMAGE)
 	// New (post r30869) style of culling using the smoothed image and variance (S/N)
 	// if we cull using the significance image, then the definition of variance is different (thus the bool in arg 8)
-	if (pmFootprintCullPeaks(signifR->image, signifR->variance, fp, nsigma_delta, fPadding, MIN_THRESHOLD, max_threshold, false) != PS_ERR_NONE) {
+	if (pmFootprintCullPeaks(signifR->image, signifR->variance, fp, nsigma_delta, fPadding, MIN_THRESHOLD, max_threshold, true) != PS_ERR_NONE) {
 	    return psError(PS_ERR_UNKNOWN, false, "Culling pmFootprint %d", fp->id);
 	}
 # else 
 	// Old (pre r30869) style of culling using the raw image and variance
-	if (pmFootprintCullPeaks(readout->image, readout->variance, fp, nsigma_delta, fPadding, MIN_THRESHOLD, max_threshold, true) != PS_ERR_NONE) {
+	if (pmFootprintCullPeaks(readout->image, readout->variance, fp, nsigma_delta, fPadding, MIN_THRESHOLD, max_threshold, false) != PS_ERR_NONE) {
 	     return psError(PS_ERR_UNKNOWN, false, "Culling pmFootprint %d", fp->id);
-	}
-# endif
-
-// Alternate style of culling using the smoothed image and raw variance (probably a bad idea)
-# if (0)
-	if (pmFootprintCullPeaks(signifR->image, readout->variance, fp, nsigma_delta, fPadding, MIN_THRESHOLD, max_threshold, true) != PS_ERR_NONE) {
-	    return psError(PS_ERR_UNKNOWN, false, "Culling pmFootprint %d", fp->id);
 	}
 # endif
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotDeblendSatstars.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotDeblendSatstars.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotDeblendSatstars.c	(revision 30975)
@@ -74,5 +74,5 @@
     for (int i = 0; i < SN->n; i++) {
         source = sources->data[i];
-        SN->data.F32[i] = source->peak->SN;
+        SN->data.F32[i] = source->peak->rawFlux;
     }
     psVector *index = psVectorSortIndex (NULL, SN);
@@ -86,5 +86,5 @@
         // XXX filter? if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
         if (source->mode & PM_SOURCE_MODE_BLEND) continue;
-        if (source->peak->flux < SAT_TEST_LEVEL) continue;
+        if (source->peak->rawFlux < SAT_TEST_LEVEL) continue;
 
 	// save these for reference below
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotEllipticalProfile.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotEllipticalProfile.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotEllipticalProfile.c	(revision 30975)
@@ -82,5 +82,5 @@
     // }
 
-    psphotPetrosianVisualProfileRadii (radius, flux, radiusRaw, fluxRaw, source->peak->flux, 0.0);
+    psphotPetrosianVisualProfileRadii (radius, flux, radiusRaw, fluxRaw, source->peak->rawFlux, 0.0);
     // psphotPetrosianVisualProfileByAngle (radius, flux);
 
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceAnalysis.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceAnalysis.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceAnalysis.c	(revision 30975)
@@ -79,5 +79,5 @@
 
     // source analysis is done in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // option to limit analysis to a specific region
@@ -105,5 +105,5 @@
 	// limit selection to some SN limit
 	assert (source->peak); // how can a source not have a peak?
-	if (source->peak->SN < SN_LIM) continue;
+	if (sqrt(source->peak->detValue) < SN_LIM) continue;
 
 	// limit selection by analysis region
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceAnalysisByObject.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceAnalysisByObject.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceAnalysisByObject.c	(revision 30975)
@@ -61,5 +61,5 @@
 
     // source analysis is done in S/N order (brightest first)
-    objects = psArraySort (objects, pmPhotObjSortBySN);
+    objects = psArraySort (objects, pmPhotObjSortByFlux);
 
     // process the objects in order.  
@@ -88,5 +88,5 @@
 	    // limit selection to some SN limit
 	    assert (source->peak); // how can a source not have a peak?
-	    if (source->peak->SN < SN_LIM) continue;
+	    if (sqrt(source->peak->detValue) < SN_LIM) continue;
 	    measureSource = true;
 	}
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c	(revision 30975)
@@ -146,5 +146,5 @@
 
     // source analysis is done in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
@@ -383,5 +383,5 @@
           // limit selection to some SN limit
           assert (source->peak); // how can a source not have a peak?
-          if (source->peak->SN < SNlim) {
+          if (sqrt(source->peak->detValue) < SNlim) {
 	      Nfaint ++;
 	      continue;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotFindDetections.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotFindDetections.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotFindDetections.c	(revision 30975)
@@ -93,5 +93,5 @@
 
     // detect the peaks in the significance image
-    detections->peaks = psphotFindPeaks (significance->variance, readout, recipe, threshold, NMAX);
+    detections->peaks = psphotFindPeaks (significance, readout, recipe, threshold, NMAX);
     psMetadataAddF32  (readout->analysis, PS_LIST_TAIL, "PEAK_THRESHOLD", PS_META_REPLACE, "Peak Detection Threshold", threshold);
     if (!detections->peaks) {
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotFindPeaks.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotFindPeaks.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotFindPeaks.c	(revision 30975)
@@ -4,5 +4,5 @@
 // image must be constructed to represent (S/N)^2.  If nMax is non-zero, only return a maximum
 // of nMax peaks
-psArray *psphotFindPeaks (psImage *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax) {
+psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax) {
 
     bool status = false;
@@ -11,5 +11,6 @@
 
     // find the peaks in the smoothed image
-    psArray *peaks = pmPeaksInImage (significance, threshold);
+    // NOTE : significance->variance actually carries the detection S/N image
+    psArray *peaks = pmPeaksInImage (significance->variance, threshold);
     if (peaks == NULL) {
 	// we only get a NULL peaks array due to a programming or config error. 
@@ -34,12 +35,13 @@
     for (int i = 0; i < peaks->n; i++) {
         pmPeak *peak = peaks->data[i];
-        peak->SN = sqrt(peak->value);
-        peak->flux = readout->image->data.F32[peak->y-row0][peak->x-col0];
-	// if (peak->flux / peak->value > 5.0/12.0) {
-	//     psWarning ("odd peak levels (1)");
-	// }
-	// if (peak->value / peak->flux > 5*12.0) {
-	//     psWarning ("odd peak levels (2)");
-	// }
+        peak->rawFlux = readout->image->data.F32[peak->y-row0][peak->x-col0];
+	peak->rawFluxStdev = sqrt(readout->variance->data.F32[peak->y-row0][peak->x-col0]);
+        peak->smoothFlux = significance->image->data.F32[peak->y-row0][peak->x-col0];
+	peak->smoothFluxStdev = peak->smoothFlux / sqrt(significance->variance->data.F32[peak->y-row0][peak->x-col0]);
+	// NOTE smoothFluxStdev is actually (sqrt(variance) / covar_factor)
+
+	// do we need this or not?
+        // peak->SN = sqrt(peak->detValue);
+
 	if (readout->variance && isfinite (peak->dx)) {
 	    peak->dx *= sqrt(readout->variance->data.F32[peak->y-row0][peak->x-col0]);
@@ -51,5 +53,5 @@
 
     // limit the total number of returned peaks as specified
-    psArraySort (peaks, pmPeakSortBySN);
+    psArraySort (peaks, pmPeaksSortByRawFluxDescend);
     if (nMax && (peaks->n > nMax)) {
 	psArray *tmpPeaks = psArrayAllocEmpty (nMax);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinear.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinear.c	(revision 30975)
@@ -174,5 +174,5 @@
 	if (modelSum < 0.8) {
 	    fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n",
-		     source->peak->xf, source->peak->yf, modelSum, source->peak->flux);
+		     source->peak->xf, source->peak->yf, modelSum, source->peak->rawFlux);
 	}
 
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotGuessModels.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotGuessModels.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotGuessModels.c	(revision 30975)
@@ -176,5 +176,5 @@
 
         // the guess central intensity comes from the peak:
-        float Io = source->peak->flux;
+        float Io = source->peak->rawFlux;
 
         // We have two options to get a guess for the object position: the position from the
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotLoadSRCTEXT.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotLoadSRCTEXT.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotLoadSRCTEXT.c	(revision 30975)
@@ -78,5 +78,6 @@
 
 	    source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE);
-	    source->peak->flux = peakFlux;
+	    source->peak->rawFlux = peakFlux;
+	    source->peak->smoothFlux = peakFlux;
 	    source->peak->dx   = dPAR[PM_PAR_XPOS];
 	    source->peak->dy   = dPAR[PM_PAR_YPOS];
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotMergeSources.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotMergeSources.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotMergeSources.c	(revision 30975)
@@ -111,6 +111,7 @@
 
                 // the supplied peak flux needs to be re-normalized
-                source->peak->flux = 1.0;
-                source->peak->value = 1.0;
+                source->peak->rawFlux = 1.0;
+                source->peak->smoothFlux = 1.0;
+                source->peak->detValue = 1.0;
 
                 // drop the loaded source modelPSF
@@ -282,5 +283,6 @@
     for (int i = 0; i < sources->n; i++) {
       pmSource *source = sources->data[i];
-      source->peak->flux = source->moments->Peak;
+      source->peak->rawFlux = source->moments->Peak;
+      source->peak->smoothFlux = source->moments->Peak;
     }
 
@@ -332,14 +334,9 @@
         float ypos = model->params->data.F32[PM_PAR_YPOS];
 
-        pmPeak *peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
+        pmPeak *peak = pmPeakAlloc(xpos, ypos, flux, PM_PEAK_LONE);
         peak->xf = xpos;
         peak->yf = ypos;
-        peak->flux = flux; // this are being set wrong, but does it matter?
-
-        if (isfinite (source->errMag) && (source->errMag > 0.0)) {
-          peak->SN = 1.0 / source->errMag;
-        } else {
-          peak->SN = 0.0;
-        }
+        peak->rawFlux = flux; // this are being set wrong, but does it matter?
+        peak->smoothFlux = flux; // this are being set wrong, but does it matter?
 
         psArrayAdd (detections->peaks, 100, peak);
@@ -383,14 +380,9 @@
         float ypos = model->params->data.F32[PM_PAR_YPOS];
 
-        pmPeak *peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
+        pmPeak *peak = pmPeakAlloc(xpos, ypos, flux, PM_PEAK_LONE);
         peak->xf = xpos;
         peak->yf = ypos;
-        peak->flux = flux; // this are being set wrong, but does it matter?
-
-        if (isfinite (source->errMag) && (source->errMag > 0.0)) {
-          peak->SN = 1.0 / source->errMag;
-        } else {
-          peak->SN = 0.0;
-        }
+        peak->rawFlux = flux; // this are being set wrong, but does it matter?
+        peak->smoothFlux = flux; // this are being set wrong, but does it matter?
 
         source->peak = peak;
@@ -686,7 +678,7 @@
 	objectsOut->data[k] = objectOut;
 
-	objectOut->SN = objectSrc->SN;
-	objectOut->x  = objectSrc->x;
-	objectOut->y  = objectSrc->y;
+	objectOut->flux = objectSrc->flux;
+	objectOut->x    = objectSrc->x;
+	objectOut->y    = objectSrc->y;
 	
 	objectOut->sources = psArrayAlloc(objectSrc->sources->n);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotMosaicSubimage.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotMosaicSubimage.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotMosaicSubimage.c	(revision 30975)
@@ -29,5 +29,5 @@
     inRegion = psRegionForImage (inImage, inRegion);
 
-    float peak = source->peak->flux;
+    float peak = source->peak->rawFlux;
 
     psImage *subImage = psImageSubset (inImage, inRegion);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotOutput.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotOutput.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotOutput.c	(revision 30975)
@@ -70,5 +70,5 @@
 	// float mpeak = model ? model->params->data.F32[PM_PAR_I0] : NAN;
 	// bool subtracted = source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED;
-	// fprintf (stderr, "%d %d : %d : %f %f : %f %f\n", source->peak->x, source->peak->y, subtracted, source->peak->flux, source->pixels->data.F32[yc][xc], mcore, mpeak); 
+	// fprintf (stderr, "%d %d : %d : %f %f : %f %f\n", source->peak->x, source->peak->y, subtracted, source->peak->rawFlux, source->pixels->data.F32[yc][xc], mcore, mpeak); 
 
 	fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n",
@@ -436,5 +436,5 @@
         if (!source->moments) continue;
 
-        float Io = source->peak->flux;
+        float Io = source->peak->rawFlux;
 
 	fprintf (f, "%f %f : %f %f :: %f\n", 
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotPetrosianAnalysis.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotPetrosianAnalysis.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotPetrosianAnalysis.c	(revision 30975)
@@ -29,5 +29,5 @@
 
     // source analysis is done in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // choose the sources of interest
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialApertures.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialApertures.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialApertures.c	(revision 30975)
@@ -79,5 +79,5 @@
     // source analysis is done in S/N order (brightest first)
     // XXX are we getting the objects out of order? does it matter?
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // option to limit analysis to a specific region
@@ -99,5 +99,5 @@
 	// limit selection to some SN limit
 	assert (source->peak); // how can a source not have a peak?
-	if (source->peak->SN < SN_LIM) continue;
+	if (sqrt(source->peak->detValue) < SN_LIM) continue;
 
 	// limit selection by analysis region
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialAperturesByObject.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialAperturesByObject.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialAperturesByObject.c	(revision 30975)
@@ -60,5 +60,5 @@
     
     // source analysis is done in S/N order (brightest first)
-    objects = psArraySort (objects, pmPhotObjSortBySN);
+    objects = psArraySort (objects, pmPhotObjSortByFlux);
 
     // generate look-up arrays for readouts
@@ -106,5 +106,5 @@
 	    // limit selection to some SN limit
 	    assert (source->peak); // how can a source not have a peak?
-	    if (source->peak->SN < SN_LIM) continue;
+	    if (sqrt(source->peak->detValue) < SN_LIM) continue;
 
 	    int index = source->imageID;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialProfile.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialProfile.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotRadialProfile.c	(revision 30975)
@@ -14,5 +14,5 @@
     float Rmax = 200;
     float fluxMin = 0.0;
-    float fluxMax = source->peak->flux;
+    float fluxMax = source->peak->rawFlux;
 
     bool RAW_RADIUS = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_RAW_RADIUS");
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotReplaceUnfit.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotReplaceUnfit.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotReplaceUnfit.c	(revision 30975)
@@ -239,5 +239,5 @@
       if (isPSF || model->isPCM) {
 	  // the guess central intensity comes from the peak:
-	  float Io = source->peak->flux;
+	  float Io = source->peak->rawFlux;
 	  float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
 	  float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSavePSFStars.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSavePSFStars.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSavePSFStars.c	(revision 30975)
@@ -17,5 +17,5 @@
 
     // examine PSF sources in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // counters to track the size of the image and area used in a row
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceFits.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceFits.c	(revision 30975)
@@ -51,5 +51,5 @@
     psArrayAdd (sourceSet, 16, source);
 
-    psTrace ("psphot", 4, "fitting blended source at %f %f : %f\n", source->peak->xf, source->peak->yf, source->peak->flux);
+    psTrace ("psphot", 4, "fitting blended source at %f %f : %f\n", source->peak->xf, source->peak->yf, source->peak->rawFlux);
 
     // we need to include all blends in the fit (unless primary is saturated?)
@@ -69,5 +69,5 @@
 
         // XXX assume local sky is 0.0?
-        model->params->data.F32[PM_PAR_I0] = blend->peak->flux;
+        model->params->data.F32[PM_PAR_I0] = blend->peak->rawFlux;
         model->params->data.F32[PM_PAR_XPOS] = blend->peak->xf;
         model->params->data.F32[PM_PAR_YPOS] = blend->peak->yf;
@@ -83,5 +83,5 @@
         psArrayAdd (sourceSet, 16, blend);
 
-	psTrace ("psphot", 5, "adding source at %f %f : %f\n", blend->peak->xf, blend->peak->yf, blend->peak->flux);
+	psTrace ("psphot", 5, "adding source at %f %f : %f\n", blend->peak->xf, blend->peak->yf, blend->peak->rawFlux);
 
         // free to avoid double counting model
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceMatch.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceMatch.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceMatch.c	(revision 30975)
@@ -233,6 +233,6 @@
 	    float peakFlux = readout->image->data.F32[(int)(obj->y-row0-0.5)][(int)(obj->x-col0-0.5)];
 	    pmPeak *peak = pmPeakAlloc(obj->x, obj->y, peakFlux, PM_PEAK_LONE);
-	    peak->flux = peakFlux;
-	    peak->SN = 1.0;
+	    peak->rawFlux = peakFlux;
+	    peak->smoothFlux = peakFlux;
 	    peak->xf = obj->x;
 	    peak->yf = obj->y;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourcePlots.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourcePlots.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourcePlots.c	(revision 30975)
@@ -18,5 +18,5 @@
 
     // examine PSF sources in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // counters to track the size of the image and area used in a row
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceSize.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceSize.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceSize.c	(revision 30975)
@@ -1268,5 +1268,5 @@
 
         // Soften variances (add systematic error)
-        float softening = options->soft * PS_SQR(source->peak->flux); // Softening for variances
+        float softening = options->soft * PS_SQR(source->peak->rawFlux); // Softening for variances
 
         // Across the middle: y = 0
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c	(revision 30975)
@@ -398,5 +398,5 @@
 
         // skip faint sources for moments measurement
-        if (source->peak->SN < MIN_SN) {
+        if (sqrt(source->peak->detValue) < MIN_SN) {
             source->mode |= PM_SOURCE_MODE_BELOW_MOMENTS_SN;
             Nfaint++;
@@ -494,6 +494,6 @@
     int   Nout[NSIGMA]; // number of stars found in clump : use this to control the number of regions measured by psphotRoughClass
 
-    // this sorts by peak->SN
-    sources = psArraySort (sources, pmSourceSortBySN);
+    // this sorts by peak->rawFlux
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // loop over radii:
@@ -508,5 +508,5 @@
 
             // skip faint sources for moments measurement
-            if (source->peak->SN < MIN_SN) {
+            if (sqrt(source->peak->detValue) < MIN_SN) {
                 continue;
             }
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotStackMatchPSFsUtils.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotStackMatchPSFsUtils.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotStackMatchPSFsUtils.c	(revision 30975)
@@ -64,5 +64,5 @@
         }
 	if (!source->peak) continue;
-	if (source->peak->SN < SN_MIN) continue;
+	if (sqrt(source->peak->detValue) < SN_MIN) continue;
         coordsFromSource(&x->data.F32[numGood], &y->data.F32[numGood], source);
         numGood++;
@@ -81,5 +81,5 @@
         }
 	if (!source->peak) continue;
-	if (source->peak->SN < SN_MIN) continue;
+	if (sqrt(source->peak->detValue) < SN_MIN) continue;
         float xSource, ySource;         // Coordinates of source
         coordsFromSource(&xSource, &ySource, source);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotTestPSF.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotTestPSF.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotTestPSF.c	(revision 30975)
@@ -17,5 +17,5 @@
 
     // examine PSF sources in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // array to store candidate PSF stars
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c	(revision 30975)
@@ -1029,5 +1029,5 @@
 
     // examine PSF sources in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // counters to track the size of the image and area used in a row
@@ -1181,5 +1181,5 @@
 
     // examine PSF sources in S/N order (brightest first)
-    sources = psArraySort (sources, pmSourceSortBySN);
+    sources = psArraySort (sources, pmSourceSortByFlux);
 
     // counters to track the size of the image and area used in a row
Index: /branches/eam_branches/ipp-20110213/psphot/test/tap_psphot_forced.pro
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/test/tap_psphot_forced.pro	(revision 30974)
+++ /branches/eam_branches/ipp-20110213/psphot/test/tap_psphot_forced.pro	(revision 30975)
@@ -134,6 +134,6 @@
 
   # create the chip output
-  echo ppImage $ppImageConfig -file $basename.fits $basename
-  exec ppImage $ppImageConfig -file $basename.fits $basename
+  echo ppImage $ppImageConfig -file $basename.fits $basename -seed 12345
+  exec ppImage $ppImageConfig -file $basename.fits $basename -seed 12345
 end
 
@@ -158,5 +158,5 @@
   $forcedOpt = $forcedOpt -psf $basename.psf
   $forcedOpt = $forcedOpt -srctext $basename.$2.frc.dat
-  exec psphotForced $forcedOpt $basename.$2.frc
+  exec psphotForced $forcedOpt $basename.$2.frc -seed 12345
 end
 
