IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 15, 2011, 4:54:05 PM (15 years ago)
Author:
rhenders
Message:

looping round all OTAs and creating tables for each; many more fields populated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/detectionbatch.py

    r31285 r31303  
    2121               "detection",
    2222               inputFile,
    23                "ThreePi") # TODO
     23               "3PI") # TODO
    2424
    2525       self.logger.info("DetectionBatch constructor. Creating batch from: '" + inputFile + "'")
    2626
     27       self.expID = expID
    2728       # create an output filename, which is {expID}.FITS
    2829       self.outputFitsFile = "%08d.FITS" % expID
     
    3334    Populates the FrameMeta table, mainly from dictionary values found in IPP FITS header
    3435    '''
    35     def populateImageMeta(self):
    36         self.log("Procesing ImageMeta table")
    37         '''
    38         sql = "INSERT INTO ImageMeta (\
    39         stackMetaID \
    40         ,skycellID \
    41         ,photoZero \
    42         ,nP2Images \
    43         ,ctype1 \
    44         ,ctype2 \
    45         ,crval1 \
    46         ,crval2 \
    47         ,crpix1 \
    48         ,crpix2 \
    49         ,cdelt1 \
    50         ,cdelt2 \
    51         ,pc001001 \
    52         ,pc001002 \
    53         ,pc002001 \
    54         ,pc002002 \
     36    def populateFrameMeta(self):
     37        self.log("Procesing FrameMeta table")
     38
     39        sql = "INSERT INTO FrameMeta (\
     40        frameID \
     41         ,photoScat \
     42         ,expStart \
     43         ,expTime \
     44         ,airmass \
     45         ,raBore \
     46         ,decBore \
     47         ,ctype1 \
     48         ,ctype2 \
     49         ,crval1 \
     50         ,crval2 \
     51         ,crpix1 \
     52         ,crpix2 \
     53         ,cdelt1 \
     54         ,cdelt2 \
     55         ,pc001001 \
     56         ,pc001002 \
     57         ,pc002001 \
     58         ,pc002002 \
     59         ,polyOrder \
     60         ,pca1x3y0 \
     61         ,pca1x2y1 \
     62         ,pca1x1y2 \
     63         ,pca1x0y3 \
     64         ,pca1x2y0 \
     65         ,pca1x1y1 \
     66         ,pca1x0y2 \
     67         ,pca2x3y0 \
     68         ,pca2x2y1 \
     69         ,pca2x1y2 \
     70         ,pca2x0y3 \
     71         ,pca2x2y0 \
     72         ,pca2x1y1 \
     73         ,pca2x0y2 \
    5574         ) VALUES ( \
    56         " + self.header['STK_ID'] + " \
    57         ," + self.skycell + " \
    58         ," + self.header['FPA.ZP'] + " \
    59         ," + self.header['NINPUTS'] + " \
     75        " + str(self.expID) + " \
     76        ," + self.header['ZPT_ERR'] + " \
     77        ," + self.header['MJD-OBS'] + " \
     78        ," + self.header['EXPREQ'] + " \
     79        ," + self.header['AIRMASS'] + " \
     80        ," + self.header['RA'] + " \
     81        ," + self.header['DEC'] + " \
    6082        ,'" + self.header['CTYPE1'] + "' \
    6183        ,'" + self.header['CTYPE2'] + "' \
     
    7092        ," + self.header['PC002001'] + " \
    7193        ," + self.header['PC002002'] + " \
     94        ," + self.header['NPLYTERM'] + " \
     95        ," + self.header['PCA1X3Y0'] + " \
     96        ," + self.header['PCA1X2Y1'] + " \
     97        ," + self.header['PCA1X1Y2'] + " \
     98        ," + self.header['PCA1X0Y3'] + " \
     99        ," + self.header['PCA1X2Y0'] + " \
     100        ," + self.header['PCA1X1Y1'] + " \
     101        ," + self.header['PCA1X0Y2'] + " \
     102        ," + self.header['PCA2X3Y0'] + " \
     103        ," + self.header['PCA2X2Y1'] + " \
     104        ," + self.header['PCA2X1Y2'] + " \
     105        ," + self.header['PCA2X0Y3'] + " \
     106        ," + self.header['PCA2X2Y0'] + " \
     107        ," + self.header['PCA2X1Y1'] + " \
     108        ," + self.header['PCA2X0Y2'] + " \
    72109        )"
    73110        self.localStmt.execute(sql)
    74111
    75         self.updateSurveyID("ImageMeta")
    76         self.updateFilterID("ImageMeta")
    77         self.updateStackTypeID("ImageMeta")
    78         '''
    79 
    80     '''
    81     Populates the Detection tables
    82     '''
    83     def populateDetectionTables(self):
    84 
    85         self.log("Procesing Detection tables")
    86         for x in range(3,4):
    87            for y in range(3,4):
    88 
    89                self.log("Populating detections for OTA %d%d" % (x, y))
    90                
    91                sql = "INSERT INTO Detection ( \
    92                       ippDetectID \
    93                       ) \
    94                       SELECT \
    95                       IPP_IDET \
    96                       FROM XY%d%d_psf" % (x, y)
    97 
    98                self.localStmt.execute(sql)
     112        self.updateSurveyID("FrameMeta")
     113        self.updateFilterID("FrameMeta")
     114
     115    '''
     116    Populates the ImageMeta table for this OTA
     117    '''
     118    def populateImageMetaTable(self, ota, header):
     119
     120        tableName = "ImageMeta_" + ota
     121        self.log("   Dealing with table " + tableName)
     122       
     123        # drop then re-create table
     124        self.dropTable(tableName)
     125        sql = "CREATE TABLE " + tableName + " LIKE ImageMeta"
     126        try: self.localStmt.execute(sql)
     127        except: pass
     128
     129        # insert all detections into table
     130        sql = "INSERT INTO " + tableName + " ( \
     131               frameID \
     132               ,sky \
     133               ,skyScat \
     134               ,magSat \
     135               ,completMag \
     136               ,astroScat \
     137               ,numAstroRef \
     138               ,numPhotoRef \
     139               ,nx \
     140               ,ny \
     141               ,psfWidMajor \
     142               ,psfWidMinor \
     143               ,psfTheta \
     144               ,momentWidMajor \
     145               ,momentWidMinor \
     146               ,apResid \
     147               ,dapResid \
     148               ,detectorID \
     149               ,detrend1 \
     150               ,detrend2 \
     151               ,detrend3 \
     152               ,ctype1 \
     153               ,ctype2 \
     154               ,crval1 \
     155               ,crval2 \
     156               ,crpix1 \
     157               ,crpix2 \
     158               ,cdelt1 \
     159               ,cdelt2 \
     160               ,pc001001 \
     161               ,pc001002 \
     162               ,pc002001 \
     163               ,pc002002 \
     164               ,polyOrder \
     165               ,pca1x3y0 \
     166               ,pca1x2y1 \
     167               ,pca1x1y2 \
     168               ,pca1x0y3 \
     169               ,pca1x2y0 \
     170               ,pca1x1y1 \
     171               ,pca1x0y2 \
     172               ,pca2x3y0 \
     173               ,pca2x2y1 \
     174               ,pca2x1y2 \
     175               ,pca2x0y3 \
     176               ,pca2x2y0 \
     177               ,pca2x1y1 \
     178               ,pca2x0y2 \
     179               ) VALUES ( \
     180               " + str(self.expID) + " \
     181               ," + header['MSKY_MN'] + " \
     182               ," + header['MSKY_SIG'] + " \
     183               ," + header['FSATUR'] + " \
     184               ," + header['FLIMIT'] + " \
     185               ," + header['CERROR'] + " \
     186               ," + header['NASTRO'] + " \
     187               ," + header['NASTRO'] + " \
     188               ," + header['CNAXIS1'] + " \
     189               ," + header['CNAXIS2'] + " \
     190               ," + header['FWHM_MAJ'] + " \
     191               ," + header['FWHM_MIN'] + " \
     192               ," + header['ANGLE'] + " \
     193               ," + header['IQ_FW1'] + " \
     194               ," + header['IQ_FW2'] + " \
     195               ," + header['APMIFIT'] + " \
     196               ," + header['DAPMIFIT'] + " \
     197               ,'" + header['DETECTOR'] + "' \
     198               ,'" + header['DETREND.MASK'] + "' \
     199               ,'" + header['DETREND.DARK'] + "' \
     200               ,'" + header['DETREND.FLAT'] + "' \
     201               ,'" + header['CTYPE1'] + "' \
     202               ,'" + header['CTYPE2'] + "' \
     203               ," + header['CRVAL1'] + " \
     204               ," + header['CRVAL2'] + " \
     205               ," + header['CRPIX1'] + " \
     206               ," + header['CRPIX2'] + " \
     207               ," + header['CDELT1'] + " \
     208               ," + header['CDELT2'] + " \
     209               ," + header['PC001001'] + " \
     210               ," + header['PC001002'] + " \
     211               ," + header['PC002001'] + " \
     212               ," + header['PC002002'] + " \
     213               ," + header['NPLYTERM'] + " \
     214               ," + header['PCA1X3Y0'] + " \
     215               ," + header['PCA1X2Y1'] + " \
     216               ," + header['PCA1X1Y2'] + " \
     217               ," + header['PCA1X0Y3'] + " \
     218               ," + header['PCA1X2Y0'] + " \
     219               ," + header['PCA1X1Y1'] + " \
     220               ," + header['PCA1X0Y2'] + " \
     221               ," + header['PCA2X3Y0'] + " \
     222               ," + header['PCA2X2Y1'] + " \
     223               ," + header['PCA2X1Y2'] + " \
     224               ," + header['PCA2X0Y3'] + " \
     225               ," + header['PCA2X2Y0'] + " \
     226               ," + header['PCA2X1Y1'] + " \
     227               ," + header['PCA2X0Y2'] + " \
     228               )"
     229        self.localStmt.execute(sql)
     230        self.updateFilterID(tableName)
     231
     232    '''
     233    Populates the Detection table for this OTA
     234    '''
     235    def populateDetectionTable(self, ota):
     236
     237        tableName = "Detection_" + ota
     238        self.log("   Dealing with table " + tableName)
     239       
     240        # drop then re-create table
     241        self.dropTable(tableName)
     242        sql = "CREATE TABLE " + tableName + " LIKE Detection"
     243        try: self.localStmt.execute(sql)
     244        except: pass
     245
     246        # insert all detections into table
     247        sql = "INSERT INTO " + tableName + " ( \
     248               ippDetectID \
     249               ,xPos \
     250               ,yPos \
     251               ,xPosErr \
     252               ,yPosErr \
     253               ,psfWidMajor \
     254               ,psfWidMinor \
     255               ,psfTheta \
     256               ,psfCf \
     257               ,momentXX \
     258               ,momentXY \
     259               ,momentYY \
     260               ,sky \
     261               ,skyErr \
     262               ,sgSep \
     263               ) \
     264               SELECT \
     265               IPP_IDET \
     266               ,X_PSF \
     267               ,Y_PSF \
     268               ,X_PSF_SIG \
     269               ,Y_PSF_SIG \
     270               ,PSF_MAJOR \
     271               ,PSF_MINOR \
     272               ,PSF_THETA \
     273               ,PSF_QF \
     274               ,MOMENTS_XX \
     275               ,MOMENTS_XY \
     276               ,MOMENTS_YY \
     277               ,SKY \
     278               ,SKY_SIGMA \
     279               ,EXT_NSIGMA \
     280               FROM " + ota + "_psf"
     281
     282        self.localStmt.execute(sql)
     283
     284        self.updateSurveyID(tableName)
     285        self.updateFilterID(tableName)
     286
     287        # now add DVO IDs
     288        self.updateDvoIDs(tableName)
     289
     290    '''
     291    Populates the SkinnyObject table for this OTA
     292    '''
     293    def populateSkinnyObjectTable(self, ota):
     294
     295        tableName = "SkinnyObject_" + ota
     296        self.log("   Dealing with table " + tableName)
     297       
     298        # drop then re-create table
     299        self.dropTable(tableName)
     300        sql = "CREATE TABLE " + tableName + " LIKE SkinnyObject"
     301        try: self.localStmt.execute(sql)
     302        except: pass
     303
     304        # insert all detections into table
     305        sql = "INSERT INTO " + tableName + " ( \
     306               objID \
     307               ,ippObjID \
     308               ,surveyID \
     309               ) \
     310               SELECT \
     311               objID \
     312               ,ippObjID \
     313               ,surveyID \
     314               FROM Detection_" + ota
     315        self.localStmt.execute(sql)
     316
     317    '''
     318    Populates the Detection table for this OTA
     319    '''
     320    def populateObjectCalColorTable(self, ota):
     321
     322        tableName = "ObjectCalColor_" + ota
     323        self.log("   Dealing with table " + tableName)
     324       
     325        # drop then re-create table
     326        self.dropTable(tableName)
     327        sql = "CREATE TABLE " + tableName + " LIKE ObjectCalColor"
     328        try: self.localStmt.execute(sql)
     329        except: pass
     330
     331        # insert all detections into table
     332        sql = "INSERT INTO " + tableName + " ( \
     333               objID \
     334               ,ippObjID \
     335               ,filterID \
     336               ) \
     337               SELECT \
     338               objID \
     339               ,ippObjID \
     340               ,filterID \
     341               FROM Detection_" + ota
     342        self.localStmt.execute(sql)
    99343
    100344
     
    123367
    124368    '''
     369    Overriden from Batch class
    125370    Updates provided table with DVO IDs from DVO table
    126371    '''
     
    142387    def populatePspsTables(self):
    143388
     389
    144390        # get filterID using init table
    145         self.filter = self.header['FILTERID']
    146         self.filter = self.filter[0:1]
    147 
    148         #self.populateStackMeta()
    149         self.populateDetectionTables()
    150         #self.populateStackModelFit()
    151         #self.populateStackApFlx()
    152 
    153         self.getIDsFromDVO("33", "8345290") # TODO need to get sourceID and imageID from chip header
    154         self.updateDvoIDs("Detection")
    155         self.setMinMaxObjID("Detection")
    156 
     391        self.filter = self.header['FILTERID'][0:1]
     392
     393        self.populateFrameMeta()
     394
     395        for x in range(3, 4):
     396            for y in range(3, 4):
     397               
     398                ota = "XY%d%d" % (x, y)
     399               
     400                # load corresponding header into memory
     401                header = self.findAndReadFITSHeader(ota + ".hdr")
     402                self.getIDsFromDVO(header['SOURCEID'], header['IMAGEID'])
     403 
     404                self.populateImageMetaTable(ota, header)
     405                self.populateDetectionTable(ota)
     406                self.populateSkinnyObjectTable(ota)
     407                self.populateObjectCalColorTable(ota)
     408
     409
     410        #self.setMinMaxObjID(tableName) # TODO set based on all tables
     411
     412
     413    '''
     414    Overriding this method
     415    '''
     416    def reportNullsInAllPspsTables(self, showPartials):
     417
     418        # loops round all imported tables, but we want to check one OTA's worth
     419        for table in self.pspsTables:
     420            if table.name == "FrameMeta": self.reportNulls(table.name, showPartials)
     421            else: self.reportNulls(table.name + "_XY33", showPartials)
    157422
    158423
     
    168433detectionBatch.populatePspsTables()
    169434detectionBatch.exportPspsTablesToFits()
    170 detectionBatch.exportPspsTablesToFits()
    171435detectionBatch.writeBatchManifest()
    172436detectionBatch.reportNullsInAllPspsTables(False)
Note: See TracChangeset for help on using the changeset viewer.