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/detectionbatch.py

    r33830 r34772  
    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 \
     
    447452               ,MOMENTS_XY \
    448453               ,MOMENTS_YY \
    449                ,AP_MAG \
     454               ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
    450455               ,KRON_FLUX / " + self.header['EXPTIME'] + " \
    451456               ,KRON_FLUX_ERR / " + self.header['EXPTIME'] + " \
    452                ,FLAGS\
    453                ,SKY \
    454                ,SKY_SIGMA \
     457               ,PSF_QF_PERFECT \
     458               ,PSF_CHISQ \
     459               ,FLAGS2 << 32 | FLAGS \
     460               ,SKY  / " + self.header['EXPTIME'] + " \
     461               ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
    455462               ,EXT_NSIGMA \
    456463               , 0 \
     
    459466               , " + str(self.config.dataRelease) + "\
    460467               FROM " + ippTableName
     468        # self.logger.info(sql)
    461469        self.scratchDb.execute(sql)
    462470
    463471        # 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 
     472        #sql="DELETE FROM " + pspsTableName + " WHERE instFlux < 0.0000001" # TODO clearly a hack = 0 not allowed for instFlux
     473        #self.scratchDb.execute(sql)
     474
     475        # add a instFlux = 0.0 -> 0.000001
     476        sql="UPDATE " + pspsTableName + " SET psfFlux = 0.0000001 WHERE psfFlux =  0"
     477        self.scratchDb.execute(sql)
     478     
    467479        # 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)
     480        #sql="UPDATE " + pspsTableName + " SET extendedLikelihood = 0, crLikelihood = 1.0 - psfLikelihood WHERE sgSep <= 0"
     481        #self.scratchDb.execute(sql)
     482        #sql="UPDATE " + pspsTableName + " SET crLikelihood = 0, extendedLikelihood = 1.0 - psfLikelihood WHERE sgSep > 0"
     483        #self.scratchDb.execute(sql)
    472484
    473485        # 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")
     486        # leave them in at this stage- don't delete them.
     487        #results['NULLINSTFLUX'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "instFlux")
     488        #results['NULLPEAKADU'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "peakADU")
     489        #we don't delete thos anymore
     490        results['NULLINSTFLUX'] = 0;
     491        results['NULLPEAKADU'] = 0;
    476492
    477493    '''
     
    504520
    505521    '''
     522    Populates the DetectionCalib table for this OTA
     523    '''
     524    def populateDetectionCalibTable(self, ota):
     525
     526        tableName = "DetectionCalib_" + ota
     527        # drop then re-create table
     528        self.scratchDb.dropTable(tableName)
     529        sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
     530        try: self.scratchDb.execute(sql)
     531        except: pass
     532
     533        # insert all detections into table
     534        sql = "INSERT INTO " + tableName + " ( \
     535               objID \
     536               ,detectID \
     537               ,ippObjID \
     538               ,ippDetectID \
     539               ,filterID \
     540               ,surveyID \
     541               ) \
     542               SELECT \
     543               objID \
     544               ,detectID \
     545               ,ippObjID \
     546               ,ippDetectID \
     547               ,filterID \
     548               ,surveyID \
     549               FROM Detection_" + ota
     550        self.scratchDb.execute(sql)
     551
     552        # insert calibration information from dvoDetections into the Table
     553        sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
     554            SET a.ra = b.ra, \
     555            a.dec = b.dec_, \
     556            a.raErr = b.raErr, \
     557            a.decErr = b.decErr, \
     558            a.zp = b.zp, \
     559            a.zpErr = b.zpErr, \
     560            a.expTime = b.expTime, \
     561            a.airMass = b.airMass   \
     562            WHERE a.objID = b.objID AND a.detectID = b.detectID"
     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    '''
     
    587648            if not self.getIDsFromDVO(): return False
    588649
     650        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
     651        # the column in PSPS
     652        self.scratchDb.execute("ALTER TABLE DetectionCalib CHANGE dec_ `dec` double")
     653
     654
     655
    589656        return True
    590657
     
    608675                extension = "XY%d%d_psf" % (x, y)
    609676                self.scratchDb.createIndex(extension, "IPP_IDET")
    610 
     677        self.logger.infoPair("created indexes on", "IPP tables")     
    611678    '''
    612679    Updates provided table with DVO IDs from DVO table
     
    620687               a.detectID = b.detectID, \
    621688               a.objID = b.objID, \
    622                a.infoFlag = b.flags << 32 | a.infoFlag \
     689               a.infoFlag = b.flags << 45 | a.infoFlag \
    623690               WHERE a.ippDetectID = b.ippDetectID \
    624691               AND b.imageID = " + str(imageID)
     
    658725                    self.logger.info("| %5s |            ------------- Bad astrometric solution : rejecting ------------                    |" % ota)
    659726                    continue
    660 
     727               # self.logger.info("populate stuff ");
    661728                # populate remainder of tables
    662729                self.populateDetectionTable(ota, results)
    663 
     730               # self.logger.info("successful populate ");
    664731                # now add DVO IDs
    665732                self.updateDvoIDs("Detection_" + ota, self.imageIDs[ota])
     733               # self.logger.info("updated dvoids")
    666734                results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + ota, "objID")
    667                 self.updateImageID("Detection_" + ota, x, y)
     735                #self.logger.info("deleted nulls")
     736                self.updateImageID("Detection_" + ota, x, y)
     737               # self.logger.info("updateImageId")
    668738                rowCount = self.scratchDb.getRowCount("Detection_" + ota)
     739              #  self.logger.info("got row count")
    669740                self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |",
    670741                        ota,
     
    675746                        results['NULLOBJID'],
    676747                        rowCount)
    677 
    678748                totalOriginal = totalOriginal + results['ORIGINALTOTAL']
    679749                totalSatDet = totalSatDet + results['SATDET']
     
    682752                totalNullObjID = totalNullObjID + results['NULLOBJID']
    683753                totalDetections = totalDetections + rowCount
    684 
     754                #self.logger.info("updated totals")
    685755                # check we have something in this Detection table TODO add this to table above
    686756                if rowCount < 1:
     
    692762                       SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(self.imageIDs[ota]))
    693763                self.scratchDb.execute(sql)
    694 
     764               
     765                #self.logger.info("updated imagedata")
    695766                self.populateSkinnyObjectTable(ota)
     767                #self.logger.info("updated skinnyobject")
    696768                self.populateObjectCalColorTable(ota)
    697 
     769                #self.logger.info("updated objectcalcolor")
     770                self.populateDetectionCalibTable(ota)
     771                #self.logger.info("updated detectioncalibtable")
     772               
    698773                # add these to list of tables to export later
    699774                self.tablesToExport.append("ImageMeta_" + ota)
     
    701776                self.tablesToExport.append("SkinnyObject_" + ota)
    702777                self.tablesToExport.append("ObjectCalColor_" + ota)
     778                self.tablesToExport.append("DetectionCalib_" + ota)
    703779                tables.append("Detection_" + ota)
    704780           
    705781                otaCount = otaCount + 1
    706 
     782                #self.logger.info("end of ota")
    707783        # print totals
    708784        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     
    757833       else : regex = ".*.psf"
    758834 
    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"
     835       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"
    760836
    761837       return super(DetectionBatch, self).importIppTables(columns, regex)
Note: See TracChangeset for help on using the changeset viewer.