- Timestamp:
- Jun 7, 2014, 5:36:39 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140423/ippToPsps/jython/batch.py
r36190 r36826 440 440 441 441 return True 442 ''' 443 Imports IPP tables from FITS file 444 445 Accepts a regular expression filter so not all tables need to be imported 446 ''' 447 def importIppSTTables(self, columns="*", filter=""): 448 449 self.logger.infoPair("Importing ST tables with filter", filter) 450 451 # print "trying to read ", self.fits.getPath() 452 453 # ST has 5 cmf files - all with the same table names. To counter this we do it like this. 454 455 filters = ["g","r","i","z","y"] 456 count = 0 457 for f in filters: 458 skip = 0 459 if (f == "g"): 460 if self.gstackID > 0: 461 fileName = self.gfits.getPath() 462 else: 463 skip = 1 464 if (f == "r"): 465 if self.rstackID > 0: 466 fileName = self.rfits.getPath() 467 else: 468 skip = 1 469 if (f == "i"): 470 if self.istackID > 0: 471 fileName = self.ifits.getPath() 472 else: 473 skip = 1 474 if (f == "z"): 475 if self.zstackID > 0: 476 fileName = self.zfits.getPath() 477 else: 478 skip = 1 479 if (f == "y"): 480 if self.ystackID > 0: 481 fileName = self.yfits.getPath() 482 else: 483 skip = 1 484 485 if skip == 1: 486 self.logger.infoPair("no files for filter" , f) 487 else: 488 self.logger.infoPair("using filename:",fileName) 489 490 try: 491 tables = stilts.treads(fileName) 492 except: 493 self.logger.errorPair("STILTS could not import from", fileName) 494 return False 495 496 #count = 0 497 for table in tables: 498 499 # print "import smf table ", table 500 match = re.match(filter, table.name) 501 502 if not match: continue 503 self.logger.infoPair("Reading IPP table", f + table.name) 504 table = stilts.tpipe(table, cmd='addcol table_index $0') 505 506 table = stilts.tpipe(table, cmd='explodeall') 507 508 # print "read smf table ", table 509 510 # drop any previous tables before import 511 self.scratchDb.dropTable(f + table.name) 512 513 # IPP FITS files are littered with infinities, so remove these 514 self.logger.debug("Removing Infinity values from all columns") 515 table = stilts.tpipe(table, cmd='keepcols "' + columns + '"') 516 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 517 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 518 # print "cleaned up values ", table 519 520 try: 521 table.write(self.scratchDb.url + '#' + f + table.name) 522 # XXX this one is not needed 523 # self.scratchDb.killLastConnectionID() 524 count = count + 1 525 except: 526 self.logger.exception("Problem writing table '" + f + table.name + "' to the database") 527 528 self.logger.infoPair("Done. Imported", "%d tables" % count) 529 self.indexIppTables() 530 531 return True 442 532 443 533 ''' … … 467 557 # replace nulls and empty fields with weird PSPS -999 pseudo-null 468 558 _table = stilts.tpipe(_table, cmd='replaceval "" -999 *') 469 470 match = re.match(regex, table) 559 self.logger.infoPair('regex', regex) 560 self.logger.infoPair('table', table) 561 match = re.search(regex, table) 471 562 newTableName = match.group(1) 472 563 … … 551 642 # for P2/ST, this reads the detection tables from the CMF/SMF file(s) 552 643 # for OB, this imports object data from DVO 553 if not self.importIppTables(): 554 if self.batchType == "OB": 555 self.logger.errorPair("skipping this batch", "no dvo tables for this region") 556 self.ippToPspsDb.updateProcessed(self.batchID, 1) 557 return True 558 559 self.logger.errorPair("Aborting this batch", "could not import IPP tables") 560 self.ippToPspsDb.updateProcessed(self.batchID, -1) 561 raise 562 644 if self.batchType == "ST": 645 self.logger.infoPair("did we get here","?") 646 if not self.importIppSTTables(): 647 self.logger.errorPair("skipping this batch", "could not import ST IPP tables") 648 self.ippToPspsDb.updateProcessed(self.batchID, -1) 649 raise 650 self.logger.infoPair("we did the ST","yes") 651 else: 652 # if not ST we do this 653 if not self.importIppTables(): 654 if self.batchType == "OB": 655 self.logger.errorPair("skipping this batch", "no dvo tables for this region") 656 self.ippToPspsDb.updateProcessed(self.batchID, 1) 657 return True 658 self.logger.errorPair("Aborting this batch", "could not import IPP tables") 659 self.ippToPspsDb.updateProcessed(self.batchID, -1) 660 raise 661 self.logger.infoPair("populatePspsTables","ok") 563 662 if not self.populatePspsTables(): 564 663 if self.skipBatch:
Note:
See TracChangeset
for help on using the changeset viewer.
