Index: trunk/ippToPsps/jython/detectionbatch.py
===================================================================
--- trunk/ippToPsps/jython/detectionbatch.py	(revision 31810)
+++ trunk/ippToPsps/jython/detectionbatch.py	(revision 31821)
@@ -6,4 +6,7 @@
 from java.lang import *
 from java.sql import *
+
+from java.lang import Math
+from org.apache.commons.math.special import Erf
 
 from xml.etree.ElementTree import ElementTree, Element, tostring
@@ -483,5 +486,5 @@
         self.logger.info("Creating indexes on PSPS tables")
         self.scratchDb.makeColumnUnique("Detection", "objID")
-        self.scratchDb.createIndex("Detection", "ippDetectID")
+        self.scratchDb.makeColumnPrimaryKey("Detection", "ippDetectID")
 
     '''
@@ -521,4 +524,34 @@
 
         self.scratchDb.execute(sql)
+
+    '''
+    Generates psf, cosmic ray and extended source likelihoods
+    '''
+    def populateLikelihoods(self, tableName):
+
+        sql = "SELECT ippDetectID, psfLikelihood, crLikelihood, extendedLikelihood, sgSep FROM " + tableName
+        rs = self.scratchDb.executeUpdatableQuery(sql)
+
+        sqrt2 = Math.sqrt(2)
+
+        while rs.next():
+
+            sgSep = rs.getDouble(5)
+            psfLikelihood = Erf.erfc(Math.abs(sgSep)/sqrt2)
+        
+            if sgSep > 0:
+                crLikelihood = 0
+                extendedLikelihood = 1.0 - psfLikelihood
+            else:
+                crLikelihood = 1.0 - psfLikelihood
+                extendedLikelihood = 0
+
+            # update columns
+            rs.updateDouble(2, psfLikelihood )
+            rs.updateDouble(3, crLikelihood )
+            rs.updateDouble(4, extendedLikelihood )
+
+            # now 'commit' to database
+            rs.updateRow();
 
 
@@ -602,4 +635,5 @@
                 self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + ota, "objID")
                 self.updateImageID("Detection_" + ota, x, y) 
+                self.populateLikelihoods("Detection_" + ota)
                 
                 # check we have something in this Detection table
