IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33678


Ignore:
Timestamp:
Apr 3, 2012, 4:35:55 PM (14 years ago)
Author:
rhenders
Message:

added methos to get region name from index using SkyTable; now storing central RA/Dec for regions when getting from DVO; various other changes to support OB loading

File:
1 edited

Legend:

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

    r33492 r33678  
    2424        self.dvoDoneTable = "dvoDone"
    2525        self.dvoSkyTable = "dvoSkyTable"
    26 
     26        self.dvoPhotcodesTable = "dvoPhotcodes"
    2727
    2828    '''
     
    249249
    250250    '''
    251     Gets the id for the cpm file for the provided region
    252     '''
    253     def getDvoCpmFileIdForRegion(self, region):
    254 
    255         id = -1
    256         sql = "SELECT id FROM " + self.dvoDoneTable + " WHERE region = '" + region + "' AND path LIKE '%.cpm'";
    257         try:
    258             rs = self.executeQuery(sql)
    259             rs.first()
    260             id = rs.getInt(1)
    261         except:
    262             self.logger.errorPair("Could not get file id from " + self.dvoDoneTable, "for region: " + region)
    263 
    264         return id
    265 
    266 
    267     '''
    268251    Gets the id for the provided file
    269252    '''
     
    277260            id = rs.getInt(1)
    278261        except:
    279             self.logger.errprPair("Could not get file id from " + self.dvoDoneTable + "for", path)
     262            self.logger.errorPair("Could not get file id from " + self.dvoDoneTable + "for", path)
    280263
    281264        return id
     
    337320                return False
    338321
    339         except:
     322        except Exception, e:
     323            print str(e)
    340324            self.logger.errorPair("No DVO files ingested for this path", path)
    341325            return False
     
    343327    '''
    344328    Checks whether the astrometric solution is ok for this chip
    345     TODO the value of 50 for numAstroRef is hardcoded here, but this should be temporary anyway
     329    TODO the value of 50 for numAstroRef (provided by Gene) is hardcoded here, but this should be temporary anyway
    346330    '''
    347331    def astrometricSolutionOK(self, ota):
     
    411395    '''
    412396    Removes the provided DVO FITS files from from dvoDone and dvoDetection tables
    413     Returns a count of the number of detections deleted
    414     '''
    415     def purgeTheseDvoRegions(self, regions):
     397    Returns a count of the number of detections deleted, if any
     398    '''
     399    def purgeTheseDvoRegions(self, regions, fileTypes):
    416400
    417401        detectionCount = self.getRowCount(self.dvoDetectionTable)
    418402        for region in regions:
    419            
    420            fileId = self.getDvoCpmFileIdForRegion(region)
    421 
    422            if fileId < 0:
    423                self.logger.errorPair("Unable to get file ID to delete " + region + " from", self.dvoDoneTable)
    424                continue
    425 
    426            sql = "DELETE FROM " + self.dvoDoneTable + " WHERE region = '" + region + "'"
    427            try: self.execute(sql)
    428            except:
    429                self.logger.errorPair("Unable to delete " + region + " from", self.dvoDoneTable)
    430 
    431         finalCount = detectionCount - self.getRowCount(self.dvoDetectionTable)
    432 
    433         # after a big delete, we should OPTIMIZE the table
    434         self.logger.infoPair("Running OPTIMIZE on ", self.dvoDetectionTable)
    435         if finalCount > 0: self.optimizeTable(self.dvoDetectionTable)
    436 
    437         return finalCount
     403         
     404           for fileType in fileTypes:
     405               sql = "DELETE FROM " + self.dvoDoneTable + " WHERE region = '" + region + "' AND path LIKE '%" + fileType + "'"
     406               try: self.execute(sql)
     407               except:
     408                    self.logger.errorPair("Unable to delete " + fileType + " file from", self.dvoDoneTable)
     409
     410               sql = "DROP TABLE " + self.getDbFriendlyTableName(region + "." + fileType)
     411               self.execute(sql)
     412
     413        deletedDetectionCount = detectionCount - self.getRowCount(self.dvoDetectionTable)
     414
     415        # after a big detection delete, we should OPTIMIZE the table
     416        if deletedDetectionCount > 0:
     417            self.logger.infoPair("Running OPTIMIZE on ", self.dvoDetectionTable)
     418            self.optimizeTable(self.dvoDetectionTable)
     419
     420        return deletedDetectionCount
    438421           
    439422    '''
     
    515498    def getDvoRegionsForThisBox(self, regions, minRa, maxRa, minDec, maxDec):
    516499
    517         sql = "SELECT name FROM " + self.dvoSkyTable + " \
     500        sql = "SELECT \
     501               INDEX_, \
     502               R_MIN+ (R_MAX - R_MIN)/2.0, \
     503               D_MIN + (D_MAX - D_MIN)/2.0, \
     504               NAME \
     505               FROM " + self.dvoSkyTable + " \
    518506               WHERE NOT ((" + str(maxRa) + " <= R_MIN) OR \
    519507                       (" + str(minRa) + " >= R_MAX) OR \
     
    523511        try:
    524512            rs = self.executeQuery(sql)
    525             while (rs.next()): regions.append(rs.getString(1))
     513            while (rs.next()): regions.append([
     514                    rs.getInt(1),
     515                    rs.getFloat(2),
     516                    rs.getFloat(3),
     517                    rs.getString(4)])
     518
    526519            rs.close()
    527520        except:
     
    529522
    530523
     524    '''
     525    Gets the id for the provided file
     526    '''
     527    def getRegionNameFromThisDvoIndex(self, index):
     528
     529        region = ""
     530        sql = "SELECT NAME FROM " + self.dvoSkyTable + " WHERE INDEX_ = " + str(index)
     531        try:
     532            rs = self.executeQuery(sql)
     533            rs.first()
     534            region = rs.getString(1)
     535            rs.close()
     536        except:
     537            self.logger.errorPair("Could not get region using index", sql )
     538
     539        return region
     540
Note: See TracChangeset for help on using the changeset viewer.