IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 6, 2011, 4:22:01 PM (15 years ago)
Author:
rhenders
Message:

New method to get a cmf for a given stack_id, which is non-trivial as there can be more than one cmfs ointed to by a given stack_id, so each must be opened and the header checked; changes to meta-data getters for P2 and ST; general purpose methid to get stage IDs from addRun for the given stage

File:
1 edited

Legend:

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

    r31806 r31831  
    88
    99from mysql import MySql
     10from fits import Fits
    1011from java.sql import *
    1112
     
    5455        rs.close()
    5556
    56         self.logger.info("Found %d items in DVO database '" % (len(ids)))
     57        self.logger.debug("Found %d items in DVO database '" % (len(ids)))
    5758
    5859        return ids
     
    6162    Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far)
    6263    '''
    63     def getIDsInThisDVODbForThisStage(self, dvoDb, stage):
    64 
    65         sql = "SELECT DISTINCT stage_id \
    66                FROM addRun \
    67                WHERE stage = '" + stage + "' \
    68                AND dvodb = '" + dvoDb + "'"
     64    def getIDsInThisDVODbForThisStage(self, dvoDb, batchType):
     65
     66        if batchType == "P2": # TODO define these someplace
     67
     68            stage = "cam"
     69            sql = "SELECT DISTINCT stage_id \
     70                   FROM addRun \
     71                   WHERE stage = '" + stage + "' \
     72                   AND dvodb = '" + dvoDb + "'"
     73
     74        elif batchType == "ST":       
     75
     76            stage = "staticsky"
     77            sql = "SELECT DISTINCT stack_id \
     78                   FROM gpc1.staticskyInput \
     79                   JOIN gpc1.addRun ON(gpc1.staticskyInput.sky_id = gpc1.addRun.stage_id) \
     80                   WHERE stage = '" + stage + "' \
     81                   AND dvodb = '" + dvoDb + "'"
    6982
    7083        try:
     
    7992        rs.close()
    8093
    81         self.logger.info("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
     94        self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
    8295
    8396        return ids
     
    116129    Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved
    117130    '''
    118     def getStackStageMeta(self, skyID, filter):
     131    def getStackStageMeta(self, stackID):
    119132
    120133        self.logger.debug("Querying GPC1 for stack meta data")
     
    122135        meta = []
    123136        sql = "SELECT \
    124                stackRun.stack_id,\
    125                stackRun.skycell_id, \
    126                stackRun.software_ver \
    127                FROM \
    128                staticskyInput, staticskyRun, stackRun, staticskyResult \
    129                WHERE staticskyRun.sky_id = staticskyInput.sky_id \
    130                AND staticskyInput.stack_id = stackRun.stack_id \
    131                AND staticskyInput.sky_id = staticskyResult.sky_id \
    132                and staticskyInput.sky_id = %d \
    133                and filter = '%s'" % (skyID, filter)
    134 
    135 
    136         try:
    137             rs = self.executeQuery(sql)
    138             rs.first()
    139             meta.append(rs.getInt(1))
     137               filter,\
     138               skycell_id, \
     139               software_ver \
     140               FROM stackRun \
     141               WHERE stack_id = %d" % stackID
     142               
     143        try:
     144            rs = self.executeQuery(sql)
     145            rs.first()
     146            meta.append(rs.getString(1))
    140147            meta.append(rs.getString(2))
    141148            meta.append(rs.getString(3))
     
    212219
    213220    '''
    214     Gets all cmf files for this sky_id. handles both absolute paths and neb paths
    215     '''
    216     def getStackStageCmfs(self, skyID):
    217 
    218         self.logger.debug("Querying GPC1 for stack cmf files")
    219 
    220         sql = "SELECT path_base, num_inputs \
    221                FROM staticskyResult \
    222                WHERE sky_id = %d" % skyID
    223 
    224         try:
    225             rs = self.executeQuery(sql)
    226             rs.first()
     221    Gets the path to the cmf file for this stack_id
     222    '''
     223    def getStackStageCmf(self, stackID):
     224     
     225        sql = "SELECT staticskyResult.path_base \
     226               FROM staticskyRun \
     227               JOIN staticskyInput USING(sky_id) \
     228               JOIN staticskyResult USING(sky_id) \
     229               JOIN stackRun USING(stack_id) \
     230               JOIN stackSumSkyfile USING(stack_id) \
     231               WHERE stack_id = %s" % stackID
     232
     233        try:
     234            rs = self.executeQuery(sql)
     235            rs.first()
     236            pathBase = rs.getString(1)
     237
     238            # now find ALL cmf files at this path_base as there can be more than one
     239            f=os.popen("neb-ls -p " + pathBase + "%cmf")
     240            for i in f.readlines():
     241
     242                path = i.rstrip()
     243                fits = Fits(self.logger, path)
     244
     245                # we need to check if this is the correct cmf file, and if so then break and return
     246                if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
     247                    return path
     248
    227249        except:
    228250            self.logger.exception("Can't query for stack cmfs")
    229251
    230         # get path to base dir of cmf files
    231         path = rs.getString(1)
    232         #path = path[0:path.rfind("/")]
    233        
    234         # list all cmf files if a neb path
    235         files = []
    236         if path.startswith("neb"):
    237 
    238             f=os.popen("neb-ls -p "+path+"%cmf")
    239             for i in f.readlines():
    240                 files.append(i.rstrip())
    241 
    242         # or not a neb path
    243         else:
    244             files = glob.glob(path + "*.cmf")
    245 
    246         return files
    247 
     252        self.logger.error("Could not find stack cmf")
     253        return "NULL"
    248254
    249255    '''
Note: See TracChangeset for help on using the changeset viewer.