IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Many things....

File:
1 edited

Legend:

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

    r31105 r31109  
    1616               #"/data/ipp053.0/eugene/md04.20110320/staticsky/MD04.V2/skycell.087/MD04.V2.skycell.087.stk.280.000.cmf",
    1717               "demo.fits",
    18                "multi.fits",
     18               "stack.fits",
    1919               "ippdb01",
    2020               "ippToPsps",
    2121               "ipp",
    22                "ipp")
     22               "ipp",
     23               "MD04") # TODO
     24
     25
     26
     27    '''
     28    Updates a table with stackMetaID
     29    '''
     30    def updateStackMetaID(self, table):
     31
     32        sql = "UPDATE " + table + "  SET stackMetaID=" + self.header['STK_ID']
     33        self.stmt.execute(sql)
     34
     35    '''
     36    Updates a table with stackTypeID grabbed from FitModel init table
     37    '''
     38    def updateStackTypeID(self, table):
     39
     40        sql = "UPDATE "+table+" AS a, StackType AS b SET a.stackTypeID=b.stackTypeID WHERE b.name = '"+self.header['STK_TYPE']+"'"
     41        self.stmt.execute(sql)
    2342
    2443
     
    2645    Updates aperture fluxes for StackApFkx table
    2746    '''
    28     def updateApFlxs(self, stmt, prefix, psfCondition):
     47    def updateApFlxs(self, prefix, psfCondition):
    2948
    3049        sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
     
    7190        WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
    7291
    73         stmt.execute(sql)
     92        self.stmt.execute(sql)
    7493
    7594    '''
    7695    Updates parameters for a particular model in the StackModelFit table
    7796    '''
    78     def updateModelFit(self, stmt, model, ippModelType):
     97    def updateModelFit(self, model, ippModelType):
     98
     99        if model == "ser":
     100            modelLong = "sersic"
     101        else:
     102            modelLong = model;
    79103
    80104        sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
    81         "+model+"Covar11=b.EXT_COVAR_00_00,  \
    82         "+model+"Covar12=b.EXT_COVAR_00_01,  \
    83         "+model+"Covar13=b.EXT_COVAR_00_02,  \
    84         "+model+"Covar14=b.EXT_COVAR_00_03,  \
    85         "+model+"Covar15=b.EXT_COVAR_00_04,  \
    86         "+model+"Covar16=b.EXT_COVAR_00_05,  \
    87         "+model+"Covar17=b.EXT_COVAR_00_06,  \
    88         "+model+"Covar22=b.EXT_COVAR_01_01,  \
    89         "+model+"Covar23=b.EXT_COVAR_01_02,  \
    90         "+model+"Covar24=b.EXT_COVAR_01_03,  \
    91         "+model+"Covar25=b.EXT_COVAR_01_04,  \
    92         "+model+"Covar26=b.EXT_COVAR_01_05,  \
    93         "+model+"Covar27=b.EXT_COVAR_01_06,  \
    94         "+model+"Covar33=b.EXT_COVAR_02_02,  \
    95         "+model+"Covar34=b.EXT_COVAR_02_03,  \
    96         "+model+"Covar35=b.EXT_COVAR_02_04,  \
    97         "+model+"Covar36=b.EXT_COVAR_02_05,  \
    98         "+model+"Covar37=b.EXT_COVAR_02_06,  \
    99         "+model+"Covar44=b.EXT_COVAR_03_03,  \
    100         "+model+"Covar45=b.EXT_COVAR_03_04,  \
    101         "+model+"Covar46=b.EXT_COVAR_03_05,  \
    102         "+model+"Covar47=b.EXT_COVAR_03_06,  \
    103         "+model+"Covar55=b.EXT_COVAR_04_04,  \
    104         "+model+"Covar56=b.EXT_COVAR_04_05,  \
    105         "+model+"Covar57=b.EXT_COVAR_04_06,  \
    106         "+model+"Covar66=b.EXT_COVAR_05_05,  \
    107         "+model+"Covar67=b.EXT_COVAR_05_06,  \
    108         "+model+"Covar77=b.EXT_COVAR_06_06   \
     105        "+model+"Radius=b.EXT_WIDTH_MAJ,  \
     106        "+model+"Mag=b.EXT_INST_MAG,  \
     107        "+model+"MagErr=b.EXT_INST_MAG_SIG,  \
     108        "+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \
     109        "+model+"Phi=b.EXT_THETA,  \
     110        "+modelLong+"Covar11=b.EXT_COVAR_00_00,  \
     111        "+modelLong+"Covar12=b.EXT_COVAR_00_01,  \
     112        "+modelLong+"Covar13=b.EXT_COVAR_00_02,  \
     113        "+modelLong+"Covar14=b.EXT_COVAR_00_03,  \
     114        "+modelLong+"Covar15=b.EXT_COVAR_00_04,  \
     115        "+modelLong+"Covar16=b.EXT_COVAR_00_05,  \
     116        "+modelLong+"Covar17=b.EXT_COVAR_00_06,  \
     117        "+modelLong+"Covar22=b.EXT_COVAR_01_01,  \
     118        "+modelLong+"Covar23=b.EXT_COVAR_01_02,  \
     119        "+modelLong+"Covar24=b.EXT_COVAR_01_03,  \
     120        "+modelLong+"Covar25=b.EXT_COVAR_01_04,  \
     121        "+modelLong+"Covar26=b.EXT_COVAR_01_05,  \
     122        "+modelLong+"Covar27=b.EXT_COVAR_01_06,  \
     123        "+modelLong+"Covar33=b.EXT_COVAR_02_02,  \
     124        "+modelLong+"Covar34=b.EXT_COVAR_02_03,  \
     125        "+modelLong+"Covar35=b.EXT_COVAR_02_04,  \
     126        "+modelLong+"Covar36=b.EXT_COVAR_02_05,  \
     127        "+modelLong+"Covar37=b.EXT_COVAR_02_06,  \
     128        "+modelLong+"Covar44=b.EXT_COVAR_03_03,  \
     129        "+modelLong+"Covar45=b.EXT_COVAR_03_04,  \
     130        "+modelLong+"Covar46=b.EXT_COVAR_03_05,  \
     131        "+modelLong+"Covar47=b.EXT_COVAR_03_06,  \
     132        "+modelLong+"Covar55=b.EXT_COVAR_04_04,  \
     133        "+modelLong+"Covar56=b.EXT_COVAR_04_05,  \
     134        "+modelLong+"Covar57=b.EXT_COVAR_04_06,  \
     135        "+modelLong+"Covar66=b.EXT_COVAR_05_05,  \
     136        "+modelLong+"Covar67=b.EXT_COVAR_05_06,  \
     137        "+modelLong+"Covar77=b.EXT_COVAR_06_06   \
    109138        WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
    110139
    111         stmt.execute(sql)
     140        self.stmt.execute(sql)
    112141
    113142        # sersic fit has an extra parameter
    114143        if ippModelType == "PS_MODEL_SERSIC":
    115144            sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
    116             "+model+"Covar18=b.EXT_COVAR_00_07,  \
    117             "+model+"Covar28=b.EXT_COVAR_01_07,  \
    118             "+model+"Covar38=b.EXT_COVAR_02_07,  \
    119             "+model+"Covar48=b.EXT_COVAR_03_07,  \
    120             "+model+"Covar58=b.EXT_COVAR_04_07,  \
    121             "+model+"Covar68=b.EXT_COVAR_05_07,  \
    122             "+model+"Covar78=b.EXT_COVAR_06_07,  \
    123             "+model+"Covar88=b.EXT_COVAR_07_07   \
     145            "+modelLong+"Covar18=b.EXT_COVAR_00_07,  \
     146            "+modelLong+"Covar28=b.EXT_COVAR_01_07,  \
     147            "+modelLong+"Covar38=b.EXT_COVAR_02_07,  \
     148            "+modelLong+"Covar48=b.EXT_COVAR_03_07,  \
     149            "+modelLong+"Covar58=b.EXT_COVAR_04_07,  \
     150            "+modelLong+"Covar68=b.EXT_COVAR_05_07,  \
     151            "+modelLong+"Covar78=b.EXT_COVAR_06_07,  \
     152            "+modelLong+"Covar88=b.EXT_COVAR_07_07   \
    124153            WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
    125154
    126             stmt.execute(sql)
     155            self.stmt.execute(sql)
    127156
    128157
     
    130159    Populates the StackMeta table, mainly from dictionary values found in IPP FITS header
    131160    '''
    132     def populateStackMeta(self, stmt):
     161    def populateStackMeta(self):
    133162        print "Procesing StackMeta table";
    134163
     
    169198        )"
    170199        print sql
    171         stmt.execute(sql)
     200        self.stmt.execute(sql)
     201
     202        self.updateSurveyID("StackMeta")
     203        self.updateFilterID("StackMeta")
     204        self.updateStackTypeID("StackMeta")
    172205
    173206    '''
    174207    Populates the StackDetection table
    175208    '''
    176     def populateStackDetection(self, stmt):
     209    def populateStackDetection(self):
    177210        print "Procesing StackDetection table";
    178211
    179212        # insert all the detections
    180         sql = "INSERT INTO StackDetection \
    181                (ippDetectID, xPos, yPos, xPosErr, yPosErr, instFlux, instFluxErr, sky, skyErr, sgSep, psfWidMajor, psfWidMinor, psfTheta, psfCf, nFrames) \
     213        sql = "INSERT INTO StackDetection (\
     214               ippDetectID \
     215               ,xPos \
     216               ,yPos \
     217               ,xPosErr \
     218               ,yPosErr \
     219               ,instFlux \
     220               ,instFluxErr \
     221               ,peakFlux \
     222               ,sky \
     223               ,skyErr \
     224               ,sgSep \
     225               ,psfWidMajor \
     226               ,psfWidMinor \
     227               ,psfTheta \
     228               ,psfCf \
     229               ,nFrames \
     230               ) \
    182231               SELECT \
    183                IPP_IDET, X_PSF, Y_PSF, X_PSF_SIG, Y_PSF_SIG, PSF_INST_FLUX, PSF_INST_FLUX_SIG, SKY, SKY_SIGMA, EXT_NSIGMA, PSF_MAJOR, PSF_MINOR, PSF_THETA, PSF_QF, N_FRAMES \
     232               IPP_IDET \
     233               ,X_PSF \
     234               ,Y_PSF \
     235               ,X_PSF_SIG \
     236               ,Y_PSF_SIG \
     237               ,PSF_INST_FLUX \
     238               ,PSF_INST_FLUX_SIG \
     239               ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / "+self.header['EXPTIME']+" \
     240               ,SKY \
     241               ,SKY_SIGMA \
     242               ,EXT_NSIGMA \
     243               ,PSF_MAJOR \
     244               ,PSF_MINOR \
     245               ,PSF_THETA \
     246               ,PSF_QF \
     247               ,N_FRAMES \
    184248               FROM SkyChip_psf"
    185249
    186         stmt.execute(sql)
     250        self.stmt.execute(sql)
     251
     252        if self.header['STK_TYPE'] != "NIGHTLY_STACK":
     253            sql = "UPDATE StackDetection SET obsTime = " + self.header['MJD-OBS']
     254            self.stmt.execute(sql)
    187255
    188256
    189257        sql = "UPDATE StackDetection SET skycellID = " + self.skycell + ", assocDate = '"+self.dateStr+"'"
    190         stmt.execute(sql)
    191 
    192     '''
    193     Populates the StackModelFit table
    194     '''
    195     def populateStackModelFit(self, stmt):
    196         print "Procesing StackModelFit table";
    197 
    198         # insert all the detections
    199         sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit"
    200         stmt.execute(sql)
    201 
    202         # populate model parameters
    203         print "    Adding deVaucouleurs fit"
    204         self.updateModelFit(stmt, "deV", "PS_MODEL_DEV")
    205         print "    Adding exponential fit"
    206         self.updateModelFit(stmt, "exp", "PS_MODEL_EXP")
    207         print "    Adding sersic fit"
    208         self.updateModelFit(stmt, "sersic", "PS_MODEL_SERSIC")
    209 
     258        self.stmt.execute(sql)
     259        self.updateSurveyID("StackDetection")
     260        self.updateFilterID("StackDetection")
     261        self.updateStackMetaID("StackDetection")
     262        self.updateStackTypeID("StackDetection")
    210263
    211264    '''
    212265    Populates the StackApFlx table
    213266    '''
    214     def populateStackApFlx(self, stmt):
     267    def populateStackApFlx(self):
    215268        print "Procesing StackApFlx table";
    216269 
     
    220273               DISTINCT IPP_IDET \
    221274               FROM SkyChip_xrad"
    222         stmt.execute(sql)
     275        self.stmt.execute(sql)
    223276
    224277        print "    Adding 1st convolved fluxes"
    225         #self.updateApFlxs(stmt, "c1", "< 7.0")
     278        self.updateApFlxs("c1", "< 7.0")
    226279        print "    Adding 2nd convolved fluxes"
    227 #        self.updateApFlxs(stmt, "c2", "> 7.0")
    228 
    229 
    230         # now add in the extended source stuff
    231         sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET petRadius=b.PETRO_RADIUS WHERE a.ippDetectID=b.IPP_IDET"
    232         stmt.execute(sql)
     280        self.updateApFlxs("c2", "> 7.0")
     281
     282        print "    Adding petrosian stuff for extended sources"
     283        sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET \
     284        petRadius=b.PETRO_RADIUS \
     285        ,petRadiusErr=b.PETRO_RADIUS_ERR \
     286        ,petMag=b.PETRO_MAG \
     287        ,petMagErr=b.PETRO_MAG_ERR \
     288        ,petR50=b.PETRO_RADIUS_50 \
     289        ,petR50Err=b.PETRO_RADIUS_50_ERR \
     290        ,petR90=b.PETRO_RADIUS_90 \
     291        ,petR90Err=b.PETRO_RADIUS_90_ERR \
     292        WHERE a.ippDetectID=b.IPP_IDET"
     293        self.stmt.execute(sql)
     294
     295        self.updateSurveyID("StackApFlx")
     296        self.updateFilterID("StackApFlx")
     297        self.updateStackMetaID("StackApFlx")
     298        self.updateStackTypeID("StackApFlx")
    233299
    234300        #rs = stmt.executeQuery(sql)
     
    240306
    241307        #rs.close()
     308
     309    '''
     310    Populates the StackModelFit table
     311    '''
     312    def populateStackModelFit(self):
     313        print "Procesing StackModelFit table";
     314
     315        # insert all the detections
     316        sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit"
     317        self.stmt.execute(sql)
     318
     319        # populate model parameters
     320        print "    Adding deVaucouleurs fit"
     321        self.updateModelFit("deV", "PS_MODEL_DEV")
     322        print "    Adding exponential fit"
     323        self.updateModelFit("exp", "PS_MODEL_EXP")
     324        print "    Adding sersic fit"
     325        self.updateModelFit("ser", "PS_MODEL_SERSIC")
     326
     327        self.updateSurveyID("StackModelFit")
     328        self.updateFilterID("StackModelFit")
     329        self.updateStackMetaID("StackModelFit")
     330        self.updateStackTypeID("StackModelFit")
     331
     332
     333    '''
     334    Applies indexes to the PSPS tables
     335    '''
     336    def indexPspsTables(self):
     337
     338        print "Creating indexes on PSPS tables"
     339        self.createIndex("StackDetection", "ippDetectID")
     340        self.createIndex("StackApFlx", "ippDetectID")
     341        self.createIndex("StackModelFit", "ippDetectID")
     342
     343    '''
     344    Applies indexes to the IPP tables
     345    '''
     346    def indexIppTables(self):
     347
     348        print "Creating indexes on IPP tables"
     349        self.createIndex("SkyChip_psf", "IPP_IDET")
     350        self.createIndex("SkyChip_xfit", "IPP_IDET")
     351        self.createIndex("SkyChip_xrad", "IPP_IDET")
     352        self.createIndex("SkyChip_xsrc", "IPP_IDET")
    242353
    243354    '''
     
    250361        self.skycell = self.skycell[8:]
    251362
    252         stmt = self.con.createStatement()
    253         self.populateStackMeta(stmt)
    254         self.populateStackDetection(stmt)
    255         self.populateStackModelFit(stmt)
    256         self.populateStackApFlx(stmt)
    257         stmt.close()
     363        # get filterID using init table
     364        self.filter = self.header['FPA.FILTER']
     365        self.filter = self.filter[0:1]
     366
     367        self.populateStackMeta()
     368        self.populateStackDetection()
     369        self.populateStackModelFit()
     370        self.populateStackApFlx()
    258371
    259372   
     
    263376stackBatch.process()
    264377stackBatch.exportPspsTablesToFits()
    265 stackBatch
Note: See TracChangeset for help on using the changeset viewer.