IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36724


Ignore:
Timestamp:
May 2, 2014, 9:28:20 AM (12 years ago)
Author:
heather
Message:

stackObject - filling in the filters

File:
1 edited

Legend:

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

    r36723 r36724  
    643643             
    644644       
    645 
    646         # insert all the detections
    647         sql = "INSERT INTO StackObject(\
    648                ippDetectID \
    649                ,skyCellID \
    650                ,projectionCellID \
    651                ,xPos \
    652                ,yPos \
    653                ,xPosErr \
    654                ,yPosErr \
    655                ,psfFlux \
    656                ,psfFluxErr \
    657                ,peakFlux \
    658                ,sky \
    659                ,skyErr \
    660                ,sgSep \
    661                ,psfWidMajor \
    662                ,psfWidMinor \
    663                ,psfTheta \
    664                ,psfLikelihood \
    665                ,infoFlag \
    666                ,psfQf \
    667                ,psfQfPerfect \
    668                ,psfChiSq \
    669                ,momentXX \
    670                ,momentXY \
    671                ,momentYY \
    672                ,momentM3C \
    673                ,momentM3S \
    674                ,momentM4C \
    675                ,momentM4S \
    676                ,momentR1 \
    677                ,momentRH \
    678                ,apFlux \
    679                ,apFluxErr \
    680                ,kronFlux \
    681                ,kronFluxErr \
    682                ,kronRad \
    683                ,nFrames \
    684                ,assocDate \
    685                ,historyModNum \
    686                ) \
    687                SELECT \
    688                IPP_IDET \
    689                ," + self.skycell + " \
    690                ," + self.projectioncell + " \
    691                ,X_PSF \
    692                ,Y_PSF \
    693                ,X_PSF_SIG \
    694                ,Y_PSF_SIG \
    695                ,PSF_INST_FLUX / " + str(self.expTime) + " \
    696                ,PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
    697                ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + str(self.expTime) + " \
    698                ,SKY / " + str(self.expTime) + " \
    699                ,SKY_SIGMA / " + str(self.expTime) + " \
    700                ,EXT_NSIGMA \
    701                ,PSF_MAJOR \
    702                ,PSF_MINOR \
    703                ,PSF_THETA \
    704                ,psfLikelihood(EXT_NSIGMA) \
    705                , FLAGS2 << 32 | FLAGS \
    706                ,PSF_QF \
    707                ,PSF_QF_PERFECT \
    708                ,PSF_CHISQ / PSF_NDOF \
    709                ,MOMENTS_XX \
    710                ,MOMENTS_XY \
    711                ,MOMENTS_YY \
    712                ,MOMENTS_M3C \
    713                ,MOMENTS_M3S \
    714                ,MOMENTS_M4C \
    715                ,MOMENTS_M4S \
    716                ,MOMENTS_R1 \
    717                ,MOMENTS_RH \
    718                ,POW(10.0, -0.4*AP_MAG) / " + str(self.expTime) + " \
    719                ,NULL \
    720                ,KRON_FLUX / " + str(self.expTime) + " \
    721                ,KRON_FLUX_ERR / " + str(self.expTime) + " \
    722                ,MOMENTS_R1 * 2.5 \
    723                ,N_FRAMES \
    724                , '" + self.dateStr + "' \
    725                ," + self.historyModNum + " \
    726                FROM SkyChip_psf"
    727 
    728 # these were used above (left over from before PSF_INST_FLUX, PSF_INST_FLUX_SIG were available?
    729 #               ,POW(10.0, (-0.4*PSF_INST_MAG)) / " + str(self.expTime) + "
    730 #               ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / " + str(self.expTime) + ")) / 1.085736)
    731 #               ,POW(10.0, -0.4*AP_MAG) / " + str(self.expTime) + "
    732 
    733 # I need a way to choose the sql above based on the cmf version: V3 (LAP.PV1) does not have AP_FLUX
    734 #               ,AP_FLUX / " + str(self.expTime) + "
    735 
    736         # print "sql: ", sql
    737         # response = raw_input("ready to insert stack det ")
    738 
    739         self.scratchDb.execute(sql)
    740 
    741         #it is possible to drop some detections from dvo (that are present in the cmf). when that happens we get a 0 for objid
     645       
     646
     647        self.logger.infoPair("inserting filter dependent cmf items into", "StackObject")
     648
     649        for f in filters:
     650          skip = 0
     651          if (f == "g"):
     652              if self.gstackID > 0: 
     653                  stackid = self.gstackID
     654                  exptime = self.gheader['EXPTIME']
     655              else:
     656                  skip = 1
     657          if (f == "r"):
     658              if self.rstackID > 0:
     659                  stackid = self.rstackID
     660                  exptime = self.rheader['EXPTIME']
     661              else:
     662                  skip = 1
     663          if (f == "i"):
     664              if self.istackID > 0:
     665                  stackid = self.istackID
     666                  exptime = self.iheader['EXPTIME']
     667              else:
     668                  skip = 1
     669          if (f == "z"):
     670              if self.zstackID > 0:
     671                  stackid = self.zstackID
     672                  exptime = self.zheader['EXPTIME']
     673              else:
     674                  skip = 1
     675          if (f == "y"):
     676              if self.ystackID > 0
     677                  stackid = self.ystackID
     678                  exptime = self.yheader['EXPTIME']:
     679              else:
     680                  skip = 1
     681
     682          if skip == 1:
     683              self.logger.infoPair("nothing for filter" , f)
     684          else:
     685             self.logger.infoPair("filter",f)
     686
     687
     688
     689             # insert all the detections
     690             sql = "INSERT INTO StackObject(\
     691                   "+f+"ippDetectID \
     692                   ,"+f+"xPos \
     693                   ,"+f+"yPos \
     694                   ,"+f+"xPosErr \
     695                   ,"+f+"yPosErr \
     696                   ,"+f+"PSFFlux \
     697                   ,"+f+"PSFFluxErr \
     698                   ,"+f+"sky \
     699                   ,"+f+"skyErr \
     700                   ,"+f+"psfMajorFWHM \
     701                   ,"+f+"psfMinorFWHM \
     702                   ,"+f+"psfTheta \
     703                   ,"+f+"psfLikelihood \
     704                   ,"+f+"infoFlag \
     705                   ,"+f+"psfQf \
     706                   ,"+f+"psfQfPerfect \
     707                   ,"+f+"psfChiSq \
     708                   ,"+f+"momentXX \
     709                   ,"+f+"momentXY \
     710                   ,"+f+"momentYY \
     711                   ,"+f+"momentR1 \
     712                   ,"+f+"momentRH \
     713                   ,"+f+"ApFlux \
     714                   ,"+f+"ApFluxErr \
     715                   ,"+f+"KronFlux \
     716                   ,"+f+"KronFluxErr \
     717                   ,"+f+"KronRad \
     718                   ,"+f+"nFrames \
     719                   ) \
     720                   SELECT \
     721                   IPP_IDET \
     722                   ,X_PSF \
     723                   ,Y_PSF \
     724                   ,X_PSF_SIG \
     725                   ,Y_PSF_SIG \
     726                   ,PSF_INST_FLUX / " + str(exptime) + " \
     727                   ,PSF_INST_FLUX_SIG / " + str(exptime) + " \
     728                   ,SKY / " + str(exptime) + " \
     729                   ,SKY_SIGMA / " + str(exptime) + " \
     730                   ,PSF_MAJOR \
     731                   ,PSF_MINOR \
     732                   ,PSF_THETA \
     733                   ,psfLikelihood(EXT_NSIGMA) \
     734                   , FLAGS2 << 32 | FLAGS \
     735                   ,PSF_QF \
     736                   ,PSF_QF_PERFECT \
     737                   ,PSF_CHISQ / PSF_NDOF \
     738                   ,MOMENTS_XX \
     739                   ,MOMENTS_XY \
     740                   ,MOMENTS_YY \
     741                   ,MOMENTS_R1 \
     742                   ,MOMENTS_RH \
     743                   ,POW(10.0, -0.4*AP_MAG) / " + str(exptime) + " \
     744                   ,NULL \
     745                   ,KRON_FLUX / " + str(exptime) + " \
     746                   ,KRON_FLUX_ERR / " + str(exptime) + " \
     747                   ,MOMENTS_R1 * 2.5 \
     748                   ,N_FRAMES \
     749                   FROM " + f + "SkyChip_psf"
     750             
     751
     752             self.scratchDb.execute(sql)
     753
     754             #it is possible to drop some detections from dvo (that are present in the cmf). when that happens we get a 0 for objid
    742755        #we drop those...
     756
    743757        sql="DELETE FROM StackObject where objID = 0"
    744758        self.scratchDb.execute(sql)
    745759        self.logger.infoPair("Deleting", "entries with StackObject.objID = 0")
    746760       
    747         # XXX EAM : this seems quite inefficient : these commands use updates to set
    748         # fields which are constant across all rows.  Why not just include these in
    749         # the original insert above?
    750 
    751761        self.scratchDb.updateAllRows("StackObject", "surveyID", str(self.surveyID))
    752762       
    753         self.scratchDb.updateFilterID("StackObject", self.filter)
     763#        self.scratchDb.updateFilterID("StackObject", f+".00000")
    754764       
    755765        self.scratchDb.updateAllRows("StackObject", "dataRelease", str(self.skychunk.dataRelease))
    756         #set primary F to 0
    757         self.scratchDb.updateAllRows("StackObject", "primaryF", "0")
    758        
    759         self.scratchDb.updateAllRows("StackObject", "activeFlag", "0")
    760        
    761766        self.updateStackMetaID("StackObject")
    762767       
    763768        self.updateStackTypeID("StackObject")
    764769       
    765         self.updateDvoIDsAndFlags("StackObject")
     770        #self.updateDvoIDsAndFlags("StackObject")
    766771        #this now updates primary F as well
    767772        # response = raw_input("updated dvo ")
     
    796801            self.scratchDb.execute(sql)
    797802            # response = raw_input("add psf flux ")
    798            
     803         
     804        #filter dependent
    799805        # NOTE : Flux limits : in the current PSPS schema, negative fluxes
    800806        # cause problems for sql queries which work in mags as SQL cannot do
    801807        # something like (f < 0.0) ? -999 : -2.5*log10(f)
    802808        # as a result, the negative fluxes here result in floating point errors
    803         sql = "UPDATE StackObject SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
    804         self.scratchDb.execute(sql)
    805        
    806         sql = "UPDATE StackObject SET apFlux = 1e20 WHERE apFlux <= 0.0"
    807         self.scratchDb.execute(sql)
    808 
    809         sql = "UPDATE StackObject SET kronFlux = 1e20 WHERE kronFlux <= 0.0"
     809        sql = "UPDATE StackObject SET gPSFFlux = 1e20 WHERE gPSFFlux <= 0.0"
     810        self.scratchDb.execute(sql)
     811       
     812        sql = "UPDATE StackObject SET gApFlux = 1e20 WHERE gApFlux <= 0.0"
     813        self.scratchDb.execute(sql)
     814
     815        sql = "UPDATE StackObject SET gKronFlux = 1e20 WHERE gKronFlux <= 0.0"
     816        self.scratchDb.execute(sql)
     817        sql = "UPDATE StackObject SET rPSFFlux = 1e20 WHERE rPSFFlux <= 0.0"
     818        self.scratchDb.execute(sql)
     819       
     820        sql = "UPDATE StackObject SET rApFlux = 1e20 WHERE rApFlux <= 0.0"
     821        self.scratchDb.execute(sql)
     822
     823        sql = "UPDATE StackObject SET rKronFlux = 1e20 WHERE rKronFlux <= 0.0"
     824        self.scratchDb.execute(sql)
     825        sql = "UPDATE StackObject SET iPSFFlux = 1e20 WHERE iPSFFlux <= 0.0"
     826        self.scratchDb.execute(sql)
     827       
     828        sql = "UPDATE StackObject SET iApFlux = 1e20 WHERE iApFlux <= 0.0"
     829        self.scratchDb.execute(sql)
     830
     831        sql = "UPDATE StackObject SET iKronFlux = 1e20 WHERE iKronFlux <= 0.0"
     832        self.scratchDb.execute(sql)
     833        sql = "UPDATE StackObject SET zPSFFlux = 1e20 WHERE zPSFFlux <= 0.0"
     834        self.scratchDb.execute(sql)
     835       
     836        sql = "UPDATE StackObject SET zApFlux = 1e20 WHERE zApFlux <= 0.0"
     837        self.scratchDb.execute(sql)
     838
     839        sql = "UPDATE StackObject SET zKronFlux = 1e20 WHERE zKronFlux <= 0.0"
     840        self.scratchDb.execute(sql)
     841        sql = "UPDATE StackObject SET yPSFFlux = 1e20 WHERE yPSFFlux <= 0.0"
     842        self.scratchDb.execute(sql)
     843       
     844        sql = "UPDATE StackObject SET yApFlux = 1e20 WHERE yApFlux <= 0.0"
     845        self.scratchDb.execute(sql)
     846
     847        sql = "UPDATE StackObject SET yKronFlux = 1e20 WHERE yKronFlux <= 0.0"
    810848        self.scratchDb.execute(sql)
    811849
Note: See TracChangeset for help on using the changeset viewer.