IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33144


Ignore:
Timestamp:
Jan 25, 2012, 1:30:33 PM (14 years ago)
Author:
rhenders
Message:

Big changes to SQL for getting both camera and stack stage files

File:
1 edited

Legend:

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

    r32778 r33144  
    4646                   JOIN chipRun USING (chip_id) \
    4747                   JOIN rawExp USING (exp_id) \
    48                    WHERE minidvodbRun.minidvodb_group = '" + dvoDb + "' \
     48                   JOIN mergedvodbRun using (minidvodb_id) \
     49                   WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
    4950                   AND minidvodbRun.state = 'merged' \
     51                   AND mergedvodbRun.state = 'full' \
    5052                   AND minidvodbProcessed.fault = 0 \
    5153                   AND addRun.stage = '" + stage + "' \
     
    5658        elif batchType == "ST":       
    5759
    58             stage = "staticsky"
     60            stage = "staticsky_multi"
    5961            sql = "SELECT DISTINCT stack_id FROM staticskyInput \
    6062                   JOIN addRun ON(staticskyInput.sky_id = addRun.stage_id) \
     
    6769                   AND addRun.state = 'full'"
    6870
     71        print sql
    6972        try:
    7073            rs = self.executeQuery(sql)
     
    193196
    194197        try:
    195         # get path to base dir of cmf files
     198            # get path to base dir of cmf files
    196199            path = rs.getString(1)
    197             path = path[0:path.rfind("/")]
    198200        except:
    199201            self.logger.errorPair("No smf files found for cam_id", str(camID) )
     
    204206        if path.startswith("neb"):
    205207
    206             f=os.popen("neb-ls -p "+path+"/%smf")
     208            f=os.popen("neb-ls -p "+path+"%smf")
    207209            for i in f.readlines():
    208210                files.append(i.rstrip())
     
    210212        # or not a neb path
    211213        else:
    212             files = glob.glob(path + "/*.smf")
     214            files = glob.glob(path + ".smf")
    213215
    214216        if len(files) < 1: return None
     
    219221    '''
    220222    Gets the path to the cmf file for this stack_id
    221     '''
    222     def getStackStageCmf(self, stackID):
    223      
    224         sql = "SELECT staticskyResult.path_base \
    225                FROM staticskyRun \
    226                JOIN staticskyInput USING(sky_id) \
     223   
     224    The logic here is fairly ridiculous due to issues with how GPC1 stores info regarding multi-filter stacks. In partcular, it
     225    is impossible to find a full path for a cmf file for a given stack_id
     226
     227    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
     228    meaning that neb-ls -p will fail.
     229
     230    our logic is as follows:
     231   
     232    - use stack_id and the DVO label to find a path base for all cmfs
     233    - loop through all the potential cmfs, run neb-ls -p on each
     234    - if neb-ls -p fails, then the file does not exists and we ignore it
     235    - 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
     236    - if it is, great, exit
     237    - if not, try the next one in the list
     238
     239    '''
     240    def getStackStageCmf(self, dvoDb, stackID):
     241     
     242        '''
     243        sql = "SELECT DISTINCT staticskyResult.path_base \
     244               FROM staticskyRun  \
     245               JOIN staticskyInput USING(sky_id)  \
    227246               JOIN staticskyResult USING(sky_id) \
    228                JOIN stackRun USING(stack_id) \
     247               JOIN stackRun USING(stack_id)  \
    229248               JOIN stackSumSkyfile USING(stack_id) \
    230                WHERE stack_id = %s" % stackID
    231 
     249               JOIN addRun ON sky_id = stage_id \
     250               JOIN minidvodbRun USING (minidvodb_name) \
     251               WHERE stack_id = " + str(stackID) + " \
     252               AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \
     253               AND minidvodbRun.state = 'merged' \
     254               AND stage = 'staticsky_multi'"
     255        '''
     256
     257        sql = "SELECT DISTINCT staticskyResult.path_base \
     258               FROM staticskyRun  \
     259               JOIN staticskyInput USING(sky_id)  \
     260               JOIN staticskyResult USING(sky_id) \
     261               JOIN stackRun USING(stack_id)  \
     262               JOIN stackSumSkyfile USING(stack_id) \
     263               JOIN addRun ON sky_id = stage_id \
     264               JOIN minidvodbRun USING (minidvodb_name) \
     265               JOIN mergedvodbRun using (minidvodb_id) \
     266               WHERE stack_id = " + str(stackID) + " \
     267               AND minidvodbRun.state = 'merged' \
     268               AND mergedvodbRun.state = 'full' \
     269               AND mergedvodbRun.mergedvodb = '" + dvoDb + "' \
     270               AND stage = 'staticsky_multi'"
     271
     272
     273        # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id
    232274        try:
    233275            rs = self.executeQuery(sql)
     
    235277            pathBase = rs.getString(1)
    236278
    237             # now find ALL cmf files at this path_base as there can be more than one
    238             f=os.popen("neb-ls -p " + pathBase + "%cmf")
    239             for i in f.readlines():
    240 
    241                 path = i.rstrip()
    242                 fits = Fits(self.logger, self.doc, path)
    243 
    244                 # we need to check if this is the correct cmf file, and if so then break and return
    245                 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
    246                     return fits
    247 
    248         except:
    249             self.logger.exception("Can't query for stack cmfs")
    250 
    251         self.logger.error("Could not find stack cmf")
     279            # now find and loop through all cmf files at this path_base
     280            files=os.popen("neb-ls " + pathBase + "%cmf")
     281            for i in files.readlines():
     282
     283                nebPath = i.rstrip()
     284
     285                # now attempt to run 'neb-ls -p' to actually read this cmf file
     286                try:
     287                    self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")
     288                    paths=os.popen("neb-ls -p " + nebPath)
     289                    path = paths.readline().rstrip()
     290                    if len(path) < 1:
     291                       self.logger.debug("zero length path - skipping")
     292                       raise
     293
     294                    # if we get here, then the cmf is readable, now check the stack_id
     295                    fits = Fits(self.logger, self.doc, path)
     296                    if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
     297                        # we have the right file!
     298                        self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
     299                        return fits
     300                    else:
     301                        # this is not the correct file
     302                        self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
     303
     304                # an exception here means that nebulous could not read this file, so we just skip it
     305                except:
     306                    self.logger.debug("NEB FAILED SKIPPING")
     307                    pass
     308
     309        except:
     310            self.logger.errorPair("Can't query for stack cmfs", "stack_id = %d" % stackID)
     311
     312        self.logger.errorPair("Couldn't find stack cmf for", "stack_id = %d" % stackID)
    252313        return None
    253314
Note: See TracChangeset for help on using the changeset viewer.