IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 26, 2012, 5:15:52 PM (14 years ago)
Author:
heather
Message:

schema change sa10

Location:
trunk/ippToPsps/jython
Files:
3 edited

Legend:

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

    r33830 r34615  
    388388        # delete all detections with PSF_INST_MAG < 17.5, as decreed by Gene
    389389        BEFORE = self.scratchDb.getRowCount(ippTableName)
    390         sql = "DELETE FROM " + ippTableName + " WHERE PSF_INST_MAG < -17.5"
    391         self.scratchDb.execute(sql)
     390        #don't do this anymore
     391        #sql = "DELETE FROM " + ippTableName + " WHERE PSF_INST_MAG < -17.5"
     392        #self.scratchDb.execute(sql)
    392393        #DELETED = BEFORE - self.scratchDb.getRowCount(ippTableName)
    393         results['SATDET'] = BEFORE - self.scratchDb.getRowCount(ippTableName)
     394        #results['SATDET'] = BEFORE - self.scratchDb.getRowCount(ippTableName)
     395        #we aren't deletng these now
     396        results['SATDET'] = 0
    394397        #self.logger.infoPair("Saturated detections", "%d deleted" % DELETED)
    395398
     
    404407               ,xPosErr \
    405408               ,yPosErr \
    406                ,instFlux \
    407                ,instFluxErr \
     409               ,psfFlux \
     410               ,psfFluxErr \
    408411               ,peakADU \
    409412               ,psfWidMajor \
     
    411414               ,psfTheta \
    412415               ,psfLikelihood \
    413                ,psfCf \
     416               ,psfQf \
    414417               ,momentXX \
    415418               ,momentXY \
    416419               ,momentYY \
    417                ,apMag \
     420               ,apFlux \
    418421               ,kronFlux \
    419422               ,kronFluxErr \
     423               ,psfQfPerfect \
     424               ,psfChiSq \
    420425               ,infoFlag \
    421426               ,sky \
     
    450455               ,KRON_FLUX / " + self.header['EXPTIME'] + " \
    451456               ,KRON_FLUX_ERR / " + self.header['EXPTIME'] + " \
    452                ,FLAGS\
     457               ,PSF_QF_PERFECT \
     458               ,PSF_CHISQ \
     459               ,FLAGS2 << 32 | FLAGS\
    453460               ,SKY \
    454461               ,SKY_SIGMA \
     
    459466               , " + str(self.config.dataRelease) + "\
    460467               FROM " + ippTableName
     468        # SA10 todo
     469        # need to correct formulas for psfFlux/psfFluxErr
     470        # need to correct apMag apFlux
     471        # need to correct unites kronFlux/Err to correct units
     472        # need to change psfqfperfect -> psfqfperfect PSF_QF_PERFECT?
     473        # need to change psfchisq  PSF_CHI_SQ?
     474        # need to change unites of sky/skyErr to adu/s/pixel
     475        # need formula for sgsep/psflikelhood
     476        # self.logger.info(sql)
    461477        self.scratchDb.execute(sql)
    462478
    463479        # now delete bad flux and bad chip positions
    464         sql="DELETE FROM " + pspsTableName + " WHERE instFlux < 0.0000001" # TODO clearly a hack = 0 not allowed for instFlux
    465         self.scratchDb.execute(sql)
    466 
     480        #sql="DELETE FROM " + pspsTableName + " WHERE instFlux < 0.0000001" # TODO clearly a hack = 0 not allowed for instFlux
     481        #self.scratchDb.execute(sql)
     482
     483        # add a instFlux = 0.0 -> 0.000001
     484        sql="UPDATE " + pspsTableName + " SET psfFlux = 0.0000001 WHERE psfFlux =  0"
     485        self.scratchDb.execute(sql)
     486     
    467487        # update cosmic ray and extended likelihoods
    468         sql="UPDATE " + pspsTableName + " SET extendedLikelihood = 0, crLikelihood = 1.0 - psfLikelihood WHERE sgSep <= 0"
    469         self.scratchDb.execute(sql)
    470         sql="UPDATE " + pspsTableName + " SET crLikelihood = 0, extendedLikelihood = 1.0 - psfLikelihood WHERE sgSep > 0"
    471         self.scratchDb.execute(sql)
     488        #sql="UPDATE " + pspsTableName + " SET extendedLikelihood = 0, crLikelihood = 1.0 - psfLikelihood WHERE sgSep <= 0"
     489        #self.scratchDb.execute(sql)
     490        #sql="UPDATE " + pspsTableName + " SET crLikelihood = 0, extendedLikelihood = 1.0 - psfLikelihood WHERE sgSep > 0"
     491        #self.scratchDb.execute(sql)
    472492
    473493        # remove detections will NULL inst flux or NULL peak ADU
    474         results['NULLINSTFLUX'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "instFlux")
    475         results['NULLPEAKADU'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "peakADU")
     494        # leave them in at this stage- don't delete them.
     495        #results['NULLINSTFLUX'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "instFlux")
     496        #results['NULLPEAKADU'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "peakADU")
     497        #we don't delete thos anymore
     498        results['NULLINSTFLUX'] = 0;
     499        results['NULLPEAKADU'] = 0;
    476500
    477501    '''
     
    504528
    505529    '''
     530    Populates the DetectionCalib table for this OTA
     531    '''
     532    def populateDetectionCalibTable(self, ota):
     533
     534        tableName = "DetectionCalib_" + ota
     535        # drop then re-create table
     536        self.scratchDb.dropTable(tableName)
     537        sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
     538        try: self.scratchDb.execute(sql)
     539        except: pass
     540
     541        # insert all detections into table
     542        sql = "INSERT INTO " + tableName + " ( \
     543               objID \
     544               ,detectID \
     545               ,ippObjID \
     546               ,ippDetectID \
     547               ,filterID \
     548               ,surveyID \
     549               ) \
     550               SELECT \
     551               objID \
     552               ,detectID \
     553               ,ippObjID \
     554               ,ippDetectID \
     555               ,filterID \
     556               ,surveyID \
     557               FROM Detection_" + ota
     558        self.scratchDb.execute(sql)
     559        #SA10 TODO
     560        # insert ra/dec/calstuff into Table
     561        # heather discovered dec is called 'dec_'
     562        sql = "UPDATE " + tableName + " SET ra = -999, dec_ =-999, raErr = -999, decErr = -999, zp = -999, zpErr = -999, expTime = -999, airMass = -999"
     563        self.scratchDb.execute(sql)
     564        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease))
     565       
     566    '''
    506567    Populates the Detection table for this OTA
    507568    '''
     
    608669                extension = "XY%d%d_psf" % (x, y)
    609670                self.scratchDb.createIndex(extension, "IPP_IDET")
    610 
     671        self.logger.infoPair("created indexes on", "IPP tables")     
    611672    '''
    612673    Updates provided table with DVO IDs from DVO table
     
    620681               a.detectID = b.detectID, \
    621682               a.objID = b.objID, \
    622                a.infoFlag = b.flags << 32 | a.infoFlag \
     683               a.infoFlag = b.flags << 46 | a.infoFlag \
    623684               WHERE a.ippDetectID = b.ippDetectID \
    624685               AND b.imageID = " + str(imageID)
     
    658719                    self.logger.info("| %5s |            ------------- Bad astrometric solution : rejecting ------------                    |" % ota)
    659720                    continue
    660 
     721               # self.logger.info("populate stuff ");
    661722                # populate remainder of tables
    662723                self.populateDetectionTable(ota, results)
    663 
     724               # self.logger.info("successful populate ");
    664725                # now add DVO IDs
    665726                self.updateDvoIDs("Detection_" + ota, self.imageIDs[ota])
     727               # self.logger.info("updated dvoids")
    666728                results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + ota, "objID")
    667                 self.updateImageID("Detection_" + ota, x, y)
     729                #self.logger.info("deleted nulls")
     730                self.updateImageID("Detection_" + ota, x, y)
     731               # self.logger.info("updateImageId")
    668732                rowCount = self.scratchDb.getRowCount("Detection_" + ota)
     733              #  self.logger.info("got row count")
    669734                self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |",
    670735                        ota,
     
    675740                        results['NULLOBJID'],
    676741                        rowCount)
    677 
    678742                totalOriginal = totalOriginal + results['ORIGINALTOTAL']
    679743                totalSatDet = totalSatDet + results['SATDET']
     
    682746                totalNullObjID = totalNullObjID + results['NULLOBJID']
    683747                totalDetections = totalDetections + rowCount
    684 
     748                #self.logger.info("updated totals")
    685749                # check we have something in this Detection table TODO add this to table above
    686750                if rowCount < 1:
     
    692756                       SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(self.imageIDs[ota]))
    693757                self.scratchDb.execute(sql)
    694 
     758               
     759                #self.logger.info("updated imagedata")
    695760                self.populateSkinnyObjectTable(ota)
     761                #self.logger.info("updated skinnyobject")
    696762                self.populateObjectCalColorTable(ota)
    697 
     763                #self.logger.info("updated objectcalcolor")
     764                self.populateDetectionCalibTable(ota)
     765                #self.logger.info("updated detectioncalibtable")
     766               
    698767                # add these to list of tables to export later
    699768                self.tablesToExport.append("ImageMeta_" + ota)
     
    701770                self.tablesToExport.append("SkinnyObject_" + ota)
    702771                self.tablesToExport.append("ObjectCalColor_" + ota)
     772                self.tablesToExport.append("DetectionCalib_" + ota)
    703773                tables.append("Detection_" + ota)
    704774           
    705775                otaCount = otaCount + 1
    706 
     776                #self.logger.info("end of ota")
    707777        # print totals
    708778        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     
    757827       else : regex = ".*.psf"
    758828 
    759        columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS SKY SKY_SIGMA EXT_NSIGMA"
     829       columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ"
    760830
    761831       return super(DetectionBatch, self).importIppTables(columns, regex)
  • trunk/ippToPsps/jython/objectbatch.py

    r34441 r34615  
    114114        for filter in filters:
    115115
    116             sql = "UPDATE Object \
    117                    JOIN " + cpsTable + " AS cps ON (cps.row = (Object.row*" + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
     116            sql = "UPDATE Object JOIN \
     117                   " + cpsTable + " AS cps ON (cps.row = (Object.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
    118118                   SET \
    119119                   n" + filter[1] + " = NCODE \
     
    122122                   ," + filter[1] + "MeanKronMag = MAG_KRON \
    123123                   ," + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
    124                    ," + filter[1] + "StackPSFFlux = FLUX_PSF \
    125                    ," + filter[1] + "StackPSFFluxErr = FLUX_PSF_ERR \
     124                   ," + filter[1] + "StackPSFMag = -2.5 * log10(FLUX_PSF) + 8.9 \
     125                   ," + filter[1] + "StackPSFMagErr = FLUX_PSF_ERR / FLUX_PSF \
    126126                   ," + filter[1] + "StackKronMag = -2.5 * log10(FLUX_KRON) + 8.9 \
    127127                   ," + filter[1] + "StackKronMagErr = FLUX_KRON_ERR / FLUX_KRON \
    128128                   ," + filter[1] + "20pct = MAG_20/1000 \
    129129                   ," + filter[1] + "80pct = MAG_80/1000 \
    130                    ," + filter[1] + "Flags = FLAGS " 
    131                    
     130                   ," + filter[1] + "Flags = FLAGS  \
     131                   ," + filter[1] + "StackDetectID = STACK_ID"
     132
     133            #stackDetectID needs to be filled still for SA10 - currently at STACK_ID for test purposes
     134            # everthing should be correctly calculated as mags for SA10       
     135            #self.logger.info(sql)
     136            self.scratchDb.execute(sql)
     137
     138        self.logger.infoPair("Calculating nDetections from", "n[filters]")
     139        for filter in filters:
     140            # now do a sum of n[filters], but do not include the ones with -999
     141            sql = "UPDATE Object \
     142                   SET nDetections = nDetections + n" + filter[1] + " \
     143                   WHERE n" + filter[1] + " != -999"
     144            self.scratchDb.execute(sql)
    132145           
    133             self.scratchDb.execute(sql)
     146
     147
    134148
    135149        # now set to null all MeanMagErr values > 0.5 (cut set by Gene, 2012-04-12)
     
    204218               ,decErr \
    205219               ,nDetections \
    206                ,extra \
     220               ,qfPerfect \
    207221               ,sgSep \
    208222               ,dataRelease \
  • trunk/ippToPsps/jython/stackbatch.py

    r34441 r34615  
    8989       self.scratchDb.dropTable("SkinnyObject")
    9090       self.scratchDb.dropTable("ObjectCalColor")
     91       self.scratchDb.dropTable("StackDetectionCalib")
    9192
    9293       # delete IPP tables
     
    140141
    141142        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, \
     143        "+prefix+"flxR1=b.APER_FLUX_1 / " + str(self.expTime) + ", \
     144        "+prefix+"flxR1Err=b.APER_FLUX_ERR_1 / " + str(self.expTime) + ", \
     145        "+prefix+"flxR1Std=b.APER_FLUX_STDEV_1 / " + str(self.expTime) + ", \
    145146        "+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, \
     147        "+prefix+"flxR2=b.APER_FLUX_2 / " + str(self.expTime) + ", \
     148        "+prefix+"flxR2Err=b.APER_FLUX_ERR_2 / " + str(self.expTime) + ", \
     149        "+prefix+"flxR2Std=b.APER_FLUX_STDEV_2 / " + str(self.expTime) + ", \
    149150        "+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, \
     151        "+prefix+"flxR3=b.APER_FLUX_3 / " + str(self.expTime) + ", \
     152        "+prefix+"flxR3Err=b.APER_FLUX_ERR_3 / " + str(self.expTime) + ", \
     153        "+prefix+"flxR3Std=b.APER_FLUX_STDEV_3 / " + str(self.expTime) + ", \
    153154        "+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, \
     155        "+prefix+"flxR4=b.APER_FLUX_4 / " + str(self.expTime) + ", \
     156        "+prefix+"flxR4Err=b.APER_FLUX_ERR_4 / " + str(self.expTime) + ", \
     157        "+prefix+"flxR4Std=b.APER_FLUX_STDEV_4 / " + str(self.expTime) + ", \
    157158        "+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, \
     159        "+prefix+"flxR5=b.APER_FLUX_5 / " + str(self.expTime) + ", \
     160        "+prefix+"flxR5Err=b.APER_FLUX_ERR_5 / " + str(self.expTime) + ", \
     161        "+prefix+"flxR5Std=b.APER_FLUX_STDEV_5 / " + str(self.expTime) + ", \
    161162        "+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, \
     163        "+prefix+"flxR6=b.APER_FLUX_6 / " + str(self.expTime) + ", \
     164        "+prefix+"flxR6Err=b.APER_FLUX_ERR_6 / " + str(self.expTime) + ", \
     165        "+prefix+"flxR6Std=b.APER_FLUX_STDEV_6 / " + str(self.expTime) + ", \
    165166        "+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, \
     167        "+prefix+"flxR7=b.APER_FLUX_7 / " + str(self.expTime) + ", \
     168        "+prefix+"flxR7Err=b.APER_FLUX_ERR_7 / " + str(self.expTime) + ", \
     169        "+prefix+"flxR7Std=b.APER_FLUX_STDEV_7 / " + str(self.expTime) + ", \
    169170        "+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, \
     171        "+prefix+"flxR8=b.APER_FLUX_8 / " + str(self.expTime) + ", \
     172        "+prefix+"flxR8Err=b.APER_FLUX_ERR_8 / " + str(self.expTime) + ", \
     173        "+prefix+"flxR8Std=b.APER_FLUX_STDEV_8 / " + str(self.expTime) + ", \
    173174        "+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, \
     175        "+prefix+"flxR9=b.APER_FLUX_9 / " + str(self.expTime) + ", \
     176        "+prefix+"flxR9Err=b.APER_FLUX_ERR_9 / " + str(self.expTime) + ", \
     177        "+prefix+"flxR9Std=b.APER_FLUX_STDEV_9 / " + str(self.expTime) + ", \
    177178        "+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, \
     179        "+prefix+"flxR10=b.APER_FLUX_10 / " + str(self.expTime) + ", \
     180        "+prefix+"flxR10Err=b.APER_FLUX_ERR_10 / " + str(self.expTime) + ", \
     181        "+prefix+"flxR10Std=b.APER_FLUX_STDEV_10 / " + str(self.expTime) + ", \
    181182        "+prefix+"flxR10Fill=b.APER_FILL_10 \
    182183        WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
     
    196197        sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
    197198        "+model+"Radius=b.EXT_WIDTH_MAJ,  \
    198         "+model+"Mag=b.EXT_INST_MAG,  \
    199         "+model+"MagErr=b.EXT_INST_MAG_SIG,  \
     199        "+model+"Flux=b.EXT_INST_MAG,  \
     200        "+model+"FluxErr=b.EXT_INST_MAG_SIG,  \
    200201        "+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \
    201202        "+model+"Phi=b.EXT_THETA,  \
     
    229230        "+modelLong+"Covar77=b.EXT_COVAR_06_06   \
    230231        WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
     232
     233        #SA10 convert mag to flux in calculation above
    231234
    232235        self.scratchDb.execute(sql)
     
    319322               ,skyCellID \
    320323               ,projectionCellID \
    321                ,obsTime \
    322324               ,xPos \
    323325               ,yPos \
    324326               ,xPosErr \
    325327               ,yPosErr \
    326                ,instFlux \
    327                ,instFluxErr \
     328               ,psfFlux \
     329               ,psfFluxErr \
    328330               ,peakFlux \
    329331               ,sky \
     
    335337               ,psfLikelihood \
    336338               ,infoFlag \
    337                ,psfCf \
     339               ,psfQf \
     340               ,psfQfPerfect \
    338341               ,momentXX \
    339342               ,momentXY \
     
    345348               ,momentR1 \
    346349               ,momentRH \
    347                ,apMag \
    348                ,apMagErr \
     350               ,apFlux \
     351               ,apFluxErr \
    349352               ,kronFlux \
    350353               ,kronFluxErr \
    351354               ,kronRad \
    352                ,kronRadErr \
     355               ,psfChiSq \
    353356               ,nFrames \
    354357               ,assocDate \
     
    359362               ," + self.skycell + " \
    360363               ," + self.projectioncell + " \
    361                ," + self.header['MJD-OBS'] + " \
    362364               ,X_PSF \
    363365               ,Y_PSF \
     
    374376               ,PSF_THETA \
    375377               ,psfLikelihood(EXT_NSIGMA) \
    376                ,FLAGS2 << 32 | FLAGS \
     378               , FLAGS2 << 32 | FLAGS \
    377379               ,PSF_QF \
     380               ,PSF_QF_PERFECT \
    378381               ,MOMENTS_XX \
    379382               ,MOMENTS_XY \
     
    389392               ,KRON_FLUX / " + str(self.expTime) + " \
    390393               ,KRON_FLUX_ERR / " + str(self.expTime) + " \
    391                , MOMENTS_R1 * 2.5 \
    392                , NULL \
     394               ,MOMENTS_R1 * 2.5 \
     395               ,PSF_CHISQ \
    393396               ,N_FRAMES \
    394397               , '" + self.dateStr + "' \
    395398               ," + self.historyModNum + " \
    396399               FROM SkyChip_psf"
     400
     401               #SA10 to do
     402               # put in correct formula for apFlux, psfFlux, psfLikelihood, sgsep
     403               # need correct units of anything in Flux
    397404        self.scratchDb.execute(sql)
    398405       
     
    417424        self.updateStackTypeID("StackDetection")
    418425       
    419         self.updateDvoIDs("StackDetection")
     426        self.updateDvoIDsAndFlags("StackDetection")
    420427       
    421428        sql = "ALTER IGNORE TABLE StackDetection ADD PRIMARY KEY (objID)"
     
    427434            #if deep stack and instFlux = null and err not null
    428435            sql = "UPDATE StackDetection AS a, SkyChip_psf AS b \
    429                    SET instFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
    430                    WHERE instFlux IS NULL \
     436                   SET psfFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
     437                   WHERE psfFlux IS NULL \
    431438                   AND a.ippDetectID = b.IPP_IDET  \
    432439                   AND b.PSF_INST_FLUX_SIG IS NOT NULL"
     
    434441            self.scratchDb.execute(sql)
    435442           
    436        
    437         self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
     443        #leave null instflux in
     444        #self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
    438445       
    439446        self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "objID")
     
    474481        petRadius=b.PETRO_RADIUS \
    475482        ,petRadiusErr=b.PETRO_RADIUS_ERR \
    476         ,petMag=b.PETRO_MAG \
    477         ,petMagErr=b.PETRO_MAG_ERR \
     483        ,petFlux=b.PETRO_MAG \
     484        ,petFluxErr=b.PETRO_MAG_ERR \
    478485        ,petR50=b.PETRO_RADIUS_50 \
    479486        ,petR50Err=b.PETRO_RADIUS_50_ERR \
     
    482489        ,petCf=b.PETRO_FILL \
    483490        WHERE a.ippDetectID=b.IPP_IDET"
     491        #SA10 Put correct calculation for PetFlux
    484492        self.scratchDb.execute(sql)
    485493
     
    586594        self.scratchDb.updateAllRows("SkinnyObject", "surveyID", str(self.surveyID))
    587595        self.scratchDb.updateAllRows("SkinnyObject", "dataRelease", str(self.config.dataRelease))
     596
     597    '''   
     598    Populates the StackDetectionCalib table
     599    '''
     600    def populateStackDetectionCalib(self):
     601        self.logger.infoPair("Processing table", "StackDetectionCalib")
     602        tableName = "StackDetectionCalib"
     603        # insert all detections into table
     604        sql = "INSERT INTO " + tableName + " ( \
     605               objID \
     606               ,stackDetectID \
     607               ,ippObjID \
     608               ,ippDetectID \
     609               ,filterID \
     610               ,surveyID \
     611               ) \
     612               SELECT \
     613               objID \
     614               ,stackDetectID \
     615               ,ippObjID \
     616               ,ippDetectID \
     617               ,filterID \
     618               ,surveyID \
     619               FROM StackDetection"
     620        self.logger.info(sql)
     621        self.scratchDb.execute(sql)
     622        #SA10 TODO
     623        # insert ra/dec/calstuff into Table
     624        # heather discovered dec is called 'dec_'
     625        sql = "UPDATE " + tableName + " SET ra = -999, dec_ =-999, raErr = -999, decErr = -999, zp = -999, zpErr = -999, expTime = -999, airMass = -999"
     626        self.logger.info(sql)
     627        self.scratchDb.execute(sql)
     628        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease))
     629       
     630   
     631
    588632
    589633    '''
     
    649693               WHERE a.ippDetectID = b.ippDetectID \
    650694               AND b.imageID = " + str(imageID)
    651        
    652         self.scratchDb.execute(sql)
    653        
     695        self.scratchDb.execute(sql)
     696   
     697    '''
     698    Updates Flags
     699    '''
     700    def updateDvoIDsAndFlags(self, table):
     701        self.logger.infoPair("getting","imageID")
     702        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
     703        self.logger.infoPair("obtained","imageID")
     704        self.logger.debug("Updating table '" + table + "' with DVO IDs...")
     705        sql = "UPDATE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
     706               a.ippObjID = b.ippObjID, \
     707               a.stackDetectID = 10 * b.detectID + " + str(self.filterID) + ", \
     708               a.objID = b.objID, \
     709               a.infoFlag = b.flags << 46 | a.infoFlag \
     710               WHERE a.ippDetectID = b.ippDetectID \
     711               AND b.imageID = " + str(imageID)
     712        self.scratchDb.execute(sql)
     713   
     714   
    654715    '''
    655716    Does the processing, i.e. pulling stuff from IPP tables into PSPS tables
     
    660721            if not self.getIDsFromDVO():
    661722                return False
    662 
     723        #self.logger.infoPair("populating","StackMeta")   
    663724        self.populateStackMeta()
     725        #self.logger.infoPair("populating","StackDetection")
    664726        self.populateStackDetection()
    665 
     727       
    666728        if self.stackType != "NIGHTLY_STACK":
     729            #self.logger.infoPair("populating","StackModelFit")
    667730            self.populateStackModelFit()
     731            #self.logger.infoPair("populating","StackApFlx")
    668732            self.populateStackApFlx()
    669    
     733        #self.logger.infoPair("populating","StackToImage")
    670734        self.populateStackToImage()
     735        #self.logger.infoPair("populating","SkinnyObject")
    671736        self.populateSkinnyObject()
     737        #self.logger.infoPair("populating","ObjectCalColor")
    672738        self.populateObjectCalColor()
     739        #self.logger.infoPair("populating","StackDetectionCalib")
     740        self.populateStackDetectionCalib()
    673741
    674742        self.setMinMaxObjID(["StackDetection"])
Note: See TracChangeset for help on using the changeset viewer.