Index: /trunk/ippToPsps/jython/detectionbatch.py
===================================================================
--- /trunk/ippToPsps/jython/detectionbatch.py	(revision 38774)
+++ /trunk/ippToPsps/jython/detectionbatch.py	(revision 38775)
@@ -413,6 +413,10 @@
         # XXX apFluxF or apFluxNpix + apFluxRadius?
 
+        # EAM 20150925: the code below populates the mysql temporary smf table with
+        # instrumental fluxes in counts/sec and calibrated sizes (arcsec).
+        # below, we convert instrumental fluxes to Jy
+
         sqlLine.group("ippDetectID",     "IPP_IDET")                                                
-#        sqlLine.group("randomDetID",     "FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)")                       
+#       sqlLine.group("randomDetID",     "FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)")                       
         sqlLine.group("randomDetID",     "RAND("+str(self.batchID)+")")                       
         sqlLine.group("filterID",        str(self.filterID))                                        
@@ -437,6 +441,6 @@
         sqlLine.group("psfFluxErr",      "PSF_INST_FLUX_SIG / " + extTimeString)
         if (self.id >= 982483):
-            sqlLine.group("psfMajorFWHM",    "PSF_FWHM_MAJ")                                               
-            sqlLine.group("psfMinorFWHM",    "PSF_FWHM_MIN")                                               
+            sqlLine.group("psfMajorFWHM",    "PSF_FWHM_MAJ * abs(PLTSCALE)")                                               
+            sqlLine.group("psfMinorFWHM",    "PSF_FWHM_MIN * abs(PLTSCALE)")                                               
             sqlLine.group("psfCore",         "PSF_CORE")                                                    
         sqlLine.group("psfTheta",        "PSF_THETA")                                               
@@ -445,13 +449,13 @@
         sqlLine.group("psfChiSq",        "PSF_CHISQ")                                     
         sqlLine.group("psfLikelihood",   "psfLikelihood(EXT_NSIGMA)")                               
-        sqlLine.group("momentXX",        "MOMENTS_XX")                                              
-        sqlLine.group("momentXY",        "MOMENTS_XY")                                              
-        sqlLine.group("momentYY",        "MOMENTS_YY")                                              
-        sqlLine.group("momentR1",        "MOMENTS_R1")                                              
-        sqlLine.group("momentRH",        "MOMENTS_RH")                                              
-        sqlLine.group("momentM3C",       "MOMENTS_M3C")                                             
-        sqlLine.group("momentM3S",       "MOMENTS_M3S")                                             
-        sqlLine.group("momentM4C",       "MOMENTS_M4C")                                             
-        sqlLine.group("momentM4S",       "MOMENTS_M4S")                                             
+        sqlLine.group("momentXX",        "MOMENTS_XX * PLTSCALE * PLTSCALE")                                              
+        sqlLine.group("momentXY",        "MOMENTS_XY * PLTSCALE * PLTSCALE")                                              
+        sqlLine.group("momentYY",        "MOMENTS_YY * PLTSCALE * PLTSCALE")                                              
+        sqlLine.group("momentR1",        "MOMENTS_R1 * abs(PLTSCALE)")                                              
+        sqlLine.group("momentRH",        "MOMENTS_RH * abs(PLTSCALE)")                                              
+        sqlLine.group("momentM3C",       "MOMENTS_M3C * PLTSCALE * PLTSCALE")                                             
+        sqlLine.group("momentM3S",       "MOMENTS_M3S * PLTSCALE * PLTSCALE")                                             
+        sqlLine.group("momentM4C",       "MOMENTS_M4C * PLTSCALE * PLTSCALE")                                             
+        sqlLine.group("momentM4S",       "MOMENTS_M4S * PLTSCALE * PLTSCALE")                                             
         if (self.id >= 982483):
             sqlLine.group("apFlux",          "AP_FLUX / " + extTimeString)
@@ -479,5 +483,8 @@
         # something like (f < 0.0) ? -999 : -2.5*log10(f)
         # as a result, the negative fluxes here result in floating point errors
-        # XXX EAM 2014072 : Is this still a problem?
+
+        # XXX EAM 20140724 : Is this still a problem?
+        # XXX EAM 20150925 : do this after inst flux -> Jy conversion?
+
         sql = "UPDATE " + pspsTableName + " SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
         try: self.scratchDb.execute(sql)
@@ -674,5 +681,5 @@
     '''
     def updateDvoIDs(self, table, externID):
-        self.logger.info("getting imge id")
+        self.logger.info("getting imageID")
         imageID = self.scratchDb.getImageIDFromExternID(externID)
         self.logger.info("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)
@@ -689,7 +696,33 @@
                a.airmass      = b.airmass, \
                a.infoFlag3    = b.flags, \
-               a.expTime      = b.expTime \
+               a.expTime      = b.expTime, \
+               a.psfFlux      = a.psfFlux     * b.zpFactor, \
+               a.psfFluxErr   = a.psfFluxErr  * b.zpFactor, \
+               a.apFlux       = a.apFlux      * b.zpFactor, \
+               a.apFluxErr    = a.apFluxErr   * b.zpFactor, \
+               a.kronFlux     = a.kronFlux    * b.zpFactor, \
+               a.kronFluxErr  = a.kronFluxErr * b.zpFactor  \
                WHERE a.ippDetectID = b.ippDetectID \
                AND b.imageID = " + str(imageID)
+
+               ## a.psfFlux      = a.psfFlux * 3630.78 * POW(10.0, -0.4*b.zp), \
+               ## a.psfFluxErr   = a.psfFluxErr * 3630.78 * POW(10.0, -0.4*b.zp), \
+               ## a.apFlux       = a.apFlux * 3630.78 * POW(10.0, -0.4*b.zp), \
+               ## a.apFluxErr    = a.apFluxErr * 3630.78 * POW(10.0, -0.4*b.zp), \
+               ## a.kronFlux     = a.kronFlux * 3630.78 * POW(10.0, -0.4*b.zp), \
+               ## a.kronFluxErr  = a.kronFluxErr * 3630.78 * POW(10.0, -0.4*b.zp) \
+
+        # instrumental flux vs Janskies:
+        # b.ZP is defined to include the airmass term and zero point offset from relative calibration or ubercal
+        # (see dvopsps/src/insert_detections_dvopsps_catalog.c:311
+        # mag_AB = -2.5*log(flux_DN/sec) + ZP
+        # flux_Jy = flux_cgs * 10^23
+        # flux_cgs = ten(-0.4*(mag_AB + 48.6)) (~by definition, ~Vega flux in V-band)
+        # flux_cgs = ten(-0.4*mag_AB - 19.44)
+        # flux_cgs = ten(-0.4*mag_AB) * 3.63078e-20
+        # flux_Jy  = ten(-0.4*mag_AB) * 3630.78
+        # flux_Jy  = ten(-0.4*(-2.5*log(flux_DN/sec) + ZP)) * 3630.78
+        # flux_Jy  = flux_DN/sec * ten(-0.4*ZP) * 3630.78
+        # NOTE: update dvopsps to populate zpFactor = 3630.78 * ten(-0.4*zp) 
 
         print sql
