{ } Raw JSON

bundles / astropy latest / astropy / io / fits / header / Header / fromstring

classmethod

astropy.io.fits.header:Header.fromstring

source: /astropy/io/fits/header.py :350

Summary

Creates an HDU header from a byte string containing the entire header data.

Parameters

data : str or bytes

String or bytes containing the entire header. In the case of bytes they will be decoded using latin-1 (only plain ASCII characters are allowed in FITS headers but latin-1 allows us to retain any invalid bytes that might appear in malformatted FITS files).

sep : str, optional

The string separating cards from each other, such as a newline. By default there is no card separator (as is the case in a raw FITS file). In general this is only used in cases where a header was printed as text (e.g. with newlines after each card) and you want to create a new Header from it by copy/pasting.

Returns

: `Header`

A new Header instance.

Examples

from astropy.io.fits import Header
hdr = Header({'SIMPLE': True})
Header.fromstring(hdr.tostring()) == hdr
True
If you want to create a `Header` from printed text it's not necessary to have the exact binary structure as it would appear in a FITS file, with the full 80 byte card length. Rather, each "card" can end in a newline and does not have to be padded out to a full card length as long as it "looks like" a FITS header:
hdr = Header.fromstring("""\
SIMPLE  =                    T / conforms to FITS standard
BITPIX  =                    8 / array data type
NAXIS   =                    0 / number of array dimensions
EXTEND  =                    T
""", sep='\n')
hdr['SIMPLE']
hdr['BITPIX']
len(hdr)
4

Aliases

  • astropy.io.fits.Header.fromstring