Index: trunk/psModules/src/objects/pmSourceMatch.c
===================================================================
--- trunk/psModules/src/objects/pmSourceMatch.c	(revision 21183)
+++ trunk/psModules/src/objects/pmSourceMatch.c	(revision 21266)
@@ -62,8 +62,10 @@
     for (long i = 0; i < numSources; i++) {
         pmSource *source = sources->data[i]; // Source of interest
-        if (!source || (source->mode & SOURCE_MASK) || !isfinite(source->psfMag) ||
-            !isfinite(source->errMag) || source->psfMag > SOURCE_FAINTEST) {
-            continue;
-        }
+        if (!source) continue;
+	if (source->mode & SOURCE_MASK) continue;
+	if (!isfinite(source->psfMag)) continue;
+	if (!isfinite(source->errMag)) continue;
+	if (source->psfMag > SOURCE_FAINTEST) continue;
+
         float xSrc, ySrc;               // Coordinates of source
         coordsFromSource(&xSrc, &ySrc, source);
@@ -76,5 +78,5 @@
         (*y)->data.F32[num] = ySrc;
         (*mag)->data.F32[num] = source->psfMag;
-        (*magErr)->data.F32[num] = source->errMag;
+        (*magErr)->data.F32[num] = source->errMag ;
         num++;
     }
@@ -486,8 +488,13 @@
             }
             float dev = mag + cal - stars->data.F32[i]; // Deviation
-            if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
+
+	    // only reject detections from photometric images (non-photometric images can
+	    // have large errors.  XXX Or: allow a much higher rejection threshold
+	    if (photo->data.U8[index]) {
+	      if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
                 numRejected++;
                 match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;
-            }
+	      }
+	    }
         }
     }
@@ -528,4 +535,28 @@
     float lastChi2 = INFINITY;          // chi^2 on last iteration
     float fracRej = INFINITY;        // Fraction of measurements rejected
+
+    // in the first passes, the transparencies are not well deteremined: use high systematic error and the rejection thresholds
+    for (int i = 0; i < 5; i++) {
+
+        // Identify photometric nights
+        int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip, photoLevel); // Number of photometric images
+        if (numPhoto < 0) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination");
+            psFree(trans);
+            psFree(photo);
+            psFree(stars);
+            return NULL;
+        }
+        psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages);
+
+	// XXX use 20 sigma rejection and 0.1 mag systematic error (move these to the recipe)
+        fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, 20.0, PS_SQR(0.1));
+        psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100);
+
+	// XXX use 0.05 mag systematic error (move these to the recipe)
+        chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, PS_SQR(0.1)); // chi^2 for solution
+        psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
+    }
+
     for (int i = 0; i < maxIter && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) {
         lastChi2 = chi2;
