IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 7, 2014, 5:36:39 AM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140423/ippToPsps/jython/detectionbatch.py

    r35994 r36826  
    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') + " \
     
    398410        sql = "INSERT IGNORE INTO " + pspsTableName + " ( \
    399411               ippDetectID \
     412               ,randomDetID \
    400413               ,filterID \
    401414               ,surveyID \
     
    407420               ,psfFlux \
    408421               ,psfFluxErr \
    409                ,peakADU \
    410                ,psfWidMajor \
    411                ,psfWidMinor \
     422               ,psfMajorFWHM \
     423               ,psfMinorFWHM \
    412424               ,psfTheta \
     425               ,psfCore \
    413426               ,psfLikelihood \
    414427               ,psfQf \
     
    416429               ,momentXY \
    417430               ,momentYY \
     431               ,momentR1 \
     432               ,momentRH \
     433               ,momentM3C \
     434               ,momentM3S \
     435               ,momentM4C \
     436               ,momentM4S \
    418437               ,apFlux \
    419438               ,kronFlux \
     
    424443               ,sky \
    425444               ,skyErr \
    426                ,sgSep \
    427                ,activeFlag \
    428                ,assocDate \
    429                ,historyModNum \
     445               ,pltScale \
     446               ,posAngle \
    430447               ,dataRelease \
    431448               ) \
    432449               SELECT \
    433450               IPP_IDET \
     451               , FLOOR(RAND()*9223372036854775807) \
    434452               , " + str(self.filterID) + "\
    435453               , " + str(self.surveyID) + " \
     
    441459               ,PSF_INST_FLUX / " + self.header['EXPTIME'] + " \
    442460               ,PSF_INST_FLUX_SIG / " + self.header['EXPTIME'] + " \
    443                ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + self.header['EXPTIME'] + " \
    444461               ,PSF_MAJOR \
    445462               ,PSF_MINOR \
    446463               ,PSF_THETA \
     464               ,-999 \
    447465               ,psfLikelihood(EXT_NSIGMA) \
    448466               ,PSF_QF \
     
    450468               ,MOMENTS_XY \
    451469               ,MOMENTS_YY \
     470               ,MOMENTS_R1 \
     471               ,MOMENTS_RH \
     472               ,MOMENTS_M3C \
     473               ,MOMENTS_M3S \
     474               ,MOMENTS_M4C \
     475               ,MOMENTS_M4S \
    452476               ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
    453477               ,KRON_FLUX / " + self.header['EXPTIME'] + " \
     
    458482               ,SKY  / " + self.header['EXPTIME'] + " \
    459483               ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
    460                ,EXT_NSIGMA \
    461                , 0 \
    462                , '" + self.dateStr + "' \
    463                , 0 \
     484               ,PLTSCALE \
     485               ,POSANGLE \
    464486               , " + str(self.skychunk.dataRelease) + "\
    465487               FROM " + ippTableName
     
    496518        # we don't delete these anymore
    497519        results['NULLINSTFLUX'] = 0;
    498         results['NULLPEAKADU'] = 0;
     520       
    499521
    500522    '''
     
    531553    def populateDetectionCalibTableUpdateInsert(self, ota):
    532554
    533         tableName = "DetectionCalib_" + ota
     555        tableName = "Detection_" + ota
    534556        # 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
     557        #self.scratchDb.dropTable(tableName)
     558        #sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
     559        #try: self.scratchDb.execute(sql)
     560        #except: pass
    539561
    540562        # insert all detections into table
     
    555577               ,surveyID \
    556578               FROM Detection_" + ota
    557         self.scratchDb.execute(sql)
     579#        self.scratchDb.execute(sql)
    558580
    559581        # insert calibration information from dvoDetections into the Table
     
    564586            a.decErr = b.decErr, \
    565587            a.zp = b.zp, \
    566             a.zpErr = b.zpErr, \
    567588            a.expTime = b.expTime, \
    568589            a.airMass = b.airMass   \
     
    577598
    578599        # target table name:
    579         tableName = "DetectionCalib_" + ota
     600        tableName = "Detection_" + ota
    580601        # 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
     602        #self.scratchDb.dropTable(tableName)
     603        #sql = "CREATE TABLE " + tableName + " LIKE Detection"
     604        #try: self.scratchDb.execute(sql)
     605        #except: pass
    585606
    586607        externID = self.imageIDs[ota]
    587608
    588609        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)
     610        self.logger.infoPair("obtained imageID",imageID)
     611        self.logger.infoPair("obtained externID",externID)
    606612
    607613        # 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 + "'"
     614        sql = "Update Detection_" + ota + " AS a, "+ self.scratchDb.dvoDetectionTable + " as b \
     615          set a.ra=b.ra,            \
     616          a.dec = b.dec_,          \
     617          a.raErr = b.raErr,         \
     618          a.decErr = b.decErr,        \
     619          a.zp = b.zp,            \
     620          a.expTime = b.expTime,       \
     621          a.airMass = b.airMass       \
     622          WHERE (a.objID = b.objID AND a.detectID = b.detectID) \
     623          AND b.imageID = " + str(imageID)  \
     624 
    630625
    631626        try: self.scratchDb.execute(sql)
    632627        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")
     628            self.logger.info("failed to update data for detectionCalib")
    641629            self.logger.infoPair("sql: ", sql)
    642630            raise
     
    751739        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
    752740        # the column in PSPS
    753         self.scratchDb.execute("ALTER TABLE DetectionCalib CHANGE dec_ `dec` double")
     741        self.scratchDb.execute("ALTER TABLE Detection CHANGE dec_ `dec` double")
    754742
    755743        return True
     
    818806            return False
    819807
    820         self.logger.info("populate stuff ");
     808        #self.logger.info("populate stuff ");
    821809        # populate remainder of tables
    822810        self.populateDetectionTable(chipname, results)
    823         self.logger.info("successful populate ");
     811        #self.logger.info("successful populate ");
    824812        # now add DVO IDs
    825813        self.updateDvoIDs("Detection_" + chipname, self.imageIDs[chipname])
    826         self.logger.info("updated dvoids")
     814        #self.logger.info("updated dvoids")
    827815        results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + chipname, "objID")
    828816        #self.logger.info("deleted nulls")
    829817        self.updateImageID("Detection_" + chipname, x, y)
    830         self.logger.info("updateImageId")
     818        #self.logger.info("updateImageId")
    831819        rowCount = self.scratchDb.getRowCount("Detection_" + chipname)
    832         self.logger.info("got row count")
    833         self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |",
     820        #self.logger.info("got row count")
     821        self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d |",
    834822                chipname,
    835823                results['ORIGINALTOTAL'],
    836824                results['SATDET'],
    837825                results['NULLINSTFLUX'],
    838                 results['NULLPEAKADU'],
    839826                results['NULLOBJID'],
    840827                rowCount)
     
    842829        self.totalSatDet       = self.totalSatDet + results['SATDET']
    843830        self.totalNulIInstFlux = self.totalNulIInstFlux + results['NULLINSTFLUX']
    844         self.totalNullPeakFlux = self.totalNullPeakFlux + results['NULLPEAKADU']
    845831        self.totalNullObjID    = self.totalNullObjID + results['NULLOBJID']
    846832        self.totalDetections   = self.totalDetections + rowCount
     
    867853        self.scratchDb.execute(sql)
    868854       
    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")
     855        #self.logger.info("updated imagedata")
     856       
    874857        self.populateDetectionCalibTable(chipname)
    875         self.logger.info("updated detectioncalibtable")
     858        #self.logger.info("updated detectioncalibtable")
    876859       
    877860        # add these to list of tables to export later
     
    882865        self.logger.info("export Detection")
    883866
    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 
     867       
    891868        tables.append("Detection_" + chipname)
    892869        self.logger.info("updated detectioncalibtable")
     
    910887        results = {}
    911888        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("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     889        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
     890        self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL obj ID   |  Remainder    |")
     891        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    915892        for x in range(self.startX, self.endX):
    916893            for y in range(self.startY, self.endY):
     
    937914
    938915        # print totals
    939         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     916        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    940917        self.logger.info("| Total | %13d | %13d | %13d | %13d | %13d | %13d |",
    941918                self.totalOriginal,
     
    945922                self.totalNullObjID,
    946923                self.totalDetections)
    947         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
     924        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
    948925
    949926        # if we only have one table export, i.e. FrameMeta, then get out of here (skip batch, but do not abort)
     
    961938        sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef)
    962939        self.scratchDb.execute(sql)
     940        #to make it stop
     941        #test = self.scratchDb.getRowCount("Object")
     942        #return False
    963943       
    964944        return True
     
    10401020
    10411021       # XXX EAM NOTE : this is fragile : requires PS1_V4
    1042        columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_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"
     1022       columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ POSANGLE PLTSCALE"
    10431023
    10441024       return super(DetectionBatch, self).importIppTables(columns, regex)
Note: See TracChangeset for help on using the changeset viewer.