IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 6, 2013, 3:16:35 PM (13 years ago)
Author:
eugene
Message:

upgrade to ippToPsps (see doc/upgrade.txt): adds native dvo to mysql ingest operations, adds autogen configuration & installation, splits out global config information from new "skychunk" information (current region on the sky being processed), adds test suites

Location:
trunk/ippToPsps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps

  • trunk/ippToPsps/jython

    • Property svn:ignore
      •  

        old new  
        11*.class
         2Makefile
         3Makefile.in
  • trunk/ippToPsps/jython/dvo.py

    r34107 r35097  
    3333
    3434    '''
    35     def __init__(self, logger, config, scratchDbName="ipptopsps_scratch"):
     35    def __init__(self, logger, config, skychunk, ippToPspsDb, scratchDbName=None):
    3636
    3737        # set up logging
    3838        self.logger = logger
    3939        self.config = config
     40        self.skychunk = skychunk
     41        self.ippToPspsDb = ippToPspsDb
    4042
    4143        # set up empty lists
     
    4648        self.regionsIngestedButOutOfDate = []
    4749       
    48         # connect to the specified scratch database
     50        # connect to the specified scratch database, if a name is given, otherwise use the first version
    4951        try:
    50             self.scratchDb = ScratchDb(self.logger, self.config, scratchDbName)
     52            self.scratchDb = ScratchDb(self.logger, self.config, '1', scratchDbName)
    5153        except: raise
    5254
     55        # we have (still) 3 modes of ingest from dvo cpt/cps/cpm files
     56        # 1) dvograbber (useFullTables == FALSE),
     57        # 2) jython/stilts (useStilts == TRUE, useFullTables == TRUE)
     58        # 3) dvopsps (useStilts == FALSE, useFullTables == TRUE)
     59        # my goal (EAM, 2013/01/31) is to migrate to only dvopsps
     60
     61        self.useStilts = 0
    5362        self.scratchDb.setUseFullTables(True)
    5463
    5564        # decide if we are using the right DVO for this scratchDb
    56         self.correctDvo = self.scratchDb.isCorrectDvo(self.config.dvoLocation)
     65        self.correctDvo = self.scratchDb.isCorrectDvo(self.skychunk.dvoLocation)
    5766
    5867        # this scratch Db either has no DVO info ingested, or a different DVO ingested. Prompt user
    5968        if not self.correctDvo:
    6069            print "*******************************************************************************"
    61             self.logger.warning("Wrong or no DVO in use. Do you want to reset and use '" + self.config.dvoLocation + "'?")
     70            self.logger.warning("Wrong or no DVO in use. Do you want to reset and use '" + self.skychunk.dvoLocation + "'?")
    6271            response = raw_input("(y/n) ")
    6372            if response == "y":
     
    101110
    102111        # check if we have up-to-date version
    103         path = self.config.dvoLocation + "/Photcodes.dat"
     112        path = self.skychunk.dvoLocation + "/Photcodes.dat"
    104113        if self.scratchDb.alreadyImportedThisDvoTable(path):
    105114            self.logger.debugPair("DVO Photcodes.dat file", "up-to-date")
     
    126135
    127136        # check if we have up-to-date version
    128         path = self.config.dvoLocation + "/Images.dat"
     137        path = self.skychunk.dvoLocation + "/Images.dat"
    129138        if self.scratchDb.alreadyImportedThisDvoTable(path):
    130139            self.logger.debugPair("DVO Images.dat file", "up-to-date")
     
    151160        if not self.correctDvo: return False
    152161
    153         path =  self.config.dvoLocation + "/SkyTable.fits"
     162        path =  self.skychunk.dvoLocation + "/SkyTable.fits"
    154163        if self.scratchDb.alreadyImportedThisDvoTable(path):
    155164            self.logger.debugPair("DVO SkyTable.fits file", "up-to-date")       
     
    158167        self.logger.infoSeparator()
    159168        self.logger.infoPair("DVO SkyTable.fits file", "NOT up-to-date")       
    160         self.importFits(
     169
     170        if self.useStilts:
     171            self.importFits(
    161172                path,
    162173                "R_MIN R_MAX D_MIN D_MAX INDEX NAME",
    163174                self.scratchDb.dvoSkyTable)
     175        else:
     176           
     177            # create dvoSkyTable
     178            sql = "drop TABLE dvoSkyTable"
     179            try:
     180                self.scratchDb.execute(sql)
     181            except: pass
     182
     183            # create dvoSkyTable
     184            sql = "CREATE TABLE dvoSkyTable (R_MIN REAL, R_MAX REAL, D_MIN REAL, D_MAX REAL, INDEX_ INT, NAME CHAR(18))"
     185            self.scratchDb.execute(sql)
     186
     187            # TODO path to DVO prog hardcoded temporarily
     188            cmd = "dvopsps skytable"
     189            cmd += " -dbhost " + self.scratchDb.dbHost
     190            cmd += " -dbname " + self.scratchDb.dbName
     191            cmd += " -dbuser " + self.scratchDb.dbUser
     192            cmd += " -dbpass " + self.scratchDb.dbPass
     193            cmd += " -D CATDIR " + self.skychunk.dvoLocation
     194
     195            self.logger.infoPair("Running dvopsps", cmd)
     196            p = Popen(cmd, shell=True, stdout=PIPE)
     197            p.wait()
    164198
    165199        self.logger.infoPair("Adding index to", self.scratchDb.dvoSkyTable)
     
    168202       
    169203        self.scratchDb.setImportedThisDvoTable(path)
    170         self.logger.infoPair("Finished importing SkyTable at", self.config.dvoLocation)
     204        self.logger.infoPair("Finished importing SkyTable at", self.skychunk.dvoLocation)
    171205
    172206        return True
     
    231265           paths = []
    232266           for fileType in self.ingestFileTypes:
    233                paths.append(self.config.dvoLocation + "/" + regionPath + "." + fileType)
     267               paths.append(self.skychunk.dvoLocation + "/" + regionPath + "." + fileType)
    234268
    235269           # check for the existence of all interested file types
     
    304338        # go no further if we've already partly ingested a different DVO
    305339        if not self.correctDvo:
    306             self.logger.infoPair("Wrong DVO in use", self.config.dvoLocation)
     340            self.logger.infoPair("Wrong DVO in use", self.skychunk.dvoLocation)
    307341            return
    308342
     
    387421        size = 0.0
    388422        for region in regions:
    389 
     423             self.logger.infoPair("sizes for region", region)
    390424             # get combined size of all interested files
    391425             for fileType in self.ingestFileTypes:
    392                  size = size + self.getDiskSize(self.config.dvoLocation + "/" + region + "." + fileType)
     426                 size = size + self.getDiskSize(self.skychunk.dvoLocation + "/" + region + "." + fileType)
     427                 # EAM TEST I/O
     428                 self.logger.infoPair(fileType, size)
    393429
    394430        return size
     
    519555          try:
    520556              if attempts > 0: self.logger.infoPair("Attempt %d to write" % attempts, table.name)
    521               table.cmd_keepcols("CODE NAME TYPE_AS_INT").write(self.scratchDb.url + '#' + tableName)
     557              table.cmd_keepcols("CODE NAME TYPE_AS_INT C_LAM K").write(self.scratchDb.url + '#' + tableName)
    522558              break
    523559          except:
     
    532568      return tableName
    533569
     570
     571    '''
     572    ingest skyregion into MySQL database using the native DVO program dvopsps
     573    Populates dvoDetections and dvoDone with FITS tables from DVO for the defined sky area, this
     574    includes purging detections outside sky area
     575    '''
     576    def nativeIngestDetections(self, boxId, raCenter, decCenter, boxSize):
     577
     578        # XXX put the chunk below in a separate method
     579        # blow away existing dvoDetection table
     580
     581        # clear the 'ingested' field for all boxes
     582        self.ippToPspsDb.clearIngestedBoxes()
     583       
     584        # drop detections table
     585        self.logger.infoPair("Dropping table", self.scratchDb.dvoDetectionTable)
     586        self.scratchDb.dropTable(self.scratchDb.dvoDetectionTable)
     587       
     588        # create detections table
     589        self.logger.infoPair("Creating table", self.scratchDb.dvoDetectionTable)
     590        sql = "CREATE TABLE " + self.scratchDb.dvoDetectionTable + " LIKE dvoDetection"
     591        try: self.scratchDb.execute(sql)
     592        except:
     593            self.logger.errorPair("Unable to create table", self.scratchDb.dvoDetectionTable)
     594            return False
     595        self.scratchDb.changeEngineToInnoDB(self.scratchDb.dvoDetectionTable)
     596       
     597        # add fileID column
     598        sql = "ALTER TABLE " + self.scratchDb.dvoDetectionTable + " ADD fileID INT NOT NULL"
     599        try: self.scratchDb.execute(sql)
     600        except:
     601            self.logger.errorPair("Unable to add fileID column to ", self.scratchDb.dvoDetectionTable)
     602            return False
     603
     604        # add an index to the fileID column
     605        self.scratchDb.createIndex(self.scratchDb.dvoDetectionTable, "fileID")
     606
     607        # make sure we have an up-to-date Images table
     608        self.loadImages()
     609
     610        # dvopsps -D catdir CATDIR -region .... -dbhost xx -dbname xx -dbuser xx -dbpass xx
     611        halfSize = boxSize / 2.0
     612        # -region raCenter-halfSize raCenter+halfSize decCenter-halfSize decCenter+halfSize
     613
     614        # TODO path to DVO prog hardcoded temporarily
     615        cmd = "dvopsps detections"
     616        cmd += " -dbhost " + self.scratchDb.dbHost
     617        cmd += " -dbname " + self.scratchDb.dbName
     618        cmd += " -dbuser " + self.scratchDb.dbUser
     619        cmd += " -dbpass " + self.scratchDb.dbPass
     620        cmd += " -D CATDIR " + self.skychunk.dvoLocation
     621        cmd += " -region "
     622        cmd += " " + str(raCenter-halfSize)
     623        cmd += " " + str(raCenter+halfSize)
     624        cmd += " " + str(decCenter-halfSize)
     625        cmd += " " + str(decCenter+halfSize)
     626
     627        if self.skychunk.parallel:
     628            cmd += " -parallel"
     629
     630        self.logger.infoPair("Running dvopsps", cmd)
     631        p = Popen(cmd, shell=True, stdout=PIPE)
     632        p.wait()
     633
     634        self.ippToPspsDb.setIngestedBox(boxId)
     635
     636        # add fileID column
     637        sql = "ANALYZE TABLE " + self.scratchDb.dvoDetectionTable
     638        try: self.scratchDb.execute(sql)
     639        except:
     640            self.logger.errorPair("Unable to analyze mysql table", self.scratchDb.dvoDetectionTable)
     641            return False
     642
     643        # update lists after attempted sync
     644        # self.printSummary()
     645
     646        return True
Note: See TracChangeset for help on using the changeset viewer.