
Last chance! 50% off unlimited learning
Sale ends in
Read a FITS header from an open connection to a FITS file.
readFITSheader(zz, maxLines = 5000, fixHdr = 'none')
file handle; see Example.
maximum number of header lines to read; see Details.
deal with non-printing characters in header; see Details.
hdr is a character vector hdr containing the header information in a format that is easy for R to parse further. See Details.
readFITSheader
reads the data from the header part of a FITS
Header and Data Unit. In addition to general header information, it
provides parameters needed to read image and binary table files by
functions readFITSarray
and readFITSbintable
. A header
unit may exist without a corresponding data unit, for instance to
carry additional coordinate information.
The maxLines variable limits the number of header lines
readFITSheader
will read to prevent endless reading if the
header is flawed and the END
statement is missing. The function generates a message an halts when the
number of reads exceeds maxLines. Increase the value as
needed for very large headers.
fixHdr attempts to fix headers with non-printing characters,
either by removing them with fixHdr = 'remove'
, reading further
into the file until 2880 valid characters are present, or by
substituting spaces for non-printing characters with fixHdr =
'substitute'
. This option should be used with caution, as non-printing
characters should not be in the header in the first place, so this
option may or may not corrupt the following data. The default is
fixHdr = 'none'
. Partial matching is allowed.
The header vector does not have an easy format for people to read (graphical FITS viewers like fv and SAOImage DS9 are good for this), but is designed for further processing by R. The header vector has a kind of keyword value keyword value … format, where keywords without values are simply followed by the next keyword. This means a search for a keyword will give the corresponding value as the next element in the vector; see the Examples.
Hanisch et al., Astron.\ Astrophys. 376, 359-380 (2001)
parseHdr
, the usual complement to readFITSheader
;
readFITS
, readFITSarray
,
readFITSbintable
, file
# NOT RUN {
require(FITSio)
## Make test image with axis information, write to disk
Z <- matrix(1:15, ncol = 3)
filename <- paste(tempdir(), "test.fits", sep="")
writeFITSim(Z, file = filename, c1 = "Test FITS file",
crpix = c(1,1), crvaln = c(10, 100), cdeltn = c(8, 2),
ctypen = c("Distance", "Time"),
cunitn = c("Furlongs", "Fortnights"))
## Read back in
## Open file, read header and array.
zz <- file(description = filename, open = "rb")
header <- readFITSheader(zz)
hdr <- parseHdr(header)
D <- readFITSarray(zz, hdr)
close(zz)
hdr[1:10] # Header sample
hdr[which(hdr=="BITPIX")+1] # BITPIX value from header
## Clean up files to avoid clutter
unlink(filename)
# }
Run the code above in your browser using DataLab