Changeset 37551 for trunk/ippToPsps
- Timestamp:
- Nov 3, 2014, 2:41:20 PM (12 years ago)
- Location:
- trunk/ippToPsps
- Files:
-
- 2 added
- 8 edited
-
config/ippToPspsDbSchema.sql (modified) (1 diff)
-
jython/Makefile.am (modified) (1 diff)
-
jython/batch.py (modified) (1 diff)
-
jython/detectionbatch.py (modified) (1 diff)
-
jython/dvoforceddetections.py (added)
-
jython/dvoforcedobjects.py (added)
-
jython/forcedobjectbatch.py (modified) (1 diff)
-
jython/forcedwarpbatch.py (modified) (1 diff)
-
jython/gpc1db.py (modified) (2 diffs)
-
jython/ipptopspsdb.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/config/ippToPspsDbSchema.sql
r37246 r37551 189 189 SET character_set_client = @saved_cs_client; 190 190 -- 191 -- Table structure for table `forcedobject` 192 -- 193 194 DROP TABLE IF EXISTS `forcedobject`; 195 SET @saved_cs_client = @@character_set_client; 196 SET character_set_client = utf8; 197 CREATE TABLE `forcedobject` ( 198 `batch_id` bigint(20) unsigned NOT NULL, 199 `region` varchar(50) default NULL, 200 KEY `batch_id` (`batch_id`), 201 CONSTRAINT `diffobject_fk_1` FOREIGN KEY (`batch_id`) REFERENCES `batch` (`batch_id`) 202 ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 203 SET character_set_client = @saved_cs_client; 204 205 -- 191 206 -- Table structure for table `diffobject` 192 207 -- -
trunk/ippToPsps/jython/Makefile.am
r37246 r37551 14 14 diffobjectbatch.py \ 15 15 dvodetections.py \ 16 dvoforceddetections.py \ 17 dvoforcedobjects.py \ 16 18 dvoobjects.py \ 17 19 dvo.py \ -
trunk/ippToPsps/jython/batch.py
r37246 r37551 579 579 # for OB, this imports object data from DVO 580 580 if not self.importIppTables(): 581 if self.batchType == "OB":581 if (self.batchType == "OB" or self.batchType =="DO" or self.batchType =="FO"): 582 582 self.logger.errorPair("skipping this batch", "no dvo tables for this region") 583 583 self.ippToPspsDb.updateProcessed(self.batchID, 1) -
trunk/ippToPsps/jython/detectionbatch.py
r37355 r37551 214 214 sqlLine.group("completMag", self.getKeyFloat(header, "%.8f", 'FLIMIT')) 215 215 sqlLine.group("astroScat", self.getKeyFloat(header, "%.8f", 'CERROR')) 216 sqlLine.group("photoScat", self.getKeyFloat(self.header, "%.8f", 'ZPT_ OBS'))216 sqlLine.group("photoScat", self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR')) 217 217 sqlLine.group("numAstroRef", self.getKeyValue(header, 'NASTRO')) 218 218 sqlLine.group("numPhotoRef", self.getKeyValue(header, 'NASTRO')) -
trunk/ippToPsps/jython/forcedobjectbatch.py
r36697 r37551 1 #!/usr/bin/env jython 2 3 import os.path 4 import sys 5 6 import stilts 7 from java.lang import * 8 from java.sql import * 9 10 from xml.etree.ElementTree import ElementTree, Element, tostring 11 12 from batch import Batch 13 from gpc1db import Gpc1Db 14 from ipptopspsdb import IppToPspsDb 15 from scratchdb import ScratchDb 16 from dvoforcedobjects import DvoForcedObjects # need one specific for cpy ? 17 from sqlUtility import sqlUtility 18 19 import logging.config 20 21 ''' 22 ForcedObjectBatch class 23 24 This class, a sub-class of Batch, processes individual DVO region file pairs (cpt, cpy, and cps files). The cpt file contains a list of all objects in that region, the cps file contains the magnitudes and so has a row per filter per object (so, generally, has rows = 5 x number of objects). The Photcode.dat table us used to figure out the number and order of filters as they appear in the cps file. 25 26 ''' 27 class ForcedMeanObjectBatch(Batch): 28 29 ''' 30 Constructor 31 ''' 32 def __init__(self, 33 logger, 34 config, 35 skychunk, 36 gpc1Db, 37 ippToPspsDb, 38 scratchDb, 39 dvoID, 40 batchID): 41 42 super(ForcedMeanObjectBatch, self).__init__( 43 logger, 44 config, 45 skychunk, 46 gpc1Db, 47 ippToPspsDb, 48 scratchDb, 49 dvoID, 50 batchID, 51 "FO", 52 None) 53 54 try: 55 self.dvoForcedObjects = DvoForcedObjects(self.logger, self.config, self.skychunk, self.ippToPspsDb, self.scratchDb) 56 except: 57 self.logger.errorPair("Unable to create instance of", "DvoForcedObjects") 58 raise 59 60 # create an output filename, which is {dvoINDEX}.FITS 61 self.outputFitsFile = "%08d.FITS" % self.id 62 self.outputFitsPath = "%s/%s" % (self.localOutPath, self.outputFitsFile) 63 64 # dump stuff to log 65 self.logger.infoPair("DVO INDEX", "%d" % self.id) 66 67 ''' 68 Overriden from batch base-class. We import from DVO directly for forced mean objects 69 ''' 70 def importIppTables(self, columns="*", filter=""): 71 72 self.region = self.scratchDb.getRegionNameFromThisDvoIndex(self.id) 73 self.ippToPspsDb.insertForcedMeanObjectMeta(self.batchID, self.region) 74 self.dvoForcedObjects.nativeIngestRegion(self.region) 75 76 cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt") 77 78 if not self.scratchDb.tableExists(cptTableName): 79 self.logger.infoPair("can't find in scratch db:","cpt table") 80 return False 81 82 cpyTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpy") 83 84 if not self.scratchDb.tableExists(cpyTableName): 85 self.logger.infoPair("can't find in scratch db:","cpy table") 86 return False 87 88 return True 89 90 ''' 91 Applies indexes to the PSPS tables 92 ''' 93 def alterPspsTables(self): 94 95 return True 96 97 ''' 98 Applies indexes to the IPP tables 99 ''' 100 def indexIppTables(self): 101 102 # since dvopsps is now used, no action is needed here 103 # self.logger.infoPair("Creating indexes on", "IPP tables") 104 105 return True 106 107 ''' 108 Inserts stuff for all mags 109 ''' 110 def updateForcedMeanObjectFromCps(self, cpsTable): 111 112 # list of all filters PSPS is interested in 113 # XXX EAM : 2014.07.24 : this list should probably be in a config file somewhere 114 interestedFilters = ['g', 'r', 'i', 'z', 'y'] 115 116 filters = self.scratchDb.getOrderedListOfFiltersFromPhotcodesTable(interestedFilters) 117 118 # get a count of the available filters 119 filterCount = self.scratchDb.getCountOfFiltersFromPhotcodesTable() 120 121 self.logger.infoPair("Available filters in Photcodes", filters) 122 123 # the 'code' now defines the order in the cps file that the mags are listed for a given filter 124 self.logger.infoPair("Adding magnitudes from", "cps table") 125 for filter in filters: 126 127 filterID = self.scratchDb.getFilterID(filter[1]) 128 129 # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000) 130 # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags 131 # XXX EAM : 20140724 this manipulation is no longer needed : [grizy]Flags is now 4 byte (was 8 byte!) 132 133 # set the MeanObject fields based largely on dvopsps cps fields: 134 135 # XXX EAM 20140724 : filterCount is meant to match 136 # Nsecfilt, but is potentially not determined correctly. 137 # use a call to a dvo-native command which knows how to 138 # find Nsecfilt (or save in the db with dvopsps) 139 140 # the math below depends on filterCount = Nsecfilt and MeanObject.row being 1 counting but cps being 0 counting? 141 # cps.row has a count of MeanObject.row * Nsecfilt + Nfilter 142 # " + cpsTable + " AS cps ON (cps.row = (MeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \ 143 144 sql = "UPDATE ForcedMeanObject JOIN \ 145 " + cpsTable + " AS cps ON (cps.row = (ForcedMeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \ 146 SET \ 147 ForcedMeanObject." + filter[1] + "nTotal = NWARP \ 148 ,ForcedMeanObject." + filter[1] + "nIncPSFMag = NUSED_WRP \ 149 ,ForcedMeanObject." + filter[1] + "nIncKronMag = NUSED_KRON_WRP \ 150 ,ForcedMeanObject." + filter[1] + "nIncApMag = NUSED_AP_WRP \ 151 ,ForcedMeanObject." + filter[1] + "PSFMag = MAG_PSF_WRP \ 152 ,ForcedMeanObject." + filter[1] + "PSFMagErr = MAG_PSF_WRP_ERR \ 153 ,ForcedMeanObject." + filter[1] + "PSFMagStd = MAG_PSF_WRP_STD \ 154 ,ForcedMeanObject." + filter[1] + "KronMag = MAG_KRON_WRP \ 155 ,ForcedMeanObject." + filter[1] + "KronMagErr = MAG_KRON_WRP_ERR \ 156 ,ForcedMeanObject." + filter[1] + "KronMagStd = MAG_KRON_WRP_STD \ 157 ,ForcedMeanObject." + filter[1] + "ApMag = MAG_AP_WRP \ 158 ,ForcedMeanObject." + filter[1] + "ApMagErr = MAG_AP_WRP_ERR \ 159 ,ForcedMeanObject." + filter[1] + "ApMagStd = MAG_AP_WRP_STD \ 160 ,ForcedMeanObject." + filter[1] + "Flags = FLAGS " 161 162 163 try: self.scratchDb.execute(sql) 164 except: 165 self.logger.errorPair("failed update MeanObject", sql) 166 raise 167 168 # now set to null all MeanMagErr values > 0.5 (cut set by Gene, 2012-04-12) 169 # XXX EAM 20140724 : keep this cut? 170 cut = 0.5 171 self.logger.infoPair("Setting to NULL all MeanMagErr value >", "%f" % cut) 172 for filter in filters: 173 174 sql = "UPDATE ForcedMeanObject \ 175 SET " + filter[1] + "PSFMagErr = null \ 176 WHERE " + filter[1] + "PSFMagErr > " + str(cut) 177 self.scratchDb.execute(sql) 178 179 self.logger.infoPair("Calculating nDetections from", "n[filters]") 180 for filter in filters: 181 # now do a sum of n[filters], but do not include the ones with -999 182 sql = "UPDATE ObjectThin " 183 sql += "SET nDetections = nDetections + n" + filter[1] 184 sql += " WHERE n" + filter[1] + " != -999" 185 self.scratchDb.execute(sql) 186 187 ''' 188 Inserts stuff for all mags from the cpy files 189 ''' 190 def updateForcedMeanObjectFromCpy(self, cpyTable): 191 192 # list of all filters PSPS is interested in 193 # XXX EAM : 2014.07.24 : this list should probably be in a config file somewhere 194 interestedFilters = ['g', 'r', 'i', 'z', 'y'] 195 196 filters = self.scratchDb.getOrderedListOfFiltersFromPhotcodesTable(interestedFilters) 197 198 # get a count of the available filters 199 filterCount = self.scratchDb.getCountOfFiltersFromPhotcodesTable() 200 201 self.logger.infoPair("Available filters in Photcodes", filters) 202 203 # the 'code' now defines the order in the cps file that the mags are listed for a given filter 204 self.logger.infoPair("Adding magnitudes from", "cpy table") 205 for filter in filters: 206 207 filterID = self.scratchDb.getFilterID(filter[1]) 208 209 # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000) 210 # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags 211 # XXX EAM : 20140724 this manipulation is no longer needed : [grizy]Flags is now 4 byte (was 8 byte!) 212 213 # set the MeanObject fields based largely on dvopsps cps fields: 214 215 # XXX EAM 20140724 : filterCount is meant to match 216 # Nsecfilt, but is potentially not determined correctly. 217 # use a call to a dvo-native command which knows how to 218 # find Nsecfilt (or save in the db with dvopsps) 219 220 # the math below depends on filterCount = Nsecfilt and MeanObject.row being 1 counting but cps being 0 counting? 221 # cps.row has a count of MeanObject.row * Nsecfilt + Nfilter 222 # " + cpsTable + " AS cps ON (cps.row = (MeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \ 223 224 sql = "UPDATE ForcedMeanObject JOIN \ 225 " + cpyTable + " AS cpy ON (cpy.row = (ForcedMeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \ 226 SET \ 227 ForcedMeanObject." + filter[1] + "nIncR5 = NMEAS \ 228 ,ForcedMeanObject." + filter[1] + "nIncR6 = NMEAS \ 229 ,ForcedMeanObject." + filter[1] + "FmeanflxR5 = FLUX_AP_R5 \ 230 ,ForcedMeanObject." + filter[1] + "FmeanflxR5Err = FLUX_ERR_AP_R5 \ 231 ,ForcedMeanObject." + filter[1] + "FmeanflxR5Std = FLUX_STD_AP_R5 \ 232 ,ForcedMeanObject." + filter[1] + "FmeanflxR5Fill = FLUX_FIL_AP_R5 \ 233 ,ForcedMeanObject." + filter[1] + "FmeanflxR6 = FLUX_AP_R6 \ 234 ,ForcedMeanObject." + filter[1] + "FmeanflxR6Err = FLUX_ERR_AP_R6 \ 235 ,ForcedMeanObject." + filter[1] + "FmeanflxR6Std = FLUX_STD_AP_R6 \ 236 ,ForcedMeanObject." + filter[1] + "FmeanflxR6Fill = FLUX_FIL_AP_R6 \ 237 ,ForcedMeanObject." + filter[1] + "LensObjSmearX11 = X11_SM_OBJ \ 238 ,ForcedMeanObject." + filter[1] + "LensObjSmearX12 = X12_SM_OBJ \ 239 ,ForcedMeanObject." + filter[1] + "LensObjSmearX22 = X22_SM_OBJ \ 240 ,ForcedMeanObject." + filter[1] + "LensObjSmearE1 = E1_SM_OBJ \ 241 ,ForcedMeanObject." + filter[1] + "LensObjSmearE2 = E2_SM_OBJ \ 242 ,ForcedMeanObject." + filter[1] + "LensObjShearX11 = X11_SH_OBJ \ 243 ,ForcedMeanObject." + filter[1] + "LensObjShearX12 = X12_SH_OBJ \ 244 ,ForcedMeanObject." + filter[1] + "LensObjShearX22 = X22_SH_OBJ \ 245 ,ForcedMeanObject." + filter[1] + "LensObjShearE1 = E1_SH_OBJ \ 246 ,ForcedMeanObject." + filter[1] + "LensObjShearE2 = E2_SH_OBJ \ 247 ,ForcedMeanObject." + filter[1] + "LensPSFSmearX11 = X11_SM_PSF \ 248 ,ForcedMeanObject." + filter[1] + "LensPSFSmearX12 = X12_SM_PSF \ 249 ,ForcedMeanObject." + filter[1] + "LensPSFSmearX22 = X22_SM_PSF \ 250 ,ForcedMeanObject." + filter[1] + "LensPSFSmearE1 = E1_SM_PSF \ 251 ,ForcedMeanObject." + filter[1] + "LensPSFSmearE2 = E2_SM_PSF \ 252 ,ForcedMeanObject." + filter[1] + "LensPSFShearX11 = X11_SH_PSF \ 253 ,ForcedMeanObject." + filter[1] + "LensPSFShearX12 = X12_SH_PSF \ 254 ,ForcedMeanObject." + filter[1] + "LensPSFShearX22 = X22_SH_PSF \ 255 ,ForcedMeanObject." + filter[1] + "LensPSFShearE1 = E1_SH_PSF \ 256 ,ForcedMeanObject." + filter[1] + "LensPSFShearE2 = E2_SH_PSF \ 257 ,ForcedMeanObject." + filter[1] + "Gamma = GAMMA \ 258 ,ForcedMeanObject." + filter[1] + "E1 = E1 \ 259 ,ForcedMeanObject." + filter[1] + "E2 = E2 " 260 261 262 try: self.scratchDb.execute(sql) 263 except: 264 self.logger.errorPair("failed update on ForcedMeanObject using cpy table", sql) 265 raise 266 267 268 ''' 269 Populates the ForcedMeanObject table 270 ''' 271 def populateForcedMeanObjectTable(self): 272 273 cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt") 274 cpsTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cps") 275 cpyTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpy") 276 277 278 self.logger.info("Populating ForcedMeanObject") 279 self.logger.info("Inserting objects from cpt file") 280 281 # note "dec" is a reserved word in MySQL 282 # XXX EAM 20140724 : do not use INGORE unless we discover unavoidable problems... 283 # INSERT IGNORE INTO ObjectThin 284 285 sqlLine = sqlUtility("INSERT INTO ForcedMeanObject (") 286 287 sqlLine.group("objID", "EXT_ID") 288 sqlLine.group("ippObjID", "OBJ_ID + (CAT_ID << 32)") # NOTE: shift by 32 bits exactly 289 sqlLine.group("batchID", "'" + str(self.batchID) + "'") 290 sqlLine.group("nDetections", "'0'") 291 sql = sqlLine.makeRaw(") SELECT ", " FROM " + cptTableName) 292 293 try: 294 self.scratchDb.execute(sql) 295 except: 296 self.logger.errorPair("Couldn't populate Object table from cpt", sql) 297 return False 298 299 # add row count columns so we can perform joins to get colors 300 self.logger.infoPair("Adding 'row' columns to", "Object and cps tables") 301 self.scratchDb.addRowCountColumn("ForcedMeanObject", "row") 302 self.scratchDb.addRowCountColumn(cpsTableName, "row") 303 304 305 self.logger.infoPair("update ForcedMeanObject from ","cps table") 306 307 self.updateForcedMeanObjectFromCps(cpsTableName) 308 309 self.logger.infoPair("update ForcedMeanObject from ","cpy table") 310 311 self.updateForcedMeanObjectFromCpy(cpyTableName) 312 313 314 self.logger.infoPair("Dropping row column from", "ForcedMeanObject table") 315 self.scratchDb.dropColumn("ForcedMeanObject", "row") 316 317 ##self.logger.infoPair("Purging from scratch Db", self.region + " region") 318 319 ##Don't do this till after MeanObject 320 ##self.dvoForcedObjects.purgeRegion(self.region) 321 322 self.setMinMaxObjID(["ForcedMeanObject"]) 323 324 return True 325 326 327 ''' 328 Does the processing, i.e. pulling stuff from IPP tables into PSPS tables 329 ''' 330 def populatePspsTables(self): 331 332 if not self.populateForcedMeanObjectTable(): return False 333 334 # now remove the objID duplicates. We could not do this before as cpt/cps tables relate by row number 335 self.logger.infoPair("Forcing uniqueness on", "objID in ForcedMeanObject table") 336 rowCountBefore = self.scratchDb.getRowCount("ForcedMeanObject") 337 338 # XXX EAM : note that in mysql versions later than 5.1, this fails 339 # unless the following is called first: 340 # set session old_alter_table=1 341 # follow the command with 342 # set session old_alter_table=0 343 # OF COURSE, this fails for mysql version < 5.5... 344 if self.scratchDb.version > 5.1: 345 self.scratchDb.execute("set session old_alter_table=1") 346 347 self.scratchDb.execute("ALTER IGNORE TABLE ForcedMeanObject ADD UNIQUE INDEX(objID)") 348 if self.scratchDb.version > 5.1: 349 self.scratchDb.execute("set session old_alter_table=0") 350 351 rowCountAfter = self.scratchDb.getRowCount("ForcedMeanObject") 352 self.logger.infoPair("Number of duplicated objIDs removed", "%d out of %d" % ((rowCountBefore - rowCountAfter), rowCountBefore)) 353 354 self.dvoForcedObjects.purgeRegion(self.region) 355 356 #this is abuse of something but this is how I get the object batches to crash to further investigate them 357 358 # rowCountAfter = self.scratchDb.getRowCount("Object") 359 return True 360 # return False -
trunk/ippToPsps/jython/forcedwarpbatch.py
r36697 r37551 1 #!/usr/bin/env jython 2 3 import os.path 4 import sys 5 import glob 6 import time 7 import stilts 8 9 from java.lang import * 10 from java.sql import * 11 12 from java.lang import Math 13 from org.apache.commons.math.special import Erf 14 15 from xml.etree.ElementTree import ElementTree, Element, tostring 16 17 from batch import Batch 18 from gpc1db import Gpc1Db 19 from ipptopspsdb import IppToPspsDb 20 from scratchdb import ScratchDb 21 from sqlUtility import sqlUtility 22 23 import logging.config 24 25 26 ''' 27 ForcedWarpBatch class 28 29 This class, a sub-class of Batch, processes single exposures in the form of IPP smf files 30 31 ''' 32 class ForcedWarpBatch(Batch): 33 34 ''' 35 Constructor 36 ''' 37 def __init__(self, 38 logger, 39 config, 40 skychunk, 41 gpc1Db, 42 ippToPspsDb, 43 scratchDb, 44 forcedWarpID, 45 batchID): 46 47 super(ForcedWarpBatch, self).__init__( 48 logger, 49 config, 50 skychunk, 51 gpc1Db, 52 ippToPspsDb, 53 scratchDb, 54 forcedWarpID, 55 batchID, 56 "P2", 57 gpc1Db.getForcedWarpStageSmf(forcedWarpID) 58 59 # get camera meta data 60 meta = self.gpc1Db.getForcedWarpStageMeta(self.id) 61 if not meta: 62 self.logger.errorPair("Could not get", "forced warp metadata") 63 raise 64 65 self.expID = meta[0]; 66 self.expName = meta[1]; 67 self.distGroup = meta[2]; 68 self.analysisVer = meta[3]; 69 self.bias = meta[4]; 70 self.biasScat = meta[5]; 71 72 if not self.analysisVer: self.analysisVer = -999 73 74 # create an output filename, which is {expID}.FITS 75 self.outputFitsFile = "%08d.FITS" % self.expID 76 self.outputFitsPath = "%s/%s" % (self.localOutPath, self.outputFitsFile) 77 self.dropTableVerbose("ForcedWarpMeasurement") 78 self.dropTableVerbose("ForcedWarpExtended") 79 self.dropTableVerbose("ForcedWarpMeta") 80 self.dropTableVerbose("ForcedWarpToImage") 81 if not self.config.retry: 82 self.scratchDb.dropTable("ForcedWarpMeasurement") 83 self.scratchDb.dropTable("ForcedWarpExtended") 84 self.scratchDb.dropTable("ForcedWarpMeta") 85 self.scratchDb.dropTable("ForcedWarpToImage") 86 self.historyModNum = "0" 87 88 # get a few primary header values. if in test mode, then use defaults 89 if self.safeDictionaryAccessWithDefault(self.header, 'MJD-OBS', "1") == "NULL": 90 self.logger.errorPair("Could not get", "MJD-OBS") 91 raise 92 93 94 if self.safeDictionaryAccessWithDefault(self.header, 'EXPTIME', "1") == "NULL": 95 self.logger.errorPair("Could not get", "EXPTIME") 96 raise 97 98 if self.safeDictionaryAccessWithDefault(self.header, 'FILTERID', "g.0000") == "NULL": 99 self.logger.errorPair("Could not get", "FILTERID") 100 raise 101 102 # MJD-OBS is the exposure start, EXTIME / 172800 = (EXPTIME sec / 84600 sec/day) / 2 103 self.obsTime = float(self.header['MJD-OBS']) + (float(self.header['EXPTIME']) / 172800.0) 104 105 # set up some defauts 106 self.calibModNum = 0 107 self.totalNumPhotoRef = 0 108 109 110 self.filter = self.header['FILTERID'][0:1] 111 self.filterID = self.scratchDb.getFilterID(self.filter) 112 113 # insert what we know about this stack batch into the stack table 114 self.ippToPspsDb.insertDetectionMeta(self.batchID, self.expID, self.filter) 115 116 # dump stuff to log 117 self.logger.infoPair("Cam ID", "%d" % self.id) 118 self.logger.infoPair("Exp ID", "%d" % self.expID) 119 self.logger.infoPair("Exp name", "%s" % self.expName) 120 self.logger.infoPair("Distribution group", "%s" % self.distGroup) 121 122 123 124 125 ''' 126 Populates the FrameMeta table, mainly from dictionary values found in IPP FITS header 127 ''' 128 def populateForcedWarpMeta(self): 129 self.logger.infoPair("Processing table", "ForcedWarpMeta") 130 131 photoCalID = str(self.scratchDb.getPhotoCalID(forcedWarpID)) 132 133 134 sqlLine = sqlUtility("INSERT INTO ForcedWarpMeta (") 135 #batchID (below) 136 #surveyID (below) 137 #filterdID (below) 138 sqlLine.group("skyCellID", str(self.skycellID)) 139 sqlLine.group("photoCalID", photoCalID) 140 sqlLine.group("magSat", self.getKeyFloat(header, "%.8f", 'FSATUR')) 141 sqlLine.group("analVer", self.analysisVer); 142 sqlLine.group("expTime", self.getKeyFloat(self.header, "%.8f", 'EXPREQ')); 143 sqlLine.group("completMag", self.getKeyFloat(header, "%.8f", 'FLIMIT')) 144 sqlLine.group("astroScat", self.getKeyFloat(header, "%.8f", 'CERROR')) 145 sqlLine.group("photoScat", self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR')); 146 sqlLine.group("nAstroRef", self.getKeyValue(header, 'NASTRO')) 147 sqlLine.group("nPhotoRef", self.getKeyValue(header, 'NASTRO')) 148 sqlLine.group("psfModelID", self.getKeyValue(header, 'PSFMODEL')) 149 sqlLine.group("psfFwhm_mean", self.getKeyFloat(header, "%.8f", 'FWHM_MAJ')) 150 sqlLine.group("psfFwhm_max", self.getKeyFloat(header, "%.8f", 'FW_MJ_UQ')) 151 sqlLine.group("photoZero", self.getKeyFloat(self.header, "%.8f", 'ZPT_OBS')) 152 #photoColor -- how do I set this? it's also not set in stack meta 153 sqlLine.group("ctype1", self.getKeyValue(self.header, 'CTYPE1')); 154 sqlLine.group("ctype2", self.getKeyValue(self.header, 'CTYPE2')); 155 sqlLine.group("crval1", self.getKeyFloat(self.header, "%.8f", 'CRVAL1')); 156 sqlLine.group("crval2", self.getKeyFloat(self.header, "%.8f", 'CRVAL2')); 157 sqlLine.group("crpix1", self.getKeyFloat(self.header, "%.8f", 'CRPIX1')); 158 sqlLine.group("crpix2", self.getKeyFloat(self.header, "%.8f", 'CRPIX2')); 159 sqlLine.group("cdelt1", self.getKeyFloat(self.header, "%.8e", 'CDELT1')); 160 sqlLine.group("cdelt2", self.getKeyFloat(self.header, "%.8e", 'CDELT2')); 161 sqlLine.group("pc001001", self.getKeyFloat(self.header, "%.8e", 'PC001001')); 162 sqlLine.group("pc001002", self.getKeyFloat(self.header, "%.8e", 'PC001002')); 163 sqlLine.group("pc002001", self.getKeyFloat(self.header, "%.8e", 'PC002001')); 164 sqlLine.group("pc002002", self.getKeyFloat(self.header, "%.8e", 'PC002002')); 165 166 167 sql = sqlLine.make(") VALUES ( ", ")") 168 169 try: self.scratchDb.execute(sql) 170 except: 171 self.logger.errorPair('failed sql: ', sql) 172 raise 173 174 self.scratchDb.updateAllRows("ForcedWarpMeta", "batchID", str(self.batchID)) 175 self.scratchDb.updateAllRows("ForcedWarpMeta", "surveyID", str(self.surveyID)) 176 self.scratchDb.updateFilterID("ForcedWarpMeta", self.filter) 177 self.scratchDb.updateAllRows("ForcedWarpMeta", "calibModNum", str(self.calibModNum)) 178 self.scratchDb.updateAllRows("ForcedWarpMeta", "dataRelease", str(self.skychunk.dataRelease)) 179 self.tablesToExport.append("ForcedWarpMeta") 180 181 ''' 182 Populates the ForcedWarpToImage table 183 ''' 184 def populateForcedWarpToImage(self): 185 186 self.logger.infoPair("Procesing table", "ForcedWarpToImage") 187 188 for filter in self.filters: 189 190 forcedwarpID = self.forcedwarpID 191 if forcedwarpID > 0: 192 193 imageIDs = self.gpc1Db.getImageIDsForThisForcedWarpID(forcedwarpID) 194 195 for imageID in imageIDs: 196 197 sql = "INSERT INTO ForcedWarpToImage (forcedwarpID, imageID) \ 198 VALUES (\ 199 " + str(forcedwarpID) + ", " + imageID + ")" 200 self.scratchDb.execute(sql) 201 202 # now update StackMeta with correct number of inputs 203 204 self.tablesToExport.append("ForcedWarpToImage") 205 206 207 208 209 210 ''' 211 Populates the ForcedWarpMeasurement table 212 ''' 213 def populateForcedWarpMeasurementTable(self, results): 214 215 pspsTableName = "ForcedWarpMeasurement" 216 ippTableName = "ForcedWarpMeasurement_psf" 217 218 219 self.logger.infoPair("Procesing table", "ForcedWarpMeasurement") 220 221 # insert the per-object data (IDs, random stack ID, dataRelease, etc) 222 self.selectDvoObjIDs() 223 224 self.generateRandomIDs() 225 226 # add indexes ForcedWarpMeasurement 227 self.scratchDb.createIndex("ForcedWarpMeasurement", "objID") 228 229 230 231 232 233 234 235 236 237 self.tablesToExport.append("ForcedWarpMeasurement") 238 239 240 ''' 241 Populates the ForcedWarpExtended table 242 ''' 243 def populateForcedWarpExtendedTable(self, results): 244 245 pspsTableName = "ForcedWarpExtended" 246 ippTableName = "ForcedWarpExtended_psf" 247 248 249 self.tablesToExport.append("ForcedWarpExtended") 250 251 252 ''' 253 Does the processing, i.e. pulling stuff from IPP tables into PSPS tables 254 ''' 255 def populatePspsTables(self): 256 self.logger.infoPair("starting","populatePspsTables"); 257 self.skipBatch = False 258 # each of the "populate*" methods below add their tables to the list: 259 self.tablesToExport=[] 260 261 #this should be done 262 self.populateForcedWarpMeta() 263 264 self.populateForcedWarpMeasurement() 265 self.populateForcedWarpExtended() 266 self.populateForcedWarpToImage() 267 268 self.setMinMaxObjID(["ForcedWarpMeasurement"]) 269 270 self.logger.infoPair("finishing","populatePspsTables"); 271 return True 272 273 274 275 ''' 276 This function reads the cmf/smf file and loads it into the database as its own table 277 ''' 278 def importIppTables(self, columns="*", tableRE=""): 279 280 if self.config.retry: return True 281 self.logger.infoPair("Importing FW tables with table match expression: ", tableRE) 282 fileName = self.fits.getPath() 283 284 self.logger.infoPair("using filename:",fileName) 285 286 try: 287 tables = stilts.treads(fileName) 288 except: 289 self.logger.errorPair("STILTS could not import from", fileName) 290 return False 291 for table in tables: 292 293 match = re.match(tableRE, table.name) 294 if not match: continue 295 self.logger.infoPair("Reading IPP table", table.name) 296 table = stilts.tpipe(table, cmd='addcol table_index $0') 297 table = stilts.tpipe(table, cmd='explodeall') 298 299 # drop any previous tables before import 300 self.scratchDb.dropTable(table.name) 301 302 # IPP FITS files are littered with infinities, so remove these 303 self.logger.info("Removing Infinity values from all columns") 304 table = stilts.tpipe(table, cmd='keepcols "' + columns + '"') 305 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 306 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 307 308 try: 309 table.write(self.scratchDb.url + '#' + table.name) 310 count = count + 1 311 except: 312 self.logger.exception("Problem writing table '" + table.name + "' to the database") 313 314 self.logger.infoPair("Done. Imported", "%d tables" % count) 315 self.indexIppTables() 316 317 return True 318 319 320 321 322 323 324 325 326 327 def generateRandomIDs(self): 328 sql = "UPDATE ForcedWarpMeasurement set randomWarpID = FLOOR(RAND()*9223372036854775807)"; 329 try: self.scratchDb.execute(sql) 330 except: 331 self.logger.errorPair('failed sql',sql) 332 return 333 334 335 336 337 338 339 340 341 342 def exportPspsTablesToFits(self, regex="(.*)"): 343 return super(DetectionBatch, self).exportPspsTablesToFits("(ForcedWarp.*)") -
trunk/ippToPsps/jython/gpc1db.py
r37246 r37551 116 116 117 117 stage = "forcedwarp" 118 sql = "SELECT differentStuff from Stufftable" 118 sql = "SELECT DISTINCT sky_id, radeg, decdeg FROM fullForceInput \ 119 JOIN addRun ON(fullForceInput.ff_id = addRun.stage_id, fullForceInput.warp_id = addRun.stage_extra1) \ 120 JOIN minidvodbRun USING(minidvodb_name) \ 121 JOIN minidvodbProcessed USING(minidvodb_id) \ 122 JOIN mergedvodbRun USING(minidvodb_id) \ 123 JOIN mergedvodbProcessed USING (merge_id) \ 124 JOIN fullForceRun USING(ff_id) \ 125 JOIN skycalRun using (skycal_id) 126 JOIN stackRun USING(stack_id) \ 127 JOIN stackSumSkyfile using (stack_id) \ 128 JOIN skycell USING(skycell_id) \ 129 WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 130 AND minidvodbRun.state = 'merged' \ 131 AND minidvodbProcessed.fault = 0 \ 132 AND mergedvodbRun.state = 'full' \ 133 AND mergedvodbProcessed.fault = 0 \ 134 AND addRun.stage = '" + stage + "' \ 135 AND addRun.state = 'full' \ 136 AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \ 137 AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 138 AND mjd_obs >= (to_days('" + tstart + "')-678941) \ 139 AND mjd_obs <= (to_days('" + tend + "') - 678941) " 119 140 120 141 try: … … 165 186 166 187 return imageIDs 188 189 190 191 192 167 193 168 194 ''' -
trunk/ippToPsps/jython/ipptopspsdb.py
r37246 r37551 756 756 757 757 self.execute(sql) 758 759 ''' 760 Inserts some forced detection metadata for this batch ID 761 ''' 762 def insertForcedWarpMeta(self, batchID, expID, filter): 763 764 sql = "INSERT INTO forcedwarp ( \ 765 batch_id \ 766 ,exp_id \ 767 ,filter \ 768 ) VALUES ( \ 769 " + str(batchID) + " \ 770 ," + str(expID) + " \ 771 ,'" + filter + "' \ 772 )" 773 774 self.execute(sql) 775 776 777 778 ''' 779 Inserts some forcedobject metadata for this batch ID 780 ''' 781 def insertForcedObjectMeta(self, batchID, region): 782 783 sql = "INSERT INTO forcedobject ( \ 784 batch_id \ 785 ,region \ 786 ) VALUES ( \ 787 " + str(batchID) + " \ 788 ,'" + region + "' \ 789 )" 790 791 self.execute(sql) 792 793 794 795 796 ''' 797 Inserts some diff metadata for this batch ID 798 ''' 799 def insertDiffMeta(self, batchID, filter, diffType): 800 801 sql = "INSERT INTO stack ( \ 802 batch_id \ 803 ,filter \ 804 ,diff_type \ 805 ) VALUES ( \ 806 " + str(batchID) + " \ 807 ,'" + filter + "' \ 808 ,'" + diffType + "')" 809 810 self.execute(sql) 811 812 813 814 815 ''' 816 Inserts some diffobject metadata for this batch ID 817 ''' 818 def insertDiffObjectMeta(self, batchID, region): 819 820 sql = "INSERT INTO diffobject ( \ 821 batch_id \ 822 ,region \ 823 ) VALUES ( \ 824 " + str(batchID) + " \ 825 ,'" + region + "' \ 826 )" 827 828 self.execute(sql) 829 830 831 832 833 834 758 835 ''' 759 836 Resets a batch ready for re-loading to the datastore
Note:
See TracChangeset
for help on using the changeset viewer.
