IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33237 for trunk/ippToPsps


Ignore:
Timestamp:
Feb 10, 2012, 1:43:48 PM (14 years ago)
Author:
rhenders
Message:

big changes to incorporate loading by region of sky

File:
1 edited

Legend:

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

    r33191 r33237  
    1717from datastore import Datastore
    1818from batch import Batch
     19from dvo import Dvo
    1920
    2021from initbatch import InitBatch
     
    4041
    4142'''
    42 Queues up all available stuff for this batch type
    43 '''
    44 def queueItems(batchType):
     43Queues up all available stuff for this batch type in a box with these dimensions
     44'''
     45def queueItemsInBox(batchType, ra, dec, boxsize):
    4546
    4647    logger.infoTitle("Queuing " + batchType + " items")
     48    logger.infoPair("Box center and size", "%f/%f/%f" %(ra, dec, boxsize))
    4749
    4850    allIDs = []
     
    6062    else:
    6163
    62         allIDs = gpc1Db.getIDsInThisDVODbForThisStage(
     64        allIDs = gpc1Db.getIDsInThisDVODbForThisStageInThisBox(
    6365                DVOGPC1LABEL,
    6466                batchType,
    65                 MINRA,
    66                 MAXRA,
    67                 MINDEC,
    68                 MAXDEC)
     67                ra,
     68                dec,
     69                boxsize)
    6970
    7071        logger.infoPair("All %s items in DVO" % batchType, "%d" % len(allIDs))
     
    8182        logger.infoPair("Consistently failing items", "%d" % len(consistaentlyFailedIDs))
    8283        logger.infoPair("Unprocessed items", "%d" % len(ids))
     84
     85    return ids
     86
     87
     88'''
     89Actually loops through items and processes them
     90'''
     91def processTheseItems(batchType, ids, useFullTables):
    8392
    8493    logger.infoPair("%s items queued" % batchType, "%d" % len(ids))
     
    108117                    ippToPspsDb,
    109118                    id,
    110                     batchID)
     119                    batchID,
     120                    useFullTables)
    111121        elif batchType == "ST":
    112122            batch = StackBatch(logger,
     
    116126                    ippToPspsDb,
    117127                    id,
    118                     batchID)
     128                    batchID,
     129                    useFullTables)
    119130
    120131        batch.run()
     
    132143Start of program.
    133144'''
    134 
    135145if len(sys.argv) > 1: CONFIG = sys.argv[1]
    136146else:
     
    156166
    157167# if in test mode, print log to screen, otherwise, only to file
    158 logger.setup(configDoc, "ippToPsps", TEST, not TEST, HOST, PID)
    159 
    160 # create database objects
     168#logger.setup(configDoc, "ippToPsps", TEST, not TEST, HOST, PID) TODO put back
     169logger.setup(configDoc, "ippToPsps")
     170
     171# create various objects
     172dvo = Dvo(logger, configDoc)
    161173gpc1Db = Gpc1Db(logger, configDoc)
    162174ippToPspsDb = IppToPspsDb(logger, configDoc)
     
    174186PUBLISH = int(configDoc.find("options/publishToDatastore").text)
    175187BASEPATH = configDoc.find("localOutPath").text
    176 QUEUE_P2 = int(configDoc.find("options/queueP2").text)
    177 QUEUE_ST = int(configDoc.find("options/queueST").text)
    178188SURVEY = configDoc.find("options/survey").text
    179189
     190# get batch types from config
     191batchTypes = []
     192if int(configDoc.find("options/queueP2").text) == 1: batchTypes.append("P2")
     193if int(configDoc.find("options/queueST").text) == 1: batchTypes.append("ST")
     194
    180195# get equatorial coord limits, if any
    181 try:
    182     MINRA = float(configDoc.find("dvo/minRA").text)
    183     MAXRA = float(configDoc.find("dvo/maxRA").text)
    184     MINDEC = float(configDoc.find("dvo/minDec").text)
    185     MAXDEC = float(configDoc.find("dvo/maxDec").text)
    186 except:
    187     MINRA = 0.0
    188     MAXRA = 360.0
    189     MINDEC = -30.0
    190     MAXDEC = 90.0
     196try: MINRA = float(configDoc.find("dvo/minRA").text)
     197except: MINRA = 0.0
     198try: MAXRA = float(configDoc.find("dvo/maxRA").text)
     199except: MAXRA = 360.0
     200try: MINDEC = float(configDoc.find("dvo/minDec").text)
     201except: MINDEC = -30.0
     202try: MAXDEC = float(configDoc.find("dvo/maxDec").text)
     203except: MAXDEC = 90.0
     204try: BOXSIZE = float(configDoc.find("dvo/boxSize").text)
     205except: BOXSIZE = 4.0
    191206
    192207# prompt user: FORCE and PUBLISH is a dangerous combination
     
    206221logger.infoPair("Loading epoch", EPOCH)
    207222logger.infoPair("DVO gpc1 label", DVOGPC1LABEL)
    208 logger.infoBool("Queuing P2 batches?", QUEUE_P2)
    209 logger.infoBool("Queuing ST batches?", QUEUE_ST)
     223for batchType in batchTypes: logger.infoPair("Queuing batch type", batchType)
    210224logger.infoBool("Forcing?", FORCE)
    211225logger.infoBool("Test mode?", TEST)
    212226logger.infoBool("Publishing?", PUBLISH)
    213227
     228# if an IN batch is requested, create and quit
     229if QUEUE_IN:
     230   batchID = ippToPspsDb.createNewBatch(
     231             "IN",
     232             0,
     233             SURVEY,
     234             EPOCH,
     235             DVOGPC1LABEL,
     236             datastore.product,
     237             1)
     238   if batchID > 0:
     239       batch = InitBatch(logger, CONFIG, configDoc, gpc1Db, ippToPspsDb, batchID)
     240       batch.run()
     241
     242   sys.exit(1)
     243
    214244'''
    215245Main processing loop:
    216246
    217  1) creates an IN batch if requested
    218  2) queues available P2 batches (if requested)
    219  3) queues available ST batches (if requested)
    220  4) if in test mode, quits
    221  5) otherwise, waits then repeats from 2
    222 
    223 '''
     247 1) queues available P2 batches (if requested)
     248 2) queues available ST batches (if requested)
     249 3) if in test mode, quits
     250 4) else waits then repeats from 2
     251
     252'''
     253BORDER = 1.60
     254HALFBOX = BOXSIZE/2.0
     255BOXSIZEWITHBORDER = BOXSIZE + (BORDER * 2)
     256
     257# this outer while loop simply waits a few minutes then starts queuing againas more stuff may appear in DVO over time
    224258while True:
    225259
    226     # queue all items for all batch types, sequentially
    227     if QUEUE_IN:
    228        batchID = ippToPspsDb.createNewBatch(
    229                  "IN",
    230                  0,
    231                  SURVEY,
    232                  EPOCH,
    233                  DVOGPC1LABEL,
    234                  datastore.product,
    235                  1)
    236        if batchID > 0:
    237            batch = InitBatch(logger, CONFIG, configDoc, gpc1Db, ippToPspsDb, batchID)
    238            batch.run()
    239        break;
     260    # starting positions
     261    ra = MINRA + HALFBOX
     262    dec = MINDEC + HALFBOX
    240263
    241264    # queue up batches that are processed but not loaded to datastore
    242265    logger.infoTitle("Previous failed datastore loads")
    243     publishAnyUnpublishedBatches("P2")
    244     publishAnyUnpublishedBatches("ST")
    245 
    246     if QUEUE_P2: queueItems("P2")
    247     if QUEUE_ST: queueItems("ST")
    248 
    249     # in the TEST mode, we quit after submitting one batch
    250     if TEST: break
     266    for batchType in batchTypes: publishAnyUnpublishedBatches(batchType)
     267
     268    # loop through full range of RA/Dec queueing stuff in boxes of size BOXSIZE
     269    while ra <= MAXRA:
     270
     271       while dec <= MAXDEC:
     272
     273           # for each batch type
     274           # - queue items in this box
     275           # - check if we should pre-load DVO region
     276           # - process the items
     277           for batchType in batchTypes:
     278               ids = queueItemsInBox(batchType, ra, dec, BOXSIZE)
     279
     280               if len(ids) < 1:
     281                   logger.infoPair("No items found in this region", "skipping")
     282                   continue
     283
     284               dvo.setSkyAreaAsBox(ra, dec, BOXSIZEWITHBORDER)
     285               dvo.printSummary()
     286
     287               sizeToBeIngested = dvo.getDiskSizeOfRegionsToBeIngested()
     288               if sizeToBeIngested == 0.0: smfsPerGB = 999999999
     289               else: smfsPerGB = len(ids)/dvo.getDiskSizeOfRegionsToBeIngested()
     290               logger.infoPair("smfs-per-GB", "%f" % smfsPerGB)
     291
     292               # do we pre-ingest stuff from DVO?
     293               if smfsPerGB > 40:
     294                   if not dvo.sync():
     295                       logger.errorPair("Could not sync DVO with MySQL", "skipping")
     296                       continue
     297
     298                   useFullTables = 1
     299               else: useFullTables = 0
     300
     301               logger.infoBool("Using pre-ingested DVO data?", useFullTables)
     302               processTheseItems(batchType, ids, useFullTables)
     303
     304               # in the TEST mode, we quit after submitting one batch
     305               if TEST: break
     306
     307           dec = dec + BOXSIZE
     308           if TEST: break
     309
     310       dec = MINDEC + HALFBOX
     311       ra = ra + BOXSIZE
     312       if TEST: break
    251313
    252314    # wait for the POLLPERIOD before checking for new ids
Note: See TracChangeset for help on using the changeset viewer.