Changeset 31291 for trunk/ippToPsps/jython/batch.py
- Timestamp:
- Apr 15, 2011, 8:53:08 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/batch.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/batch.py
r31286 r31291 102 102 self.dateStr = now.strftime("%Y-%m-%d") 103 103 104 if self.inputFitsPath != "": self.parseFitsHeader() 104 if self.inputFitsPath != "": 105 file = open(self.inputFitsPath) 106 self.header = self.parseFitsHeader(file) 107 # TODO close file? 105 108 106 109 # create DVO table … … 115 118 self.localStmt.close() 116 119 self.localCon.close() 120 121 ''' 122 Finds and reads a header extension 123 ''' 124 def findAndReadFITSHeader(self, name): 125 126 self.logger.info("Searching for header extension: '" + name + "'...") 127 128 file = open(self.inputFitsPath, 'r') 129 130 index = 0 131 found = False 132 while True: 133 134 file.seek(index, 0) 135 136 record = file.read(80) 137 if not record: break; 138 139 header = {} 140 141 # quit when we reach 'END' 142 if record.startswith("XTENSION= 'IMAGE"): 143 144 header = self.parseFitsHeader(file) 145 if header['EXTNAME'] == name: 146 found = True 147 break 148 149 index = index + 2880 150 151 if found != True: self.logger.error("...could not find extension '" + name + "'") 152 else: self.logger.info("...read header at '" + name + "' and found " + str(len(header)) + " header cards") 153 154 # TODO close file? 155 return header 156 117 157 118 158 ''' … … 265 305 Reads FITS header and stores all fields in a dictionary object 266 306 ''' 267 def parseFitsHeader(self): 268 269 fitsFile = open(self.inputFitsPath) 270 271 self.header = {} 307 def parseFitsHeader(self, fitsFile): 308 309 header = {} 272 310 273 311 while (True): 312 274 313 record = fitsFile.read(80) 275 314 276 315 # quit when we reach 'END' 277 if record.startswith("END"): break 278 279 # ignore comments 280 if record.startswith("COMMENT"): continue 281 match = re.match('(.*)=(.*)', record) 316 if re.match('END\s+', record): break 317 318 # this regex will get param/value pairs for all header cards, ignoring comments and parsing out 'HIERACH' prefixes 319 match = re.match('^(HIERARCH )*([a-zA-Z0-9-_\.]+)\s*=\s+\'*([a-zA-Z0-9-_\.:\s@#]+)\'*\\/*', record) 282 320 if match: 283 321 284 # remove HIERARCH prefix 285 param = match.group(1).replace("HIERARCH", "") 286 param = param.strip() 287 288 value = match.group(2) 289 # remove trailing comment after / char, if there is one 290 index = value.find("/") 291 if index != -1: value = value[0:index] 292 293 # remove ' chars around content 294 value = value.replace("'", "") 295 296 # remove leading and trailing whitespace 297 value = value.strip() 298 299 # store in out dictionary object 300 self.header[param] = value 322 param = match.group(2) 323 value = match.group(3).strip() 324 header[param] = value 301 325 302 326 #print param + "|" + value + "|" 327 328 return header 303 329 304 330 ''' … … 363 389 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 364 390 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 391 #params = table.parameters() 392 #print params 365 393 366 394 try:
Note:
See TracChangeset
for help on using the changeset viewer.
