IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 28, 2014, 6:20:27 AM (12 years ago)
Author:
eugene
Message:

dropping options for stilts dvo import methods; fixing a number of previously ignored errors (eg, dropping non-existent tables); allowing queue questions to strip leading and trailing spaces (so we can read from an input file); echo back the response so input from a file is clearer; re-write big sql blocks with new sql utility code; updating names in MeanObject, ObjectThin to be more consistent; add a new test code program; update detection fields to match new schema; drop the code for the old now-unused tables (detecitonCalib, SkinnyObject, etc)

Location:
branches/eam_branches/ipp-20140717/ippToPsps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140717/ippToPsps

  • branches/eam_branches/ipp-20140717/ippToPsps/jython/detectionbatch.py

    r36744 r37129  
    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
     
    124123        self.logger.infoPair("Proccesing table", "FrameMeta")
    125124
    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
     125        sqlLine = sqlUtility("INSERT INTO FrameMeta (")
     126
     127        sqlLine.group("frameID",               str(self.expID));
     128        sqlLine.group("frameName",             self.expName);
     129        sqlLine.group("cameraID",              "1");
     130        sqlLine.group("cameraConfigID",        "1");
     131        sqlLine.group("telescopeID",           "1");
     132        sqlLine.group("analysisVer",           str(self.analysisVer));
     133        sqlLine.group("p1Recip",               " ");
     134        sqlLine.group("p2Recip",               " ");
     135        sqlLine.group("p3Recip",               " ");
     136        sqlLine.group("photoScat",             "self.safeDictionaryAccess(self.header, 'ZPT_ERR')");
     137        sqlLine.group("expStart",              "self.safeDictionaryAccess(self.header, 'MJD-OBS')");
     138        sqlLine.group("expTime",               "self.safeDictionaryAccess(self.header, 'EXPREQ')");
     139        sqlLine.group("airmass",               "self.safeDictionaryAccess(self.header, 'AIRMASS')");
     140        sqlLine.group("raBore",                "self.safeDictionaryAccess(self.header, 'RA')");
     141        sqlLine.group("decBore",               "self.safeDictionaryAccess(self.header, 'DEC')");
     142        sqlLine.group("ctype1",                self.safeDictionaryAccess(self.header, 'CTYPE1'));
     143        sqlLine.group("ctype2",                self.safeDictionaryAccess(self.header, 'CTYPE2'));
     144        sqlLine.group("crval1",                "self.safeDictionaryAccess(self.header, 'CRVAL1')");
     145        sqlLine.group("crval2",                "self.safeDictionaryAccess(self.header, 'CRVAL2')");
     146        sqlLine.group("crpix1",                "self.safeDictionaryAccess(self.header, 'CRPIX1')");
     147        sqlLine.group("crpix2",                "self.safeDictionaryAccess(self.header, 'CRPIX2')");
     148        sqlLine.group("cdelt1",                "self.safeDictionaryAccess(self.header, 'CDELT1')");
     149        sqlLine.group("cdelt2",                "self.safeDictionaryAccess(self.header, 'CDELT2')");
     150        sqlLine.group("pc001001",              "self.safeDictionaryAccess(self.header, 'PC001001')");
     151        sqlLine.group("pc001002",              "self.safeDictionaryAccess(self.header, 'PC001002')");
     152        sqlLine.group("pc002001",              "self.safeDictionaryAccess(self.header, 'PC002001')");
     153        sqlLine.group("pc002002",              "self.safeDictionaryAccess(self.header, 'PC002002')");
     154        sqlLine.group("polyOrder",             "self.safeDictionaryAccess(self.header, 'NPLYTERM')");
     155        sqlLine.group("pca1x3y0",              "self.safeDictionaryAccess(self.header, 'PCA1X3Y0')");
     156        sqlLine.group("pca1x2y1",              "self.safeDictionaryAccess(self.header, 'PCA1X2Y1')");
     157        sqlLine.group("pca1x1y2",              "self.safeDictionaryAccess(self.header, 'PCA1X1Y2')");
     158        sqlLine.group("pca1x0y3",              "self.safeDictionaryAccess(self.header, 'PCA1X0Y3')");
     159        sqlLine.group("pca1x2y0",              "self.safeDictionaryAccess(self.header, 'PCA1X2Y0')");
     160        sqlLine.group("pca1x1y1",              "self.safeDictionaryAccess(self.header, 'PCA1X1Y1')");
     161        sqlLine.group("pca1x0y2",              "self.safeDictionaryAccess(self.header, 'PCA1X0Y2')");
     162        sqlLine.group("pca2x3y0",              "self.safeDictionaryAccess(self.header, 'PCA2X3Y0')");
     163        sqlLine.group("pca2x2y1",              "self.safeDictionaryAccess(self.header, 'PCA2X2Y1')");
     164        sqlLine.group("pca2x1y2",              "self.safeDictionaryAccess(self.header, 'PCA2X1Y2')");
     165        sqlLine.group("pca2x0y3",              "self.safeDictionaryAccess(self.header, 'PCA2X0Y3')");
     166        sqlLine.group("pca2x2y0",              "self.safeDictionaryAccess(self.header, 'PCA2X2Y0')");
     167        sqlLine.group("pca2x1y1",              "self.safeDictionaryAccess(self.header, 'PCA2X1Y1')");
     168        sqlLine.group("pca2x0y2",              "self.safeDictionaryAccess(self.header, 'PCA2X0Y2')");
     169
     170        sql = sqlLine.make(") VALUES ( ", ")")
     171        print "frame meta sql: ", sql
    215172
    216173        self.scratchDb.execute(sql)
     
    228185        tableName = "ImageMeta_" + ota
    229186       
    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)
     187        # we drop the table before calling this functoin so it is not left behind on failure
    233188        sql = "CREATE TABLE " + tableName + " LIKE ImageMeta"
    234189        try: self.scratchDb.execute(sql)
    235190        except: pass
     191
    236192        if (ota[0:2] == "XY"): ccdID = ota[2:4]
    237193        else: ccdID = 0
    238194
     195        psfFwhm = 0.5*(self.safeDictionaryAccess(header, 'FWHM_MAJ') + self.safeDictionaryAccess(header, 'FWHM_MIN'))
     196
    239197        # 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                ,momentXX \
    260                ,momentXY \
    261                ,momentYY \
    262                ,momentM3C \
    263                ,momentM3S \
    264                ,momentM4C \
    265                ,momentM4S \
    266                ,momentR1 \
    267                ,momentRH \
    268                ,apResid \
    269                ,dapResid \
    270                ,detectorID \
    271                ,qaFlags \
    272                ,detrend1 \
    273                ,detrend2 \
    274                ,detrend3 \
    275                ,detrend4 \
    276                ,detrend5 \
    277                ,detrend6 \
    278                ,detrend7 \
    279                ,detrend8 \
    280                ,photoZero \
    281                ,ctype1 \
    282                ,ctype2 \
    283                ,crval1 \
    284                ,crval2 \
    285                ,crpix1 \
    286                ,crpix2 \
    287                ,cdelt1 \
    288                ,cdelt2 \
    289                ,pc001001 \
    290                ,pc001002 \
    291                ,pc002001 \
    292                ,pc002002 \
    293                ,polyOrder \
    294                ,pca1x3y0 \
    295                ,pca1x2y1 \
    296                ,pca1x1y2 \
    297                ,pca1x0y3 \
    298                ,pca1x2y0 \
    299                ,pca1x1y1 \
    300                ,pca1x0y2 \
    301                ,pca2x3y0 \
    302                ,pca2x2y1 \
    303                ,pca2x1y2 \
    304                ,pca2x0y3 \
    305                ,pca2x2y0 \
    306                ,pca2x1y1 \
    307                ,pca2x0y2 \
    308                ) VALUES ( \
    309                " + str(self.expID) + " \
    310                ," + str(ccdID) + " \
    311                ," + str(self.bias) + " \
    312                ," + str(self.biasScat) + " \
    313                ," + self.safeDictionaryAccess(header, 'MSKY_MN') + " \
    314                ," + self.safeDictionaryAccess(header, 'MSKY_SIG') + " \
    315                ," + self.safeDictionaryAccess(header, 'FSATUR') + " \
    316                ," + self.safeDictionaryAccess(header, 'FLIMIT') + " \
    317                ," + self.safeDictionaryAccess(header, 'CERROR') + " \
    318                ," + self.safeDictionaryAccess(self.header, 'ZPT_OBS') + " \
    319                ," + self.safeDictionaryAccess(header, 'NASTRO') + " \
    320                ," + self.safeDictionaryAccess(header, 'NASTRO') + " \
    321                ," + self.safeDictionaryAccess(header, 'CNAXIS1') + " \
    322                ," + self.safeDictionaryAccess(header, 'CNAXIS2') + " \
    323                , ( " + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " + " + self.safeDictionaryAccess(header, 'FWHM_MIN') + " ) / 2.0 \
    324                ," + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " \
    325                ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \
    326                ," + self.safeDictionaryAccess(header, 'ANGLE') + " \
    327                ,-999 \
    328                ,-999 \
    329                ,-999 \
    330                ,-999 \
    331                ,-999 \
    332                ,-999 \
    333                ,-999 \
    334                ,-999 \
    335                ,-999 \
    336                ," + self.safeDictionaryAccess(header, 'APMIFIT') + " \
    337                ," + self.safeDictionaryAccess(header, 'DAPMIFIT') + " \
    338                ,'" + self.safeDictionaryAccess(header, 'DETECTOR') + "' \
    339                ," + str(self.scratchDb.getDvoImageFlags(header['IMAGEID'])) + " \
    340                ,'" + self.safeDictionaryAccess(header, 'DETREND.MASK') + "' \
    341                ,'" + self.safeDictionaryAccess(header, 'DETREND.DARK') + "' \
    342                ,'" + self.safeDictionaryAccess(header, 'DETREND.FLAT') + "' \
    343                ,' ' \
    344                ,' ' \
    345                ,' ' \
    346                ,' ' \
    347                ,' ' \
    348                ," + self.safeDictionaryAccess(self.header, 'ZPT_OBS') + " \
    349                ,'" + self.safeDictionaryAccess(header, 'CTYPE1') + "' \
    350                ,'" + self.safeDictionaryAccess(header, 'CTYPE2') + "' \
    351                ," + self.safeDictionaryAccess(header, 'CRVAL1') + " \
    352                ," + self.safeDictionaryAccess(header, 'CRVAL2') + " \
    353                ," + self.safeDictionaryAccess(header, 'CRPIX1') + " \
    354                ," + self.safeDictionaryAccess(header, 'CRPIX2') + " \
    355                ," + self.safeDictionaryAccess(header, 'CDELT1') + " \
    356                ," + self.safeDictionaryAccess(header, 'CDELT2') + " \
    357                ," + self.safeDictionaryAccess(header, 'PC001001') + " \
    358                ," + self.safeDictionaryAccess(header, 'PC001002') + " \
    359                ," + self.safeDictionaryAccess(header, 'PC002001') + " \
    360                ," + self.safeDictionaryAccess(header, 'PC002002') + " \
    361                ," + self.safeDictionaryAccess(header, 'NPLYTERM') + " \
    362                ," + self.safeDictionaryAccess(header, 'PCA1X3Y0') + " \
    363                ," + self.safeDictionaryAccess(header, 'PCA1X2Y1') + " \
    364                ," + self.safeDictionaryAccess(header, 'PCA1X1Y2') + " \
    365                ," + self.safeDictionaryAccess(header, 'PCA1X0Y3') + " \
    366                ," + self.safeDictionaryAccess(header, 'PCA1X2Y0') + " \
    367                ," + self.safeDictionaryAccess(header, 'PCA1X1Y1') + " \
    368                ," + self.safeDictionaryAccess(header, 'PCA1X0Y2') + " \
    369                ," + self.safeDictionaryAccess(header, 'PCA2X3Y0') + " \
    370                ," + self.safeDictionaryAccess(header, 'PCA2X2Y1') + " \
    371                ," + self.safeDictionaryAccess(header, 'PCA2X1Y2') + " \
    372                ," + self.safeDictionaryAccess(header, 'PCA2X0Y3') + " \
    373                ," + self.safeDictionaryAccess(header, 'PCA2X2Y0') + " \
    374                ," + self.safeDictionaryAccess(header, 'PCA2X1Y1') + " \
    375                ," + self.safeDictionaryAccess(header, 'PCA2X0Y2') + " \
    376                )"
     198        sqlLine = sqlUtility("INSERT INTO " + tableName + "(")
     199
     200        sqlLine.group("frameID",          str(self.expID))
     201        sqlLine.group("ccdID",            str(ccdID))
     202        sqlLine.group("bias",             str(self.bias))
     203        sqlLine.group("biasScat",         str(self.biasScat))
     204        sqlLine.group("sky",              "self.safeDictionaryAccess(header, 'MSKY_MN')")
     205        sqlLine.group("skyScat",          "self.safeDictionaryAccess(header, 'MSKY_SIG')")
     206        sqlLine.group("magSat",           "self.safeDictionaryAccess(header, 'FSATUR')")
     207        sqlLine.group("completMag",       "self.safeDictionaryAccess(header, 'FLIMIT')")
     208        sqlLine.group("astroScat",        "self.safeDictionaryAccess(header, 'CERROR')")
     209        sqlLine.group("photoScat",        "self.safeDictionaryAccess(self.header, 'ZPT_OBS')")
     210        sqlLine.group("numAstroRef",      "self.safeDictionaryAccess(header, 'NASTRO')")
     211        sqlLine.group("numPhotoRef",      "self.safeDictionaryAccess(header, 'NASTRO')")
     212        sqlLine.group("nx",               "self.safeDictionaryAccess(header, 'CNAXIS1')")
     213        sqlLine.group("ny",               "self.safeDictionaryAccess(header, 'CNAXIS2')")
     214        sqlLine.group("psfFwhm",          str(psfFwhm))
     215        sqlLine.group("psfWidMajor",      "self.safeDictionaryAccess(header, 'FWHM_MAJ')")
     216        sqlLine.group("psfWidMinor",      "self.safeDictionaryAccess(header, 'FWHM_MIN')")
     217        sqlLine.group("psfTheta",         "self.safeDictionaryAccess(header, 'ANGLE')")
     218        sqlLine.group("momentXX",         "-999")
     219        sqlLine.group("momentXY",         "-999")
     220        sqlLine.group("momentYY",         "-999")
     221        sqlLine.group("momentM3C",        "-999")
     222        sqlLine.group("momentM3S",        "-999")
     223        sqlLine.group("momentM4C",        "-999")
     224        sqlLine.group("momentM4S",        "-999")
     225        sqlLine.group("momentR1",         "-999")
     226        sqlLine.group("momentRH",         "-999")
     227        sqlLine.group("apResid",          "self.safeDictionaryAccess(header, 'APMIFIT')")
     228        sqlLine.group("dapResid",         "self.safeDictionaryAccess(header, 'DAPMIFIT')")
     229        sqlLine.group("detectorID",       self.safeDictionaryAccess(header, 'DETECTOR'))
     230        sqlLine.group("qaFlags",          str(self.scratchDb.getDvoImageFlags(header['IMAGEID'])))
     231        sqlLine.group("detrend1",         self.safeDictionaryAccess(header, 'DETREND.MASK'))
     232        sqlLine.group("detrend2",         self.safeDictionaryAccess(header, 'DETREND.DARK'))
     233        sqlLine.group("detrend3",         self.safeDictionaryAccess(header, 'DETREND.FLAT'))
     234        sqlLine.group("detrend4",         " ")
     235        sqlLine.group("detrend5",         " ")
     236        sqlLine.group("detrend6",         " ")
     237        sqlLine.group("detrend7",         " ")
     238        sqlLine.group("detrend8",         " ")
     239        sqlLine.group("photoZero",        "self.safeDictionaryAccess(self.header, 'ZPT_OBS')")
     240        sqlLine.group("ctype1",           "self.safeDictionaryAccess(header, 'CTYPE1')")
     241        sqlLine.group("ctype2",           "self.safeDictionaryAccess(header, 'CTYPE2')")
     242        sqlLine.group("crval1",           "self.safeDictionaryAccess(header, 'CRVAL1')")
     243        sqlLine.group("crval2",           "self.safeDictionaryAccess(header, 'CRVAL2')")
     244        sqlLine.group("crpix1",           "self.safeDictionaryAccess(header, 'CRPIX1')")
     245        sqlLine.group("crpix2",           "self.safeDictionaryAccess(header, 'CRPIX2')")
     246        sqlLine.group("cdelt1",           "self.safeDictionaryAccess(header, 'CDELT1')")
     247        sqlLine.group("cdelt2",           "self.safeDictionaryAccess(header, 'CDELT2')")
     248        sqlLine.group("pc001001",         "self.safeDictionaryAccess(header, 'PC001001')")
     249        sqlLine.group("pc001002",         "self.safeDictionaryAccess(header, 'PC001002')")
     250        sqlLine.group("pc002001",         "self.safeDictionaryAccess(header, 'PC002001')")
     251        sqlLine.group("pc002002",         "self.safeDictionaryAccess(header, 'PC002002')")
     252        sqlLine.group("polyOrder",        "self.safeDictionaryAccess(header, 'NPLYTERM')")
     253        sqlLine.group("pca1x3y0",         "self.safeDictionaryAccess(header, 'PCA1X3Y0')")
     254        sqlLine.group("pca1x2y1",         "self.safeDictionaryAccess(header, 'PCA1X2Y1')")
     255        sqlLine.group("pca1x1y2",         "self.safeDictionaryAccess(header, 'PCA1X1Y2')")
     256        sqlLine.group("pca1x0y3",         "self.safeDictionaryAccess(header, 'PCA1X0Y3')")
     257        sqlLine.group("pca1x2y0",         "self.safeDictionaryAccess(header, 'PCA1X2Y0')")
     258        sqlLine.group("pca1x1y1",         "self.safeDictionaryAccess(header, 'PCA1X1Y1')")
     259        sqlLine.group("pca1x0y2",         "self.safeDictionaryAccess(header, 'PCA1X0Y2')")
     260        sqlLine.group("pca2x3y0",         "self.safeDictionaryAccess(header, 'PCA2X3Y0')")
     261        sqlLine.group("pca2x2y1",         "self.safeDictionaryAccess(header, 'PCA2X2Y1')")
     262        sqlLine.group("pca2x1y2",         "self.safeDictionaryAccess(header, 'PCA2X1Y2')")
     263        sqlLine.group("pca2x0y3",         "self.safeDictionaryAccess(header, 'PCA2X0Y3')")
     264        sqlLine.group("pca2x2y0",         "self.safeDictionaryAccess(header, 'PCA2X2Y0')")
     265        sqlLine.group("pca2x1y1",         "self.safeDictionaryAccess(header, 'PCA2X1Y1')")
     266        sqlLine.group("pca2x0y2",         "self.safeDictionaryAccess(header, 'PCA2X0Y2')")
     267
     268        sql = sqlLine.make(") VALUES ( ", ")")
    377269
    378270        try: self.scratchDb.execute(sql)
     
    407299        results['SATDET'] = 0
    408300
    409         # insert all detections into table
    410         sql = "INSERT IGNORE INTO " + pspsTableName + " ( \
    411                ippDetectID \
    412                ,randomDetID \
    413                ,filterID \
    414                ,surveyID \
    415                ,obsTime \
    416                ,xPos \
    417                ,yPos \
    418                ,xPosErr \
    419                ,yPosErr \
    420                ,psfFlux \
    421                ,psfFluxErr \
    422                ,psfMajorFWHM \
    423                ,psfMinorFWHM \
    424                ,psfTheta \
    425                ,psfCore \
    426                ,psfLikelihood \
    427                ,psfQf \
    428                ,momentXX \
    429                ,momentXY \
    430                ,momentYY \
    431                ,momentR1 \
    432                ,momentRH \
    433                ,momentM3C \
    434                ,momentM3S \
    435                ,momentM4C \
    436                ,momentM4S \
    437                ,apFlux \
    438                ,kronFlux \
    439                ,kronFluxErr \
    440                ,psfQfPerfect \
    441                ,psfChiSq \
    442                ,infoFlag \
    443                ,sky \
    444                ,skyErr \
    445                ,pltScale \
    446                ,posAngle \
    447                ,dataRelease \
    448                ) \
    449                SELECT \
    450                IPP_IDET \
    451                , FLOOR(RAND()*9223372036854775807) \
    452                , " + str(self.filterID) + "\
    453                , " + str(self.surveyID) + " \
    454                ," + str(self.obsTime) + " \
    455                ,X_PSF \
    456                ,Y_PSF \
    457                ,X_PSF_SIG \
    458                ,Y_PSF_SIG \
    459                ,PSF_INST_FLUX / " + self.header['EXPTIME'] + " \
    460                ,PSF_INST_FLUX_SIG / " + self.header['EXPTIME'] + " \
    461                ,PSF_MAJOR \
    462                ,PSF_MINOR \
    463                ,PSF_THETA \
    464                ,-999 \
    465                ,psfLikelihood(EXT_NSIGMA) \
    466                ,PSF_QF \
    467                ,MOMENTS_XX \
    468                ,MOMENTS_XY \
    469                ,MOMENTS_YY \
    470                ,MOMENTS_R1 \
    471                ,MOMENTS_RH \
    472                ,MOMENTS_M3C \
    473                ,MOMENTS_M3S \
    474                ,MOMENTS_M4C \
    475                ,MOMENTS_M4S \
    476                ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
    477                ,KRON_FLUX / " + self.header['EXPTIME'] + " \
    478                ,KRON_FLUX_ERR / " + self.header['EXPTIME'] + " \
    479                ,PSF_QF_PERFECT \
    480                ,PSF_CHISQ \
    481                ,FLAGS2 << 32 | FLAGS \
    482                ,SKY  / " + self.header['EXPTIME'] + " \
    483                ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
    484                ,PLTSCALE \
    485                ,POSANGLE \
    486                , " + str(self.skychunk.dataRelease) + "\
    487                FROM " + ippTableName
    488         # self.logger.info(sql)
    489 
    490 # these were used above (left over from before PSF_INST_FLUX, PSF_INST_FLUX_SIG were available?
    491 #               ,POW(10.0, (-0.4*PSF_INST_MAG)) / " + self.header['EXPTIME'] + "
    492 #               ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / " + self.header['EXPTIME'] + ")) / 1.085736)
    493 
    494 # I need a way to choose the sql above based on the cmf version: V3 (LAP.PV1) does not have AP_FLUX
    495 # AP_FLUX is no              ,AP_FLUX / " + self.header['EXPTIME'] + "
    496 
    497         self.scratchDb.execute(sql)
    498 
    499         # XXX EAM : I removed this old fix for invalid fluxes
    500         # add a instFlux = 0.0 -> 0.000001
    501         # XXX EAM : why is this done?
    502         # sql="UPDATE " + pspsTableName + " SET psfFlux = 0.0000001 WHERE psfFlux =  0"
    503         # self.scratchDb.execute(sql)
    504      
     301        extTimeString = str(self.header['EXPTIME'])
     302
     303        # insert all detections into table : do NOT include the IGNORE unless we have to
     304        # sqlLine = sqlUtility("INSERT IGNORE INTO " + pspsTableName + " (")
     305        sqlLine = sqlUtility("INSERT INTO " + pspsTableName + " (")
     306
     307        # XXX WARNING: need to apply platescale to convert sizes to arcsec
     308        # XXX apFluxF or apFluxNpix + apFluxRadius?
     309
     310        sqlLine.group("ippDetectID",     "IPP_IDET")                                               
     311        sqlLine.group("randomDetID",     "FLOOR(RAND()*9223372036854775807)")                       
     312        sqlLine.group("filterID",        str(self.filterID))                                       
     313        sqlLine.group("surveyID",        str(self.surveyID))                                       
     314        sqlLine.group("obsTime",         str(self.obsTime))                                         
     315        sqlLine.group("xPos",            "X_PSF")                                                   
     316        sqlLine.group("yPos",            "Y_PSF")                                                   
     317        sqlLine.group("xPosErr",         "X_PSF_SIG")                                               
     318        sqlLine.group("yPosErr",         "Y_PSF_SIG")                                               
     319        sqlLine.group("pltScale",        "PLTSCALE")                                     
     320        sqlLine.group("posAngle",        "POSANGLE")                                     
     321        sqlLine.group("psfFlux",         "PSF_INST_FLUX / " + extTimeString)
     322        sqlLine.group("psfFluxErr",      "PSF_INST_FLUX_SIG / " + extTimeString)
     323        sqlLine.group("psfMajorFWHM",    "PSF_FWHM_MAJ")                                               
     324        sqlLine.group("psfMinorFWHM",    "PSF_FWHM_MIN")                                               
     325        sqlLine.group("psfTheta",        "PSF_THETA")                                               
     326        sqlLine.group("psfCore",         "PSF_CORE")                                                   
     327        sqlLine.group("psfQf",           "PSF_QF")                                                 
     328        sqlLine.group("psfQfPerfect",    "PSF_QF_PERFECT")                               
     329        sqlLine.group("psfChiSq",        "PSF_CHISQ")                                     
     330        sqlLine.group("psfLikelihood",   "psfLikelihood(EXT_NSIGMA)")                               
     331        sqlLine.group("momentXX",        "MOMENTS_XX")                                             
     332        sqlLine.group("momentXY",        "MOMENTS_XY")                                             
     333        sqlLine.group("momentYY",        "MOMENTS_YY")                                             
     334        sqlLine.group("momentR1",        "MOMENTS_R1")                                             
     335        sqlLine.group("momentRH",        "MOMENTS_RH")                                             
     336        sqlLine.group("momentM3C",       "MOMENTS_M3C")                                             
     337        sqlLine.group("momentM3S",       "MOMENTS_M3S")                                             
     338        sqlLine.group("momentM4C",       "MOMENTS_M4C")                                             
     339        sqlLine.group("momentM4S",       "MOMENTS_M4S")                                             
     340        sqlLine.group("apFlux",          "AP_FLUX / " + extTimeString)
     341        sqlLine.group("apFluxErr",       "AP_FLUX_SIG / " + extTimeString)
     342        sqlLine.group("apFluxNpix",      "AP_NPIX")
     343        sqlLine.group("kronFlux",        "KRON_FLUX / " + extTimeString)
     344        sqlLine.group("kronFluxErr",     "KRON_FLUX_ERR / " + extTimeString)
     345        sqlLine.group("kronRad",         "MOMENTS_R1 * 2.5")
     346        sqlLine.group("sky",             "SKY  / " + extTimeString)
     347        sqlLine.group("skyErr",          "SKY_SIGMA  / " + extTimeString)
     348        sqlLine.group("infoFlag",        "FLAGS")                         
     349        sqlLine.group("infoFlag2",       "FLAGS2")                         
     350        sqlLine.group("dataRelease",     str(self.skychunk.dataRelease))                 
     351
     352        sqlLine.make(") SELECT ", " FROM " + ippTableName)
     353
     354        print "sql: " + sql
     355
     356        self.scratchDb.execute(sql)
     357
    505358        # NOTE : Flux limits : in the current PSPS schema, negative fluxes
    506359        # cause problems for sql queries which work in mags as SQL cannot do
    507360        # something like (f < 0.0) ? -999 : -2.5*log10(f)
    508361        # as a result, the negative fluxes here result in floating point errors
     362        # XXX EAM 2014072 : Is this still a problem?
    509363        sql = "UPDATE " + pspsTableName + " SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
    510364        self.scratchDb.execute(sql)
     
    518372        # we don't delete these anymore
    519373        results['NULLINSTFLUX'] = 0;
    520        
    521374
    522375    '''
     
    547400
    548401        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    549 
    550     '''
    551     Populates the DetectionCalib table for this OTA
    552     '''
    553     def populateDetectionCalibTableUpdateInsert(self, ota):
    554 
    555         tableName = "Detection_" + ota
     402    '''
     403    Populates the SkinnyObject table for this OTA
     404    '''
     405    def populateSkinnyObjectTable(self, ota):
     406
     407        tableName = "SkinnyObject_" + ota
     408       
    556409        # drop then re-create table
    557         #self.scratchDb.dropTable(tableName)
    558         #sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
    559         #try: self.scratchDb.execute(sql)
    560         #except: pass
     410        self.scratchDb.dropTable(tableName)
     411        sql = "CREATE TABLE " + tableName + " LIKE SkinnyObject"
     412        try: self.scratchDb.execute(sql)
     413        except: pass
    561414
    562415        # insert all detections into table
    563416        sql = "INSERT INTO " + tableName + " ( \
    564417               objID \
    565                ,detectID \
    566418               ,ippObjID \
    567                ,ippDetectID \
    568                ,filterID \
    569419               ,surveyID \
    570420               ) \
    571421               SELECT \
    572422               objID \
    573                ,detectID \
    574423               ,ippObjID \
    575                ,ippDetectID \
    576                ,filterID \
    577424               ,surveyID \
    578425               FROM Detection_" + ota
    579 #        self.scratchDb.execute(sql)
    580 
    581         # insert calibration information from dvoDetections into the Table
    582         sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
    583             SET a.ra = b.ra, \
    584             a.dec = b.dec_, \
    585             a.raErr = b.raErr, \
    586             a.decErr = b.decErr, \
    587             a.zp = b.zp, \
    588             a.expTime = b.expTime, \
    589             a.airMass = b.airMass   \
    590             WHERE a.objID = b.objID AND a.detectID = b.detectID"
    591         self.scratchDb.execute(sql)
    592         self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    593        
    594     '''
    595     Populates the DetectionCalib table for this OTA
    596     '''
    597     def populateDetectionCalibTable(self, ota):
    598 
    599         # target table name:
    600         tableName = "Detection_" + ota
    601         # drop then re-create table
    602         #self.scratchDb.dropTable(tableName)
    603         #sql = "CREATE TABLE " + tableName + " LIKE Detection"
    604         #try: self.scratchDb.execute(sql)
    605         #except: pass
    606 
    607         externID = self.imageIDs[ota]
    608 
    609         imageID = self.scratchDb.getImageIDFromExternID(externID)
    610         self.logger.infoPair("obtained imageID",imageID)
    611         self.logger.infoPair("obtained externID",externID)
    612 
    613         # insert all detections into table
    614         sql = "Update Detection_" + ota + " AS a, "+ self.scratchDb.dvoDetectionTable + " as b \
    615           set a.ra=b.ra,            \
    616           a.dec = b.dec_,          \
    617           a.raErr = b.raErr,         \
    618           a.decErr = b.decErr,        \
    619           a.zp = b.zp,            \
    620           a.expTime = b.expTime,       \
    621           a.airMass = b.airMass       \
    622           WHERE (a.objID = b.objID AND a.detectID = b.detectID) \
    623           AND b.imageID = " + str(imageID)  \
    624  
    625 
    626         try: self.scratchDb.execute(sql)
    627         except:
    628             self.logger.info("failed to update data for detectionCalib")
    629             self.logger.infoPair("sql: ", sql)
    630             raise
    631        
    632     '''
    633     Populates the Detection table for this OTA
    634     '''
    635     def populateObjectCalColorTable(self, ota):
    636 
    637         tableName = "ObjectCalColor_" + ota
    638        
    639         # drop then re-create table
    640         self.scratchDb.dropTable(tableName)
    641         sql = "CREATE TABLE " + tableName + " LIKE ObjectCalColor"
    642         try: self.scratchDb.execute(sql)
    643         except: pass
    644 
    645         # insert all detections into table
    646         sql = "INSERT INTO " + tableName + " ( \
    647                objID \
    648                ,ippObjID \
    649                ,filterID \
    650                ) \
    651                SELECT \
    652                objID \
    653                ,ippObjID \
    654                ,filterID \
    655                FROM Detection_" + ota
    656         self.scratchDb.execute(sql)
    657 
    658         self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
     426        self.scratchDb.execute(sql)
     427
    659428        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    660429
     
    685454       
    686455        # store sourceID/imageID combo in Db so DVO can look up later
    687         if not self.useFullTables:
    688             self.scratchDb.insertNewDvoExternID(header['SOURCEID'], header['IMAGEID'])
     456        self.scratchDb.insertNewDvoExternID(header['SOURCEID'], header['IMAGEID'])
    689457           
    690458        # store these for later
     
    734502
    735503        # now run DVO code to get all IDs
    736         if not self.useFullTables:
    737             if not self.getIDsFromDVO(): return False
     504        if not self.getIDsFromDVO(): return False
    738505
    739506        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
     
    774541        imageID = self.scratchDb.getImageIDFromExternID(externID)
    775542        self.logger.debug("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)
     543
    776544        sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
    777                a.ippObjID = b.ippObjID, \
    778                a.detectID = b.detectID, \
    779                a.objID = b.objID, \
    780                a.infoFlag = b.flags << 45 | a.infoFlag \
     545               a.objID        = b.objID, \
     546               a.detectID     = b.detectID, \
     547               a.ippObjID     = b.ippObjID, \
     548               a.ra           = b.ra, \
     549               a.dec_         = b.dec_, \
     550               a.raErr        = b.raErr, \
     551               a.decErr       = b.decErr, \
     552               a.zp           = b.zp, \
     553               a.telluricExt  = b.telluricExt, \
     554               a.airmass      = b.airmass, \
     555               a.expTime      = b.expTime, \
     556               a.infoFlag2    = (b.flags << 13) | a.infoFlag2 \
    781557               WHERE a.ippDetectID = b.ippDetectID \
    782558               AND b.imageID = " + str(imageID)
    783559
     560        # XXX need to add dvoRegion
     561
    784562        self.scratchDb.execute(sql)
    785563
     
    788566    '''
    789567    def populatePspsTablesChip(self, chipname, x, y, results, tables):
    790         # XXX EAM NOTE: drop tables (Detection_, SkinnyObject_, DetectionCalib_, Detection_) here so
     568        # XXX EAM NOTE: drop tables Detection_* here so
    791569        # they do not polute the db?
    792570        # XXX or put an explicit drop at the end of the loop?
    793571
    794         #self.logger.infoTitle("Processing " + chipname)
     572        # self.logger.infoTitle("Processing " + chipname)
    795573        # this is a bit crude: if the chip is not present, this test will fail and the chip
    796574        # will be (correctly) skipped.  would be better to carry that information explicitly ("chip is missing")
     
    853631        self.scratchDb.execute(sql)
    854632       
    855         #self.logger.info("updated imagedata")
    856        
    857         self.populateDetectionCalibTable(chipname)
    858         #self.logger.info("updated detectioncalibtable")
    859        
    860633        # add these to list of tables to export later
    861634        self.tablesToExport.append("ImageMeta_" + chipname)
     
    865638        self.logger.info("export Detection")
    866639
    867        
    868640        tables.append("Detection_" + chipname)
    869         self.logger.info("updated detectioncalibtable")
     641        self.logger.info("updated detection")
    870642
    871643        self.validChips.append(chipname)
     
    1024796       return super(DetectionBatch, self).importIppTables(columns, regex)
    1025797
    1026 
    1027798    '''
    1028799    Overriding this method. Use regex to trim off, eg _XY33 extension
     
    1030801    def exportPspsTablesToFits(self, regex="(.*)"):
    1031802       return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)")
    1032 
Note: See TracChangeset for help on using the changeset viewer.