IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31286


Ignore:
Timestamp:
Apr 14, 2011, 3:17:49 PM (15 years ago)
Author:
rhenders
Message:

removing Infinity values prior to entry into database; method to call DVO C program to get IDs; improved logic for constructor args; only writing certain fields to manifest when defined

File:
1 edited

Legend:

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

    r31222 r31286  
    6060        self.gpc1Db = Gpc1Db(self.logger)
    6161
     62        if self.survey != "":
     63
    6264        # get survey ID from init table
    63         sql = "SELECT surveyID from Survey WHERE name = '" + survey + "'"
    64         try:
    65             rs = self.localStmt.executeQuery(sql) 
    66             rs.first()
    67             self.surveyID = rs.getInt(1)
    68         except:
    69             self.logger.exception("No survey ID found for this survey: '" + survey + "'")
    70             self.surveyID = -1;
     65            sql = "SELECT surveyID from Survey WHERE name = '" + self.getPspsSurveyType() + "'"
     66            try:
     67                rs = self.localStmt.executeQuery(sql) 
     68                rs.first()
     69                self.surveyID = rs.getInt(1)
     70            except:
     71                self.logger.exception("No survey ID found for this survey: '" + self.getPspsSurveyType() + "'")
     72                self.surveyID = -1;
    7173   
    7274        # get dvo info from config
    73         if survey != "":
    7475            dvoName = doc.find(survey+"dvo/name").text
    75             dvoLocation = doc.find(survey+"dvo/location").text
     76            self.dvoLocation = doc.find(survey+"dvo/location").text
    7677        else:
    7778            dvoName = ""
    78             dvoLocation = ""
     79            self.dvoLocation = ""
     80            self.surveyID = -1;
    7981         
    8082        # get datastore info from config
     
    127129        root.attrib['name'] = self.batchName
    128130        root.attrib['type'] = self.getPspsBatchType()
    129         root.attrib['survey'] = self.getPspsSurveyType()
    130131        root.attrib['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    131         root.attrib['minObjId'] = str(self.minObjID)
    132         root.attrib['maxObjId'] = str(self.maxObjID)
     132        if self.survey != "":
     133            root.attrib['survey'] = self.getPspsSurveyType()
     134        try: self.minObjID
     135        except: pass
     136        else: root.attrib['minObjId'] = str(self.minObjID)
     137        try: self.maxObjID
     138        except: pass
     139        else: root.attrib['maxObjId'] = str(self.maxObjID)
    133140
    134141        # get md5sum
     
    198205    def getPspsSurveyType(self):
    199206
     207        try:
     208            self.survey
     209        except:
     210            return "NA"
     211
    200212        if self.survey == "ThreePi": return "3PI"
    201         elif self.survey == "MD04": return "MD04"
    202         else: self.logger.error("Don't know this survey: " + self.survey)
     213        elif self.survey == "MD04": return "MD4"
     214        else:
     215            self.logger.error("Don't know this survey: '" + self.survey + "'")
     216            return "NA"
    203217
    204218    '''
     
    232246        self.maxObjID = rs.getLong(2)
    233247
    234         print "MIN mAX = %d %d" % (self.minObjID,  self.maxObjID)
    235 
    236248    '''
    237249    Updates a table with surveyID
     
    332344    Imports IPP tables from FITS file
    333345
    334     Accepts a regular expression filter so not all tabls need to be imported
     346    Accepts a regular expression filter so not all tables need to be imported
    335347    '''
    336348    def importIppTables(self, filter):
    337349
    338350      tables = stilts.treads(self.inputFitsPath)
     351      self.logger.info("Attempting to import tables from input FITS file")
    339352
    340353      count = 0
     
    343356          match = re.match(filter, table.name)
    344357          if not match: continue
    345           self.logger.info("Creating IPP table " + table.name)
     358          self.logger.info("   Reading IPP table " + table.name + " from FITS file")
    346359          table = stilts.tpipe(table, cmd='explodeall')
     360
     361          # IPP FITS files are littered with infinities, so remove these
     362          self.logger.info("   Removing Infinity values from all columns")
     363          table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
     364          table = stilts.tpipe(table, cmd='replaceval Infinity null *')
     365
    347366          try:
    348367              table.write(self.localUrl + '#' + table.name)
    349368          except:
    350               self.logger.exception("Problem writing table '" + table.name + "' to the database")
     369              self.logger.exception("   Problem writing table '" + table.name + "' to the database")
    351370
    352371          count = count + 1
    353372
    354       self.logger.info("Imported %d tables from '%s' " % (count, self.inputFitsPath))
     373      self.logger.info("Done. Imported %d tables" % count)
    355374
    356375      self.indexIppTables()
     
    367386        for table in self.pspsTables:
    368387           _table = stilts.tread(self.localUrl + '#SELECT * FROM ' + table.name)
     388           #           if table.name == "StackDetection": _table.cmd_keepcols('stackDetectID projectionCellID').cmd_head(4).write()
     389
     390           self.logger.info("   Replacing NULLs with weird PSPS -999 constant for " + table.name)
     391           _table = stilts.tpipe(_table, cmd='replaceval "" -999 *') # TODO doesn't work
     392           #if table.name == "StackDetection": _table.cmd_keepcols('stackDetectID projectionCellID').cmd_head(4).write()
    369393           _table = stilts.tpipe(_table, cmd='tablename ' + table.name)
    370394           _tables.append(_table)
     
    480504        sql = "DROP TABLE dvo"
    481505        self.localStmt.execute(sql)
    482         sql = "CREATE TABLE dvo (ippDetectID BIGINT PRIMARY KEY, ippObjID BIGINT, objID BIGINT)"
     506        sql = "CREATE TABLE dvo (ippDetectID BIGINT PRIMARY KEY, detectID BIGINT, ippObjID BIGINT, objID BIGINT)"
    483507        self.localStmt.execute(sql)
    484508
     509
     510    '''
     511    Calls DVO program to 'query' DVO database and populate results to local MySQL Db table
     512    '''
     513    def getIDsFromDVO(self, sourceID, imageID):
     514
     515        # TODO path to DVO prog hardcoded temporarily
     516        cmd = "../src/dvo %s %s %s" % (self.dvoLocation, sourceID, imageID)
     517        self.logger.info("Running: '" + cmd + "'...")
     518        p = Popen(cmd, shell=True, stdout=PIPE)
     519        p.wait()
     520        #        out = p.stdout.read()
     521        self.logger.info("...done")
     522
Note: See TracChangeset for help on using the changeset viewer.