IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 6, 2012, 6:32:19 PM (14 years ago)
Author:
watersc1
Message:

merge from trunk. Preliminary versions of stacktool/warptool updates and regenerate_background.pl script. The warp code is finished and tested, and I still need to get the stack version resolved.

Location:
branches/czw_branch/20120906/ippToPsps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20120906/ippToPsps

  • branches/czw_branch/20120906/ippToPsps/jython/stackbatch.py

    r34165 r34772  
    7676       self.projectioncell = self.skycell
    7777
     78       # proposed new values. Need to coordinate with the SkyCell table
     79       # this fits in 32 bits for 0 < tessID < 214
     80       # self.skycell = str( (tessID * (10000 * 1000)) + (int(self.projectioncell) * 1000) + cellID )
     81
    7882       self.analysisVer = meta[2];
    7983
     
    8993       self.scratchDb.dropTable("SkinnyObject")
    9094       self.scratchDb.dropTable("ObjectCalColor")
     95       self.scratchDb.dropTable("StackDetectionCalib")
    9196
    9297       # delete IPP tables
     
    140145
    141146        sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
    142         "+prefix+"flxR1=b.APER_FLUX_1, \
    143         "+prefix+"flxR1Err=b.APER_FLUX_ERR_1, \
    144         "+prefix+"flxR1Std=b.APER_FLUX_STDEV_1, \
     147        "+prefix+"flxR1=b.APER_FLUX_1 / " + str(self.expTime) + ", \
     148        "+prefix+"flxR1Err=b.APER_FLUX_ERR_1 / " + str(self.expTime) + ", \
     149        "+prefix+"flxR1Std=b.APER_FLUX_STDEV_1 / " + str(self.expTime) + ", \
    145150        "+prefix+"flxR1Fill=b.APER_FILL_1, \
    146         "+prefix+"flxR2=b.APER_FLUX_2, \
    147         "+prefix+"flxR2Err=b.APER_FLUX_ERR_2, \
    148         "+prefix+"flxR2Std=b.APER_FLUX_STDEV_2, \
     151        "+prefix+"flxR2=b.APER_FLUX_2 / " + str(self.expTime) + ", \
     152        "+prefix+"flxR2Err=b.APER_FLUX_ERR_2 / " + str(self.expTime) + ", \
     153        "+prefix+"flxR2Std=b.APER_FLUX_STDEV_2 / " + str(self.expTime) + ", \
    149154        "+prefix+"flxR2Fill=b.APER_FILL_2, \
    150         "+prefix+"flxR3=b.APER_FLUX_3, \
    151         "+prefix+"flxR3Err=b.APER_FLUX_ERR_3, \
    152         "+prefix+"flxR3Std=b.APER_FLUX_STDEV_3, \
     155        "+prefix+"flxR3=b.APER_FLUX_3 / " + str(self.expTime) + ", \
     156        "+prefix+"flxR3Err=b.APER_FLUX_ERR_3 / " + str(self.expTime) + ", \
     157        "+prefix+"flxR3Std=b.APER_FLUX_STDEV_3 / " + str(self.expTime) + ", \
    153158        "+prefix+"flxR3Fill=b.APER_FILL_3, \
    154         "+prefix+"flxR4=b.APER_FLUX_4, \
    155         "+prefix+"flxR4Err=b.APER_FLUX_ERR_4, \
    156         "+prefix+"flxR4Std=b.APER_FLUX_STDEV_4, \
     159        "+prefix+"flxR4=b.APER_FLUX_4 / " + str(self.expTime) + ", \
     160        "+prefix+"flxR4Err=b.APER_FLUX_ERR_4 / " + str(self.expTime) + ", \
     161        "+prefix+"flxR4Std=b.APER_FLUX_STDEV_4 / " + str(self.expTime) + ", \
    157162        "+prefix+"flxR4Fill=b.APER_FILL_4, \
    158         "+prefix+"flxR5=b.APER_FLUX_5, \
    159         "+prefix+"flxR5Err=b.APER_FLUX_ERR_5, \
    160         "+prefix+"flxR5Std=b.APER_FLUX_STDEV_5, \
     163        "+prefix+"flxR5=b.APER_FLUX_5 / " + str(self.expTime) + ", \
     164        "+prefix+"flxR5Err=b.APER_FLUX_ERR_5 / " + str(self.expTime) + ", \
     165        "+prefix+"flxR5Std=b.APER_FLUX_STDEV_5 / " + str(self.expTime) + ", \
    161166        "+prefix+"flxR5Fill=b.APER_FILL_5, \
    162         "+prefix+"flxR6=b.APER_FLUX_6, \
    163         "+prefix+"flxR6Err=b.APER_FLUX_ERR_6, \
    164         "+prefix+"flxR6Std=b.APER_FLUX_STDEV_6, \
     167        "+prefix+"flxR6=b.APER_FLUX_6 / " + str(self.expTime) + ", \
     168        "+prefix+"flxR6Err=b.APER_FLUX_ERR_6 / " + str(self.expTime) + ", \
     169        "+prefix+"flxR6Std=b.APER_FLUX_STDEV_6 / " + str(self.expTime) + ", \
    165170        "+prefix+"flxR6Fill=b.APER_FILL_6, \
    166         "+prefix+"flxR7=b.APER_FLUX_7, \
    167         "+prefix+"flxR7Err=b.APER_FLUX_ERR_7, \
    168         "+prefix+"flxR7Std=b.APER_FLUX_STDEV_7, \
     171        "+prefix+"flxR7=b.APER_FLUX_7 / " + str(self.expTime) + ", \
     172        "+prefix+"flxR7Err=b.APER_FLUX_ERR_7 / " + str(self.expTime) + ", \
     173        "+prefix+"flxR7Std=b.APER_FLUX_STDEV_7 / " + str(self.expTime) + ", \
    169174        "+prefix+"flxR7Fill=b.APER_FILL_7, \
    170         "+prefix+"flxR8=b.APER_FLUX_8, \
    171         "+prefix+"flxR8Err=b.APER_FLUX_ERR_8, \
    172         "+prefix+"flxR8Std=b.APER_FLUX_STDEV_8, \
     175        "+prefix+"flxR8=b.APER_FLUX_8 / " + str(self.expTime) + ", \
     176        "+prefix+"flxR8Err=b.APER_FLUX_ERR_8 / " + str(self.expTime) + ", \
     177        "+prefix+"flxR8Std=b.APER_FLUX_STDEV_8 / " + str(self.expTime) + ", \
    173178        "+prefix+"flxR8Fill=b.APER_FILL_8, \
    174         "+prefix+"flxR9=b.APER_FLUX_9, \
    175         "+prefix+"flxR9Err=b.APER_FLUX_ERR_9, \
    176         "+prefix+"flxR9Std=b.APER_FLUX_STDEV_9, \
     179        "+prefix+"flxR9=b.APER_FLUX_9 / " + str(self.expTime) + ", \
     180        "+prefix+"flxR9Err=b.APER_FLUX_ERR_9 / " + str(self.expTime) + ", \
     181        "+prefix+"flxR9Std=b.APER_FLUX_STDEV_9 / " + str(self.expTime) + ", \
    177182        "+prefix+"flxR9Fill=b.APER_FILL_9, \
    178         "+prefix+"flxR10=b.APER_FLUX_10, \
    179         "+prefix+"flxR10Err=b.APER_FLUX_ERR_10, \
    180         "+prefix+"flxR10Std=b.APER_FLUX_STDEV_10, \
     183        "+prefix+"flxR10=b.APER_FLUX_10 / " + str(self.expTime) + ", \
     184        "+prefix+"flxR10Err=b.APER_FLUX_ERR_10 / " + str(self.expTime) + ", \
     185        "+prefix+"flxR10Std=b.APER_FLUX_STDEV_10 / " + str(self.expTime) + ", \
    181186        "+prefix+"flxR10Fill=b.APER_FILL_10 \
    182187        WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
     
    196201        sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
    197202        "+model+"Radius=b.EXT_WIDTH_MAJ,  \
    198         "+model+"Mag=b.EXT_INST_MAG,  \
    199         "+model+"MagErr=b.EXT_INST_MAG_SIG, \
     203        "+model+"Flux=POW(10, -0.4 * b.EXT_INST_MAG) / " + str(self.expTime) + " ,  \
     204        "+model+"FluxErr=ABS(b.EXT_INST_MAG_SIG) * POW(10, -0.4 * b.EXT_INST_MAG) / " + str(self.expTime) + " / 1.085736, \
    200205        "+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \
    201206        "+model+"Phi=b.EXT_THETA,  \
     
    319324               ,skyCellID \
    320325               ,projectionCellID \
    321                ,obsTime \
    322326               ,xPos \
    323327               ,yPos \
    324328               ,xPosErr \
    325329               ,yPosErr \
    326                ,instFlux \
    327                ,instFluxErr \
     330               ,psfFlux \
     331               ,psfFluxErr \
    328332               ,peakFlux \
    329333               ,sky \
     
    335339               ,psfLikelihood \
    336340               ,infoFlag \
    337                ,psfCf \
     341               ,psfQf \
     342               ,psfQfPerfect \
    338343               ,momentXX \
    339344               ,momentXY \
     
    345350               ,momentR1 \
    346351               ,momentRH \
    347                ,apMag \
    348                ,apMagErr \
     352               ,apFlux \
     353               ,apFluxErr \
    349354               ,kronFlux \
    350355               ,kronFluxErr \
    351356               ,kronRad \
    352                ,kronRadErr \
     357               ,psfChiSq \
    353358               ,nFrames \
    354359               ,assocDate \
     
    359364               ," + self.skycell + " \
    360365               ," + self.projectioncell + " \
    361                ," + self.header['MJD-OBS'] + " \
    362366               ,X_PSF \
    363367               ,Y_PSF \
     
    367371               ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / " + str(self.expTime) + ")) / 1.085736) \
    368372               ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + str(self.expTime) + " \
    369                ,SKY \
    370                ,SKY_SIGMA \
     373               ,SKY / " + str(self.expTime) + " \
     374               ,SKY_SIGMA / " + str(self.expTime) + " \
    371375               ,EXT_NSIGMA \
    372376               ,PSF_MAJOR \
     
    374378               ,PSF_THETA \
    375379               ,psfLikelihood(EXT_NSIGMA) \
    376                ,FLAGS << 32 | FLAGS2 \
     380               , FLAGS2 << 32 | FLAGS \
    377381               ,PSF_QF \
     382               ,PSF_QF_PERFECT \
    378383               ,MOMENTS_XX \
    379384               ,MOMENTS_XY \
     
    385390               ,MOMENTS_R1 \
    386391               ,MOMENTS_RH \
    387                ,AP_MAG \
    388                , NULL \
     392               ,POW(10.0, -0.4*AP_MAG) / " + str(self.expTime) + " \
     393               ,NULL \
    389394               ,KRON_FLUX / " + str(self.expTime) + " \
    390395               ,KRON_FLUX_ERR / " + str(self.expTime) + " \
    391                , NULL \
    392                , NULL \
     396               ,MOMENTS_R1 * 2.5 \
     397               ,PSF_CHISQ \
    393398               ,N_FRAMES \
    394399               , '" + self.dateStr + "' \
    395400               ," + self.historyModNum + " \
    396401               FROM SkyChip_psf"
    397 
    398         self.scratchDb.execute(sql)
     402        self.scratchDb.execute(sql)
     403       
    399404        #it is possible to drop some detections from dvo (that are present in the cmf). when that happens we get a 0 for objid
    400405        #we drop those...
     
    402407        self.scratchDb.execute(sql)
    403408        self.logger.infoPair("Deleting", "entries with StackDetection.objID = 0")
    404 
     409       
    405410        self.scratchDb.updateAllRows("StackDetection", "surveyID", str(self.surveyID))
     411       
    406412        self.scratchDb.updateFilterID("StackDetection", self.filter)
     413       
    407414        self.scratchDb.updateAllRows("StackDetection", "dataRelease", str(self.config.dataRelease))
     415       
    408416        self.scratchDb.updateAllRows("StackDetection", "primaryF", "0")
     417       
    409418        self.scratchDb.updateAllRows("StackDetection", "activeFlag", "0")
     419       
    410420        self.updateStackMetaID("StackDetection")
     421       
    411422        self.updateStackTypeID("StackDetection")
    412         self.updateDvoIDs("StackDetection")
     423       
     424        self.updateDvoIDsAndFlags("StackDetection")
     425       
    413426        sql = "ALTER IGNORE TABLE StackDetection ADD PRIMARY KEY (objID)"
     427       
    414428        self.scratchDb.execute(sql)
    415429 
     
    418432            #if deep stack and instFlux = null and err not null
    419433            sql = "UPDATE StackDetection AS a, SkyChip_psf AS b \
    420                    SET instFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
    421                    WHERE instFlux IS NULL \
     434                   SET psfFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
     435                   WHERE psfFlux IS NULL \
    422436                   AND a.ippDetectID = b.IPP_IDET  \
    423437                   AND b.PSF_INST_FLUX_SIG IS NOT NULL"
     438           
    424439            self.scratchDb.execute(sql)
    425440           
    426         self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
     441        #leave null instflux in
     442        #self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
     443       
    427444        self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "objID")
     445       
    428446        sql="DELETE FROM StackDetection where objID = 0"
    429         self.scratchDb.execute(sql)
    430         self.logger.infoPair("Deleting", "entries with StackDetection.objID = 0")
    431 
     447       
     448        self.scratchDb.execute(sql)
     449        self.logger.infoPair("Delleting", "entries with StackDetection.objID = 0")
     450       
    432451
    433452    '''
     
    460479        petRadius=b.PETRO_RADIUS \
    461480        ,petRadiusErr=b.PETRO_RADIUS_ERR \
    462         ,petMag=b.PETRO_MAG \
    463         ,petMagErr=b.PETRO_MAG_ERR \
     481        ,petFlux=POW(10.0, -0.4 * b.PETRO_MAG) /" + str(self.expTime) + " \
     482        ,petFluxErr=ABS(b.PETRO_MAG_ERR) * POW(10.0, (-0.4*b.PETRO_MAG)) / " + str(self.expTime) + " / 1.085736 \
    464483        ,petR50=b.PETRO_RADIUS_50 \
    465484        ,petR50Err=b.PETRO_RADIUS_50_ERR \
     
    573592        self.scratchDb.updateAllRows("SkinnyObject", "dataRelease", str(self.config.dataRelease))
    574593
     594    '''   
     595    Populates the StackDetectionCalib table
     596    '''
     597    def populateStackDetectionCalib(self):
     598        self.logger.infoPair("Processing table", "StackDetectionCalib")
     599        tableName = "StackDetectionCalib"
     600        # insert all detections into table
     601        sql = "INSERT INTO " + tableName + " ( \
     602               objID \
     603               ,stackDetectID \
     604               ,ippObjID \
     605               ,ippDetectID \
     606               ,filterID \
     607               ,surveyID \
     608               ) \
     609               SELECT \
     610               objID \
     611               ,stackDetectID \
     612               ,ippObjID \
     613               ,ippDetectID \
     614               ,filterID \
     615               ,surveyID \
     616               FROM StackDetection"
     617        self.scratchDb.execute(sql)
     618        # insert calibration information from dvoDetections into the Table
     619        sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
     620            SET a.ra = b.ra, \
     621            a.dec = b.dec_, \
     622            a.raErr = b.raErr, \
     623            a.decErr = b.decErr, \
     624            a.zp = b.zp, \
     625            a.zpErr = b.zpErr, \
     626            a.expTime = b.expTime, \
     627            a.airMass = b.airMass   \
     628            WHERE a.stackDetectID = b.detectID"
     629        self.scratchDb.execute(sql)
     630        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease))
     631       
     632   
     633
     634
    575635    '''
    576636    Populates the ObjectCalColor table
     
    600660
    601661        self.logger.debug("Altering PSPS tables")
     662        # heather uncommented the unique line -- well that no worky
    602663        #self.scratchDb.makeColumnUnique("StackDetection", "objID")
    603664        self.scratchDb.createIndex("StackDetection", "ippDetectID")
    604665        self.scratchDb.createIndex("StackApFlx", "ippDetectID")
    605666        self.scratchDb.createIndex("StackModelFit", "ippDetectID")
     667
     668        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
     669        # the column in PSPS
     670        self.scratchDb.execute("ALTER TABLE StackDetectionCalib CHANGE dec_ `dec` double")
    606671
    607672        return True
     
    624689    '''
    625690    def updateDvoIDs(self, table):
    626 
     691        self.logger.infoPair("getting","imageID")
    627692        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
     693        self.logger.infoPair("obtained","imageID")
    628694        self.logger.debug("Updating table '" + table + "' with DVO IDs...")
    629695        sql = "UPDATE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
    630696               a.ippObjID = b.ippObjID, \
    631                a.stackDetectID = 10 * b.detectID + " + str(self.filterID) + ", \
     697               a.stackDetectID = b.detectID, \
    632698               a.objID = b.objID \
    633699               WHERE a.ippDetectID = b.ippDetectID \
    634700               AND b.imageID = " + str(imageID)
    635701        self.scratchDb.execute(sql)
    636 
     702   
     703    '''
     704    Updates Flags
     705    '''
     706    def updateDvoIDsAndFlags(self, table):
     707        self.logger.infoPair("getting","imageID")
     708        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
     709        self.logger.infoPair("obtained","imageID")
     710        self.logger.debug("Updating table '" + table + "' with DVO IDs...")
     711        sql = "UPDATE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
     712               a.ippObjID = b.ippObjID, \
     713               a.stackDetectID = b.detectID, \
     714               a.objID = b.objID, \
     715               a.infoFlag = b.flags << 45 | a.infoFlag \
     716               WHERE a.ippDetectID = b.ippDetectID \
     717               AND b.imageID = " + str(imageID)
     718        self.scratchDb.execute(sql)
     719   
     720   
    637721    '''
    638722    Does the processing, i.e. pulling stuff from IPP tables into PSPS tables
     
    643727            if not self.getIDsFromDVO():
    644728                return False
    645 
     729        #self.logger.infoPair("populating","StackMeta")   
    646730        self.populateStackMeta()
     731        #self.logger.infoPair("populating","StackDetection")
    647732        self.populateStackDetection()
    648 
     733       
    649734        if self.stackType != "NIGHTLY_STACK":
     735            #self.logger.infoPair("populating","StackModelFit")
    650736            self.populateStackModelFit()
     737            #self.logger.infoPair("populating","StackApFlx")
    651738            self.populateStackApFlx()
    652    
     739        #self.logger.infoPair("populating","StackToImage")
    653740        self.populateStackToImage()
     741        #self.logger.infoPair("populating","SkinnyObject")
    654742        self.populateSkinnyObject()
     743        #self.logger.infoPair("populating","ObjectCalColor")
    655744        self.populateObjectCalColor()
     745        #self.logger.infoPair("populating","StackDetectionCalib")
     746        self.populateStackDetectionCalib()
    656747
    657748        self.setMinMaxObjID(["StackDetection"])
Note: See TracChangeset for help on using the changeset viewer.