Index: /branches/eam_branches/ipp-20140717/ippToPsps/jython/detectionbatch.py
===================================================================
--- /branches/eam_branches/ipp-20140717/ippToPsps/jython/detectionbatch.py	(revision 37203)
+++ /branches/eam_branches/ipp-20140717/ippToPsps/jython/detectionbatch.py	(revision 37204)
@@ -257,18 +257,39 @@
         sqlLine.group("pc002002",         self.getKeyValue(header, 'PC002002'))
         sqlLine.group("polyOrder",        self.getKeyValue(header, 'NPLYTERM'))
-        sqlLine.group("pca1x3y0",         self.getKeyValue(header, 'PCA1X3Y0'))
-        sqlLine.group("pca1x2y1",         self.getKeyValue(header, 'PCA1X2Y1'))
-        sqlLine.group("pca1x1y2",         self.getKeyValue(header, 'PCA1X1Y2'))
-        sqlLine.group("pca1x0y3",         self.getKeyValue(header, 'PCA1X0Y3'))
-        sqlLine.group("pca1x2y0",         self.getKeyValue(header, 'PCA1X2Y0'))
-        sqlLine.group("pca1x1y1",         self.getKeyValue(header, 'PCA1X1Y1'))
-        sqlLine.group("pca1x0y2",         self.getKeyValue(header, 'PCA1X0Y2'))
-        sqlLine.group("pca2x3y0",         self.getKeyValue(header, 'PCA2X3Y0'))
-        sqlLine.group("pca2x2y1",         self.getKeyValue(header, 'PCA2X2Y1'))
-        sqlLine.group("pca2x1y2",         self.getKeyValue(header, 'PCA2X1Y2'))
-        sqlLine.group("pca2x0y3",         self.getKeyValue(header, 'PCA2X0Y3'))
-        sqlLine.group("pca2x2y0",         self.getKeyValue(header, 'PCA2X2Y0'))
-        sqlLine.group("pca2x1y1",         self.getKeyValue(header, 'PCA2X1Y1'))
-        sqlLine.group("pca2x0y2",         self.getKeyValue(header, 'PCA2X0Y2'))
+
+        nPolyterm = int(self.getKeyValue(header, 'NPLYTERM'))
+        if nPolyterm > 1:
+            sqlLine.group("pca1x2y0",         self.getKeyValue(header, 'PCA1X2Y0'))
+            sqlLine.group("pca1x1y1",         self.getKeyValue(header, 'PCA1X1Y1'))
+            sqlLine.group("pca1x0y2",         self.getKeyValue(header, 'PCA1X0Y2'))
+            sqlLine.group("pca2x2y0",         self.getKeyValue(header, 'PCA2X2Y0'))
+            sqlLine.group("pca2x1y1",         self.getKeyValue(header, 'PCA2X1Y1'))
+            sqlLine.group("pca2x0y2",         self.getKeyValue(header, 'PCA2X0Y2'))
+        else:
+            sqlLine.group("pca1x2y0",         "-999")
+            sqlLine.group("pca1x1y1",         "-999")
+            sqlLine.group("pca1x0y2",         "-999")
+            sqlLine.group("pca2x2y0",         "-999")
+            sqlLine.group("pca2x1y1",         "-999")
+            sqlLine.group("pca2x0y2",         "-999")
+            
+        if nPolyterm > 2:
+            sqlLine.group("pca1x3y0",         self.getKeyValue(header, 'PCA1X3Y0'))
+            sqlLine.group("pca1x2y1",         self.getKeyValue(header, 'PCA1X2Y1'))
+            sqlLine.group("pca1x1y2",         self.getKeyValue(header, 'PCA1X1Y2'))
+            sqlLine.group("pca1x0y3",         self.getKeyValue(header, 'PCA1X0Y3'))
+            sqlLine.group("pca2x3y0",         self.getKeyValue(header, 'PCA2X3Y0'))
+            sqlLine.group("pca2x2y1",         self.getKeyValue(header, 'PCA2X2Y1'))
+            sqlLine.group("pca2x1y2",         self.getKeyValue(header, 'PCA2X1Y2'))
+            sqlLine.group("pca2x0y3",         self.getKeyValue(header, 'PCA2X0Y3'))
+        else:
+            sqlLine.group("pca1x3y0",         "-999")
+            sqlLine.group("pca1x2y1",         "-999")
+            sqlLine.group("pca1x1y2",         "-999")
+            sqlLine.group("pca1x0y3",         "-999")
+            sqlLine.group("pca2x3y0",         "-999")
+            sqlLine.group("pca2x2y1",         "-999")
+            sqlLine.group("pca2x1y2",         "-999")
+            sqlLine.group("pca2x0y3",         "-999")
 
         sql = sqlLine.make(") VALUES ( ", ")")
@@ -491,19 +512,22 @@
         self.logger.infoPair("Reading", "FITS headers")
         self.logger.infoPair("Populating table", "ImageMeta")
-        for x in range(self.startX, self.endX):
-            for y in range(self.startY, self.endY):
-               
-                # dodge the corners
-                if x==0 and y==0: continue
-                if x==0 and y==7: continue
-                if x==7 and y==0: continue
-                if x==7 and y==7: continue
-
-                ota = "XY%d%d" % (x, y)
+
+        if self.config.camera == "gpc1":
+            for x in range(self.startX, self.endX):
+                for y in range(self.startY, self.endY):
+                    
+                    # dodge the corners
+                    if x==0 and y==0: continue
+                    if x==0 and y==7: continue
+                    if x==7 and y==0: continue
+                    if x==7 and y==7: continue
+                    
+                    ota = "XY%d%d" % (x, y)
                 
-                self.alterPspsTablesChip(ota, ota + ".hdr", x, y)
-
-        # try the test Chip
-        self.alterPspsTablesChip("Chip", "Chip.hdr", 0, 0)
+                    self.alterPspsTablesChip(ota, ota + ".hdr", x, y)
+
+        if self.config.camera == "simtest":
+            # try the test Chip
+            self.alterPspsTablesChip("Chip", "Chip.hdr", 0, 0)
 
         # now run DVO code to get all IDs ( XXX deprecated, uses dvograbber)
Index: /branches/eam_branches/ipp-20140717/ippToPsps/jython/objectbatch.py
===================================================================
--- /branches/eam_branches/ipp-20140717/ippToPsps/jython/objectbatch.py	(revision 37203)
+++ /branches/eam_branches/ipp-20140717/ippToPsps/jython/objectbatch.py	(revision 37204)
@@ -326,13 +326,13 @@
         # sqlLine.group("gcobjID",       "EXT_ID_GC")  # drop this one?
         sqlLine.group("ippObjID",        "OBJ_ID + (CAT_ID << 32)") # NOTE: shift by 32 bits exactly
-        sqlLine.group("surveyID",        str(self.surveyID))
-        sqlLine.group("skyCellID",       "-999") # XXX This does not make sense
+        sqlLine.group("surveyID",        "'" + str(self.surveyID) + "'")
+        sqlLine.group("skyCellID",       "'-999'") # XXX This does not make sense
         sqlLine.group("randomID",        "FLOOR(RAND()*9223372036854775807)") # XXX where does this number come from??
-        sqlLine.group("batchID",         str(self.batchID))
+        sqlLine.group("batchID",         "'" + str(self.batchID) + "'")
         sqlLine.group("dvoRegionID",     "DVO_REGION") # XXX add to dvopsps output for cpt
-        sqlLine.group("dataRelease",     str(self.skychunk.dataRelease))
+        sqlLine.group("dataRelease",     "'" + str(self.skychunk.dataRelease) + "'")
         sqlLine.group("objInfoFlag",     "FLAGS") 
         sqlLine.group("qualityFlag",     "FLAGS >> 24 & 0xFF")
-        sqlLine.group("consistencyFlag", "0") 
+        sqlLine.group("consistencyFlag", "'0'") 
         sqlLine.group("raStack",         "RA_STK")
         sqlLine.group("decStack",        "DEC_STK") 
@@ -343,10 +343,10 @@
         sqlLine.group("raMeanErr",       "RA_ERR")
         sqlLine.group("decMeanErr",      "DEC_ERR")
-        sqlLine.group("raMeanStd",       "-999") # XXX I do not calculate this, use chisq?
-        sqlLine.group("decMeanStd",      "-999")
-        sqlLine.group("nStackObjectRows", "0") # XXX I need to add / define this in dvopsps
-        sqlLine.group("nStackDetections", "0")
-        sqlLine.group("nDetections",      "0")
-        sql = sqlLine.make(") SELECT ", " FROM " + cptTableName)
+        sqlLine.group("raMeanStd",       "'-999'") # XXX I do not calculate this, use chisq?
+        sqlLine.group("decMeanStd",      "'-999'")
+        sqlLine.group("nStackObjectRows", "'0'") # XXX I need to add / define this in dvopsps
+        sqlLine.group("nStackDetections", "'0'")
+        sqlLine.group("nDetections",      "'0'")
+        sql = sqlLine.makeRaw(") SELECT ", " FROM " + cptTableName)
 
         try:
Index: /branches/eam_branches/ipp-20140717/ippToPsps/jython/stackbatch.py
===================================================================
--- /branches/eam_branches/ipp-20140717/ippToPsps/jython/stackbatch.py	(revision 37203)
+++ /branches/eam_branches/ipp-20140717/ippToPsps/jython/stackbatch.py	(revision 37204)
@@ -893,4 +893,8 @@
         self.scratchDb.execute(sql)
 
+        for filter in self.filters:
+            column = filter + "haveData"
+            self.scratchDb.dropColumn(tableName, column)
+
     '''
     Applies indexes to the PSPS tables
