PyFITS is being used within the STScI operations pipelines and is a supported product. Currently PyFITS takes a fairly strict interpretation of FITS files. There are likely to be problems with FITS data that do not strictly conform to the standard. Undoubtedly, use with a wider variety of files and uses will uncover problems; please contact help@stsci.edu when such problems are encountered.
We intend to accomodate such variances, particularly if they involve widely used or available data (so please let us know when such problems occur).
PyFITS requires numpy (or numarray) to be installed.
hdul=pyfits.open('in.fits',checksum=True)
hdul.writeto('out.fits',checksum=True)
hdul.insert(2,hdu)
pyfits.open('infile.fits',ignore_missing_end=True)
>>> import pyfits >>> pyfits.setExtensionNameCaseSensitive()
>>> pyfits.setExtensionNameCaseSensitive(False)
>>> hdu=pyfits.CompImageHDU(imageData,imageHeader)
>>> hdu.writeto('compressed_image.fits')
def __init__(self, data=None, header=None, name=None,
compressionType='RICE_1',
tileSize=None,
hcompScale=0.,
hcompSmooth=0,
quantizeLevel=16.):
"""data: data of the image
header: header to be associated with the
image
name: the EXTNAME value; if this value
is None, then the name from the
input image header will be used;
if there is no name in the input
image header then the default name
'COMPRESSED_IMAGE' is used
compressionType: compression algorithm 'RICE_1',
'PLIO_1', 'GZIP_1', 'HCOMPRESS_1'
tileSize: compression tile sizes default
treats each row of image as a tile
hcompScale: HCOMPRESS scale parameter
hcompSmooth: HCOMPRESS smooth parameter
quantizeLevel: floating point quantization level;
"""
>>> import pyfits
>>> hdul=pyfits.open('o4sp040b0_raw.fits',uint16=1)
>>> hdul[1].data
array([[1507, 1509, 1505, ..., 1498, 1500, 1487],
[1508, 1507, 1509, ..., 1498, 1505, 1490],
[1505, 1507, 1505, ..., 1499, 1504, 1491],
...,
[1505, 1506, 1507, ..., 1497, 1502, 1487],
[1507, 1507, 1504, ..., 1495, 1499, 1486],
[1515, 1507, 1504, ..., 1492, 1498, 1487]], dtype=uint16)
>>> hdul.writeto('tmp.fits')
>>> hdul1=pyfits.open('tmp.fits',uint16=1)
>>> hdul1[1].data
array([[1507, 1509, 1505, ..., 1498, 1500, 1487],
[1508, 1507, 1509, ..., 1498, 1505, 1490],
[1505, 1507, 1505, ..., 1499, 1504, 1491],
...,
[1505, 1506, 1507, ..., 1497, 1502, 1487],
[1507, 1507, 1504, ..., 1495, 1499, 1486],
[1515, 1507, 1504, ..., 1492, 1498, 1487]], dtype=uint16)
>>> hdul1=pyfits.open('tmp.fits')
>>> hdul1[1].data
array([[ 1507., 1509., 1505., ..., 1498., 1500., 1487.],
[ 1508., 1507., 1509., ..., 1498., 1505., 1490.],
[ 1505., 1507., 1505., ..., 1499., 1504., 1491.],
...,
[ 1505., 1506., 1507., ..., 1497., 1502., 1487.],
[ 1507., 1507., 1504., ..., 1495., 1499., 1486.],
[ 1515., 1507., 1504., ..., 1492., 1498., 1487.]], dtype=float32)
keyword= 'field-specifier: float'where keyword is a standard eight-character FITS keyword name, float is the standard FITS ASCII representation of a floating point number, and these are separated by a colon followed by a single blank.
The grammer for field-specifier is:
field-specifier:
field
field-specifier.field
field:
identifier
identifier.index
where identifier is a sequence of letters (upper or lower case), underscores, and digits of which the first character must not be a digit, and index is a sequence of digits. No blank characters may occur in the field-specifier. The index is provided primarily for defining array elements though it need not be used for that purpose.
Multiple record-valued keywords of the same name but differing values may be present in a FITS header. The field-specifier may be viewed as part of the keyword name.
Some examples follow:
DP1 = 'NAXIS: 2' DP1 = 'AXIS.1: 1' DP1 = 'AXIS.2: 2' DP1 = 'NAUX: 2' DP1 = 'AUX.1.COEFF.0: 0' DP1 = 'AUX.1.POWER.0: 1' DP1 = 'AUX.1.COEFF.1: 0.00048828125' DP1 = 'AUX.1.POWER.1: 1'
>>> print hdr[10] NAXIS: 2 >>> print hdr[11] AXIS.1: 1
>>> print hdr['DP1'] NAXIS: 2
>>> print hdr['DP1.NAXIS'] 2.0
>>> print hdr['DP1.NAXIS'] 2.0 >>> hdr['DP1.NAXIS'] = 3.0 >>> print hdr['DP1.NAXIS'] 3.0
>>> hdr.update('DP1', 'AXIS.3: 1', 'a comment', after='DP1.AXIS.2')
>>> del hdr['DP1.AXIS.1']
>>> cl=hdr['DP1.AXIS.*'] >>> print cl DP1 = 'AXIS.1: 1' DP1 = 'AXIS.2: 2' >>> cl=hdr['DP1.*'] >>> print cl DP1 = 'NAXIS: 2' DP1 = 'NAUX: 2' >>> cl=hdr['DP1.AUX...'] >>> print cl DP1 = 'AUX.1.COEFF.0: 0' DP1 = 'AUX.1.POWER.0: 1' DP1 = 'AUX.1.COEFF.1: 0.00048828125' DP1 = 'AUX.1.POWER.1: 1' >>> cl=hdr['DP?.NAXIS'] >>> print cl DP1 = 'NAXIS: 2' DP2 = 'NAXIS: 2' DP3 = 'NAXIS: 2' >>> cl=hdr['DP1.A*S.*'] >>> print cl DP1 = 'AXIS.1: 1' DP1 = 'AXIS.2: 2'
>>> del hdr['DP3.A*...']
>>> cl=hdr['DP1...'] >>> print cl DP1 = 'NAXIS: 2' DP1 = 'AXIS.1: 1' DP1 = 'AXIS.2: 2' DP1 = 'NAUX: 2' DP1 = 'AUX.1.COEFF.1: 0.000488' DP1 = 'AUX.2.COEFF.2: 0.00097656' >>> cl1=cl['*.*AUX...'] >>> print cl1 DP1 = 'NAUX: 2' DP1 = 'AUX.1.COEFF.1: 0.000488' DP1 = 'AUX.2.COEFF.2: 0.00097656'
>>> cl=hdr['DP1.AXIS.*'] >>> print cl DP1 = 'AXIS.1: 1' DP1 = 'AXIS.2: 2' >>> cl.keys() ['DP1.AXIS.1', 'DP1.AXIS.2']
>>> cl=hdr['DP1.AXIS.*'] >>> print cl DP1 = 'AXIS.1: 1' DP1 = 'AXIS.2: 2' >>> cl.values() [1.0, 2.0]
>>> cl=hdr['DP1.AXIS.*'] >>> c=cl[0] >>> print c DP1 = 'AXIS.1: 1' >>> c=cl['DP1.AXIS.2'] >>> print c DP1 = 'AXIS.2: 2'
>>> cl=hdr['DP1.AXIS.*'] >>> cl[0].value 1.0
>>> hdr['DP1.AXIS.1'] 1.0 >>> cl=hdr['DP1.AXIS.*'] >>> cl[0].value = 4.0 >>> hdr['DP1.AXIS.1'] 4.0 >>> del cl[0] >>> print cl['DP1.AXIS.1'] Traceback (most recent call last): File "", line 1, in File "NP_pyfits.py", line 977, in __getitem__ return self.ascard[key].value File "NP_pyfits.py", line 1258, in __getitem__ _key = self.index_of(key) File "NP_pyfits.py", line 1403, in index_of raise KeyError, 'Keyword %s not found.' % `key` KeyError: "Keyword 'DP1.AXIS.1' not found." >>> hdr['DP1.AXIS.1'] 4.0
>>> c1 = pyfits.RecordValuedKeywordCard('DP1', 'NAXIS: 2', 'Number of variables')
>>> c2 = pyfits.RecordValuedKeywordCard('DP1.AXIS.1', 1.0, 'Axis number')
>>> c1 = pyfits.RecordValuedKeywordCard().fromstring(
"DP1 = 'NAXIS: 2' / Number of independent variables")
>>> c2 = pyfits.RecordValuedKeywordCard().fromstring(
"DP1 = 'AXIS.1: X' / Axis number")
>>> print c1; print c2
DP1 = 'NAXIS: 2' / Number of independent variables
DP1 = 'AXIS.1: X' / Axis number
>>> c2.verify()
Output verification result:
Card image is not FITS standard (unparsable value string).
>>> c1 = pyfits.Card('DP1','AUX: 1','comment')
>>> c2 = pyfits.RecordValuedKeywordCard.coerce(c1)
>>> print type(c2)
<class 'pyfits.NP_pyfits.RecordValuedKeywordCard'>
>>> c1 = pyfits.RecordValuedKeywordCard.createCard('DP1','AUX: 1','comment)
or
>>> c1 = pyfits.createCard('DP1','AUX: 1','comment)
>>> print type(c1)
<class 'pyfits.NP_pyfits.RecordValuedKeywordCard'>
>>> c1 = pyfits.RecordValuedKeywordCard.createCard('DP1','AUX 1','comment)
or
>>> c1 = pyfits.createCard('DP1','AUX 1','comment)
>>> print type(c1)
<class 'pyfits.NP_pyfits.Card'>
>>> c1 = pyfits.RecordValuedKeywordCard.createCardFromString \
("DP1 = 'AUX: 1.0' / comment")
or
>>> c1 = pyfits.createCardFromString("DP1 = 'AUX: 1.0' / comment")
>>> print type(c1)
<class 'pyfits.NP_pyfits.RecordValuedKeywordCard'>
python -Wignore yourscript.py
The changes to PyFITS were primarily to improve the docstrings and to reclassify some public functions and variables as private. Readgeis and fitsdiff which were distributed with PyFITS in previous releases were moved to pytools. This release of PyFITS is v1.0.1. The next release of PyFITS will support both numarray and numpy (and will be available separately from stsci_python, as are all the python packages contained within stsci_python). An alpha release for PyFITS numpy support will be made around the time of this stsci_python release.
Major Changes since v0.9.6:
Minor changes since v0.9.6:
PyFITS Version 1.0 REQUIRES Python 2.3 or later.
Major changes since v0.9.3:
Some minor changes:
Changes since v0.9.0:
Changes since v0.8.0:
NOTE: This version will only work with numarray Version 0.6. In addition, earlier versions of PyFITS will not work with numarray 0.6. Therefore, both must be updated simultaneously.
Changes since 0.7.6:
NOTE: This version will only work with numarray Version 0.4.
Changes since 0.7.5:
After running drizzle on ACS images it creates a CD matrix whose elements have very many digits, e.g.:
CD1_1 = 1.1187596304411E-05 / partial of first axis coordinate w.r.t. x CD1_2 = -8.502767249350019E-06 / partial of first axis coordinate w.r.t. ywith pyfits, an "update" on these header items and write in new values which has fewer digits, e.g.:
CD1_1 = 1.0963011E-05 / partial of first axis coordinate w.r.t. x CD1_2 = -8.527229E-06 / partial of first axis coordinate w.r.t. y
old name new name
__octalRegex _octalRegex
__readblock() _readblock()
__formatter() _formatter().
__value_RE _value_RE
__numr _numr
__comment_RE _comment_RE
__keywd_RE _keywd_RE
__number_RE _number_RE.
tmpName() _tmpName()
dimShape _dimShape
ErrList _ErrList
self.__dict__ = input.__dict__to
self.__setstate__(input.__getstate__())in order for pyfits to run under numarray 0.4.
Changes since v0.7.3:
A couple of bugs were addressed in this version.
The two major improvements from Version 0.6.2 are:
Other changes include:
This version requires numarray version 0.2.
Things not yet supported but are part of future development: