IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 11, 2015, 11:08:06 AM (11 years ago)
Author:
eugene
Message:

use Ohana / fhead to read headers (ex PHU) so we avoid seek problems, etc; merge reading of exptime, zp, zperr, ninjected, magerf into the init methods of diff and stack batches

File:
1 edited

Legend:

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

    r39085 r39103  
    66import hashlib
    77from subprocess import call, PIPE, Popen
     8
     9import tempfile
    810
    911'''
     
    121123
    122124    '''
     125    Find and read a header extension.
     126    '''
     127    def findAndReadHeader(self, name, VERBOSE):
     128
     129        if False:
     130            status = self.findAndReadHeaderRaw(name, VERBOSE)
     131            return status
     132
     133        status = self.findAndReadHeaderOhana(name, VERBOSE)
     134        return status
     135
     136    '''
    123137    Finds and reads a header extension.
    124138
     
    132146    through STILTS
    133147    '''
    134     def findAndReadHeader(self, name, VERBOSE):
     148    def findAndReadHeaderRaw(self, name, VERBOSE):
    135149
    136150        found = False
     
    167181
    168182    '''
     183    Find and read a header extension.
     184    '''
     185    def findAndReadHeaderOhana(self, name, VERBOSE):
     186
     187        cmd = "fhead -n %s %s" % (name, self.originalPath)
     188        p = Popen(cmd, shell=True, stdout=PIPE)
     189        output = p.communicate()[0]       
     190
     191        header = {}
     192
     193        # split the output header bytes into key/value pairs for each 80-byte line
     194        for i in range(0, len(output), 80):
     195            # print "line %d : %s" % (i, output[i:i+80])
     196            record = output[i:i+80]
     197
     198            match = re.match('^(HIERARCH )*([a-zA-Z0-9-_\.]+)\s*=\s+\'*([a-zA-Z0-9-+_\.:\s@#\(\)\,]+)\'*\\/*', record)
     199
     200            if match:
     201                param = match.group(2)
     202                value = match.group(3).strip()
     203                if value == "NaN": value = "NULL"
     204                header[param] = value
     205
     206        return header
     207
     208    '''
    169209    Reads FITS header and stores all fields in a dictionary object
    170210    '''
Note: See TracChangeset for help on using the changeset viewer.