Index: trunk/ippToPsps/jython/detectionbatch.py
===================================================================
--- trunk/ippToPsps/jython/detectionbatch.py	(revision 31403)
+++ trunk/ippToPsps/jython/detectionbatch.py	(revision 31406)
@@ -529,4 +529,9 @@
                     self.scratchDb.insertNewDvoImage(header['SOURCEID'], header['IMAGEID'])
 
+                # check we have valid sourceID/imageID pair from the header
+                if 'SOURCEID' not in header or 'IMAGEID' not in header: 
+                    self.logger.error("Can't read SOURCEID/IMAGEID pair from " + ota + " header")
+                    continue
+
                 # store these for later
                 sourceIDs[ota] = header['SOURCEID']
@@ -555,4 +560,6 @@
 
                 ota = "XY%d%d" % (x, y)
+                if ota not in sourceIDs: continue
+
                 self.logger.info("******************* Dealing with OTA " + ota + " *******************")
 
@@ -633,5 +640,4 @@
 gpc1Db = Gpc1Db(logger)
 camIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.V2", "cam")
-
 logger.info("Found %d exposures" % len(camIDs))
 
