Index: /branches/eam_branches/ipp-20100621/psModules/src/imcombine/pmSubtraction.c
===================================================================
--- /branches/eam_branches/ipp-20100621/psModules/src/imcombine/pmSubtraction.c	(revision 28903)
+++ /branches/eam_branches/ipp-20100621/psModules/src/imcombine/pmSubtraction.c	(revision 28904)
@@ -1223,4 +1223,5 @@
     bool threaded = pmSubtractionThreaded(); // Running threaded?
 
+    // XXX This is no longer used 
     psImage *convMask = NULL;           // Convolved mask image (common to inputs 1 and 2)
     if (subMask) {
Index: /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSource.h	(revision 28903)
+++ /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSource.h	(revision 28904)
@@ -74,10 +74,14 @@
     float errMag;                       ///< error in psfMag OR extMag (depending on type)
     float apMag;                        ///< apMag corresponding to psfMag or extMag (depending on type)
-    float pixWeight;                    ///< model-weighted coverage of valid pixels
+    float apMagRaw;                     ///< raw mag in given aperture
+    float apRadius;			///< radius for aperture magnitude
+
+    float psfWeightNotBad;              ///< PSF-weighted coverage of unmasked (not BAD) pixels
+    float psfWeightNotPoor;             ///< PSF-weighted coverage of unmasked (not POOR) pixels
+
     float psfChisq;                     ///< probability of PSF
     float crNsigma;                     ///< Nsigma deviation from PSF to CR
     float extNsigma;                    ///< Nsigma deviation from PSF to EXT
     float sky, skyErr;                  ///< The sky and its error at the center of the object
-    float apRadius;
     psRegion region;                    ///< area on image covered by selected pixels
     pmSourceExtendedPars *extpars;      ///< extended source parameters
Index: /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.c	(revision 28903)
+++ /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.c	(revision 28904)
@@ -155,5 +155,5 @@
     // measure the contribution of included pixels
     if (mode & PM_SOURCE_PHOT_WEIGHT) {
-        pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal);
+        pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal);
     }
 
@@ -201,5 +201,5 @@
 
     // measure object aperture photometry
-    status = pmSourcePhotometryAper  (&source->apMag, model, flux, mask, maskVal);
+    status = pmSourcePhotometryAper  (&source->apMagRaw, model, flux, mask, maskVal);
     if (!status) {
         psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
@@ -211,9 +211,12 @@
     if (isfinite (source->apMag) && isPSF && psf) {
         if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
-            source->apMag += pmGrowthCurveCorrect (psf->growth, source->apRadius);
+            source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
         }
         if (mode & PM_SOURCE_PHOT_APCORR) {
             // XXX this should be removed -- we no longer fit for the 'sky bias'
+	    // XXX is this happening???
             rflux   = pow (10.0, 0.4*source->psfMag);
+	    psAssert (psf->skyBias == 0.0, "sky bias not 0");
+	    psAssert (psf->skySat == 0.0, "sky sat not 0");
             source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux;
         }
@@ -306,5 +309,5 @@
 
 // return source aperture magnitude
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal)
+bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal)
 {
     PS_ASSERT_PTR_NON_NULL(pixWeight, false);
@@ -313,5 +316,6 @@
 
     float modelSum = 0;
-    float validSum = 0;
+    float notBadSum = 0;
+    float notPoorSum = 0;
     float sky = 0;
     float value;
@@ -321,5 +325,6 @@
     int dY, DY, NY;
 
-    *pixWeight = 0.0;
+    *pixWeightNotBad = 0.0;
+    *pixWeightNotPoor = 0.0;
 
     // we only care about the value of the object model, not the local sky
@@ -361,28 +366,26 @@
 
             // for the full model, add all points
-            value = model->modelFunc (NULL, params, coord) - sky;
+            value = fabs(model->modelFunc (NULL, params, coord) - sky);
             modelSum += value;
 
             // include count only the unmasked pixels within the image area
-            if (mx < 0)
-                continue;
-            if (my < 0)
-                continue;
-            if (mx >= NX)
-                continue;
-            if (my >= NY)
-                continue;
-            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)
-                continue;
-
-            validSum += value;
+            if (mx < 0) continue;
+            if (my < 0) continue;
+            if (mx >= NX) continue;
+            if (my >= NY) continue;
+
+            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) {
+		notBadSum += value;
+	    }
+            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & ~markVal)) {
+		notPoorSum += value;
+	    }
         }
     }
     psFree (coord);
 
-    if (validSum <= 0)
-        return false;
-
-    *pixWeight = validSum / modelSum;
+    *pixWeightNotBad  = notBadSum  / modelSum;
+    *pixWeightNotPoor = notPoorSum / modelSum;
+
     return (true);
 }
Index: /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.h	(revision 28903)
+++ /branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.h	(revision 28904)
@@ -53,5 +53,7 @@
 bool pmSourceMagnitudesInit (psMetadata *config);
 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal);
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal);
+
+bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal);
+
 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal, const float covarFactor);
 
