IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38981


Ignore:
Timestamp:
Oct 27, 2015, 4:00:17 PM (11 years ago)
Author:
eugene
Message:

add options to import FITS tables using Ohana fits_to_mysql

Location:
trunk/ippToPsps/jython
Files:
3 edited

Legend:

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

    r38973 r38981  
    446446        self.logger.warn("alterPspsTables not implemented")
    447447
     448
     449    '''
     450    Imports IPP tables from FITS file
     451
     452    Accepts a regular expression filter so not all tables need to be imported
     453    '''
     454    def importIppTablesOhana(self):
     455       
     456        self.logger.infoPair("Importing IPP tables", "using fits_to_mysql")
     457
     458        ## use stilts to get a list of the tables from the header
     459        try:
     460            tables = stilts.treads(self.fits.getPath())
     461        except:
     462            self.logger.errorPair("STILTS could not import from", self.fits.getPath())
     463            return False
     464
     465        loadFITStoMYSQL(self.fits.getPath(), "none")
     466
     467        ## may need to do this with direct sql:
     468        # table = stilts.tpipe(table, cmd='addcol table_index $0')
     469
     470        self.tablesLoaded = []
     471
     472        count = 0
     473        for table in tables:
     474
     475            # example of listing all columns in a table:
     476            ## print "-----table: " + table.name
     477            ## columns = table.columns()
     478            ## for column in columns:
     479            ##     print column
     480            ##
     481            ## print "-----"
     482
     483            self.logger.debugPair("Read IPP table", table.name)
     484
     485            self.tablesLoaded.append(table.name)
     486            count ++
     487
     488        self.logger.infoPair("Done. Imported", "%d tables" % count)
     489        self.indexIppTables()
     490
     491        return True
     492
    448493    '''
    449494    Imports IPP tables from FITS file
  • trunk/ippToPsps/jython/dvo.py

    r38951 r38981  
    581581
    582582          count = count + 1
     583
     584      self.logger.debugPair("Finished importing", tableName)
     585
     586      return tableName
     587
     588    '''
     589    Imports the Photcode file
     590    '''
     591    def importPhotcodesOhana(self, path, tableName):
     592
     593      self.logger.infoPair("Importing file", "%s (%s)" % (path, self.getFileSizeStr(self.getDiskSize(path))))
     594      self.logger.debugPair("Writing to database table", tableName)
     595
     596      ## XXX may need to do this in mysql after table is read
     597      # convert the 1-char field TYPE to an int for querying ease (probably more sophisticated ways to do this...)
     598      # table = stilts.tpipe(table, cmd='addcol -after TYPE TYPE_AS_INT "TYPE + 0"')
     599
     600      loadFITStoMYSQL (path, tableName)
    583601
    584602      self.logger.debugPair("Finished importing", tableName)
  • trunk/ippToPsps/jython/scratchdb.py

    r38951 r38981  
    803803
    804804        return res
     805
     806    '''
     807    Use Ohana fits_to_mysql to load FITS tables into scratch db
     808    '''
     809    def loadFITStoMYSQL(self, filename, tablename):
     810
     811        # TODO path to DVO prog hardcoded temporarily
     812        cmd = "fits_to_mysql"
     813        cmd += " -dbhost " + self.scratchDb.dbHost
     814        cmd += " -dbname " + self.scratchDb.dbName
     815        cmd += " -dbuser " + self.scratchDb.dbUser
     816        cmd += " -dbpass " + self.scratchDb.dbPass
     817        cmd += filename
     818
     819        if tablename != "none":
     820            cmd += " -tablename " + tablename
     821
     822        (stdoutFile, stdoutName) = tempfile.mkstemp(prefix="fits_to_mysql.stdout.", dir="/tmp")
     823        (stderrFile, stderrName) = tempfile.mkstemp(prefix="fits_to_mysql.stderr.", dir="/tmp")
     824
     825        self.logger.infoPair("Running fits_to_mysql", cmd)
     826        self.logger.infoPair("Stdout to ", stdoutName)
     827        self.logger.infoPair("Stderr to ", stderrName)
     828        p = Popen(cmd, shell=True, stdout=stdoutFile, stderr=stderrFile)
     829
     830        p.wait()
     831
     832        if p.returncode < 0:
     833            self.logger.errorPair("fits_to_mysql terminated on signal for: ", cmd)
     834            os._exit(1)
     835
     836        if p.returncode > 0:
     837            self.logger.errorPair("fits_to_mysql failed for: ", cmd)
     838            os._exit(1)
     839
     840        os.close(loadFITStoMYSQL)
     841        os.close(loadFITStoMYSQL)
Note: See TracChangeset for help on using the changeset viewer.