IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 15, 2011, 1:52:28 PM (15 years ago)
Author:
rhenders
Message:

added methid to count rows in database table; now checking for empty tables and not nwriting them to fits

File:
1 edited

Legend:

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

    r31291 r31299  
    6262        if self.survey != "":
    6363
    64         # get survey ID from init table
    65             sql = "SELECT surveyID from Survey WHERE name = '" + self.getPspsSurveyType() + "'"
     64            # get survey ID from init table
     65            sql = "SELECT surveyID from Survey WHERE name = '" + self.survey + "'"
    6666            try:
    6767                rs = self.localStmt.executeQuery(sql) 
     
    6969                self.surveyID = rs.getInt(1)
    7070            except:
    71                 self.logger.exception("No survey ID found for this survey: '" + self.getPspsSurveyType() + "'")
     71                self.logger.exception("No survey ID found for this survey: '" + self.survey + "'")
    7272                self.surveyID = -1;
    7373   
    74         # get dvo info from config
     74            # get dvo info from config
    7575            dvoName = doc.find(survey+"dvo/name").text
    7676            self.dvoLocation = doc.find(survey+"dvo/location").text
     
    109109        # create DVO table
    110110        self.createDvoTable()
     111        header = self.findAndReadFITSHeader("XY86.hdr")
    111112
    112113    '''
     
    171172        root.attrib['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    172173        if self.survey != "":
    173             root.attrib['survey'] = self.getPspsSurveyType()
     174            root.attrib['survey'] = self.getBatchFriendlySurveyType()
    174175        try: self.minObjID
    175176        except: pass
     
    243244    Gets PSPS-friendly survey type
    244245    '''
    245     def getPspsSurveyType(self):
     246    def getBatchFriendlySurveyType(self):
    246247
    247248        try:
     
    287288
    288289    '''
     290    Drops a table
     291    '''
     292    def dropTable(self, table):
     293
     294        sql = "DROP TABLE " + table
     295        try: self.localStmt.execute(sql)
     296        except: return
     297
     298    '''
    289299    Updates a table with surveyID
    290300    '''
     
    413423        self.logger.info("    Selecting database tables")
    414424        for table in self.pspsTables:
     425
     426           # check for an empty table
     427           if self.getRowCount(table.name) < 1: continue
     428
     429           # get everything from table
    415430           _table = stilts.tread(self.localUrl + '#SELECT * FROM ' + table.name)
    416            #           if table.name == "StackDetection": _table.cmd_keepcols('stackDetectID projectionCellID').cmd_head(4).write()
    417431
    418432           self.logger.info("   Replacing NULLs with weird PSPS -999 constant for " + table.name)
    419            _table = stilts.tpipe(_table, cmd='replaceval "" -999 *') # TODO doesn't work
    420            #if table.name == "StackDetection": _table.cmd_keepcols('stackDetectID projectionCellID').cmd_head(4).write()
     433
     434           # replace nulls and empty fields with weird PSPS -999 pseudo-null
     435           _table = stilts.tpipe(_table, cmd='replaceval "" -999 *')
     436
     437           # change table names
    421438           _table = stilts.tpipe(_table, cmd='tablename ' + table.name)
    422439           _tables.append(_table)
     
    425442        stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
    426443        self.logger.info("    ...done")
     444
    427445
    428446    '''
     
    537555
    538556    '''
     557    Returns a row count for this table
     558    '''
     559    def getRowCount(self, table):
     560
     561        sql = "SELECT COUNT(*) FROM " + table
     562        try:
     563            rs = self.localStmt.executeQuery(sql) 
     564            rs.first()
     565            return rs.getInt(1)
     566        except:
     567            self.logger.exception("Could not count rows for table: '" + table + "'")
     568            return -1
     569
     570
     571    '''
    539572    Calls DVO program to 'query' DVO database and populate results to local MySQL Db table
    540573    '''
Note: See TracChangeset for help on using the changeset viewer.