IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 30, 2014, 11:43:09 AM (12 years ago)
Author:
heather
Message:

working detectionbatch, needs lot of work on stack

File:
1 edited

Legend:

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

    r36447 r36706  
    9898       # delete PSPS tables
    9999       self.scratchDb.dropTable("StackMeta")
    100        self.scratchDb.dropTable("StackDetection")
     100       self.scratchDb.dropTable("StackObject")
    101101       self.scratchDb.dropTable("StackModelFit")
    102102       self.scratchDb.dropTable("StackApFlx")
    103103       self.scratchDb.dropTable("StackToImage")
    104        self.scratchDb.dropTable("SkinnyObject")
    105        #self.scratchDb.dropTable("ObjectCalColor")
    106        self.scratchDb.dropTable("StackDetectionCalib")
    107 
    108        # self.testprint()
     104             # self.testprint()
    109105
    110106       # delete IPP tables
     
    447443
    448444    '''
    449     Populates the StackDetection table
    450     '''
    451     def populateStackDetection(self):
    452 
    453         self.logger.infoPair("Procesing table", "StackDetection")
     445    Populates the StackObject table
     446    '''
     447    def populateStackObject(self):
     448
     449        self.logger.infoPair("Procesing table", "StackObject")
    454450
    455451        # insert all the detections
    456         sql = "INSERT INTO StackDetection (\
     452        sql = "INSERT INTO StackObject(\
    457453               ippDetectID \
    458454               ,skyCellID \
     
    550546        #it is possible to drop some detections from dvo (that are present in the cmf). when that happens we get a 0 for objid
    551547        #we drop those...
    552         sql="DELETE FROM StackDetection where objID = 0"
    553         self.scratchDb.execute(sql)
    554         self.logger.infoPair("Deleting", "entries with StackDetection.objID = 0")
     548        sql="DELETE FROM StackObject where objID = 0"
     549        self.scratchDb.execute(sql)
     550        self.logger.infoPair("Deleting", "entries with StackObject.objID = 0")
    555551       
    556552        # XXX EAM : this seems quite inefficient : these commands use updates to set
     
    558554        # the original insert above?
    559555
    560         self.scratchDb.updateAllRows("StackDetection", "surveyID", str(self.surveyID))
    561        
    562         self.scratchDb.updateFilterID("StackDetection", self.filter)
    563        
    564         self.scratchDb.updateAllRows("StackDetection", "dataRelease", str(self.skychunk.dataRelease))
     556        self.scratchDb.updateAllRows("StackObject", "surveyID", str(self.surveyID))
     557       
     558        self.scratchDb.updateFilterID("StackObject", self.filter)
     559       
     560        self.scratchDb.updateAllRows("StackObject", "dataRelease", str(self.skychunk.dataRelease))
    565561        #set primary F to 0
    566         self.scratchDb.updateAllRows("StackDetection", "primaryF", "0")
    567        
    568         self.scratchDb.updateAllRows("StackDetection", "activeFlag", "0")
    569        
    570         self.updateStackMetaID("StackDetection")
    571        
    572         self.updateStackTypeID("StackDetection")
    573        
    574         self.updateDvoIDsAndFlags("StackDetection")
     562        self.scratchDb.updateAllRows("StackObject", "primaryF", "0")
     563       
     564        self.scratchDb.updateAllRows("StackObject", "activeFlag", "0")
     565       
     566        self.updateStackMetaID("StackObject")
     567       
     568        self.updateStackTypeID("StackObject")
     569       
     570        self.updateDvoIDsAndFlags("StackObject")
    575571        #this now updates primary F as well
    576572        # response = raw_input("updated dvo ")
     
    585581            self.scratchDb.execute("set session old_alter_table=1")
    586582
    587         sql = "ALTER IGNORE TABLE StackDetection ADD PRIMARY KEY (objID)"
     583        sql = "ALTER IGNORE TABLE StackObject ADD PRIMARY KEY (objID)"
    588584       
    589585        if self.scratchDb.version > 5.1:
     
    597593
    598594            #if deep stack and instFlux = null and err not null
    599             sql = "UPDATE StackDetection AS a, SkyChip_psf AS b \
     595            sql = "UPDATE StackObject AS a, SkyChip_psf AS b \
    600596                   SET psfFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
    601597                   WHERE psfFlux IS NULL \
     
    610606        # something like (f < 0.0) ? -999 : -2.5*log10(f)
    611607        # as a result, the negative fluxes here result in floating point errors
    612         sql = "UPDATE StackDetection SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
    613         self.scratchDb.execute(sql)
    614        
    615         sql = "UPDATE StackDetection SET apFlux = 1e20 WHERE apFlux <= 0.0"
    616         self.scratchDb.execute(sql)
    617 
    618         sql = "UPDATE StackDetection SET kronFlux = 1e20 WHERE kronFlux <= 0.0"
     608        sql = "UPDATE StackObject SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
     609        self.scratchDb.execute(sql)
     610       
     611        sql = "UPDATE StackObject SET apFlux = 1e20 WHERE apFlux <= 0.0"
     612        self.scratchDb.execute(sql)
     613
     614        sql = "UPDATE StackObject SET kronFlux = 1e20 WHERE kronFlux <= 0.0"
    619615        self.scratchDb.execute(sql)
    620616
    621617        #leave null instflux in
    622         #self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
    623        
    624         self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "objID")
     618        #self.scratchDb.reportAndDeleteRowsWithNULLS("StackObject", "instFlux")
     619       
     620        self.scratchDb.reportAndDeleteRowsWithNULLS("StackObject", "objID")
    625621        # response = raw_input("delete nulls ")
    626622       
    627         sql="DELETE FROM StackDetection where objID = 0"
    628        
    629         self.scratchDb.execute(sql)
    630         self.logger.infoPair("Deleting", "entries with StackDetection.objID = 0")
     623        sql="DELETE FROM StackObject where objID = 0"
     624       
     625        self.scratchDb.execute(sql)
     626        self.logger.infoPair("Deleting", "entries with StackObject.objID = 0")
    631627        # response = raw_input("deleted objID is 0 ")
    632628       
     
    709705        self.updateDvoIDs("StackApFlx")
    710706        self.scratchDb.reportAndDeleteRowsWithNULLS("StackApFlx", "objID")
    711         self.deleteDetectionsNotInStackDetection("StackApFlx")
     707        self.deleteDetectionsNotInStackObject("StackApFlx")
    712708
    713709
     
    759755        self.updateDvoIDs("StackModelFit")
    760756        self.scratchDb.reportAndDeleteRowsWithNULLS("StackModelFit", "objID")
    761         self.deleteDetectionsNotInStackDetection("StackModelFit")
    762 
    763     '''
    764     Reports and deletes detections in this table that are not in StackDetection
    765     '''
    766     def deleteDetectionsNotInStackDetection(self, table):
    767 
    768         sql = "SELECT COUNT(*) FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackDetection)"
     757        self.deleteDetectionsNotInStackObject("StackModelFit")
     758
     759    '''
     760    Reports and deletes detections in this table that are not in StackObject
     761    '''
     762    def deleteDetectionsNotInStackObject(self, table):
     763
     764        sql = "SELECT COUNT(*) FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackObject)"
    769765        rs = self.scratchDb.executeQuery(sql)
    770766        rs.first()
     
    773769        if nMissing < 1: return
    774770       
    775         sql = "DELETE FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackDetection)"
    776         self.scratchDb.execute(sql)
    777         self.logger.infoPair("Detections not in StackDetection", "%d deleted from %s" % (nMissing, table))
     771        sql = "DELETE FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackObject)"
     772        self.scratchDb.execute(sql)
     773        self.logger.infoPair("Detections not in StackObject", "%d deleted from %s" % (nMissing, table))
    778774       
    779775
     
    797793        self.scratchDb.execute(sql)
    798794
    799     '''
    800     Populates the SkinnyObject table
    801     '''
    802     def populateSkinnyObject(self):
    803 
    804         self.logger.infoPair("Procesing table", "SkinnyObject")
    805 
    806         sql = "INSERT INTO SkinnyObject (\
    807                objID \
    808                ,ippObjID \
    809                ,projectionCellID \
    810                ) \
    811                SELECT \
    812                DISTINCT objID \
    813                ,ippObjID \
    814                ,projectionCellID \
    815                FROM StackDetection"
    816         self.scratchDb.execute(sql)
    817 
    818         self.scratchDb.updateAllRows("SkinnyObject", "surveyID", str(self.surveyID))
    819         self.scratchDb.updateAllRows("SkinnyObject", "dataRelease", str(self.skychunk.dataRelease))
    820795
    821796    '''   
    822     Populates the StackDetectionCalib table
     797    Populates the StackObjectCalib table
    823798    XXX this can probably get a big speed increase by using 'SELECT () INTO OUTFILE '/tmp/name' and then
    824799    calling the load data infile '/tmp/name' into table;
    825800    '''
    826     def populateStackDetectionCalibInsertUpdate(self):
    827         self.logger.infoPair("Processing table", "StackDetectionCalib")
    828         tableName = "StackDetectionCalib"
    829         # insert all detections into table
    830         sql = "INSERT INTO " + tableName + " ( \
    831                objID \
    832                ,stackDetectID \
    833                ,ippObjID \
    834                ,ippDetectID \
    835                ,filterID \
    836                ,surveyID \
    837                ) \
    838                SELECT \
    839                objID \
    840                ,stackDetectID \
    841                ,ippObjID \
    842                ,ippDetectID \
    843                ,filterID \
    844                ,surveyID \
    845                FROM StackDetection"
    846         self.scratchDb.execute(sql)
     801    def populateStackObjectCalibInsertUpdate(self):
     802        self.logger.infoPair("Processing table", "StackObject")
     803        tableName = "StackObject"
    847804
    848805        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
     
    856813            a.decErr = b.decErr, \
    857814            a.zp = b.zp, \
    858             a.zpErr = b.zpErr, \
    859815            a.expTime = b.expTime, \
    860816            a.airMass = b.airMass   \
     
    864820        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    865821       
    866     def populateStackDetectionCalib(self):
    867 
    868         tableName = "StackDetectionCalib"
     822    def populateStackObjectCalib(self):
     823
     824        tableName = "StackObject"
    869825        self.logger.infoPair("Processing table", tableName)
    870826
    871827        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
    872828        self.logger.infoPair("obtained","imageID")
    873 
    874         # check for & create output directory first
    875         datadumpDir = "/tmp/datadump"
    876         try:
    877             statinfo = os.stat(datadumpDir)
    878             # check on the stat results?
    879         except:
    880             print "making the data dump directory ", datadumpDir
    881             os.mkdir(datadumpDir)
    882             os.chmod(datadumpDir, 0777)
    883             statinfo = os.stat(datadumpDir)
    884 
    885         dumpFile = datadumpDir + "/genetest.xx.dat"
    886         files = glob.glob(dumpFile)
    887         if len(files) > 0:
    888             os.unlink(dumpFile)
    889 
    890         # insert all detections into table
    891         sql = "SELECT \
    892           a.objID,    \
    893           a.stackDetectID, \
    894           a.ippObjID,      \
    895           a.ippDetectID,   \
    896           a.filterID,      \
    897           a.surveyID,      \
    898           b.ra,            \
    899           b.dec_,          \
    900           b.raErr,         \
    901           b.decErr,        \
    902           b.zp,            \
    903           b.zpErr,         \
    904           b.expTime,       \
    905           b.airMass,       \
    906           " + str(self.skychunk.dataRelease) + " \
    907          FROM              \
    908            StackDetection as a \
    909          JOIN " + self.scratchDb.dvoDetectionTable + " as b \
    910          ON (a.stackDetectID = b.detectID) where b.imageID = " + str(imageID) + \
    911          " INTO OUTFILE '" + dumpFile + "'"
    912 
    913         try: self.scratchDb.execute(sql)
    914         except:
    915             self.logger.info("failed to select data for stackDetectionCalib")
    916             self.logger.infoPair("sql: ", sql)
    917             raise
    918 
    919         sql = "LOAD DATA INFILE '" + dumpFile + "' INTO TABLE " + tableName
    920         try: self.scratchDb.execute(sql)
    921         except:
    922             self.logger.info("failed to load data from infile for stackDetectionCalib")
    923             self.logger.infoPair("sql: ", sql)
    924             raise
     829        sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
     830            SET a.ra = b.ra, \
     831            a.dec = b.dec_, \
     832            a.raErr = b.raErr, \
     833            a.decErr = b.decErr, \
     834            a.zp = b.zp, \
     835            a.expTime = b.expTime, \
     836            a.airMass = b.airMass   \
     837            WHERE a.stackDetectID = b.detectID \
     838            AND b.imageID = " + str(imageID)
     839        self.scratchDb.execute(sql)
     840        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    925841
    926842        ## XXX write this with the select/insert
     
    928844
    929845    '''
    930     Populates the ObjectCalColor table
    931     '''
    932     def populateObjectCalColor(self):
    933 
    934         self.logger.infoPair("Procesing table", "ObjectCalColor table")
    935 
    936         sql = "INSERT INTO ObjectCalColor (\
    937                objID \
    938                ,ippObjID \
    939                ) \
    940                SELECT \
    941                DISTINCT objID \
    942                ,ippObjID \
    943                FROM StackDetection"
    944         self.scratchDb.execute(sql)
    945 
    946         self.scratchDb.updateFilterID("ObjectCalColor", self.filter)
    947         self.scratchDb.updateAllRows("ObjectCalColor", "dataRelease", str(self.skychunk.dataRelease))
    948 
    949 
    950     '''
    951846    Applies indexes to the PSPS tables
    952847    '''
     
    955850        self.logger.debug("Altering PSPS tables")
    956851        # heather uncommented the unique line -- well that no worky
    957         #self.scratchDb.makeColumnUnique("StackDetection", "objID")
    958         self.scratchDb.createIndex("StackDetection", "ippDetectID")
    959         self.scratchDb.createIndex("StackDetection", "stackDetectID")
     852        #self.scratchDb.makeColumnUnique("StackObject", "objID")
     853        self.scratchDb.createIndex("StackObject", "ippDetectID")
     854        self.scratchDb.createIndex("StackObject", "stackDetectID")
    960855        self.scratchDb.createIndex("StackApFlx", "ippDetectID")
    961856        self.scratchDb.createIndex("StackModelFit", "ippDetectID")
     
    963858        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
    964859        # the column in PSPS
    965         self.scratchDb.execute("ALTER TABLE StackDetectionCalib CHANGE dec_ `dec` double")
     860        self.scratchDb.execute("ALTER TABLE StackObject CHANGE dec_ `dec` double")
    966861
    967862        return True
     
    1030925        #self.logger.infoPair("populating","StackMeta")   
    1031926        self.populateStackMeta()
    1032         #self.logger.infoPair("populating","StackDetection")
    1033         self.populateStackDetection()
     927        #self.logger.infoPair("populating","StackObject")
     928        self.populateStackObject()
    1034929       
    1035930        if self.stackType != "NIGHTLY_STACK":
     
    1040935        #self.logger.infoPair("populating","StackToImage")
    1041936        self.populateStackToImage()
    1042         #self.logger.infoPair("populating","SkinnyObject")
    1043         self.populateSkinnyObject()
    1044         #self.logger.infoPair("populating","ObjectCalColor")
    1045         #self.populateObjectCalColor()
    1046         #self.logger.infoPair("populating","StackDetectionCalib")
    1047         self.populateStackDetectionCalib()
    1048 
    1049         self.setMinMaxObjID(["StackDetection"])
     937        #self.logger.infoPair("populating","StackObjectCalib")
     938        self.populateStackObjectCalib()
     939
     940        self.setMinMaxObjID(["StackObject"])
    1050941       
    1051942        if self.totalDetections < 1:
Note: See TracChangeset for help on using the changeset viewer.