IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2013, 2:23:09 PM (13 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20130207/ippToPsps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130207/ippToPsps

  • branches/eam_branches/ipp-20130207/ippToPsps/jython/dvo.py

    r35097 r35235  
    66import sys
    77import os
     8import math
    89import logging
    910import glob
     
    3334
    3435    '''
    35     def __init__(self, logger, config, skychunk, ippToPspsDb, scratchDbName=None):
     36    def __init__(self, logger, config, skychunk, ippToPspsDb, scratchDb):
    3637
    3738        # set up logging
     
    4041        self.skychunk = skychunk
    4142        self.ippToPspsDb = ippToPspsDb
     43        self.scratchDb = scratchDb
    4244
    4345        # set up empty lists
     
    4850        self.regionsIngestedButOutOfDate = []
    4951       
    50         # connect to the specified scratch database, if a name is given, otherwise use the first version
    51         try:
    52             self.scratchDb = ScratchDb(self.logger, self.config, '1', scratchDbName)
    53         except: raise
    54 
    5552        # we have (still) 3 modes of ingest from dvo cpt/cps/cpm files
    5653        # 1) dvograbber (useFullTables == FALSE),
     
    211208    def setSkyAreaAsStripe(self, ra=0., width=4.):
    212209
     210        print "this function should not reached now, error"
     211        raise
     212
    213213        self.setSkyArea(ra, ra+width, -91., 91.)
    214214
     
    217217    '''
    218218    def setSkyAreaAsBox(self, ra=180., dec=0., side=181.0):
     219
     220        print "this function should not reached now, error"
     221        raise
    219222
    220223        halfSide = side/2.0
     
    223226    '''
    224227    Determines what DVO files need to be ingested to the defines region
     228    XXX EAM : this function has been substantially reduced / stripped down to work with the parallel dvo
     229    XXX EAM : some additional review of the goals would be useful
    225230    '''
    226231    def setSkyArea(self, minRa=-1., maxRa=361., minDec=-91., maxDec=91):
     
    263268
    264269           # get paths for this region for the file types we are interested in
    265            paths = []
    266            for fileType in self.ingestFileTypes:
    267                paths.append(self.skychunk.dvoLocation + "/" + regionPath + "." + fileType)
     270           # XXX ipptopsps cannot check files -- it does not know where they are
     271           ## paths = []
     272           ## for fileType in self.ingestFileTypes:
     273           ##     paths.append(self.skychunk.dvoLocation + "/" + regionPath + "." + fileType)
    268274
    269275           # check for the existence of all interested file types
    270            skipThisRegion = False
    271            for path in paths:
    272                if not os.path.isfile(path):
    273                    skipThisRegion = True
    274                    break
    275 
    276            if skipThisRegion: continue
     276           # XXX ipptopsps cannot check files -- it does not know where they are
     277           ## skipThisRegion = False
     278           ## for path in paths:
     279           ##     if not os.path.isfile(path):
     280           ##         skipThisRegion = True
     281           ##         break
     282
     283           ## if skipThisRegion: continue
    277284
    278285           # ok, have real, populated files so add this region to the list
     
    281288
    282289           # if we have already imported up-to-date versions of all interested files, then we skip this region
    283            alreadyIngested = True
    284            for path in paths:
    285                if not self.scratchDb.alreadyImportedThisDvoTable(path):
    286                    alreadyIngested = False
    287                    break
    288    
     290           ## alreadyIngested = True
     291           ## for path in paths:
     292           ##     if not self.scratchDb.alreadyImportedThisDvoTable(path):
     293           ##         alreadyIngested = False
     294           ##         break
     295
     296           alreadyIngested = False
    289297           if alreadyIngested:
    290298               self.regionsAlreadyIngested.append(regionPath)
     
    299307
    300308           # check if we have out-of-date versions of any interested files, if so, add region to the purge list
    301            outOfDate = False
    302            for path in paths:
    303                if self.scratchDb.haveOutOfDateVersionOfThisDvoTable(path):
    304                    outOfDate = True
    305                    break
    306 
    307            if outOfDate: self.regionsIngestedButOutOfDate.append(regionPath)
     309           ## outOfDate = False
     310           ## for path in paths:
     311           ##     if self.scratchDb.haveOutOfDateVersionOfThisDvoTable(path):
     312           ##         outOfDate = True
     313           ##         break
     314           ##
     315           ## if outOfDate: self.regionsIngestedButOutOfDate.append(regionPath)
     316
     317           print "using region: ", regionPath
    308318
    309319           self.regionsToIngest.append(regionPath)
     
    389399        self.logger.infoPair("Purging", "%d regions" % len(regions))
    390400
    391         detectionDeleteCount = self.scratchDb.purgeTheseDvoRegions(regions, self.ingestFileTypes)
    392         if detectionDeleteCount > 0: self.logger.infoPair("Deleted", "%d detections" % detectionDeleteCount)
     401        self.scratchDb.purgeTheseDvoRegions(regions, self.ingestFileTypes)
     402
     403        ## detectionDeleteCount = self.scratchDb.purgeTheseDvoRegions(regions, self.ingestFileTypes)
     404        ## if detectionDeleteCount > 0: self.logger.infoPair("Deleted", "%d detections" % detectionDeleteCount)
    393405
    394406        return True
     
    420432
    421433        size = 0.0
     434        return size
     435
    422436        for region in regions:
    423437             self.logger.infoPair("sizes for region", region)
    424438             # get combined size of all interested files
    425439             for fileType in self.ingestFileTypes:
     440                 print "trying ", fileType
    426441                 size = size + self.getDiskSize(self.skychunk.dvoLocation + "/" + region + "." + fileType)
    427442                 # EAM TEST I/O
     
    574589    includes purging detections outside sky area
    575590    '''
    576     def nativeIngestDetections(self, boxId, raCenter, decCenter, boxSize):
     591    def nativeIngestDetections(self, boxId, boxDim):
    577592
    578593        # XXX put the chunk below in a separate method
    579594        # blow away existing dvoDetection table
    580595
    581         # clear the 'ingested' field for all boxes
    582         self.ippToPspsDb.clearIngestedBoxes()
     596        # clear the 'ingested' field for all boxes owned by this host
     597        self.ippToPspsDb.clearIngestedBoxes(self.scratchDb.dbHost)
    583598       
     599        ## print "*******************************************************************************"
     600        ## self.logger.warning("about to delete detection table and re-ingest; is this correct?")
     601        ## response = raw_input("(y/n) ")
     602        ## if response != "y":
     603        ##     raise
     604        ## self.logger.warning("Are you ABSOLUTELY sure you want to do this?")
     605        ## response = raw_input("(y/n) ")
     606        ## if response != "y":
     607        ##     raise
     608
    584609        # drop detections table
    585610        self.logger.infoPair("Dropping table", self.scratchDb.dvoDetectionTable)
     
    608633        self.loadImages()
    609634
    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
     635        # the box dimensions are the area used to select the items of
     636        # interest from the gpc1 database (camera smfs / skycal cmfs).
     637        # for dvopsps, we need to include a border region large enough
     638        # to grab all detections / objects which are contributed by an
     639        # item with the center in the given box
     640        dR_border = self.skychunk.BORDER / math.cos(math.radians(boxDim['DEC']))
     641        dD_border = self.skychunk.BORDER
     642
     643        minRA  = boxDim['minRA']  - dR_border
     644        maxRA  = boxDim['maxRA']  + dR_border
     645        minDEC = boxDim['minDEC'] - dD_border
     646        maxDEC = boxDim['maxDEC'] + dD_border
    613647
    614648        # TODO path to DVO prog hardcoded temporarily
     
    620654        cmd += " -D CATDIR " + self.skychunk.dvoLocation
    621655        cmd += " -region "
    622         cmd += " " + str(raCenter-halfSize)
    623         cmd += " " + str(raCenter+halfSize)
    624         cmd += " " + str(decCenter-halfSize)
    625         cmd += " " + str(decCenter+halfSize)
     656        cmd += " " + str(minRA)
     657        cmd += " " + str(maxRA)
     658        cmd += " " + str(minDEC)
     659        cmd += " " + str(maxDEC)
    626660
    627661        if self.skychunk.parallel:
     
    632666        p.wait()
    633667
    634         self.ippToPspsDb.setIngestedBox(boxId)
     668        ## dvopsps can take a very long time. try 2 or 3 times to re-establish communication with the db before proceeding?
     669
     670        self.ippToPspsDb.setIngestedBox(boxId, self.scratchDb.dbHost)
    635671
    636672        # add fileID column
Note: See TracChangeset for help on using the changeset viewer.