IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 11, 2015, 1:31:50 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/ippToPsps/jython/gpc1db.py

    r37246 r37801  
    108108                   AND mjd_obs <= (to_days('" + tend + "') - 678941) "
    109109           # self.logger.infoPair("sql",sql)     
    110         elif batchType == "DF":
     110        elif batchType == "DF":            # this is specifically only for WARPSTACK types of diffs -
     111            # it only makes sense for the date to come from the warp1
     112            # may need to be more clever if we do other types of diffs
    111113
    112114            stage = "diff"
    113             sql = "SELECT stuff from stufftable"
     115            sql = "SELECT DISTINCT stage_extra1, radeg,decdeg \
     116                   FROM addRun \
     117                   JOIN addProcessedExp using (add_id) \
     118                   JOIN minidvodbRun using (minidvodb_name) \
     119                   JOIN minidvodbProcessed using (minidvodb_id)  \
     120                   JOIN mergedvodbRun using (minidvodb_id) \
     121                   JOIN mergedvodbProcessed using (merge_id) \
     122                   JOIN diffInputSkyfile \
     123                   ON (diff_id = stage_id AND diff_skyfile_id = stage_extra1 \
     124                   AND stage = 'diff') \
     125                   JOIN skycell using (skycell_id, tess_id) \
     126                   JOIN warpRun on (warp1 = warp_id \
     127                   AND diffInputSkyfile.skycell_id = skycell_id) \
     128                   JOIN fakeRun using (fake_id) \
     129                   JOIN camRun using (cam_id) \
     130                   JOIN chipRun using (chip_id)  \
     131                   JOIN rawExp using (exp_id) \
     132                   WHERE  mergedvodbRun.mergedvodb = '" + dvoDb + "' \
     133                   AND minidvodbRun.state = 'merged' \
     134                   AND minidvodbProcessed.fault = 0 \
     135                   AND mergedvodbRun.state = 'full' \
     136                   AND mergedvodbProcessed.fault = 0 \
     137                   AND addRun.stage = '" + stage + "' \
     138                   AND addRun.state = 'full' \
     139                   AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \
     140                   AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \
     141                   AND dateobs >= '" + tstart + "'\
     142                   AND dateobs <= '" + tend  + "'"
     143
    114144
    115145        elif batchType == "FW":
    116146           
    117147            stage = "forcedwarp"
    118             sql = "SELECT differentStuff from Stufftable"
     148            sql = "SELECT DISTINCT sky_id, radeg, decdeg FROM fullForceInput \
     149                   JOIN addRun ON(fullForceInput.ff_id = addRun.stage_id, fullForceInput.warp_id = addRun.stage_extra1) \
     150                   JOIN minidvodbRun USING(minidvodb_name) \
     151                   JOIN minidvodbProcessed USING(minidvodb_id) \
     152                   JOIN mergedvodbRun USING(minidvodb_id) \
     153                   JOIN mergedvodbProcessed USING (merge_id) \
     154                   JOIN fullForceRun USING(ff_id) \
     155                   JOIN skycalRun using (skycal_id) \
     156                   JOIN stackRun USING(stack_id) \
     157                   JOIN stackSumSkyfile using (stack_id) \
     158                   JOIN skycell USING(skycell_id) \
     159                   WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
     160                   AND minidvodbRun.state = 'merged' \
     161                   AND minidvodbProcessed.fault = 0 \
     162                   AND mergedvodbRun.state = 'full' \
     163                   AND mergedvodbProcessed.fault = 0 \
     164                   AND addRun.stage = '" + stage + "' \
     165                   AND addRun.state = 'full' \
     166                   AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \
     167                   AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \
     168                   AND mjd_obs >= (to_days('" + tstart + "')-678941) \
     169                   AND mjd_obs <= (to_days('" + tend + "') - 678941) "
    119170
    120171        try:
     
    166217        return imageIDs
    167218
     219   
     220
     221
     222
     223
    168224    '''
    169225    Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved
     
    196252        return meta
    197253
     254
     255    '''
     256    Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved
     257    '''
     258    def getDiffStageMeta(self, diffSkyfileID):
     259
     260        self.logger.debug("Querying GPC1 for stack meta data")
     261
     262        meta = []
     263        sql = "SELECT \
     264               filter,\
     265               diff_mode, \
     266               warp1, \
     267               stack2, \
     268               skycell_id, \
     269               diffRun.software_ver, \
     270               exp_time, \
     271               (to_days(dateobs)-678941 + time_to_sec(dateobs)/86400.) \
     272               FROM diffRun join diffInputSkyfile using (diff_id) \
     273               JOIN warpRun on (warp1=warp_id) \
     274               JOIN fakeRun using (fake_id) \
     275               JOIN camRun using (cam_id) \
     276               JOIN chipRun using (chip_id) \
     277               JOIN rawExp using (exp_id) \
     278               WHERE diff_skyfile_id = %d" % diffSkyfileID
     279        #this is a crappy way to get the mjd from the diff but we don't save it anywhere       
     280        try:
     281            rs = self.executeQuery(sql)
     282            rs.first()
     283        except:
     284            self.logger.infoPair ("this sql is broken:",sql)
     285            self.logger.errorPair("Can't query for", "stack meta data")
     286           
     287        try:
     288            meta.append(rs.getString(1))
     289            meta.append(rs.getString(2))
     290            meta.append(rs.getString(3))
     291            meta.append(rs.getString(4))
     292            meta.append(rs.getString(5))
     293            meta.append(rs.getString(6))
     294            meta.append(rs.getString(7))
     295            meta.append(rs.getString(8))
     296        except:
     297            self.logger.errorPair("getDiffStageMeta()", "empty meta data")
     298     
     299        return meta
     300
     301    '''
     302    get diff stage cmf name
     303    '''
     304    def getDiffStageCmf(self, dvoDb, diffSkyfileID):
     305        print "got here, diffstagecmf"
     306        sql = "SELECT DISTINCT diffSkyfile.path_base \
     307               FROM mergedvodbRun join minidvodbRun using (minidvodb_id) \
     308               JOIN addRun using (minidvodb_name) \
     309               JOIN diffInputSkyfile on (diff_skyfile_id = stage_extra1 \
     310               AND diff_id = stage_id AND stage = 'diff') \
     311               JOIN diffSkyfile using (diff_id, skycell_id) \
     312               WHERE diff_skyfile_id = " + str(diffSkyfileID) + " \
     313               AND minidvodbRun.state = 'merged' \
     314               AND mergedvodbRun.state = 'full' \
     315               AND mergedvodbRun.mergedvodb = '" + dvoDb + "' \
     316               AND stage = 'diff'"
     317
     318        try:
     319            rs = self.executeQuery(sql)
     320            rs.first()
     321        except:
     322            self.logger.infoPair("failed sql", sql)
     323            self.logger.errorPair("can't query for diff cmf", "dfif_skyfile_id = %d" %diff_skyfile_id)
     324            return None
     325        print "query worked"
     326        try:
     327            pathBase = rs.getString(1)
     328        except:   
     329            self.logger.errorPair("no diff cms found for diff_skyfile_id = %d" %diff_skyfile_id)
     330            return None
     331        print pathBase
     332        files = []
     333        if pathBase.startswith("neb"):
     334            print "open"
     335            f=os.popen("neb-ls -p " + pathBase + ".cmf")
     336            for i in f.readlines():
     337                print "i",i
     338                files.append(i.rstrip())
     339                print "append"
     340        print i
     341        if len(files) < 1: return None
     342        fits = Fits(self.logger, self.config, files[0])
     343        return fits
     344
     345    '''
     346    Gets a list of PSPS image IDs for this diff ID
     347    '''
     348    def getImageIDsForThisDiffID(self, diffID):
     349
     350        self.logger.debug("Querying GPC1 for image IDs for diff ID: " + str(diffID))
     351
     352        # JOIN stackInputSkyfile shoule use stack_id as well as warp_id, right? (maybe not -- the join to warp is first)
     353        sql = "SELECT DISTINCT CONCAT(exp_id, SUBSTR(class_id, 3, 4)) FROM ( \
     354               SELECT DISTINCT exp_id,class_id \
     355               FROM warpSkyCellMap \
     356               JOIN warpRun USING(warp_id) \
     357               JOIN diffInputSkyfile on warp1 = warp_id  \
     358               JOIN fakeRun using (fake_id) \
     359               JOIN camRun using (cam_id) \
     360               JOIN chipRun using (chip_id) \
     361               WHERE diffInputSkyfile.diff_skyfile_id = " + str(diffID) + ") AS a"
     362
     363        try:
     364            rs = self.executeQuery(sql)
     365        except:
     366            self.logger.infoPair("failed sql:",sql)
     367            self.logger.exception("Can't query for imageIDs")
     368           
     369
     370        imageIDs = []
     371        while (rs.next()):
     372            imageIDs.append(rs.getString(1))
     373        rs.close()
     374
     375        return imageIDs
     376
     377   
     378
     379
     380   
    198381    '''
    199382    Gets some camera-stage meta data for this cam_id
     
    368551    def getStackStageCmf(self, dvoDb, stackID):
    369552     
    370         '''
    371         sql = "SELECT DISTINCT staticskyResult.path_base \
    372                FROM staticskyRun  \
    373                JOIN staticskyInput USING(sky_id)  \
    374                JOIN staticskyResult USING(sky_id) \
    375                JOIN stackRun USING(stack_id)  \
    376                JOIN stackSumSkyfile USING(stack_id) \
    377                JOIN addRun ON sky_id = stage_id \
    378                JOIN minidvodbRun USING (minidvodb_name) \
    379                WHERE stack_id = " + str(stackID) + " \
    380                AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \
    381                AND minidvodbRun.state = 'merged' \
    382                AND stage = 'staticsky'"
    383         '''
    384 
    385553        sql = "SELECT DISTINCT skycalResult.path_base \
    386554               FROM skycalRun  \
     
    432600        fits = Fits(self.logger, self.config, files[0])
    433601        return fits
    434 
    435         # XXX validate the file?
    436         # if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
    437 
    438             # now find and loop through all cmf files at this path_base
    439 
    440             ## XXX the code below was needed when we ingested from staticsky (N files per run)
    441             ## XXX ingesting from skycal solves this problem (1 file per run)
    442             ## files=os.popen("neb-ls " + pathBase + "%cmf")
    443             ## for i in files.readlines():
    444             ##     nebPath = i.rstrip()
    445             ##
    446             ##     # now attempt to run 'neb-ls -p' to actually read this cmf file
    447             ##     try:
    448             ##         self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")
    449             ##         paths=os.popen("neb-ls -p " + nebPath)
    450             ##         path = paths.readline().rstrip()
    451             ##         if len(path) < 1:
    452             ##            self.logger.debug("zero length path - skipping")
    453             ##            raise
    454             ##
    455             ##         print "starint stack stage cmf 3"
    456             ##
    457             ##         # if we get here, then the cmf is readable, now check the stack_id
    458             ##         fits = Fits(self.logger, self.config, path)
    459             ##         if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
    460             ##             # we have the right file!
    461             ##             self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
    462             ##             return fits
    463             ##         else:
    464             ##             # this is not the correct file
    465             ##             self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
    466             ##
    467             ##     # an exception here means that nebulous could not read this file, so we just skip it
    468             ##     except:
    469             ##         self.logger.debug("NEB FAILED SKIPPING")
    470             ##         pass
    471602
    472603    '''
Note: See TracChangeset for help on using the changeset viewer.