IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2014, 4:05:27 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ps2-tc3-20130727

  • branches/eam_branches/ps2-tc3-20130727/ippToPsps/jython/detectionbatch.py

    r36680 r37403  
    1919from ipptopspsdb import IppToPspsDb
    2020from scratchdb import ScratchDb
     21from sqlUtility import sqlUtility
    2122
    2223import logging.config
     
    4142                 scratchDb,
    4243                 camID,
    43                  batchID,
    44                  useFullTables):
     44                 batchID):
    4545
    4646       super(DetectionBatch, self).__init__(
     
    5454               batchID,
    5555               "P2",
    56                gpc1Db.getCameraStageSmf(camID,skychunk.P2_smf_version),
    57                useFullTables)
     56               gpc1Db.getCameraStageSmf(camID,skychunk.P2_smf_version))
    5857
    5958       # get camera meta data
     
    9998           raise
    10099       
     100       # MJD-OBS is the exposure start, EXTIME / 172800 = (EXPTIME sec / 84600 sec/day) / 2
    101101       self.obsTime = float(self.header['MJD-OBS']) + (float(self.header['EXPTIME']) / 172800.0)
    102102     
     
    124124        self.logger.infoPair("Proccesing table", "FrameMeta")
    125125
    126         sql = "INSERT INTO FrameMeta (\
    127           frameID \
    128          ,frameName \
    129          ,cameraID \
    130          ,cameraConfigID \
    131          ,telescopeID \
    132          ,analysisVer \
    133          ,p1Recip \
    134          ,p2Recip \
    135          ,p3Recip \
    136          ,photoScat \
    137          ,expStart \
    138          ,expTime \
    139          ,airmass \
    140          ,raBore \
    141          ,decBore \
    142          ,ctype1 \
    143          ,ctype2 \
    144          ,crval1 \
    145          ,crval2 \
    146          ,crpix1 \
    147          ,crpix2 \
    148          ,cdelt1 \
    149          ,cdelt2 \
    150          ,pc001001 \
    151          ,pc001002 \
    152          ,pc002001 \
    153          ,pc002002 \
    154          ,polyOrder \
    155          ,pca1x3y0 \
    156          ,pca1x2y1 \
    157          ,pca1x1y2 \
    158          ,pca1x0y3 \
    159          ,pca1x2y0 \
    160          ,pca1x1y1 \
    161          ,pca1x0y2 \
    162          ,pca2x3y0 \
    163          ,pca2x2y1 \
    164          ,pca2x1y2 \
    165          ,pca2x0y3 \
    166          ,pca2x2y0 \
    167          ,pca2x1y1 \
    168          ,pca2x0y2 \
    169          ) VALUES ( \
    170         " + str(self.expID) + " \
    171         ,'" + self.expName + "' \
    172         ,1  \
    173         ,1  \
    174         ,1  \
    175         ,'" + str(self.analysisVer) + "' \
    176         ,' ' \
    177         ,' ' \
    178         ,' ' \
    179         ," + self.safeDictionaryAccess(self.header, 'ZPT_ERR') + " \
    180         ," + self.safeDictionaryAccess(self.header, 'MJD-OBS') + " \
    181         ," + self.safeDictionaryAccess(self.header, 'EXPREQ') + " \
    182         ," + self.safeDictionaryAccess(self.header, 'AIRMASS') + " \
    183         ," + self.safeDictionaryAccess(self.header, 'RA') + " \
    184         ," + self.safeDictionaryAccess(self.header, 'DEC') + " \
    185         ,'" + self.safeDictionaryAccess(self.header, 'CTYPE1') + "' \
    186         ,'" + self.safeDictionaryAccess(self.header, 'CTYPE2') + "' \
    187         ," + self.safeDictionaryAccess(self.header, 'CRVAL1') + " \
    188         ," + self.safeDictionaryAccess(self.header, 'CRVAL2') + " \
    189         ," + self.safeDictionaryAccess(self.header, 'CRPIX1') + " \
    190         ," + self.safeDictionaryAccess(self.header, 'CRPIX2') + " \
    191         ," + self.safeDictionaryAccess(self.header, 'CDELT1') + " \
    192         ," + self.safeDictionaryAccess(self.header, 'CDELT2') + " \
    193         ," + self.safeDictionaryAccess(self.header, 'PC001001') + " \
    194         ," + self.safeDictionaryAccess(self.header, 'PC001002') + " \
    195         ," + self.safeDictionaryAccess(self.header, 'PC002001') + " \
    196         ," + self.safeDictionaryAccess(self.header, 'PC002002') + " \
    197         ," + self.safeDictionaryAccess(self.header, 'NPLYTERM') + " \
    198         ," + self.safeDictionaryAccess(self.header, 'PCA1X3Y0') + " \
    199         ," + self.safeDictionaryAccess(self.header, 'PCA1X2Y1') + " \
    200         ," + self.safeDictionaryAccess(self.header, 'PCA1X1Y2') + " \
    201         ," + self.safeDictionaryAccess(self.header, 'PCA1X0Y3') + " \
    202         ," + self.safeDictionaryAccess(self.header, 'PCA1X2Y0') + " \
    203         ," + self.safeDictionaryAccess(self.header, 'PCA1X1Y1') + " \
    204         ," + self.safeDictionaryAccess(self.header, 'PCA1X0Y2') + " \
    205         ," + self.safeDictionaryAccess(self.header, 'PCA2X3Y0') + " \
    206         ," + self.safeDictionaryAccess(self.header, 'PCA2X2Y1') + " \
    207         ," + self.safeDictionaryAccess(self.header, 'PCA2X1Y2') + " \
    208         ," + self.safeDictionaryAccess(self.header, 'PCA2X0Y3') + " \
    209         ," + self.safeDictionaryAccess(self.header, 'PCA2X2Y0') + " \
    210         ," + self.safeDictionaryAccess(self.header, 'PCA2X1Y1') + " \
    211         ," + self.safeDictionaryAccess(self.header, 'PCA2X0Y2') + " \
    212         )"
    213 
    214         # print "frame meta sql: ", sql
    215 
    216         self.scratchDb.execute(sql)
     126        sqlLine = sqlUtility("INSERT INTO FrameMeta (")
     127
     128        # sqlLine.group("p1Recip",               ' ');
     129        # sqlLine.group("p2Recip",               ' ');
     130        # sqlLine.group("p3Recip",               ' ');
     131
     132        sqlLine.group("frameID",               str(self.expID));
     133        sqlLine.group("frameName",             self.expName);
     134        sqlLine.group("cameraID",              "1");
     135        sqlLine.group("cameraConfigID",        "1");
     136        sqlLine.group("telescopeID",           "1");
     137        sqlLine.group("analysisVer",           self.analysisVer);
     138        sqlLine.group("photoScat",             self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR'));
     139        sqlLine.group("expStart",              self.getKeyFloat(self.header, "%.10f", 'MJD-OBS'));
     140        sqlLine.group("expTime",               self.getKeyFloat(self.header, "%.8f", 'EXPREQ'));
     141        sqlLine.group("airmass",               self.getKeyFloat(self.header, "%.8f", 'AIRMASS'));
     142        sqlLine.group("raBore",                self.getKeyFloat(self.header, "%.10f", 'RA'));
     143        sqlLine.group("decBore",               self.getKeyFloat(self.header, "%.10f", 'DEC'));
     144        sqlLine.group("ctype1",                self.getKeyValue(self.header, 'CTYPE1'));
     145        sqlLine.group("ctype2",                self.getKeyValue(self.header, 'CTYPE2'));
     146        sqlLine.group("crval1",                self.getKeyFloat(self.header, "%.8f", 'CRVAL1'));
     147        sqlLine.group("crval2",                self.getKeyFloat(self.header, "%.8f", 'CRVAL2'));
     148        sqlLine.group("crpix1",                self.getKeyFloat(self.header, "%.8f", 'CRPIX1'));
     149        sqlLine.group("crpix2",                self.getKeyFloat(self.header, "%.8f", 'CRPIX2'));
     150        sqlLine.group("cdelt1",                self.getKeyFloat(self.header, "%.8e", 'CDELT1'));
     151        sqlLine.group("cdelt2",                self.getKeyFloat(self.header, "%.8e", 'CDELT2'));
     152        sqlLine.group("pc001001",              self.getKeyFloat(self.header, "%.8e", 'PC001001'));
     153        sqlLine.group("pc001002",              self.getKeyFloat(self.header, "%.8e", 'PC001002'));
     154        sqlLine.group("pc002001",              self.getKeyFloat(self.header, "%.8e", 'PC002001'));
     155        sqlLine.group("pc002002",              self.getKeyFloat(self.header, "%.8e", 'PC002002'));
     156        sqlLine.group("polyOrder",             self.getKeyValue(self.header, 'NPLYTERM'));
     157        sqlLine.group("pca1x3y0",              self.getKeyFloat(self.header, "%.8e", 'PCA1X3Y0'));
     158        sqlLine.group("pca1x2y1",              self.getKeyFloat(self.header, "%.8e", 'PCA1X2Y1'));
     159        sqlLine.group("pca1x1y2",              self.getKeyFloat(self.header, "%.8e", 'PCA1X1Y2'));
     160        sqlLine.group("pca1x0y3",              self.getKeyFloat(self.header, "%.8e", 'PCA1X0Y3'));
     161        sqlLine.group("pca1x2y0",              self.getKeyFloat(self.header, "%.8e", 'PCA1X2Y0'));
     162        sqlLine.group("pca1x1y1",              self.getKeyFloat(self.header, "%.8e", 'PCA1X1Y1'));
     163        sqlLine.group("pca1x0y2",              self.getKeyFloat(self.header, "%.8e", 'PCA1X0Y2'));
     164        sqlLine.group("pca2x3y0",              self.getKeyFloat(self.header, "%.8e", 'PCA2X3Y0'));
     165        sqlLine.group("pca2x2y1",              self.getKeyFloat(self.header, "%.8e", 'PCA2X2Y1'));
     166        sqlLine.group("pca2x1y2",              self.getKeyFloat(self.header, "%.8e", 'PCA2X1Y2'));
     167        sqlLine.group("pca2x0y3",              self.getKeyFloat(self.header, "%.8e", 'PCA2X0Y3'));
     168        sqlLine.group("pca2x2y0",              self.getKeyFloat(self.header, "%.8e", 'PCA2X2Y0'));
     169        sqlLine.group("pca2x1y1",              self.getKeyFloat(self.header, "%.8e", 'PCA2X1Y1'));
     170        sqlLine.group("pca2x0y2",              self.getKeyFloat(self.header, "%.8e", 'PCA2X0Y2'));
     171
     172        sql = sqlLine.make(") VALUES ( ", ")")
     173
     174        try: self.scratchDb.execute(sql)
     175        except:
     176            self.logger.errorPair('failed sql: ', sql)
     177            raise
     178
    217179        self.scratchDb.updateAllRows("FrameMeta", "batchID", str(self.batchID))
    218180        self.scratchDb.updateAllRows("FrameMeta", "surveyID", str(self.surveyID))
     
    228190        tableName = "ImageMeta_" + ota
    229191       
    230         # XXX we drop the table above so it is not left behind on failure
    231         # drop then re-create table
    232         # self.scratchDb.dropTable(tableName)
     192        # we drop the table before calling this functoin so it is not left behind on failure
    233193        sql = "CREATE TABLE " + tableName + " LIKE ImageMeta"
    234194        try: self.scratchDb.execute(sql)
    235195        except: pass
     196
    236197        if (ota[0:2] == "XY"): ccdID = ota[2:4]
    237198        else: ccdID = 0
    238199
     200        psfFwhmMajor = self.getKeyFloat(header, "%.8f", 'FWHM_MAJ')
     201        psfFwhmMinor = self.getKeyFloat(header, "%.8f", 'FWHM_MIN')
     202        psfFwhm = 0.5*(float(psfFwhmMajor) + float(psfFwhmMinor))
     203
    239204        # insert image metadata into table
    240         sql = "INSERT INTO " + tableName + " ( \
    241                frameID \
    242                ,ccdID \
    243                ,bias \
    244                ,biasScat \
    245                ,sky \
    246                ,skyScat \
    247                ,magSat \
    248                ,completMag \
    249                ,astroScat \
    250                ,photoScat \
    251                ,numAstroRef \
    252                ,numPhotoRef \
    253                ,nx \
    254                ,ny \
    255                ,psfFwhm \
    256                ,psfWidMajor \
    257                ,psfWidMinor \
    258                ,psfTheta \
    259                ,momentFwhm \
    260                ,momentWidMajor \
    261                ,momentWidMinor \
    262                ,apResid \
    263                ,dapResid \
    264                ,detectorID \
    265                ,qaFlags \
    266                ,detrend1 \
    267                ,detrend2 \
    268                ,detrend3 \
    269                ,detrend4 \
    270                ,detrend5 \
    271                ,detrend6 \
    272                ,detrend7 \
    273                ,detrend8 \
    274                ,photoZero \
    275                ,ctype1 \
    276                ,ctype2 \
    277                ,crval1 \
    278                ,crval2 \
    279                ,crpix1 \
    280                ,crpix2 \
    281                ,cdelt1 \
    282                ,cdelt2 \
    283                ,pc001001 \
    284                ,pc001002 \
    285                ,pc002001 \
    286                ,pc002002 \
    287                ,polyOrder \
    288                ,pca1x3y0 \
    289                ,pca1x2y1 \
    290                ,pca1x1y2 \
    291                ,pca1x0y3 \
    292                ,pca1x2y0 \
    293                ,pca1x1y1 \
    294                ,pca1x0y2 \
    295                ,pca2x3y0 \
    296                ,pca2x2y1 \
    297                ,pca2x1y2 \
    298                ,pca2x0y3 \
    299                ,pca2x2y0 \
    300                ,pca2x1y1 \
    301                ,pca2x0y2 \
    302                ) VALUES ( \
    303                " + str(self.expID) + " \
    304                ," + str(ccdID) + " \
    305                ," + str(self.bias) + " \
    306                ," + str(self.biasScat) + " \
    307                ," + self.safeDictionaryAccess(header, 'MSKY_MN') + " \
    308                ," + self.safeDictionaryAccess(header, 'MSKY_SIG') + " \
    309                ," + self.safeDictionaryAccess(header, 'FSATUR') + " \
    310                ," + self.safeDictionaryAccess(header, 'FLIMIT') + " \
    311                ," + self.safeDictionaryAccess(header, 'CERROR') + " \
    312                ," + self.safeDictionaryAccess(self.header, 'ZPT_OBS') + " \
    313                ," + self.safeDictionaryAccess(header, 'NASTRO') + " \
    314                ," + self.safeDictionaryAccess(header, 'NASTRO') + " \
    315                ," + self.safeDictionaryAccess(header, 'CNAXIS1') + " \
    316                ," + self.safeDictionaryAccess(header, 'CNAXIS2') + " \
    317                , ( " + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " + " + self.safeDictionaryAccess(header, 'FWHM_MIN') + " ) / 2.0 \
    318                ," + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " \
    319                ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \
    320                ," + self.safeDictionaryAccess(header, 'ANGLE') + " \
    321                , ( " + self.safeDictionaryAccess(header, 'IQ_FW1') + " + " + self.safeDictionaryAccess(header, 'IQ_FW2') + " ) / 2.0  \
    322                ," + self.safeDictionaryAccess(header, 'IQ_FW1') + " \
    323                ," + self.safeDictionaryAccess(header, 'IQ_FW2') + " \
    324                ," + self.safeDictionaryAccess(header, 'APMIFIT') + " \
    325                ," + self.safeDictionaryAccess(header, 'DAPMIFIT') + " \
    326                ,'" + self.safeDictionaryAccess(header, 'DETECTOR') + "' \
    327                ," + str(self.scratchDb.getDvoImageFlags(header['IMAGEID'])) + " \
    328                ,'" + self.safeDictionaryAccess(header, 'DETREND.MASK') + "' \
    329                ,'" + self.safeDictionaryAccess(header, 'DETREND.DARK') + "' \
    330                ,'" + self.safeDictionaryAccess(header, 'DETREND.FLAT') + "' \
    331                ,' ' \
    332                ,' ' \
    333                ,' ' \
    334                ,' ' \
    335                ,' ' \
    336                ," + self.safeDictionaryAccess(self.header, 'ZPT_OBS') + " \
    337                ,'" + self.safeDictionaryAccess(header, 'CTYPE1') + "' \
    338                ,'" + self.safeDictionaryAccess(header, 'CTYPE2') + "' \
    339                ," + self.safeDictionaryAccess(header, 'CRVAL1') + " \
    340                ," + self.safeDictionaryAccess(header, 'CRVAL2') + " \
    341                ," + self.safeDictionaryAccess(header, 'CRPIX1') + " \
    342                ," + self.safeDictionaryAccess(header, 'CRPIX2') + " \
    343                ," + self.safeDictionaryAccess(header, 'CDELT1') + " \
    344                ," + self.safeDictionaryAccess(header, 'CDELT2') + " \
    345                ," + self.safeDictionaryAccess(header, 'PC001001') + " \
    346                ," + self.safeDictionaryAccess(header, 'PC001002') + " \
    347                ," + self.safeDictionaryAccess(header, 'PC002001') + " \
    348                ," + self.safeDictionaryAccess(header, 'PC002002') + " \
    349                ," + self.safeDictionaryAccess(header, 'NPLYTERM') + " \
    350                ," + self.safeDictionaryAccess(header, 'PCA1X3Y0') + " \
    351                ," + self.safeDictionaryAccess(header, 'PCA1X2Y1') + " \
    352                ," + self.safeDictionaryAccess(header, 'PCA1X1Y2') + " \
    353                ," + self.safeDictionaryAccess(header, 'PCA1X0Y3') + " \
    354                ," + self.safeDictionaryAccess(header, 'PCA1X2Y0') + " \
    355                ," + self.safeDictionaryAccess(header, 'PCA1X1Y1') + " \
    356                ," + self.safeDictionaryAccess(header, 'PCA1X0Y2') + " \
    357                ," + self.safeDictionaryAccess(header, 'PCA2X3Y0') + " \
    358                ," + self.safeDictionaryAccess(header, 'PCA2X2Y1') + " \
    359                ," + self.safeDictionaryAccess(header, 'PCA2X1Y2') + " \
    360                ," + self.safeDictionaryAccess(header, 'PCA2X0Y3') + " \
    361                ," + self.safeDictionaryAccess(header, 'PCA2X2Y0') + " \
    362                ," + self.safeDictionaryAccess(header, 'PCA2X1Y1') + " \
    363                ," + self.safeDictionaryAccess(header, 'PCA2X0Y2') + " \
    364                )"
     205        sqlLine = sqlUtility("INSERT INTO " + tableName + "(")
     206
     207        sqlLine.group("frameID",          str(self.expID))
     208        sqlLine.group("ccdID",            str(ccdID))
     209        sqlLine.group("bias",             str(self.bias))
     210        sqlLine.group("biasScat",         str(self.biasScat))
     211        sqlLine.group("sky",              self.getKeyFloat(header, "%.8f", 'MSKY_MN'))
     212        sqlLine.group("skyScat",          self.getKeyFloat(header, "%.8f", 'MSKY_SIG'))
     213        sqlLine.group("magSat",           self.getKeyFloat(header, "%.8f", 'FSATUR'))
     214        sqlLine.group("completMag",       self.getKeyFloat(header, "%.8f", 'FLIMIT'))
     215        sqlLine.group("astroScat",        self.getKeyFloat(header, "%.8f", 'CERROR'))
     216        sqlLine.group("photoScat",        self.getKeyFloat(self.header, "%.8f", 'ZPT_OBS'))
     217        sqlLine.group("numAstroRef",      self.getKeyValue(header, 'NASTRO'))
     218        sqlLine.group("numPhotoRef",      self.getKeyValue(header, 'NASTRO'))
     219        sqlLine.group("nx",               self.getKeyInt(header, 0, 'CNAXIS1'))
     220        sqlLine.group("ny",               self.getKeyInt(header, 0, 'CNAXIS2'))
     221        sqlLine.group("psfFwhm",          str(psfFwhm))
     222        sqlLine.group("psfWidMajor",      psfFwhmMajor)
     223        sqlLine.group("psfWidMinor",      psfFwhmMinor)
     224        sqlLine.group("psfTheta",         self.getKeyFloat(header, "%.8f", 'ANGLE'))
     225        sqlLine.group("momentMajor",      self.getKeyFloat(header, "%.8f", 'IQ_FW1'))
     226        sqlLine.group("momentMinor",      self.getKeyFloat(header, "%.8f", 'IQ_FW2'))
     227        sqlLine.group("momentM2C",        self.getKeyFloat(header, "%.8f", 'IQ_M2C'))
     228        sqlLine.group("momentM2S",        self.getKeyFloat(header, "%.8f", 'IQ_M2S'))
     229        sqlLine.group("momentM3",         self.getKeyFloat(header, "%.8f", 'IQ_M3'))
     230        sqlLine.group("momentM4",         self.getKeyFloat(header, "%.8f", 'IQ_M4'))
     231        sqlLine.group("apResid",          self.getKeyFloat(header, "%.8f", 'APMIFIT'))
     232        sqlLine.group("dapResid",         self.getKeyFloat(header, "%.8f", 'DAPMIFIT'))
     233        sqlLine.group("detectorID",       self.getKeyValue(header, 'DETECTOR'))
     234        sqlLine.group("qaFlags",          str(self.scratchDb.getDvoImageFlags(header['IMAGEID'])))
     235        sqlLine.group("detrend1",         self.getKeyValue(header, 'DETREND.MASK'))
     236        sqlLine.group("detrend2",         self.getKeyValue(header, 'DETREND.DARK'))
     237        sqlLine.group("detrend3",         self.getKeyValue(header, 'DETREND.FLAT'))
     238        # sqlLine.group("detrend4",         " ")
     239        # sqlLine.group("detrend5",         " ")
     240        # sqlLine.group("detrend6",         " ")
     241        # sqlLine.group("detrend7",         " ")
     242        # sqlLine.group("detrend8",         " ")
     243        sqlLine.group("photoZero",        self.getKeyFloat(self.header, "%.8f", 'ZPT_OBS'))
     244        sqlLine.group("ctype1",           self.getKeyValue(header, 'CTYPE1'))
     245        sqlLine.group("ctype2",           self.getKeyValue(header, 'CTYPE2'))
     246        sqlLine.group("crval1",           self.getKeyFloat(header, "%.8f", 'CRVAL1'))
     247        sqlLine.group("crval2",           self.getKeyFloat(header, "%.8f", 'CRVAL2'))
     248        sqlLine.group("crpix1",           self.getKeyFloat(header, "%.8f", 'CRPIX1'))
     249        sqlLine.group("crpix2",           self.getKeyFloat(header, "%.8f", 'CRPIX2'))
     250        sqlLine.group("cdelt1",           self.getKeyFloat(header, "%.8e", 'CDELT1'))
     251        sqlLine.group("cdelt2",           self.getKeyFloat(header, "%.8e", 'CDELT2'))
     252        sqlLine.group("pc001001",         self.getKeyFloat(header, "%.8e", 'PC001001'))
     253        sqlLine.group("pc001002",         self.getKeyFloat(header, "%.8e", 'PC001002'))
     254        sqlLine.group("pc002001",         self.getKeyFloat(header, "%.8e", 'PC002001'))
     255        sqlLine.group("pc002002",         self.getKeyFloat(header, "%.8e", 'PC002002'))
     256        sqlLine.group("polyOrder",        self.getKeyInt(header, 0, 'NPLYTERM'))
     257
     258        nPolyterm = int(self.getKeyInt(header, 0, 'NPLYTERM'))
     259        if nPolyterm > 1:
     260            sqlLine.group("pca1x2y0",         self.getKeyFloat(header, "%.8e", 'PCA1X2Y0'))
     261            sqlLine.group("pca1x1y1",         self.getKeyFloat(header, "%.8e", 'PCA1X1Y1'))
     262            sqlLine.group("pca1x0y2",         self.getKeyFloat(header, "%.8e", 'PCA1X0Y2'))
     263            sqlLine.group("pca2x2y0",         self.getKeyFloat(header, "%.8e", 'PCA2X2Y0'))
     264            sqlLine.group("pca2x1y1",         self.getKeyFloat(header, "%.8e", 'PCA2X1Y1'))
     265            sqlLine.group("pca2x0y2",         self.getKeyFloat(header, "%.8e", 'PCA2X0Y2'))
     266        else:
     267            sqlLine.group("pca1x2y0",         "-999")
     268            sqlLine.group("pca1x1y1",         "-999")
     269            sqlLine.group("pca1x0y2",         "-999")
     270            sqlLine.group("pca2x2y0",         "-999")
     271            sqlLine.group("pca2x1y1",         "-999")
     272            sqlLine.group("pca2x0y2",         "-999")
     273           
     274        if nPolyterm > 2:
     275            sqlLine.group("pca1x3y0",         self.getKeyFloat(header, "%.8e", 'PCA1X3Y0'))
     276            sqlLine.group("pca1x2y1",         self.getKeyFloat(header, "%.8e", 'PCA1X2Y1'))
     277            sqlLine.group("pca1x1y2",         self.getKeyFloat(header, "%.8e", 'PCA1X1Y2'))
     278            sqlLine.group("pca1x0y3",         self.getKeyFloat(header, "%.8e", 'PCA1X0Y3'))
     279            sqlLine.group("pca2x3y0",         self.getKeyFloat(header, "%.8e", 'PCA2X3Y0'))
     280            sqlLine.group("pca2x2y1",         self.getKeyFloat(header, "%.8e", 'PCA2X2Y1'))
     281            sqlLine.group("pca2x1y2",         self.getKeyFloat(header, "%.8e", 'PCA2X1Y2'))
     282            sqlLine.group("pca2x0y3",         self.getKeyFloat(header, "%.8e", 'PCA2X0Y3'))
     283        else:
     284            sqlLine.group("pca1x3y0",         "-999")
     285            sqlLine.group("pca1x2y1",         "-999")
     286            sqlLine.group("pca1x1y2",         "-999")
     287            sqlLine.group("pca1x0y3",         "-999")
     288            sqlLine.group("pca2x3y0",         "-999")
     289            sqlLine.group("pca2x2y1",         "-999")
     290            sqlLine.group("pca2x1y2",         "-999")
     291            sqlLine.group("pca2x0y3",         "-999")
     292
     293        sql = sqlLine.make(") VALUES ( ", ")")
    365294
    366295        try: self.scratchDb.execute(sql)
    367         except: print sql
     296        except:
     297            self.logger.errorPair('failed sql: ', sql)
     298            raise
    368299
    369300        self.scratchDb.updateFilterID(tableName, self.filter)
     
    395326        results['SATDET'] = 0
    396327
    397         # insert all detections into table
    398         sql = "INSERT IGNORE INTO " + pspsTableName + " ( \
    399                ippDetectID \
    400                ,filterID \
    401                ,surveyID \
    402                ,obsTime \
    403                ,xPos \
    404                ,yPos \
    405                ,xPosErr \
    406                ,yPosErr \
    407                ,psfFlux \
    408                ,psfFluxErr \
    409                ,peakADU \
    410                ,psfWidMajor \
    411                ,psfWidMinor \
    412                ,psfTheta \
    413                ,psfLikelihood \
    414                ,psfQf \
    415                ,momentXX \
    416                ,momentXY \
    417                ,momentYY \
    418                ,apFlux \
    419                ,kronFlux \
    420                ,kronFluxErr \
    421                ,psfQfPerfect \
    422                ,psfChiSq \
    423                ,infoFlag \
    424                ,sky \
    425                ,skyErr \
    426                ,sgSep \
    427                ,activeFlag \
    428                ,assocDate \
    429                ,historyModNum \
    430                ,dataRelease \
    431                ) \
    432                SELECT \
    433                IPP_IDET \
    434                , " + str(self.filterID) + "\
    435                , " + str(self.surveyID) + " \
    436                ," + str(self.obsTime) + " \
    437                ,X_PSF \
    438                ,Y_PSF \
    439                ,X_PSF_SIG \
    440                ,Y_PSF_SIG \
    441                ,PSF_INST_FLUX / " + self.header['EXPTIME'] + " \
    442                ,PSF_INST_FLUX_SIG / " + self.header['EXPTIME'] + " \
    443                ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + self.header['EXPTIME'] + " \
    444                ,PSF_MAJOR \
    445                ,PSF_MINOR \
    446                ,PSF_THETA \
    447                ,psfLikelihood(EXT_NSIGMA) \
    448                ,PSF_QF \
    449                ,MOMENTS_XX \
    450                ,MOMENTS_XY \
    451                ,MOMENTS_YY \
    452                ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
    453                ,KRON_FLUX / " + self.header['EXPTIME'] + " \
    454                ,KRON_FLUX_ERR / " + self.header['EXPTIME'] + " \
    455                ,PSF_QF_PERFECT \
    456                ,PSF_CHISQ \
    457                ,FLAGS2 << 32 | FLAGS \
    458                ,SKY  / " + self.header['EXPTIME'] + " \
    459                ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
    460                ,EXT_NSIGMA \
    461                , 0 \
    462                , '" + self.dateStr + "' \
    463                , 0 \
    464                , " + str(self.skychunk.dataRelease) + "\
    465                FROM " + ippTableName
    466         # self.logger.info(sql)
    467 
    468 # these were used above (left over from before PSF_INST_FLUX, PSF_INST_FLUX_SIG were available?
    469 #               ,POW(10.0, (-0.4*PSF_INST_MAG)) / " + self.header['EXPTIME'] + "
    470 #               ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / " + self.header['EXPTIME'] + ")) / 1.085736)
    471 
    472 # I need a way to choose the sql above based on the cmf version: V3 (LAP.PV1) does not have AP_FLUX
    473 # AP_FLUX is no              ,AP_FLUX / " + self.header['EXPTIME'] + "
    474 
    475         self.scratchDb.execute(sql)
    476 
    477         # XXX EAM : I removed this old fix for invalid fluxes
    478         # add a instFlux = 0.0 -> 0.000001
    479         # XXX EAM : why is this done?
    480         # sql="UPDATE " + pspsTableName + " SET psfFlux = 0.0000001 WHERE psfFlux =  0"
    481         # self.scratchDb.execute(sql)
    482      
     328        extTimeString = str(self.header['EXPTIME'])
     329
     330        # insert all detections into table : do NOT include the IGNORE unless we have to
     331        # sqlLine = sqlUtility("INSERT IGNORE INTO " + pspsTableName + " (")
     332        sqlLine = sqlUtility("INSERT INTO " + pspsTableName + " (")
     333
     334        # XXX WARNING: need to apply platescale to convert sizes to arcsec
     335        # XXX apFluxF or apFluxNpix + apFluxRadius?
     336
     337        sqlLine.group("ippDetectID",     "IPP_IDET")                                               
     338        sqlLine.group("randomDetID",     "FLOOR(RAND()*9223372036854775807)")                       
     339        sqlLine.group("filterID",        str(self.filterID))                                       
     340        sqlLine.group("surveyID",        str(self.surveyID))                                       
     341        sqlLine.group("obsTime",         str(self.obsTime))                                         
     342        sqlLine.group("xPos",            "X_PSF")                                                   
     343        sqlLine.group("yPos",            "Y_PSF")                                                   
     344        sqlLine.group("xPosErr",         "X_PSF_SIG")                                               
     345        sqlLine.group("yPosErr",         "Y_PSF_SIG")                                               
     346        if (self.id >= 982483):
     347            sqlLine.group("pltScale",        "PLTSCALE")                                     
     348            sqlLine.group("posAngle",        "POSANGLE")                                     
     349            sqlLine.group("raErr",           "X_PSF_SIG * abs(PLTSCALE)")
     350            sqlLine.group("decErr",          "Y_PSF_SIG * abs(PLTSCALE)")
     351        else:
     352            sqlLine.group("pltScale",        "0.257")                                     
     353            sqlLine.group("posAngle",        "-999")                                     
     354            sqlLine.group("raErr",           "X_PSF_SIG * 0.257")
     355            sqlLine.group("decErr",          "Y_PSF_SIG * 0.257")
     356        sqlLine.group("psfFlux",         "PSF_INST_FLUX / " + extTimeString)
     357        sqlLine.group("psfFluxErr",      "PSF_INST_FLUX_SIG / " + extTimeString)
     358        if (self.id >= 982483):
     359            sqlLine.group("psfMajorFWHM",    "PSF_FWHM_MAJ")                                               
     360            sqlLine.group("psfMinorFWHM",    "PSF_FWHM_MIN")                                               
     361            sqlLine.group("psfCore",         "PSF_CORE")                                                   
     362        sqlLine.group("psfTheta",        "PSF_THETA")                                               
     363        sqlLine.group("psfQf",           "PSF_QF")                                                 
     364        sqlLine.group("psfQfPerfect",    "PSF_QF_PERFECT")                               
     365        sqlLine.group("psfChiSq",        "PSF_CHISQ")                                     
     366        sqlLine.group("psfLikelihood",   "psfLikelihood(EXT_NSIGMA)")                               
     367        sqlLine.group("momentXX",        "MOMENTS_XX")                                             
     368        sqlLine.group("momentXY",        "MOMENTS_XY")                                             
     369        sqlLine.group("momentYY",        "MOMENTS_YY")                                             
     370        sqlLine.group("momentR1",        "MOMENTS_R1")                                             
     371        sqlLine.group("momentRH",        "MOMENTS_RH")                                             
     372        sqlLine.group("momentM3C",       "MOMENTS_M3C")                                             
     373        sqlLine.group("momentM3S",       "MOMENTS_M3S")                                             
     374        sqlLine.group("momentM4C",       "MOMENTS_M4C")                                             
     375        sqlLine.group("momentM4S",       "MOMENTS_M4S")                                             
     376        if (self.id >= 982483):
     377            sqlLine.group("apFlux",          "AP_FLUX / " + extTimeString)
     378            sqlLine.group("apFluxErr",       "AP_FLUX_SIG / " + extTimeString)
     379            sqlLine.group("apFillF",         "AP_NPIX / (3.14159265359 * POW(AP_MAG_RADIUS - 0.5, 2))")
     380        sqlLine.group("apRadius",        "AP_MAG_RADIUS")
     381        sqlLine.group("kronFlux",        "KRON_FLUX / " + extTimeString)
     382        sqlLine.group("kronFluxErr",     "KRON_FLUX_ERR / " + extTimeString)
     383        sqlLine.group("kronRad",         "MOMENTS_R1 * 2.5")
     384        sqlLine.group("sky",             "SKY  / " + extTimeString)
     385        sqlLine.group("skyErr",          "SKY_SIGMA  / " + extTimeString)
     386        sqlLine.group("infoFlag",        "FLAGS")                         
     387        sqlLine.group("infoFlag2",       "FLAGS2")                         
     388        sqlLine.group("dataRelease",     str(self.skychunk.dataRelease))                 
     389
     390        sql = sqlLine.makeRaw(") SELECT ", " FROM " + ippTableName)
     391
     392        try: self.scratchDb.execute(sql)
     393        except:
     394            self.logger.errorPair("failed sql: ", sql)
     395            raise
     396
    483397        # NOTE : Flux limits : in the current PSPS schema, negative fluxes
    484398        # cause problems for sql queries which work in mags as SQL cannot do
    485399        # something like (f < 0.0) ? -999 : -2.5*log10(f)
    486400        # as a result, the negative fluxes here result in floating point errors
     401        # XXX EAM 2014072 : Is this still a problem?
    487402        sql = "UPDATE " + pspsTableName + " SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
    488403        self.scratchDb.execute(sql)
     
    496411        # we don't delete these anymore
    497412        results['NULLINSTFLUX'] = 0;
    498         results['NULLPEAKADU'] = 0;
    499413
    500414    '''
     
    525439
    526440        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    527 
    528     '''
    529     Populates the DetectionCalib table for this OTA
    530     '''
    531     def populateDetectionCalibTableUpdateInsert(self, ota):
    532 
    533         tableName = "DetectionCalib_" + ota
     441    '''
     442    Populates the SkinnyObject table for this OTA
     443    '''
     444    def populateSkinnyObjectTable(self, ota):
     445
     446        tableName = "SkinnyObject_" + ota
     447       
    534448        # drop then re-create table
    535449        self.scratchDb.dropTable(tableName)
    536         sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
     450        sql = "CREATE TABLE " + tableName + " LIKE SkinnyObject"
    537451        try: self.scratchDb.execute(sql)
    538452        except: pass
     
    541455        sql = "INSERT INTO " + tableName + " ( \
    542456               objID \
    543                ,detectID \
    544457               ,ippObjID \
    545                ,ippDetectID \
    546                ,filterID \
    547458               ,surveyID \
    548459               ) \
    549460               SELECT \
    550461               objID \
    551                ,detectID \
    552462               ,ippObjID \
    553                ,ippDetectID \
    554                ,filterID \
    555463               ,surveyID \
    556464               FROM Detection_" + ota
    557465        self.scratchDb.execute(sql)
    558466
    559         # insert calibration information from dvoDetections into the Table
    560         sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
    561             SET a.ra = b.ra, \
    562             a.dec = b.dec_, \
    563             a.raErr = b.raErr, \
    564             a.decErr = b.decErr, \
    565             a.zp = b.zp, \
    566             a.zpErr = b.zpErr, \
    567             a.expTime = b.expTime, \
    568             a.airMass = b.airMass   \
    569             WHERE a.objID = b.objID AND a.detectID = b.detectID"
    570         self.scratchDb.execute(sql)
    571         self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    572        
    573     '''
    574     Populates the DetectionCalib table for this OTA
    575     '''
    576     def populateDetectionCalibTable(self, ota):
    577 
    578         # target table name:
    579         tableName = "DetectionCalib_" + ota
    580         # drop then re-create table
    581         self.scratchDb.dropTable(tableName)
    582         sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
    583         try: self.scratchDb.execute(sql)
    584         except: pass
    585 
    586         externID = self.imageIDs[ota]
    587 
    588         imageID = self.scratchDb.getImageIDFromExternID(externID)
    589         self.logger.infoPair("obtained","imageID")
    590 
    591         # check for & create output directory first
    592         datadumpDir = "/tmp/datadump"
    593         try:
    594             statinfo = os.stat(datadumpDir)
    595             # check on the stat results?
    596         except:
    597             print "making the data dump directory ", datadumpDir
    598             os.mkdir(datadumpDir)
    599             os.chmod(datadumpDir, 0777)
    600             statinfo = os.stat(datadumpDir)
    601 
    602         dumpFile = datadumpDir + "/genetest.xx.dat"
    603         files = glob.glob(dumpFile)
    604         if len(files) > 0:
    605             os.unlink(dumpFile)
    606 
    607         # insert all detections into table
    608         sql = "SELECT \
    609           a.objID,    \
    610           a.detectID, \
    611           a.ippObjID,      \
    612           a.ippDetectID,   \
    613           a.filterID,      \
    614           a.surveyID,      \
    615           b.ra,            \
    616           b.dec_,          \
    617           b.raErr,         \
    618           b.decErr,        \
    619           b.zp,            \
    620           b.zpErr,         \
    621           b.expTime,       \
    622           b.airMass,       \
    623           " + str(self.skychunk.dataRelease) + " \
    624          FROM              \
    625            Detection_" + ota + " as a \
    626          JOIN " + self.scratchDb.dvoDetectionTable + " as b \
    627          ON (a.objID = b.objID AND a.detectID = b.detectID) \
    628          WHERE b.imageID = " + str(imageID) + \
    629          " INTO OUTFILE '" + dumpFile + "'"
    630 
    631         try: self.scratchDb.execute(sql)
    632         except:
    633             self.logger.info("failed to select data for detectionCalib")
    634             self.logger.infoPair("sql: ", sql)
    635             raise
    636 
    637         sql = "LOAD DATA INFILE '" + dumpFile + "' INTO TABLE " + tableName
    638         try: self.scratchDb.execute(sql)
    639         except:
    640             self.logger.info("failed to load data from infile for detectionCalib")
    641             self.logger.infoPair("sql: ", sql)
    642             raise
    643        
    644     '''
    645     Populates the Detection table for this OTA
    646     '''
    647     def populateObjectCalColorTable(self, ota):
    648 
    649         tableName = "ObjectCalColor_" + ota
    650        
    651         # drop then re-create table
    652         self.scratchDb.dropTable(tableName)
    653         sql = "CREATE TABLE " + tableName + " LIKE ObjectCalColor"
    654         try: self.scratchDb.execute(sql)
    655         except: pass
    656 
    657         # insert all detections into table
    658         sql = "INSERT INTO " + tableName + " ( \
    659                objID \
    660                ,ippObjID \
    661                ,filterID \
    662                ) \
    663                SELECT \
    664                objID \
    665                ,ippObjID \
    666                ,filterID \
    667                FROM Detection_" + ota
    668         self.scratchDb.execute(sql)
    669 
    670         self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
    671467        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    672468
     
    693489       
    694490        # check we have valid sourceID/imageID pair from the header
    695         if self.safeDictionaryAccess(header, 'SOURCEID') == "NULL": return False
    696         if self.safeDictionaryAccess(header, 'IMAGEID') == "NULL": return False
    697        
    698         # store sourceID/imageID combo in Db so DVO can look up later
    699         if not self.useFullTables:
    700             self.scratchDb.insertNewDvoExternID(header['SOURCEID'], header['IMAGEID'])
     491        if self.getKeyValue(header, 'SOURCEID') == "NULL": return False
     492        if self.getKeyValue(header, 'IMAGEID') == "NULL": return False
     493       
     494        # store sourceID/imageID combo in Db so DVO can look up later (XXX deprecated?)
     495        # self.scratchDb.insertNewDvoExternID(header['SOURCEID'], header['IMAGEID'])
    701496           
    702497        # store these for later
     
    729524        self.logger.infoPair("Reading", "FITS headers")
    730525        self.logger.infoPair("Populating table", "ImageMeta")
     526
     527        if self.config.camera == "gpc1":
     528            for x in range(self.startX, self.endX):
     529                for y in range(self.startY, self.endY):
     530                   
     531                    # dodge the corners
     532                    if x==0 and y==0: continue
     533                    if x==0 and y==7: continue
     534                    if x==7 and y==0: continue
     535                    if x==7 and y==7: continue
     536                   
     537                    ota = "XY%d%d" % (x, y)
     538               
     539                    # I need better control over this..
     540                    if False and self.config.test and not ((x == 0) and (y == 1)):
     541                        print "skipping ota: " + ota
     542                        continue
     543                       
     544                    self.alterPspsTablesChip(ota, ota + ".hdr", x, y)
     545
     546        if self.config.camera == "simtest":
     547            # try the test Chip
     548            self.alterPspsTablesChip("Chip", "Chip.hdr", 0, 0)
     549
     550        # now run DVO code to get all IDs ( XXX deprecated, uses dvograbber)
     551        # if not self.getIDsFromDVO(): return False
     552
     553        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
     554        # the column in PSPS
     555        self.scratchDb.execute("ALTER TABLE Detection CHANGE dec_ `dec` double")
     556
     557        return True
     558
     559
     560    '''
     561    Applies indexes to the IPP tables
     562    '''
     563    def indexIppTables(self):
     564
     565        self.logger.infoPair("Creating indexes on", "IPP tables")
     566
    731567        for x in range(self.startX, self.endX):
    732568            for y in range(self.startY, self.endY):
    733                
     569
    734570                # dodge the corners
    735571                if x==0 and y==0: continue
     
    738574                if x==7 and y==7: continue
    739575
    740                 ota = "XY%d%d" % (x, y)
    741                
    742                 self.alterPspsTablesChip(ota, ota + ".hdr", x, y)
    743 
    744         # try the test Chip
    745         self.alterPspsTablesChip("Chip", "Chip.hdr", 0, 0)
    746 
    747         # now run DVO code to get all IDs
    748         if not self.useFullTables:
    749             if not self.getIDsFromDVO(): return False
    750 
    751         # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
    752         # the column in PSPS
    753         self.scratchDb.execute("ALTER TABLE DetectionCalib CHANGE dec_ `dec` double")
    754 
    755         return True
    756 
    757 
    758     '''
    759     Applies indexes to the IPP tables
    760     '''
    761     def indexIppTables(self):
    762 
    763         self.logger.infoPair("Creating indexes on", "IPP tables")
    764 
    765         for x in range(self.startX, self.endX):
    766             for y in range(self.startY, self.endY):
    767 
    768                 # dodge the corners
    769                 if x==0 and y==0: continue
    770                 if x==0 and y==7: continue
    771                 if x==7 and y==0: continue
    772                 if x==7 and y==7: continue
    773 
    774576                extension = "XY%d%d_psf" % (x, y)
    775577                self.scratchDb.createIndex(extension, "IPP_IDET")
     
    786588        imageID = self.scratchDb.getImageIDFromExternID(externID)
    787589        self.logger.debug("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)
     590
    788591        sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
    789                a.ippObjID = b.ippObjID, \
    790                a.detectID = b.detectID, \
    791                a.objID = b.objID, \
    792                a.infoFlag = b.flags << 45 | a.infoFlag \
     592               a.objID        = b.objID, \
     593               a.detectID     = b.detectID, \
     594               a.ippObjID     = b.ippObjID, \
     595               a.dvoRegionID  = b.catID, \
     596               a.ra           = b.ra, \
     597               a.dec          = b.dec_, \
     598               a.zp           = b.zp, \
     599               a.telluricExt  = b.telluricExt, \
     600               a.airmass      = b.airmass, \
     601               a.expTime      = b.expTime, \
     602               a.infoFlag2    = (b.flags << 13) | a.infoFlag2 \
    793603               WHERE a.ippDetectID = b.ippDetectID \
    794604               AND b.imageID = " + str(imageID)
     
    800610    '''
    801611    def populatePspsTablesChip(self, chipname, x, y, results, tables):
    802         # XXX EAM NOTE: drop tables (Detection_, SkinnyObject_, DetectionCalib_, Detection_) here so
     612        # XXX EAM NOTE: drop tables Detection_* here so
    803613        # they do not polute the db?
    804614        # XXX or put an explicit drop at the end of the loop?
    805615
    806         #self.logger.infoTitle("Processing " + chipname)
     616        # self.logger.infoTitle("Processing " + chipname)
    807617        # this is a bit crude: if the chip is not present, this test will fail and the chip
    808618        # will be (correctly) skipped.  would be better to carry that information explicitly ("chip is missing")
     
    818628            return False
    819629
    820         self.logger.info("populate stuff ");
     630        #self.logger.info("populate stuff ");
    821631        # populate remainder of tables
    822632        self.populateDetectionTable(chipname, results)
    823         self.logger.info("successful populate ");
     633        #self.logger.info("successful populate ");
    824634        # now add DVO IDs
    825635        self.updateDvoIDs("Detection_" + chipname, self.imageIDs[chipname])
    826         self.logger.info("updated dvoids")
     636        #self.logger.info("updated dvoids")
    827637        results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + chipname, "objID")
    828638        #self.logger.info("deleted nulls")
    829639        self.updateImageID("Detection_" + chipname, x, y)
    830         self.logger.info("updateImageId")
     640        #self.logger.info("updateImageId")
    831641        rowCount = self.scratchDb.getRowCount("Detection_" + chipname)
    832         self.logger.info("got row count")
    833         self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |",
     642        #self.logger.info("got row count")
     643        self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d |",
    834644                chipname,
    835645                results['ORIGINALTOTAL'],
    836646                results['SATDET'],
    837647                results['NULLINSTFLUX'],
    838                 results['NULLPEAKADU'],
    839648                results['NULLOBJID'],
    840649                rowCount)
     
    842651        self.totalSatDet       = self.totalSatDet + results['SATDET']
    843652        self.totalNulIInstFlux = self.totalNulIInstFlux + results['NULLINSTFLUX']
    844         self.totalNullPeakFlux = self.totalNullPeakFlux + results['NULLPEAKADU']
    845653        self.totalNullObjID    = self.totalNullObjID + results['NULLOBJID']
    846654        self.totalDetections   = self.totalDetections + rowCount
     
    867675        self.scratchDb.execute(sql)
    868676       
    869         self.logger.info("updated imagedata")
    870         self.populateSkinnyObjectTable(chipname)
    871         self.logger.info("updated skinnyobject")
    872         #self.populateObjectCalColorTable(chipname)
    873         #self.logger.info("updated objectcalcolor")
    874         self.populateDetectionCalibTable(chipname)
    875         self.logger.info("updated detectioncalibtable")
    876        
    877677        # add these to list of tables to export later
    878678        self.tablesToExport.append("ImageMeta_" + chipname)
     
    882682        self.logger.info("export Detection")
    883683
    884         self.tablesToExport.append("SkinnyObject_" + chipname)
    885         self.logger.info("export Skinny")
    886 
    887         #self.tablesToExport.append("ObjectCalColor_" + chipname)
    888         self.tablesToExport.append("DetectionCalib_" + chipname)
    889         self.logger.info("export DetectionCalib")
    890 
    891684        tables.append("Detection_" + chipname)
    892         self.logger.info("updated detectioncalibtable")
     685        self.logger.info("updated detection")
    893686
    894687        self.validChips.append(chipname)
     
    910703        results = {}
    911704        self.totalOriginal = self.totalSatDet = self.totalNulIInstFlux = self.totalNullPeakFlux = self.totalNullObjID = self.totalDetections = 0
    912         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
    913         self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL peak ADU | NULL obj ID   |  Remainder    |")
    914         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     705        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
     706        self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL obj ID   |  Remainder    |")
     707        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    915708        for x in range(self.startX, self.endX):
    916709            for y in range(self.startY, self.endY):
     
    925718                if ota not in self.imageIDs: continue
    926719
     720                if False and self.config.test and not ((x == 0) and (y == 1)):
     721                    print "skipping ota " + ota
     722                    continue
     723
    927724                if self.populatePspsTablesChip(ota, x, y, results, tables): otaCount = otaCount + 1
    928725                if self.skipBatch:
     
    937734
    938735        # print totals
    939         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     736        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    940737        self.logger.info("| Total | %13d | %13d | %13d | %13d | %13d | %13d |",
    941738                self.totalOriginal,
     
    945742                self.totalNullObjID,
    946743                self.totalDetections)
    947         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     744        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    948745
    949746        # if we only have one table export, i.e. FrameMeta, then get out of here (skip batch, but do not abort)
     
    961758        sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef)
    962759        self.scratchDb.execute(sql)
     760        #to make it stop
     761        #test = self.scratchDb.getRowCount("Object")
     762        #return False
    963763       
    964764        return True
     
    1031831    '''
    1032832    def importIppTables(self, filter=""):
    1033 
    1034        ## if self.config.test: regex = "XY33.psf"
    1035        ## else : regex = ".*.psf"
    1036        regex = ".*.psf"
    1037  
    1038        # XXX EAM NOTE : this is fragile : requires PS1_V4
    1039        # columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG AP_FLUX KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ"
    1040 
    1041        # XXX EAM NOTE : this is fragile : requires PS1_V4
    1042        columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ"
    1043 
    1044        return super(DetectionBatch, self).importIppTables(columns, regex)
    1045 
     833       
     834        regex = ".*.psf"
     835        if False and self.config.test and self.config.camera == "gpc1":
     836            regex = "XY01.psf"
     837           
     838        print "my ID: " + str(self.id)
     839
     840        if (self.id < 982483):
     841            # XXX EAM NOTE : this is fragile : requires PS1_V4
     842            columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG                   PSF_INST_FLUX PSF_INST_FLUX_SIG       PSF_MAJOR PSF_MINOR PSF_THETA          PSF_QF PSF_QF_PERFECT PSF_CHISQ EXT_NSIGMA MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S                             AP_MAG_RADIUS KRON_FLUX KRON_FLUX_ERR SKY SKY_SIGMA FLAGS FLAGS2"
     843        else:
     844            # XXX EAM NOTE : this is fragile : requires PS1_V5
     845            columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG POSANGLE PLTSCALE PSF_INST_FLUX PSF_INST_FLUX_SIG PSF_FWHM_MAJ PSF_FWHM_MIN PSF_THETA PSF_CORE PSF_QF PSF_QF_PERFECT PSF_CHISQ EXT_NSIGMA MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S AP_FLUX AP_FLUX_SIG AP_NPIX AP_MAG_RADIUS KRON_FLUX KRON_FLUX_ERR SKY SKY_SIGMA FLAGS FLAGS2"
     846
     847        return super(DetectionBatch, self).importIppTables(columns, regex)
    1046848
    1047849    '''
     
    1050852    def exportPspsTablesToFits(self, regex="(.*)"):
    1051853       return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)")
    1052 
Note: See TracChangeset for help on using the changeset viewer.