Changeset 37160
- Timestamp:
- Jul 31, 2014, 2:34:33 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140717/ippToPsps/jython
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140717/ippToPsps/jython/batch.py
r37138 r37160 242 242 243 243 if key in header: return header[key] 244 else: 245 self.logger.errorPair("Missing header field", key) 246 return "NULL" 247 248 ''' 249 Returns the string keyword value from this header or else "NULL" 250 ''' 251 def getKeyFloat(self, header, format, key): 252 253 if key in header: 254 value = format % float(header[key]) 255 return value 244 256 else: 245 257 self.logger.errorPair("Missing header field", key) -
branches/eam_branches/ipp-20140717/ippToPsps/jython/config.py
r37156 r37160 24 24 self.resetDvo = False 25 25 self.gpc1test = True 26 self.retry = False 27 self.camera = "gpc1" 26 28 27 29 if sys.argv.count("-test"): … … 47 49 sys.argv.remove("-reset-dvo") 48 50 51 if sys.argv.count("-retry"): 52 self.retry = True 53 sys.argv.remove("-retry") 54 55 if sys.argv.count("-simtest"): 56 self.camera = "simtest" 57 sys.argv.remove("-simtest") 58 49 59 print "test: " + str(self.test) 50 60 print "gpc1test: " + str(self.gpc1test) 51 61 print "resetDvo: " + str(self.resetDvo) 62 print "retry: " + str(self.retry) 63 print "camera: " + self.camera 52 64 53 65 for arg in sys.argv: -
branches/eam_branches/ipp-20140717/ippToPsps/jython/dvo.py
r37156 r37160 679 679 useP2 = 1 680 680 681 if (useP2 == 0 and useST ==1):681 if (useP2 == 0 and useST == 1): 682 682 # grab only stacks 683 if self.config.gpc1test:684 # gpc1test ->SIMTEST.x.SkyChip683 if (self.config.camera == "simtest"): 684 # SIMTEST.x.SkyChip 685 685 cmd += " -photcode-start 14100 -photcode-end 14500" 686 686 else: … … 688 688 cmd += " -photcode-start 11000 -photcode-end 11500" 689 689 690 if (useP2 == 1 and useST==0):691 # grab only P2s (4000-4500 are test cameras, SIMTEST and SIMMOSAIC)692 if self.config.gpc1test:693 # gpc1test ->SIMTEST.x.Chip690 if (useP2 == 1 and useST == 0): 691 # grab only P2s (4000-4500 are test cameras, SIMTEST and SIMMOSAIC) 692 if (self.config.camera == "simtest"): 693 # SIMTEST.x.Chip 694 694 cmd += " -photcode-start 4100 -photcode-end 4500" 695 695 else: -
branches/eam_branches/ipp-20140717/ippToPsps/jython/mysql.py
r37156 r37160 283 283 #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'") 284 284 285 def addPrimaryKeyWithIgnore(self, table, column) 285 def addPrimaryKeyWithIgnore(self, table, column): 286 286 # note that in mysql versions later than 5.1, this fails 287 287 # unless the following is called first: -
branches/eam_branches/ipp-20140717/ippToPsps/jython/stackbatch.py
r37156 r37160 103 103 104 104 if not (str(stackID) == header['IMAGEID']): 105 self.logger.errorPair("inconsistency: header IMAGEID does not match stackID", st ackID+ " vs " + header['IMAGEID'])105 self.logger.errorPair("inconsistency: header IMAGEID does not match stackID", str(stackID) + " vs " + header['IMAGEID']) 106 106 raise 107 107 … … 173 173 174 174 # delete IPP tables 175 self.logger.info("dropping Stack cmf tables") 176 for filter in self.filters: 177 tableName = filter + "SkyChip_psf" 178 self.scratchDb.dropTable(tableName) 179 tableName = filter + "SkyChip_xrad" 180 self.scratchDb.dropTable(tableName) 181 tableName = filter + "SkyChip_xsrc" 182 self.scratchDb.dropTable(tableName) 183 tableName = filter + "SkyChip_xfit" 184 self.scratchDb.dropTable(tableName) 175 if not self.config.retry: 176 self.logger.info("dropping Stack cmf tables") 177 for filter in self.filters: 178 tableName = filter + "SkyChip_psf" 179 self.scratchDb.dropTable(tableName) 180 tableName = filter + "SkyChip_xrad" 181 self.scratchDb.dropTable(tableName) 182 tableName = filter + "SkyChip_xsrc" 183 self.scratchDb.dropTable(tableName) 184 tableName = filter + "SkyChip_xfit" 185 self.scratchDb.dropTable(tableName) 185 186 186 187 # create an output filename, which is {stackID}.FITS … … 350 351 self.logger.infoPair("Populating table", tablename) 351 352 352 self.fwhm_maj = self.getKeyValue(header, 'FWHM_MAJ')353 self.fwhm_maj_uq = self.getKeyValue(header, 'FW_MJ_UQ')354 self.psfmodel = self.getKeyValue(header, 'PSFMODEL')355 356 if ( self.fwhm_maj == "NULL"): self.fwhm_maj = -999357 if ( self.fwhm_maj_uq == "NULL"): self.fwhm_maj_uq = -999353 fwhm_maj = self.getKeyValue(header, 'FWHM_MAJ') 354 fwhm_maj_uq = self.getKeyValue(header, 'FW_MJ_UQ') 355 psfmodel = self.getKeyValue(header, 'PSFMODEL') 356 357 if (fwhm_maj == "NULL"): fwhm_maj = -999 358 if (fwhm_maj_uq == "NULL"): fwhm_maj_uq = -999 358 359 359 360 # make a table … … 363 364 photoCalID = str(self.scratchDb.getPhotoCalID(stackID)) 364 365 365 # XXXmysql is sensitive to values which are ambiugously float. eg366 # mysql is sensitive to values which are ambiugously float. eg 366 367 # a warning is raised if we try to insert '25.' into a float field. 367 # I should make a function to sanitize float values to a desired number 368 # of decimal points 369 zpString = "%5.5f" % float(header['FPA.ZP']) 368 # use getKeyFloat(hdr, format, key) to avoid this problem 370 369 371 370 sql = "CREATE TABLE " + tablename + " LIKE StackMeta" … … 382 381 sqlLine.group("skyCellID", self.skycell) 383 382 sqlLine.group("photoCalID", photoCalID) 384 sqlLine.group("photoZero", zpString) # XXX see note above385 sqlLine.group("expTime", header['EXPTIME'])386 sqlLine.group("psfModelID", self.psfmodel)387 sqlLine.group("psfFwhm_mean", str(self.fwhm_maj))388 sqlLine.group("psfFwhm_max", str(self.fwhm_maj_uq))383 sqlLine.group("photoZero", self.getKeyFloat(header, "%.5f", 'FPA.ZP')) 384 sqlLine.group("expTime", self.getKeyFloat(header, "%.5f", 'EXPTIME')) 385 sqlLine.group("psfModelID", psfmodel) 386 sqlLine.group("psfFwhm_mean", fwhm_maj) 387 sqlLine.group("psfFwhm_max", fwhm_maj_uq) 389 388 sqlLine.group("ctype1", header['CTYPE1']) 390 389 sqlLine.group("ctype2", header['CTYPE2']) 391 sqlLine.group("crval1", header['CRVAL1'])392 sqlLine.group("crval2", header['CRVAL2'])393 sqlLine.group("crpix1", header['CRPIX1'])394 sqlLine.group("crpix2", header['CRPIX2'])395 sqlLine.group("cdelt1", header['CDELT1'])396 sqlLine.group("cdelt2", header['CDELT2'])397 sqlLine.group("pc001001", header['PC001001'])398 sqlLine.group("pc001002", header['PC001002'])399 sqlLine.group("pc002001", header['PC002001'])400 sqlLine.group("pc002002", header['PC002002'])390 sqlLine.group("crval1", self.getKeyFloat(header, "%.8f", 'CRVAL1')) 391 sqlLine.group("crval2", self.getKeyFloat(header, "%.8f", 'CRVAL2')) 392 sqlLine.group("crpix1", self.getKeyFloat(header, "%.8f", 'CRPIX1')) 393 sqlLine.group("crpix2", self.getKeyFloat(header, "%.8f", 'CRPIX2')) 394 sqlLine.group("cdelt1", self.getKeyFloat(header, "%.8e", 'CDELT1')) 395 sqlLine.group("cdelt2", self.getKeyFloat(header, "%.8e", 'CDELT2')) 396 sqlLine.group("pc001001", self.getKeyFloat(header, "%.8e", 'PC001001')) 397 sqlLine.group("pc001002", self.getKeyFloat(header, "%.8e", 'PC001002')) 398 sqlLine.group("pc002001", self.getKeyFloat(header, "%.8e", 'PC002001')) 399 sqlLine.group("pc002002", self.getKeyFloat(header, "%.8e", 'PC002002')) 401 400 402 401 sql = sqlLine.make(") VALUES ( ", ")") … … 469 468 # insert values coming from the CMF, not carried by DVO 470 469 header = self.headerSet[filter] 471 exptime = header['EXPTIME']470 exptime = self.getKeyFloat(header, "%.5f", "EXPTIME") 472 471 473 472 sqlLine = sqlUtility("UPDATE StackObjectThin AS a , " + filter + "SkyChip_psf AS b SET") … … 516 515 517 516 header = self.headerSet[filter] 518 exptime = header['EXPTIME']517 exptime = self.getKeyFloat(header, "%.5f", "EXPTIME") 519 518 520 519 # insert all the detections … … 603 602 604 603 for filter in self.filters: 605 populateStackModelFitFilter(model, ippModelType, filter)604 self.populateStackModelFitFilter(model, ippModelType, filter) 606 605 607 606 ''' 608 607 Updates parameters for a particular model in the StackModelFit table 609 608 ''' 610 def populateStackModelFitFilter(self, model, ippModelType, filter, exptime): 609 def populateStackModelFitFilter(self, model, ippModelType, filter): 610 611 if self.stackIDs[filter] <= 0: 612 self.logger.infoPair("no stack data for filter" , filter) 613 return True 614 615 table = "StackModelFit" + model 611 616 612 617 header = self.headerSet[filter] 613 exptime = header['EXPTIME']614 615 sqlLine = sqlUtility("UPDATE StackModelFitAS a, " + filter + "SkyChip_xfit AS b SET")618 exptime = self.getKeyFloat(header, "%.5f", "EXPTIME") 619 620 sqlLine = sqlUtility("UPDATE " + table + " AS a, " + filter + "SkyChip_xfit AS b SET") 616 621 617 622 # these lines yield the flux, flux error values, but I do not think we want those in the database... … … 630 635 sqlLine.group("a." + filter + model + "PhiErr", "b.EXT_THETA_ERR") # these are not correctly defined. 631 636 632 sqlLine.group("a." + filter + model + "Ra", "b.RA_EXT")633 sqlLine.group("a." + filter + model + "Dec", "b.DEC_EXT")634 635 sqlLine.group("a." + filter + model + "RaErr", "b.X_EXT_SIG * b.PLTSCALE")636 sqlLine.group("a." + filter + model + "DecErr", "b.Y_EXT_SIG * b.PLTSCALE")637 # XXX this is tricky: RA_EXT is not defined, but X_EXT is... 638 # sqlLine.group("a." + filter + model + "Ra", "b.RA_EXT") 639 # sqlLine.group("a." + filter + model + "Dec", "b.DEC_EXT") 640 # sqlLine.group("a." + filter + model + "RaErr", "b.X_EXT_SIG * b.PLTSCALE") 641 # sqlLine.group("a." + filter + model + "DecErr", "b.Y_EXT_SIG * b.PLTSCALE") 637 642 638 643 # sersic fit has an extra parameter … … 874 879 875 880 self.logger.infoPair("Creating indexes on", "IPP tables") 876 self.scratchDb.createIndex("SkyChip_psf", "IPP_IDET")881 self.scratchDb.createIndex("SkyChip_psf", "IPP_IDET") 877 882 self.scratchDb.createIndex("SkyChip_xfit", "IPP_IDET") 878 883 self.scratchDb.createIndex("SkyChip_xrad", "IPP_IDET") … … 1091 1096 ''' 1092 1097 def importIppTables(self, columns="*", tableRE=""): 1093 1094 self.logger.infoPair("Importing ST tables with table match expression: ", tableRE) 1095 1096 count = 0 1097 for filter in self.filters: 1098 if self.stackIDs[filter] <= 0: 1099 self.logger.infoPair("no files for filter" , filter) 1100 continue 1101 1102 fileName = self.fits[filter].getPath() 1103 1104 self.logger.infoPair("using filename:",fileName) 1105 1106 try: 1107 tables = stilts.treads(fileName) 1108 except: 1109 self.logger.errorPair("STILTS could not import from", fileName) 1110 return False 1098 1099 if self.config.retry: return True 1100 1101 self.logger.infoPair("Importing ST tables with table match expression: ", tableRE) 1102 1103 count = 0 1104 for filter in self.filters: 1105 if self.stackIDs[filter] <= 0: 1106 self.logger.infoPair("no files for filter" , filter) 1107 continue 1108 1109 fileName = self.fits[filter].getPath() 1110 1111 self.logger.infoPair("using filename:",fileName) 1112 1113 try: 1114 tables = stilts.treads(fileName) 1115 except: 1116 self.logger.errorPair("STILTS could not import from", fileName) 1117 return False 1118 1119 # count = 0 1120 for table in tables: 1111 1121 1112 # count = 0 1113 for table in tables: 1114 1115 # print "import smf table ", table 1116 match = re.match(tableRE, table.name) 1117 if not match: continue 1118 1119 self.logger.infoPair("Reading IPP table", filter + table.name) 1120 table = stilts.tpipe(table, cmd='addcol table_index $0') 1121 table = stilts.tpipe(table, cmd='explodeall') 1122 # print "import smf table ", table 1123 match = re.match(tableRE, table.name) 1124 if not match: continue 1125 1126 self.logger.infoPair("Reading IPP table", filter + table.name) 1127 table = stilts.tpipe(table, cmd='addcol table_index $0') 1128 table = stilts.tpipe(table, cmd='explodeall') 1122 1129 1123 # print "read smf table ", table 1130 # print "read smf table ", table 1131 1132 # drop any previous tables before import 1133 self.scratchDb.dropTable(filter + table.name) 1124 1134 1125 # drop any previous tables before import 1126 self.scratchDb.dropTable(filter + table.name) 1135 # IPP FITS files are littered with infinities, so remove these 1136 self.logger.debug("Removing Infinity values from all columns") 1137 table = stilts.tpipe(table, cmd='keepcols "' + columns + '"') 1138 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 1139 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 1140 # print "cleaned up values ", table 1127 1141 1128 # IPP FITS files are littered with infinities, so remove these 1129 self.logger.debug("Removing Infinity values from all columns") 1130 table = stilts.tpipe(table, cmd='keepcols "' + columns + '"') 1131 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 1132 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 1133 # print "cleaned up values ", table 1134 1135 try: 1136 table.write(self.scratchDb.url + '#' + filter + table.name) 1137 count = count + 1 1138 except: 1139 self.logger.exception("Problem writing table '" + filter + table.name + "' to the database") 1142 try: 1143 table.write(self.scratchDb.url + '#' + filter + table.name) 1144 count = count + 1 1145 except: 1146 self.logger.exception("Problem writing table '" + filter + table.name + "' to the database") 1140 1147 1141 self.logger.infoPair("Done. Imported", "%d tables" % count)1142 self.indexIppTables()1148 self.logger.infoPair("Done. Imported", "%d tables" % count) 1149 self.indexIppTables() 1143 1150 1144 return True1151 return True
Note:
See TracChangeset
for help on using the changeset viewer.
