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

    r35994 r36706  
    257257               ,psfWidMinor \
    258258               ,psfTheta \
    259                ,momentFwhm \
    260                ,momentWidMajor \
    261                ,momentWidMinor \
     259               ,momentXX \
     260               ,momentXY \
     261               ,momentYY \
     262               ,momentM3C \
     263               ,momentM3S \
     264               ,momentM4C \
     265               ,momentM4S \
     266               ,momentR1 \
     267               ,momentRH \
    262268               ,apResid \
    263269               ,dapResid \
     
    319325               ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \
    320326               ," + self.safeDictionaryAccess(header, 'ANGLE') + " \
    321                , ( " + self.safeDictionaryAccess(header, 'IQ_FW1') + " + " + self.safeDictionaryAccess(header, 'IQ_FW2') + " ) / 2.0  \
    322                ," + self.safeDictionaryAccess(header, 'IQ_FW1') + " \
    323                ," + self.safeDictionaryAccess(header, 'IQ_FW2') + " \
     327               ,-999 \
     328               ,-999 \
     329               ,-999 \
     330               ,-999 \
     331               ,-999 \
     332               ,-999 \
     333               ,-999 \
     334               ,-999 \
     335               ,-999 \
    324336               ," + self.safeDictionaryAccess(header, 'APMIFIT') + " \
    325337               ," + self.safeDictionaryAccess(header, 'DAPMIFIT') + " \
     
    407419               ,psfFlux \
    408420               ,psfFluxErr \
    409                ,peakADU \
    410                ,psfWidMajor \
    411                ,psfWidMinor \
     421               ,psfMajorFWHM \
     422               ,psfMinorFWHM \
    412423               ,psfTheta \
     424               ,psfCore \
    413425               ,psfLikelihood \
    414426               ,psfQf \
     
    416428               ,momentXY \
    417429               ,momentYY \
     430               ,momentR1 \
     431               ,momentRH \
     432               ,momentM3C \
     433               ,momentM3S \
     434               ,momentM4C \
     435               ,momentM4S \
    418436               ,apFlux \
    419437               ,kronFlux \
     
    424442               ,sky \
    425443               ,skyErr \
    426                ,sgSep \
    427                ,activeFlag \
    428                ,assocDate \
    429                ,historyModNum \
    430444               ,dataRelease \
    431445               ) \
     
    441455               ,PSF_INST_FLUX / " + self.header['EXPTIME'] + " \
    442456               ,PSF_INST_FLUX_SIG / " + self.header['EXPTIME'] + " \
    443                ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + self.header['EXPTIME'] + " \
    444457               ,PSF_MAJOR \
    445458               ,PSF_MINOR \
    446459               ,PSF_THETA \
     460               ,-999 \
    447461               ,psfLikelihood(EXT_NSIGMA) \
    448462               ,PSF_QF \
     
    450464               ,MOMENTS_XY \
    451465               ,MOMENTS_YY \
     466               ,-999 \
     467               ,-999 \
     468               ,-999 \
     469               ,-999 \
     470               ,-999 \
     471               ,-999 \
    452472               ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
    453473               ,KRON_FLUX / " + self.header['EXPTIME'] + " \
     
    458478               ,SKY  / " + self.header['EXPTIME'] + " \
    459479               ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
    460                ,EXT_NSIGMA \
    461                , 0 \
    462                , '" + self.dateStr + "' \
    463                , 0 \
    464480               , " + str(self.skychunk.dataRelease) + "\
    465481               FROM " + ippTableName
     
    496512        # we don't delete these anymore
    497513        results['NULLINSTFLUX'] = 0;
    498         results['NULLPEAKADU'] = 0;
     514       
    499515
    500516    '''
     
    531547    def populateDetectionCalibTableUpdateInsert(self, ota):
    532548
    533         tableName = "DetectionCalib_" + ota
     549        tableName = "Detection_" + ota
    534550        # drop then re-create table
    535         self.scratchDb.dropTable(tableName)
    536         sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
    537         try: self.scratchDb.execute(sql)
    538         except: pass
     551        #self.scratchDb.dropTable(tableName)
     552        #sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
     553        #try: self.scratchDb.execute(sql)
     554        #except: pass
    539555
    540556        # insert all detections into table
     
    555571               ,surveyID \
    556572               FROM Detection_" + ota
    557         self.scratchDb.execute(sql)
     573#        self.scratchDb.execute(sql)
    558574
    559575        # insert calibration information from dvoDetections into the Table
     
    564580            a.decErr = b.decErr, \
    565581            a.zp = b.zp, \
    566             a.zpErr = b.zpErr, \
    567582            a.expTime = b.expTime, \
    568583            a.airMass = b.airMass   \
     
    577592
    578593        # target table name:
    579         tableName = "DetectionCalib_" + ota
     594        tableName = "Detection_" + ota
    580595        # drop then re-create table
    581         self.scratchDb.dropTable(tableName)
    582         sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
    583         try: self.scratchDb.execute(sql)
    584         except: pass
     596        #self.scratchDb.dropTable(tableName)
     597        #sql = "CREATE TABLE " + tableName + " LIKE Detection"
     598        #try: self.scratchDb.execute(sql)
     599        #except: pass
    585600
    586601        externID = self.imageIDs[ota]
    587602
    588603        imageID = self.scratchDb.getImageIDFromExternID(externID)
    589         self.logger.infoPair("obtained","imageID")
    590 
    591         # check for & create output directory first
    592         datadumpDir = "/tmp/datadump"
    593         try:
    594             statinfo = os.stat(datadumpDir)
    595             # check on the stat results?
    596         except:
    597             print "making the data dump directory ", datadumpDir
    598             os.mkdir(datadumpDir)
    599             os.chmod(datadumpDir, 0777)
    600             statinfo = os.stat(datadumpDir)
    601 
    602         dumpFile = datadumpDir + "/genetest.xx.dat"
    603         files = glob.glob(dumpFile)
    604         if len(files) > 0:
    605             os.unlink(dumpFile)
     604        self.logger.infoPair("obtained imageID",imageID)
     605        self.logger.infoPair("obtained externID",externID)
    606606
    607607        # insert all detections into table
    608         sql = "SELECT \
    609           a.objID,    \
    610           a.detectID, \
    611           a.ippObjID,      \
    612           a.ippDetectID,   \
    613           a.filterID,      \
    614           a.surveyID,      \
    615           b.ra,            \
    616           b.dec_,          \
    617           b.raErr,         \
    618           b.decErr,        \
    619           b.zp,            \
    620           b.zpErr,         \
    621           b.expTime,       \
    622           b.airMass,       \
    623           " + str(self.skychunk.dataRelease) + " \
    624          FROM              \
    625            Detection_" + ota + " as a \
    626          JOIN " + self.scratchDb.dvoDetectionTable + " as b \
    627          ON (a.objID = b.objID AND a.detectID = b.detectID) \
    628          WHERE b.imageID = " + str(imageID) + \
    629          " INTO OUTFILE '" + dumpFile + "'"
     608        sql = "Update Detection_" + ota + " AS a, "+ self.scratchDb.dvoDetectionTable + " as b \
     609          set a.ra=b.ra,            \
     610          a.dec = b.dec_,          \
     611          a.raErr = b.raErr,         \
     612          a.decErr = b.decErr,        \
     613          a.zp = b.zp,            \
     614          a.expTime = b.expTime,       \
     615          a.airMass = b.airMass       \
     616          WHERE (a.objID = b.objID AND a.detectID = b.detectID) \
     617          AND b.imageID = " + str(imageID)  \
     618 
    630619
    631620        try: self.scratchDb.execute(sql)
    632621        except:
    633             self.logger.info("failed to select data for detectionCalib")
    634             self.logger.infoPair("sql: ", sql)
    635             raise
    636 
    637         sql = "LOAD DATA INFILE '" + dumpFile + "' INTO TABLE " + tableName
    638         try: self.scratchDb.execute(sql)
    639         except:
    640             self.logger.info("failed to load data from infile for detectionCalib")
     622            self.logger.info("failed to update data for detectionCalib")
    641623            self.logger.infoPair("sql: ", sql)
    642624            raise
     
    751733        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
    752734        # the column in PSPS
    753         self.scratchDb.execute("ALTER TABLE DetectionCalib CHANGE dec_ `dec` double")
     735        self.scratchDb.execute("ALTER TABLE Detection CHANGE dec_ `dec` double")
    754736
    755737        return True
     
    818800            return False
    819801
    820         self.logger.info("populate stuff ");
     802        #self.logger.info("populate stuff ");
    821803        # populate remainder of tables
    822804        self.populateDetectionTable(chipname, results)
    823         self.logger.info("successful populate ");
     805        #self.logger.info("successful populate ");
    824806        # now add DVO IDs
    825807        self.updateDvoIDs("Detection_" + chipname, self.imageIDs[chipname])
    826         self.logger.info("updated dvoids")
     808        #self.logger.info("updated dvoids")
    827809        results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + chipname, "objID")
    828810        #self.logger.info("deleted nulls")
    829811        self.updateImageID("Detection_" + chipname, x, y)
    830         self.logger.info("updateImageId")
     812        #self.logger.info("updateImageId")
    831813        rowCount = self.scratchDb.getRowCount("Detection_" + chipname)
    832         self.logger.info("got row count")
    833         self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |",
     814        #self.logger.info("got row count")
     815        self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d |",
    834816                chipname,
    835817                results['ORIGINALTOTAL'],
    836818                results['SATDET'],
    837819                results['NULLINSTFLUX'],
    838                 results['NULLPEAKADU'],
    839820                results['NULLOBJID'],
    840821                rowCount)
     
    842823        self.totalSatDet       = self.totalSatDet + results['SATDET']
    843824        self.totalNulIInstFlux = self.totalNulIInstFlux + results['NULLINSTFLUX']
    844         self.totalNullPeakFlux = self.totalNullPeakFlux + results['NULLPEAKADU']
    845825        self.totalNullObjID    = self.totalNullObjID + results['NULLOBJID']
    846826        self.totalDetections   = self.totalDetections + rowCount
     
    867847        self.scratchDb.execute(sql)
    868848       
    869         self.logger.info("updated imagedata")
    870         self.populateSkinnyObjectTable(chipname)
    871         self.logger.info("updated skinnyobject")
    872         #self.populateObjectCalColorTable(chipname)
    873         #self.logger.info("updated objectcalcolor")
     849        #self.logger.info("updated imagedata")
     850       
    874851        self.populateDetectionCalibTable(chipname)
    875         self.logger.info("updated detectioncalibtable")
     852        #self.logger.info("updated detectioncalibtable")
    876853       
    877854        # add these to list of tables to export later
     
    882859        self.logger.info("export Detection")
    883860
    884         self.tablesToExport.append("SkinnyObject_" + chipname)
    885         self.logger.info("export Skinny")
    886 
    887         #self.tablesToExport.append("ObjectCalColor_" + chipname)
    888         self.tablesToExport.append("DetectionCalib_" + chipname)
    889         self.logger.info("export DetectionCalib")
    890 
     861       
    891862        tables.append("Detection_" + chipname)
    892863        self.logger.info("updated detectioncalibtable")
     
    910881        results = {}
    911882        self.totalOriginal = self.totalSatDet = self.totalNulIInstFlux = self.totalNullPeakFlux = self.totalNullObjID = self.totalDetections = 0
    912         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
    913         self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL peak ADU | NULL obj ID   |  Remainder    |")
    914         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     883        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
     884        self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL obj ID   |  Remainder    |")
     885        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    915886        for x in range(self.startX, self.endX):
    916887            for y in range(self.startY, self.endY):
     
    937908
    938909        # print totals
    939         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     910        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    940911        self.logger.info("| Total | %13d | %13d | %13d | %13d | %13d | %13d |",
    941912                self.totalOriginal,
     
    945916                self.totalNullObjID,
    946917                self.totalDetections)
    947         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     918        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    948919
    949920        # if we only have one table export, i.e. FrameMeta, then get out of here (skip batch, but do not abort)
Note: See TracChangeset for help on using the changeset viewer.