Index: trunk/ippToPsps/jython/detectionbatch.py
===================================================================
--- trunk/ippToPsps/jython/detectionbatch.py	(revision 32037)
+++ trunk/ippToPsps/jython/detectionbatch.py	(revision 32051)
@@ -367,14 +367,22 @@
     def populateDetectionTable(self, ota):
 
-        tableName = "Detection_" + ota
+        pspsTableName = "Detection_" + ota
+        ippTableName = ota + "_psf"
         
         # drop then re-create table
-        self.scratchDb.dropTable(tableName)
-        sql = "CREATE TABLE " + tableName + " LIKE Detection"
+        self.scratchDb.dropTable(pspsTableName)
+        sql = "CREATE TABLE " + pspsTableName + " LIKE Detection"
         try: self.scratchDb.execute(sql)
         except: pass
+       
+        # delete all detections with PSF_INST_MAG < 17.5, as decreed by Gene
+        BEFORE = self.scratchDb.getRowCount(ippTableName)
+        sql = "DELETE FROM " + ippTableName + " WHERE PSF_INST_MAG < -17.5"
+        self.scratchDb.execute(sql)
+        DELETED = BEFORE - self.scratchDb.getRowCount(ippTableName)
+        self.logger.infoPair("Saturated detections", "%d deleted" % DELETED)
 
         # insert all detections into table
-        sql = "INSERT IGNORE INTO " + tableName + " ( \
+        sql = "INSERT IGNORE INTO " + pspsTableName + " ( \
                ippDetectID \
                ,xPos \
@@ -423,19 +431,19 @@
                ,SKY_SIGMA \
                ,EXT_NSIGMA \
-               FROM " + ota + "_psf"
+               FROM " + ippTableName
         self.scratchDb.execute(sql)
 
         # set obsTime
-        sql = "UPDATE " + tableName + " SET obsTime = %f, assocDate = '%s', activeFlag = 0" % (self.obsTime, self.dateStr)
-        self.scratchDb.execute(sql)
-        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease))
-        self.scratchDb.updateAllRows(tableName, "historyModNum", "0")
-
-        self.scratchDb.updateAllRows(tableName, "surveyID", str(self.surveyID))
-        self.scratchDb.updateFilterID(tableName, self.filter)
+        sql = "UPDATE " + pspsTableName + " SET obsTime = %f, assocDate = '%s', activeFlag = 0" % (self.obsTime, self.dateStr)
+        self.scratchDb.execute(sql)
+        self.scratchDb.updateAllRows(pspsTableName, "dataRelease", str(self.dataRelease))
+        self.scratchDb.updateAllRows(pspsTableName, "historyModNum", "0")
+
+        self.scratchDb.updateAllRows(pspsTableName, "surveyID", str(self.surveyID))
+        self.scratchDb.updateFilterID(pspsTableName, self.filter)
 
         # now delete bad flux and bad chip positions
-        self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "instFlux")
-        self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "peakADU")
+        self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "instFlux")
+        self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "peakADU")
 
     '''
