IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 17, 2014, 12:30:45 PM (12 years ago)
Author:
eugene
Message:

merge changes (from past YEAR) into trunk

Location:
branches/eam_branches/ipp-ops-20130712/ippToPsps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-ops-20130712/ippToPsps

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/gpc1db.py

    r35417 r37066  
    4949    NB this uses Bill's potentially temporary 'skycells' database when finding RA/Dec for stacks.
    5050    '''
    51     def getItemsInThisDVODbForThisStage(self, dvoDb, batchType, minRA=-999, maxRA=999, minDec=-999, maxDec=999):
     51    def getItemsInThisDVODbForThisStage(self, dvoDb, batchType, minRA=-999, maxRA=999, minDec=-999, maxDec=999, tstart="0000-00-00 00:00:00", tend = "0000-00-00 00:00:00"):
    5252
    5353        self.logger.debugPair("GPC1 RA range", "%.2f -> %.2f" % (minRA, maxRA))
    5454        self.logger.debugPair("GPC1 Dec range", "%.2f -> %.2f" % (minDec, maxDec))
    55 
     55       
    5656        rows = []
    5757
     
    8080                   AND addRun.state = 'full' \
    8181                   AND decl BETWEEN RADIANS(" + str(minDec) + ") AND RADIANS(" + str(maxDec) + ") \
    82                    AND ra BETWEEN RADIANS(" + str(minRA) + ") AND RADIANS(" + str(maxRA) + ")"
     82                   AND ra BETWEEN RADIANS(" + str(minRA) + ") AND RADIANS(" + str(maxRA) + ") \
     83                   AND dateobs >= '" + tstart + "'\
     84                   AND dateobs <= '" + tend  + "'"
    8385
    8486        elif batchType == "ST":       
    8587
    8688            stage = "skycal"
    87             sql = "SELECT DISTINCT stack_id, radeg, decdeg FROM skycalRun \
     89            sql = "SELECT DISTINCT sky_id, radeg, decdeg FROM skycalRun \
    8890                   JOIN addRun ON(skycalRun.skycal_id = addRun.stage_id) \
    8991                   JOIN minidvodbRun USING(minidvodb_name) \
     
    9193                   JOIN mergedvodbRun USING(minidvodb_id) \
    9294                   JOIN mergedvodbProcessed USING (merge_id) \
    93                    JOIN  stackRun USING(stack_id) JOIN skycell USING(skycell_id) \
     95                   JOIN stackRun USING(stack_id) \
     96                   JOIN stackSumSkyfile using (stack_id) \
     97                   JOIN skycell USING(skycell_id) \
    9498                   WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
    9599                   AND minidvodbRun.state = 'merged' \
     
    100104                   AND addRun.state = 'full' \
    101105                   AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \
    102                    AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA)
     106                   AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \
     107                   AND mjd_obs >= (to_days('" + tstart + "')-678941) \
     108                   AND mjd_obs <= (to_days('" + tend + "') - 678941) "
     109           # self.logger.infoPair("sql",sql)     
     110        elif batchType == "DF":
     111
     112            stage = "diff"
     113            sql = "SELECT stuff from stufftable"
     114
     115        elif batchType == "FW":
    103116           
     117            stage = "forcedwarp"
     118            sql = "SELECT differentStuff from Stufftable"
     119
    104120        try:
    105121            # XXX EAM : test output
     
    212228    Gets a camera-stage smf for this cam_id
    213229    '''
    214     def getCameraStageSmf(self, camID):
    215 
     230    def getCameraStageSmf(self, camID, smfversion):
     231        self.logger.infoPair("using", smfversion)
    216232        self.logger.debug("Querying GPC1 for camera smf files with cam_id = " + str(camID))
    217233
     
    237253        # list all smf files if a neb path
    238254        files = []
    239         if path.startswith("neb"):
    240 
    241             # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
    242             f=os.popen("neb-ls -p "+path+"%smf")
    243             for i in f.readlines():
    244                 files.append(i.rstrip())
    245 
    246         # or not a neb path
    247         else:
    248             files = glob.glob(path + ".smf")
     255
     256
     257        #there are a couple of states for smfversion
     258
     259        # "use_new" => we have reprocessed the data, use the .smf file
     260
     261        # "not_reproc" => this has not been reprocessed, use the .smf file
     262
     263        # "use_original" => we *may* have reprocessed the data,
     264        #    use (file).smf.original if camRun.state = 'full' and if there is a .smf and .orig
     265        #    use (file).smf if camRun.state = 'full' and if there is only a .smf
     266        #    fault out if camRun.state != 'full' -- that is a race condition we don't want.
     267       
     268       
     269        if (smfversion == "not_reproc") or (smfversion == "use_new"):
     270            if path.startswith("neb"):
     271
     272                # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
     273                f=os.popen("neb-ls -p "+path+"%smf")
     274                for i in f.readlines():
     275                    files.append(i.rstrip())
     276
     277                # or not a neb path
     278            else:
     279                files = glob.glob(path + ".smf")
     280
     281        if (smfversion == "use_original"):
     282            # get state of camRun
     283            sql = "SELECT state \
     284               FROM camProcessedExp \
     285               JOIN camRun USING(cam_id) \
     286               WHERE camRun.cam_id = %d" % camID
     287            try:
     288                rs = self.executeQuery(sql)
     289                rs.first()
     290            except:
     291                self.logger.errorPair("Can't query for camRun.state for cam_id",  str(camID))
     292                return None
     293
     294            try:
     295                # get state of camRun.cam_id
     296                camrunstate = rs.getString(1)
     297            except:
     298                self.logger.errorPair("No state found for cam_id", str(camID) )
     299                return None
     300           
     301            if (camrunstate == "full"):
     302              self.logger.infoPair("camRun.state is ",camrunstate)   
     303                 # if full find smf files
     304              if path.startswith("neb"):
     305
     306                 # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
     307                 fsmf=os.popen("neb-ls -p "+path+"%smf")
     308                 fsmfs = fsmf.readlines()
     309                 fsmforig=os.popen("neb-ls -p "+path+"%smf.original")
     310                 fsmforigs = fsmforig.readlines()
     311                 smfCount = len(fsmfs)
     312                 smfOrigCount = len (fsmforigs)
     313
     314                 if (smfCount > 0  and smfOrigCount > 0):
     315                     #smf and original  so use original
     316                     self.logger.infoPair("using:", path+"%smf.original")
     317                     for i in fsmforigs:
     318                         files.append(i.rstrip())
     319
     320                 if (smfCount > 0 and smfOrigCount == 0):
     321                     self.logger.infoPair("using:", path+"%smf")
     322                     #smf file and no smf.original use .smf
     323                     for i in fsmfs:
     324                         files.append(i.rstrip())
     325
     326                 #if not smf dont' find files ??)       
     327                 # or not a neb path
     328
     329              else:
     330                # this is broken for non neb - on the other hand we probably won't do .original if so
     331                files = glob.glob(path + ".smf")
     332
     333
     334
     335            # if .smf and .original use .original
     336            else:
     337                self.logger.infoPair("camRun.state not full, can't ingest", str(camID) )
     338                return None
     339
    249340
    250341        # XXX EAM : test output
     
    307398
    308399        # print "staring stack stage cmf"
    309 
     400        #self.logger.infoPair("in stackstagecmf - sql is: ", sql)
    310401        # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id
    311402        try:
     
    408499
    409500
     501    '''
     502    grabs the stackID for a particular skyId, filter, and dvodb
     503    the mapping of stack_id from sky_id is not unique unless
     504    joined to the dvodb
     505    '''
     506    def getStackIDFromSkyIDAndFilter(self,dvoDb,skyID,filter):
     507
     508        self.logger.infoPair("finding stack_ids from gpc1 for sky_id ", skyID)
     509
     510        sql = "SELECT DISTINCT stack_id from skycalRun \
     511               JOIN addRun ON(skycalRun.skycal_id = addRun.stage_id) \
     512               JOIN minidvodbRun USING(minidvodb_name) \
     513               JOIN minidvodbProcessed USING(minidvodb_id) \
     514               JOIN mergedvodbRun USING(minidvodb_id) \
     515               JOIN mergedvodbProcessed USING(merge_id) \
     516               JOIN stackRun USING (stack_id) \
     517               WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
     518               AND minidvodbRun.state = 'merged' \
     519               AND minidvodbProcessed.fault = 0 \
     520               AND mergedvodbRun.state = 'full' \
     521               AND mergedvodbProcessed.fault = 0  \
     522               AND addRun.stage = 'skycal' \
     523               AND addRun.state = 'full' \
     524               AND filter = '" + filter + "' \
     525               AND sky_id = %d" % skyID
     526
     527#        self.logger.infoPair("sql",sql)
     528
     529        try:
     530            rs = self.executeQuery(sql)
     531                         
     532        except:   
     533            self.logger.exception("can't query for stackid in DVO")
     534            self.logger.infoPair("failed sql:", sql)
     535            return 0
     536
     537        rs.first()
     538        try:
     539            stackid = rs.getInt(1)
     540            self.logger.infoPair("found stack_ID", stackid)
     541        except:
     542            stackid = -999
     543            self.logger.infoPair("using stack_ID",stackid)
     544           
     545        return stackid   
Note: See TracChangeset for help on using the changeset viewer.