Index: trunk/psModules/src/objects/pmPSF.c
===================================================================
--- trunk/psModules/src/objects/pmPSF.c	(revision 18042)
+++ trunk/psModules/src/objects/pmPSF.c	(revision 18554)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-01-02 20:41:55 $
+ *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-15 20:25:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -404,5 +404,5 @@
 
 // we generate the growth curve for the center of the image with the specified psf model
-bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType mark)
+bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -416,4 +416,7 @@
     // create template model
     pmModel *modelRef = pmModelAlloc(psf->type);
+
+    // maskVal is used to test for rejected pixels, and must include markVal
+    maskVal |= markVal;
 
     // use the center of the center pixel of the image
@@ -465,5 +468,5 @@
 
         // mask the given aperture and measure the apMag
-        psImageKeepCircle (mask, xc, yc, radius, "OR", mark);
+        psImageKeepCircle (mask, xc, yc, radius, "OR", markVal);
         if (!pmSourcePhotometryAper (&apMag, model, image, mask, maskVal)) {
             psError(PM_ERR_PHOTOM, false, "Measuring apMag for radius == %g", radius);
@@ -473,7 +476,5 @@
             break;
         }
-
-        // XXX since we re-mask on each pass, this could be dropped.
-        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(mark));
+        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(markVal));
 
         // the 'ignore' mode is for testing
Index: trunk/psModules/src/objects/pmPSFtry.c
===================================================================
--- trunk/psModules/src/objects/pmPSFtry.c	(revision 18042)
+++ trunk/psModules/src/objects/pmPSFtry.c	(revision 18554)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-06-10 01:32:15 $
+ *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-15 20:25:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -98,5 +98,5 @@
 
 // generate a pmPSFtry with a copy of the test PSF sources
-pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psMaskType maskVal, psMaskType mark)
+pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psMaskType maskVal, psMaskType markVal)
 {
     bool status;
@@ -116,4 +116,7 @@
         return NULL;
     }
+
+    // maskVal is used to test for rejected pixels, and must include markVal
+    maskVal |= markVal;
 
     // stage 1:  fit an EXT model to all candidates PSF sources
@@ -129,9 +132,12 @@
         }
 
-        // set object mask to define valid pixels -- XXX not unset?
-        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "OR", mark);
+        // set object mask to define valid pixels
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "OR", markVal);
 
         // fit model as EXT, not PSF
         status = pmSourceFitModel (source, source->modelEXT, PM_SOURCE_FIT_EXT, maskVal);
+
+	// clear object mask to define valid pixels
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
 
         // exclude the poor fits
@@ -170,6 +176,6 @@
         source->modelPSF->radiusFit = options->radius;
 
-        // set object mask to define valid pixels -- XXX not unset?
-        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "OR", mark);
+        // set object mask to define valid pixels
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "OR", markVal);
 
         // fit the PSF model to the source
@@ -178,4 +184,5 @@
         // skip poor fits
         if (!status) {
+	    psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
             psfTry->mask->data.U8[i] = PSFTRY_MASK_PSF_FAIL;
             psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : failed PSF fit\n", i, source->peak->x, source->peak->y);
@@ -183,11 +190,14 @@
         }
 
-        // XXX : use a different aperture radius from the fit radius?
-        status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal, mark);
+        status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal);
 	if (!status || isnan(source->apMag)) {
+	    psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
             psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_PHOT;
             psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : poor photometry\n", i, source->peak->x, source->peak->y);
             continue;
         }
+
+	// clear object mask to define valid pixels
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
 
         psfTry->fitMag->data.F32[i] = source->psfMag;
Index: trunk/psModules/src/objects/pmSource.c
===================================================================
--- trunk/psModules/src/objects/pmSource.c	(revision 18042)
+++ trunk/psModules/src/objects/pmSource.c	(revision 18554)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-06-10 02:26:17 $
+ *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-15 20:25:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -838,6 +838,5 @@
 
 // should we call pmSourceCacheModel if it does not exist?
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add,
-                 psMaskType maskVal, int dx, int dy)
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy)
 {
     PS_ASSERT_PTR_NON_NULL(source, false);
Index: trunk/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 18042)
+++ trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 18554)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-06-09 00:43:46 $
+ *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-15 20:25:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -64,6 +64,5 @@
 
 // XXX masked region should be (optionally) elliptical
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode,
-                         psMaskType maskVal, psMaskType mark)
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(source, false);
@@ -230,18 +229,13 @@
         mask = source->maskObj;
     }
-    // set aperture mask circle to model radius
-    // XXX use a different radius for apertures and fits...
-    // XXX can I remove this?  the source should have the mask defined when it is constructed or
-    // when the fit / aperture radius is changed...
-    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "OR", mark);
 
     // measure the weight of included pixels
     // XXX is this supposed to use the weight or the flux?
     if (mode & PM_SOURCE_PHOT_WEIGHT) {
-        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal | mark);
+        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal);
     }
 
     // measure object aperture photometry
-    status = pmSourcePhotometryAper  (&source->apMag, model, flux, mask, maskVal | mark);
+    status = pmSourcePhotometryAper  (&source->apMag, model, flux, mask, maskVal);
     if (!status) {
         psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
@@ -264,8 +258,4 @@
         psFree(mask);
     }
-
-    // unmask aperture
-    // XXX can I remove this?  this will probably break things downstream...
-    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "AND", PS_NOT_U8(mark));
 
     // if source was originally subtracted, re-subtract object, leave local sky
@@ -308,6 +298,5 @@
 
 // return source aperture magnitude
-bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask,
-                             psMaskType maskVal)
+bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(apMag, false);
@@ -347,6 +336,5 @@
 
 // return source aperture magnitude
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask,
-                          psMaskType maskVal)
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(pixWeight, false);
Index: trunk/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 18042)
+++ trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 18554)
@@ -4,6 +4,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-20 02:22:26 $
+ * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-07-15 20:25:00 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -50,5 +50,5 @@
 
 bool pmSourceMagnitudesInit (psMetadata *config);
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal, psMaskType mark);
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal);
 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal);
 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psMaskType maskVal);
Index: trunk/psModules/src/objects/pmSourcePlotMoments.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePlotMoments.c	(revision 18042)
+++ trunk/psModules/src/objects/pmSourcePlotMoments.c	(revision 18554)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-11-10 01:09:20 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-15 20:25:00 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -95,6 +95,6 @@
     graphdata.xmin = -0.05;
     graphdata.ymin = -0.05;
-    graphdata.xmax = +2.05;
-    graphdata.ymax = +2.05;
+    graphdata.xmax = +4.05;
+    graphdata.ymax = +4.05;
     KapaSetLimits (kapa, &graphdata);
 
Index: trunk/psModules/src/objects/pmSourceSky.c
===================================================================
--- trunk/psModules/src/objects/pmSourceSky.c	(revision 18042)
+++ trunk/psModules/src/objects/pmSourceSky.c	(revision 18554)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-01-02 20:39:04 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-15 20:25:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -42,4 +42,6 @@
 
 The source.pixels and source.mask must already exist
+
+This function modifies the source mask; it should only be called before the object aperture is defined
 *****************************************************************************/
 
@@ -49,5 +51,5 @@
     psF32 Radius,
     psMaskType maskVal,
-    psMaskType mark)
+    psMaskType markVal)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -69,15 +71,18 @@
     psRegion srcRegion;
 
+    // maskVal is used to test for rejected pixels, and must include markVal
+    maskVal |= markVal;
+
     srcRegion = psRegionForSquare(peak->x, peak->y, Radius);
     srcRegion = psRegionForImage(mask, srcRegion);
 
-    psImageMaskRegion(mask, srcRegion, "OR", mark);
+    psImageMaskRegion(mask, srcRegion, "OR", markVal);
     psStats *myStats = psStatsAlloc(statsOptions);
-    if (!psImageStats(myStats, image, mask, maskVal | mark)) {
+    if (!psImageStats(myStats, image, mask, maskVal)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
         psFree(myStats);
         return false;
     }
-    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(mark));
+    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(markVal));
     double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
@@ -101,5 +106,5 @@
     psF32 Radius,
     psMaskType maskVal,
-    psMaskType mark
+    psMaskType markVal
 )
 {
@@ -110,4 +115,7 @@
     PS_ASSERT_PTR_NON_NULL(source->peak, false);
     PS_ASSERT_INT_POSITIVE(Radius, false);
+
+    // maskVal is used to test for rejected pixels, and must include markVal
+    maskVal |= markVal;
 
     psStatsOptions statistic = psStatsSingleOption(statsOptions);
@@ -125,12 +133,12 @@
     srcRegion = psRegionForImage(mask, srcRegion);
 
-    psImageMaskRegion(mask, srcRegion, "OR", mark);
+    psImageMaskRegion(mask, srcRegion, "OR", markVal);
     psStats *myStats = psStatsAlloc(statsOptions);
-    if (!psImageStats(myStats, image, mask, maskVal | mark)) {
+    if (!psImageStats(myStats, image, mask, maskVal)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
         psFree(myStats);
         return false;
     }
-    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(mark));
+    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(markVal));
     double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
