IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 12, 2015, 12:24:24 PM (12 years ago)
Author:
eugene
Message:

various updates merged from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pv3-20140717-merge/ippToPsps/jython/gpc1db.py

    r36715 r37820  
    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"
    119 
    120         try:
    121             # XXX EAM : test output
    122             rs = self.executeQuery(sql)
    123             while (rs.next()):
    124                rows.append([rs.getInt(1), rs.getFloat(2), rs.getFloat(3)])
    125             rs.close()
     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) "
     170
     171        try:
     172            rs = self.executeQuery(sql)
     173
    126174        except:
    127175            self.logger.exception("Can't query for ids in DVO")
    128176            self.logger.infoPair("failed sql:", sql)
    129             return rows
     177            sys.exit(1)
     178
     179        while (rs.next()):
     180            rows.append([rs.getInt(1), rs.getFloat(2), rs.getFloat(3)])
     181
     182        rs.close()
    130183
    131184        self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(rows), dvoDb, stage))
     
    164217        return imageIDs
    165218
     219   
     220
     221
     222
     223
    166224    '''
    167225    Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved
     
    194252        return meta
    195253
     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   
    196381    '''
    197382    Gets some camera-stage meta data for this cam_id
     
    339524
    340525
    341         # XXX EAM : test output
    342526        self.logger.infoPair("smf files:", files)
    343527        if len(files) < 1: return None
     
    367551    def getStackStageCmf(self, dvoDb, stackID):
    368552     
    369         '''
    370         sql = "SELECT DISTINCT staticskyResult.path_base \
    371                FROM staticskyRun  \
    372                JOIN staticskyInput USING(sky_id)  \
    373                JOIN staticskyResult USING(sky_id) \
    374                JOIN stackRun USING(stack_id)  \
    375                JOIN stackSumSkyfile USING(stack_id) \
    376                JOIN addRun ON sky_id = stage_id \
    377                JOIN minidvodbRun USING (minidvodb_name) \
    378                WHERE stack_id = " + str(stackID) + " \
    379                AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \
    380                AND minidvodbRun.state = 'merged' \
    381                AND stage = 'staticsky'"
    382         '''
    383 
    384553        sql = "SELECT DISTINCT skycalResult.path_base \
    385554               FROM skycalRun  \
     
    431600        fits = Fits(self.logger, self.config, files[0])
    432601        return fits
    433 
    434         # XXX validate the file?
    435         # if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
    436 
    437             # now find and loop through all cmf files at this path_base
    438 
    439             ## XXX the code below was needed when we ingested from staticsky (N files per run)
    440             ## XXX ingesting from skycal solves this problem (1 file per run)
    441             ## files=os.popen("neb-ls " + pathBase + "%cmf")
    442             ## for i in files.readlines():
    443             ##     nebPath = i.rstrip()
    444             ##
    445             ##     # now attempt to run 'neb-ls -p' to actually read this cmf file
    446             ##     try:
    447             ##         self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")
    448             ##         paths=os.popen("neb-ls -p " + nebPath)
    449             ##         path = paths.readline().rstrip()
    450             ##         if len(path) < 1:
    451             ##            self.logger.debug("zero length path - skipping")
    452             ##            raise
    453             ##
    454             ##         print "starint stack stage cmf 3"
    455             ##
    456             ##         # if we get here, then the cmf is readable, now check the stack_id
    457             ##         fits = Fits(self.logger, self.config, path)
    458             ##         if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
    459             ##             # we have the right file!
    460             ##             self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
    461             ##             return fits
    462             ##         else:
    463             ##             # this is not the correct file
    464             ##             self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
    465             ##
    466             ##     # an exception here means that nebulous could not read this file, so we just skip it
    467             ##     except:
    468             ##         self.logger.debug("NEB FAILED SKIPPING")
    469             ##         pass
    470602
    471603    '''
Note: See TracChangeset for help on using the changeset viewer.