IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2012, 5:19:48 PM (14 years ago)
Author:
mhuber
Message:

merging latest r33407 trunk changes to meh_branches/ppstack_test

Location:
branches/meh_branches/ppstack_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/ippToPsps/jython/gpc1db.py

    r32018 r33415  
    2020    Constructor
    2121    '''
    22     def __init__(self, logger, doc):
    23         super(Gpc1Db, self).__init__(logger, doc, "gpc1database")
     22    def __init__(self, logger, config):
     23        super(Gpc1Db, self).__init__(logger, config, "gpc1database")
    2424
    2525    '''
     
    3232
    3333    '''
    34     TODO
    35     '''
    36     def getIDsInThisDVODbForThisStageFudge(self):
    37 
    38         sql = "SELECT staticskyRun.sky_id \
    39                FROM staticskyInput, staticskyRun, stackRun, staticskyResult \
    40                WHERE staticskyRun.sky_id = staticskyInput.sky_id \
    41                AND staticskyInput.stack_id = stackRun.stack_id \
    42                AND staticskyInput.sky_id = staticskyResult.sky_id \
    43                AND staticskyRun.label like 'MD04.staticsky' \
    44                AND stackRun.filter like 'i%'"
    45 
    46         try:
    47             rs = self.executeQuery(sql)
    48         except:
    49             self.logger.exception("Can't query for ids in DVO")
     34    Gets a list of ids in this DVO database for this stage, could be cam or staticsky, for a box with defined center and side length
     35    '''
     36    def getIDsInThisDVODbForThisStageInThisBox(self, dvoDb, batchType, ra=180., dec=0., side=181.):
     37
     38        halfSide = side/2.0
     39        return self.getIDsInThisDVODbForThisStage(dvoDb, batchType, ra-halfSide, ra+halfSide, dec-halfSide, dec+halfSide)
     40
     41
     42    '''
     43    Gets a list of ids in this DVO database for this stage, could be cam or staticsky, and a box can be defined with equatorial coordinates
     44    '''
     45    def getIDsInThisDVODbForThisStage(self, dvoDb, batchType, minRA=-999, maxRA=999, minDec=-999, maxDec=999):
     46
     47        self.logger.debugPair("GPC1 RA range", "%.2f -> %.2f" % (minRA, maxRA))
     48        self.logger.debugPair("GPC1 Dec range", "%.2f -> %.2f" % (minDec, maxDec))
    5049
    5150        ids = []
    52         while (rs.next()):
    53             ids.append(rs.getInt(1))
    54 
    55         rs.close()
    56 
    57         self.logger.debug("Found %d items in DVO database '" % (len(ids)))
    58 
    59         return ids
    60 
    61     '''
    62     Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far)
    63     '''
    64     def getIDsInThisDVODbForThisStage(self, dvoDb, batchType):
    6551
    6652        if batchType == "P2": # TODO define these someplace
     
    7157                   JOIN minidvodbRun USING(minidvodb_name) \
    7258                   JOIN minidvodbProcessed USING(minidvodb_id) \
    73                    WHERE minidvodbRun.minidvodb_group = '" + dvoDb + "' \
     59                   JOIN camRun ON (stage_id = cam_id) \
     60                   JOIN chipRun USING (chip_id) \
     61                   JOIN rawExp USING (exp_id) \
     62                   JOIN mergedvodbRun using (minidvodb_id) \
     63                   WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
    7464                   AND minidvodbRun.state = 'merged' \
     65                   AND mergedvodbRun.state = 'full' \
    7566                   AND minidvodbProcessed.fault = 0 \
    7667                   AND addRun.stage = '" + stage + "' \
    77                    AND addRun.state = 'full'"
     68                   AND addRun.state = 'full' \
     69                   AND decl BETWEEN RADIANS(" + str(minDec) + ") AND RADIANS(" + str(maxDec) + ") \
     70                   AND ra BETWEEN RADIANS(" + str(minRA) + ") AND RADIANS(" + str(maxRA) + ")"
    7871
    7972        elif batchType == "ST":       
    8073
    81             stage = "staticsky"
    82             sql = "SELECT DISTINCT stack_id \
    83                    FROM staticskyInput \
     74            stage = "staticsky_multi"
     75            sql = "SELECT DISTINCT stack_id FROM staticskyInput \
    8476                   JOIN addRun ON(staticskyInput.sky_id = addRun.stage_id) \
    8577                   JOIN minidvodbRun USING(minidvodb_name) \
     
    9082                   AND addRun.stage = '" + stage + "' \
    9183                   AND addRun.state = 'full'"
    92            
    93         try:
    94             rs = self.executeQuery(sql)
     84
     85        try:
     86            rs = self.executeQuery(sql)
     87            while (rs.next()): ids.append(rs.getInt(1))
     88            rs.close()
    9589        except:
    9690            self.logger.exception("Can't query for ids in DVO")
    97 
    98         ids = []
    99         while (rs.next()):
    100             ids.append(rs.getInt(1))
    101 
    102         rs.close()
     91            return ids
     92
    10393
    10494        self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
     
    154144            rs = self.executeQuery(sql)
    155145            rs.first()
     146        except:
     147            self.logger.errorPair("Can't query for", "stack meta data")
     148           
     149        try:
    156150            meta.append(rs.getString(1))
    157151            meta.append(rs.getString(2))
    158152            meta.append(rs.getString(3))
    159153        except:
    160             self.logger.exception("Can't query for stack meta")
    161 
     154            self.logger.errorPair("getStackStageMeta()", "empty meta data")
     155     
    162156        return meta
    163157
     
    178172            rs = self.executeQuery(sql)
    179173            rs.first()
     174        except:
     175            self.logger.errorPair("Can't query for", "camera meta data")
     176
     177        try:
    180178            meta.append(rs.getInt(1))
    181179            meta.append(rs.getString(2))
     
    185183            meta.append(rs.getString(6))
    186184        except:
    187             self.logger.exception("Can't query for camera meta")
     185            self.logger.errorPair("getCameraStageMeta()", "empty meta data")
    188186
    189187        return meta
     
    205203            rs.first()
    206204        except:
    207             self.logger.exception("Can't query for camera smfs")
    208 
    209         # get path to base dir of cmf files
    210         path = rs.getString(1)
    211         path = path[0:path.rfind("/")]
     205            self.logger.errorPair("Can't query for smf file for cam_id",  str(camID))
     206            return None
     207
     208        try:
     209            # get path to base dir of cmf files
     210            path = rs.getString(1)
     211        except:
     212            self.logger.errorPair("No smf files found for cam_id", str(camID) )
     213            return None
    212214       
    213215        # list all smf files if a neb path
     
    215217        if path.startswith("neb"):
    216218
    217             f=os.popen("neb-ls -p "+path+"/%smf")
     219            f=os.popen("neb-ls -p "+path+"%smf")
    218220            for i in f.readlines():
    219221                files.append(i.rstrip())
     
    221223        # or not a neb path
    222224        else:
    223             files = glob.glob(path + "/*.smf")
     225            files = glob.glob(path + ".smf")
    224226
    225227        if len(files) < 1: return None
    226228
    227         return Fits(self.logger, self.doc, files[0]) # TODO just returning first file - check
     229        return Fits(self.logger, self.config, files[0]) # TODO just returning first file - check
    228230
    229231
    230232    '''
    231233    Gets the path to the cmf file for this stack_id
    232     '''
    233     def getStackStageCmf(self, stackID):
    234      
    235         sql = "SELECT staticskyResult.path_base \
    236                FROM staticskyRun \
    237                JOIN staticskyInput USING(sky_id) \
     234   
     235    The logic here is fairly ridiculous due to issues with how GPC1 stores info regarding multi-filter stacks. In partcular, it
     236    is impossible to find a full path for a cmf file for a given stack_id
     237
     238    Instead, we get a path_base to a directory with a collection of cmfs. neb-ls will list 5 files, but a number < 5 may actually exist
     239    meaning that neb-ls -p will fail.
     240
     241    our logic is as follows:
     242   
     243    - use stack_id and the DVO label to find a path base for all cmfs
     244    - loop through all the potential cmfs, run neb-ls -p on each
     245    - if neb-ls -p fails, then the file does not exists and we ignore it
     246    - if neb-ls -p succeeds, we open that cmf file and check the STK_ID value in its header to see if it is the one we want
     247    - if it is, great, exit
     248    - if not, try the next one in the list
     249
     250    '''
     251    def getStackStageCmf(self, dvoDb, stackID):
     252     
     253        '''
     254        sql = "SELECT DISTINCT staticskyResult.path_base \
     255               FROM staticskyRun  \
     256               JOIN staticskyInput USING(sky_id)  \
    238257               JOIN staticskyResult USING(sky_id) \
    239                JOIN stackRun USING(stack_id) \
     258               JOIN stackRun USING(stack_id)  \
    240259               JOIN stackSumSkyfile USING(stack_id) \
    241                WHERE stack_id = %s" % stackID
    242 
     260               JOIN addRun ON sky_id = stage_id \
     261               JOIN minidvodbRun USING (minidvodb_name) \
     262               WHERE stack_id = " + str(stackID) + " \
     263               AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \
     264               AND minidvodbRun.state = 'merged' \
     265               AND stage = 'staticsky_multi'"
     266        '''
     267
     268        sql = "SELECT DISTINCT staticskyResult.path_base \
     269               FROM staticskyRun  \
     270               JOIN staticskyInput USING(sky_id)  \
     271               JOIN staticskyResult USING(sky_id) \
     272               JOIN stackRun USING(stack_id)  \
     273               JOIN stackSumSkyfile USING(stack_id) \
     274               JOIN addRun ON sky_id = stage_id \
     275               JOIN minidvodbRun USING (minidvodb_name) \
     276               JOIN mergedvodbRun using (minidvodb_id) \
     277               WHERE stack_id = " + str(stackID) + " \
     278               AND minidvodbRun.state = 'merged' \
     279               AND mergedvodbRun.state = 'full' \
     280               AND mergedvodbRun.mergedvodb = '" + dvoDb + "' \
     281               AND stage = 'staticsky_multi'"
     282
     283
     284        # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id
    243285        try:
    244286            rs = self.executeQuery(sql)
     
    246288            pathBase = rs.getString(1)
    247289
    248             # now find ALL cmf files at this path_base as there can be more than one
    249             f=os.popen("neb-ls -p " + pathBase + "%cmf")
    250             for i in f.readlines():
    251 
    252                 path = i.rstrip()
    253                 fits = Fits(self.logger, self.doc, path)
    254 
    255                 # we need to check if this is the correct cmf file, and if so then break and return
    256                 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
    257                     return fits
    258 
    259         except:
    260             self.logger.exception("Can't query for stack cmfs")
    261 
    262         self.logger.error("Could not find stack cmf")
     290            # now find and loop through all cmf files at this path_base
     291            files=os.popen("neb-ls " + pathBase + "%cmf")
     292            for i in files.readlines():
     293
     294                nebPath = i.rstrip()
     295
     296                # now attempt to run 'neb-ls -p' to actually read this cmf file
     297                try:
     298                    self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")
     299                    paths=os.popen("neb-ls -p " + nebPath)
     300                    path = paths.readline().rstrip()
     301                    if len(path) < 1:
     302                       self.logger.debug("zero length path - skipping")
     303                       raise
     304
     305                    # if we get here, then the cmf is readable, now check the stack_id
     306                    fits = Fits(self.logger, self.config, path)
     307                    if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
     308                        # we have the right file!
     309                        self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
     310                        return fits
     311                    else:
     312                        # this is not the correct file
     313                        self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
     314
     315                # an exception here means that nebulous could not read this file, so we just skip it
     316                except:
     317                    self.logger.debug("NEB FAILED SKIPPING")
     318                    pass
     319
     320        except:
     321            self.logger.errorPair("Can't query for stack cmfs", "stack_id = %d" % stackID)
     322
     323        self.logger.errorPair("Couldn't find stack cmf for", "stack_id = %d" % stackID)
    263324        return None
    264325
Note: See TracChangeset for help on using the changeset viewer.