Index: trunk/ippToPsps/jython/diffbatch.py
===================================================================
--- trunk/ippToPsps/jython/diffbatch.py	(revision 39084)
+++ trunk/ippToPsps/jython/diffbatch.py	(revision 39094)
@@ -5,4 +5,5 @@
 import glob
 import time
+import math
 import stilts
 import re
@@ -154,18 +155,18 @@
            self.logger.infoPair("TessName ",tessName)
 
-           # XXX EAM 20140812 : I am hardwiring the parsing logic for RINGS vs LOCAL
            if self.tessName[num] == 'RINGS.V3':
-           # skycell is, eg "skycell.1133.081"
-           #                 0123456789012345
+               # skycell is, eg "skycell.1133.081"
+               #                 0123456789012345
                self.projectionID[num] = self.skycellName[num][8:12]
-               self.skycellID[num] = self.skycellName[num][13:]
-               self.skycellID[num] = self.skycellName[num][8:] 
+               self.skycellID[num] = self.skycellName[num][13:] 
            else:
-           # skycell is, eg "skycell.081"
-           #                 01234567890
+               # skycell is, eg "skycell.081"
+               #                 01234567890
                self.projectionID[num] = 0
-               self.skycellID[num] = self.skycellName[num][8:11]
-               self.skycellID[num]=self.skycellName[num][8:]
-           if self.skycellID[num] == "":
+               self.skycellID[num] = self.skycellName[num][8:]
+               
+           if self.projectionID[num] == "": 
+               self.projectionID[num] = -1
+           if self.skycellID[num] == "": 
                self.skycellID[num] = -1
 
@@ -183,5 +184,4 @@
            self.psfModelID[num]  = self.scratchDb.getFitModelID(self.psfModelName[num])
 
-
            # drop the existing tables    
 
@@ -191,5 +191,5 @@
            self.dropTableVerbose("DiffDetEffMeta_"+str(num))
 
-           if not self.analysisVer[num]: self.analysisVer[num] = -999
+           # if not self.analysisVer[num]: self.analysisVer[num] = -999
 
            self.logger.infoPair("getPhotoCalID",diffSkyFileID)
@@ -222,4 +222,12 @@
         self.logger.infoPair("Proccesing table", "DiffMeta_"+str(num))
 
+        header = self.header[num]
+
+        # Convert detectionThreshold to appropriate magnitudes
+        detectionThreshold = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF')
+        zpImage            = self.getKeyFloat(header, "%.8f", 'FPA.ZP')
+           
+        detectionThreshold = detectionThreshold + zpImage + 2.5 * math.log10(float(self.expTime[num]))
+
         sql = "CREATE TABLE DiffMeta_"+str(num)+" like DiffMeta"
         try: self.scratchDb.execute(sql)
@@ -234,4 +242,5 @@
         sqlLine.group("negImageID",            self.negImageID[num]);
         sqlLine.group("ippDiffID",             self.ippDiffID[num]);
+	sqlLine.group("tessID",                str(self.tessID[num]))
 	sqlLine.group("projectionID",          str(self.projectionID[num]))
         sqlLine.group("skycellID",             str(self.skycellID[num]))
@@ -239,4 +248,5 @@
         sqlLine.group("analysisVer",           str(self.analysisVer[num]));
 	sqlLine.group("md5sum",                str(self.md5sum[num]))
+        sqlLine.group("detectionThreshold",    detectionThreshold)
         sqlLine.group("expTime",               self.expTime[num]);
         sqlLine.group("psfModelID",            self.psfModelID[num])
@@ -244,25 +254,26 @@
         sqlLine.group("psfWidMajor",           self.psfFwhmMajor[num])
         sqlLine.group("psfWidMinor",           self.psfFwhmMinor[num])
-        sqlLine.group("kernel",                self.getKeyValue(self.header[num], 'SUBTRACTION.KERNEL'))
-        sqlLine.group("mode",                  self.getKeyValue(self.header[num], 'SUBTRACTION.MODE'))
-        sqlLine.group("psfTheta",              self.getKeyFloat(self.header[num], "%.8f", 'ANGLE'))
-        sqlLine.group("numStamps",             self.getKeyValue(self.header[num], 'SUBTRACTION.STAMPS'))
-        sqlLine.group("stampDevMean",          self.getKeyFloat(self.header[num], "%.8e", 'SUBTRACTION.DEV.MEAN'))
-        sqlLine.group("stampDevRMS",           self.getKeyFloat(self.header[num], "%.8e", 'SUBTRACTION.DEV.RMS'))
-        sqlLine.group("normalization",         self.getKeyFloat(self.header[num], "%.8e", 'SUBTRACTION.NORM'))
-        sqlLine.group("convolveMax",           self.getKeyFloat(self.header[num], "%.8e", 'SUBTRACTION.CONV.MAX'))
-        sqlLine.group("deconvolveMax",         self.getKeyFloat(self.header[num], "%.8e", 'SUBTRACTION.DECONV.MAX'))
-        sqlLine.group("ctype1",                self.getKeyValue(self.header[num], 'CTYPE1'));
-        sqlLine.group("ctype2",                self.getKeyValue(self.header[num], 'CTYPE2'));
-        sqlLine.group("crval1",                self.getKeyFloat(self.header[num], "%.8f", 'CRVAL1'));
-        sqlLine.group("crval2",                self.getKeyFloat(self.header[num], "%.8f", 'CRVAL2'));
-        sqlLine.group("crpix1",                self.getKeyFloat(self.header[num], "%.8f", 'CRPIX1'));
-        sqlLine.group("crpix2",                self.getKeyFloat(self.header[num], "%.8f", 'CRPIX2'));
-        sqlLine.group("cdelt1",                self.getKeyFloat(self.header[num], "%.8e", 'CDELT1'));
-        sqlLine.group("cdelt2",                self.getKeyFloat(self.header[num], "%.8e", 'CDELT2'));
-        sqlLine.group("pc001001",              self.getKeyFloat(self.header[num], "%.8e", 'PC001001'));
-        sqlLine.group("pc001002",              self.getKeyFloat(self.header[num], "%.8e", 'PC001002'));
-        sqlLine.group("pc002001",              self.getKeyFloat(self.header[num], "%.8e", 'PC002001'));
-        sqlLine.group("pc002002",              self.getKeyFloat(self.header[num], "%.8e", 'PC002002'));
+
+        sqlLine.group("kernel",                self.getKeyValue(header, 'SUBTRACTION.KERNEL'))
+        sqlLine.group("mode",                  self.getKeyValue(header, 'SUBTRACTION.MODE'))
+        sqlLine.group("psfTheta",              self.getKeyFloat(header, "%.8f", 'ANGLE'))
+        sqlLine.group("numStamps",             self.getKeyValue(header, 'SUBTRACTION.STAMPS'))
+        sqlLine.group("stampDevMean",          self.getKeyFloat(header, "%.8e", 'SUBTRACTION.DEV.MEAN'))
+        sqlLine.group("stampDevRMS",           self.getKeyFloat(header, "%.8e", 'SUBTRACTION.DEV.RMS'))
+        sqlLine.group("normalization",         self.getKeyFloat(header, "%.8e", 'SUBTRACTION.NORM'))
+        sqlLine.group("convolveMax",           self.getKeyFloat(header, "%.8e", 'SUBTRACTION.CONV.MAX'))
+        sqlLine.group("deconvolveMax",         self.getKeyFloat(header, "%.8e", 'SUBTRACTION.DECONV.MAX'))
+        sqlLine.group("ctype1",                self.getKeyValue(header, 'CTYPE1'));
+        sqlLine.group("ctype2",                self.getKeyValue(header, 'CTYPE2'));
+        sqlLine.group("crval1",                self.getKeyFloat(header, "%.8f", 'CRVAL1'));
+        sqlLine.group("crval2",                self.getKeyFloat(header, "%.8f", 'CRVAL2'));
+        sqlLine.group("crpix1",                self.getKeyFloat(header, "%.8f", 'CRPIX1'));
+        sqlLine.group("crpix2",                self.getKeyFloat(header, "%.8f", 'CRPIX2'));
+        sqlLine.group("cdelt1",                self.getKeyFloat(header, "%.8e", 'CDELT1'));
+        sqlLine.group("cdelt2",                self.getKeyFloat(header, "%.8e", 'CDELT2'));
+        sqlLine.group("pc001001",              self.getKeyFloat(header, "%.8e", 'PC001001'));
+        sqlLine.group("pc001002",              self.getKeyFloat(header, "%.8e", 'PC001002'));
+        sqlLine.group("pc002001",              self.getKeyFloat(header, "%.8e", 'PC002001'));
+        sqlLine.group("pc002002",              self.getKeyFloat(header, "%.8e", 'PC002002'));
 
         sql = sqlLine.make(") VALUES ( ", ")")
@@ -323,4 +334,6 @@
             sqlLine.group("filterID",        str(self.filterID[num]))
             sqlLine.group("surveyID",        str(self.surveyID))
+            sqlLine.group("tessID",          str(self.tessID[num]))
+            sqlLine.group("projectionID",    str(self.projectionID[num]))
             sqlLine.group("skycellID",       str(self.skycellID[num]))
             sqlLine.group("expTime",         str(self.expTime[num]))
@@ -336,6 +349,6 @@
                 sqlLine.group("decErr",          "Y_PSF_SIG * abs(PLTSCALE)")
             else:
-                sqlLine.group("pltScale",        "0.257")
-                sqlLine.group("posAngle",        "-999")
+                sqlLine.group("pltScale",        "0.25")
+                # sqlLine.group("posAngle",        "-999")
                 sqlLine.group("raErr",           "X_PSF_SIG * 0.25")
                 sqlLine.group("decErr",          "Y_PSF_SIG * 0.25")
@@ -433,5 +446,4 @@
         self.logger.infoPair("Dropping row column from", "DiffDetection table")
         self.scratchDb.dropColumn("DiffDetection_"+str(num), "row")
- 
 
     '''
@@ -494,22 +506,16 @@
 
         header = self.header[num]
-        # CZW: this is broken, and can't get the zeropoint
-        #        zpImage = self.scratchDb.getImageZeroPoint(diffSkyFileID)
-        zpImage = 0.0
-
-        if zpImage < 0.0:
-            zpImage = 0.0
+        zpImage = self.getKeyFloat(header,"%.8f","FPA.ZP")
+
         if zpImage == 0.0:
             self.logger.infoPair("CZW If this value for the zeropoint is zero, the getImageZeroPoint call is likely still broken", str(zpImage))
 
-
         magref = self.getKeyFloat(header,"%.8f","DETEFF.MAGREF") + zpImage
         self.logger.infoPair("Found zeropoint and set magref", str(magref))
-        self.logger.infoPair("CZW If that magref is -5.804804, then it's reading from the PHU, not the Deteff extension.","In a test, I mean.")
+
         sqlLine = sqlUtility("INSERT INTO " + ippTableName + "(")
         sqlLine.group("diffImageID", str(diffSkyFileID))
         sqlLine.group("magref",       magref)
         sql = sqlLine.make(") VALUES ( ", ")")
-            
 
         try: self.scratchDb.execute(sql)
