Factory function to open a FITS file and return an HDUList object.
Parameters: | |
---|---|
name : file path, file object or file-like object
mode : str
memmap : bool
classExtensions : dict (‘’Deprecated’‘)
kwargs : dict
|
|
Returns: | |
hdulist : an HDUList object
|
The functions in this module provide shortcuts for some of the most basic operations on FITS files, such as reading and updating the header. They are included directly in the ‘pyfits’ namespace so that they can be used like:
>>> pyfits.getheader(...)
These functions are primarily for convenience when working with FITS files in the command-line interpreter. If performing several operations on the same file, such as in a script, it is better to not use these functions, as each one must open and re-parse the file. In such cases it is better to use pyfits.open() and work directly with the pyfits.HDUList object and underlying HDU objects.
Several of the convenience functions, such as getheader and getdata support special arguments for selecting which extension HDU to use when working with a multi-extension FITS file. There are a few supported argument formats for selecting the extension. See the documentation for getdata for an explanation of all the different formats.
Warning
All arguments to convenience functions other than the filename that are not for selecting the extension HDU should be passed in as keyword arguments. This is to avoid ambiguity and conflicts with the extension arguments. For example, to set NAXIS=1 on the Primary HDU:
Wrong:
>>> pyfits.setval('myimage.fits', 'NAXIS', 1)
The above example will try to set the NAXIS value on the first extension HDU to blank. That is, the argument ‘1’ is assumed to specify an extension HDU.
Right:
>>> pyfits.setval('myimage.fits', 'NAXIS', value=1)
This will set the NAXIS keyword to 1 on the primary HDU (the default). To specify the first extension HDU use:
>>> pyfits.setval('myimage.fits', 'NAXIS', value=1, ext=1)
This complexity arises out of the attempt to simultaneously support multiple argument formats that were used in past versions of PyFITS. Unfortunately, it is not possible to support all formats without introducing some ambiguity. A future PyFITS release may standardize around a single format and offically deprecate the other formats.
Get the data from an extension of a FITS file (and optionally the header).
Parameters: | |
---|---|
filename : file path, file object, or file like object
ext :
header : bool (optional)
lower, upper : bool (optional)
view : ndarray (optional)
kwargs :
|
|
Returns: | |
array : array, record array or groups data object
|
Get the header from an extension of a FITS file.
Parameters: | |
---|---|
filename : file path, file object, or file like object
ext, extname, extver :
kwargs :
|
|
Returns: | |
header : Header object |
Get a keyword’s value from a header in a FITS file.
Parameters: | |
---|---|
filename : file path, file object, or file like object
keyword : str
ext, extname, extver :
kwargs :
|
|
Returns: | |
keyword value : string, integer, or float |
Set a keyword’s value from a header in a FITS file.
If the keyword already exists, it’s value/comment will be updated. If it does not exist, a new card will be created and it will be placed before or after the specified location. If no before or after is specified, it will be appended at the end.
When updating more than one keyword in a file, this convenience function is a much less efficient approach compared with opening the file for update, modifying the header, and closing the file.
Parameters: | |
---|---|
filename : file path, file object, or file like object
keyword : str
value : str, int, float (optional)
comment : str (optional)
before : str, int (optional)
after : str, int (optional)
savecomment : bool (optional) ext, extname, extver :
kwargs :
|
Delete all instances of keyword from a header in a FITS file.
Parameters: | |
---|---|
filename : file path, file object, or file like object
keyword : str, int
ext, extname, extver :
kwargs :
|
Create a new FITS file using the supplied data/header.
Parameters: | |
---|---|
filename : file path, file object, or file like object
data : array, record array, or groups data object
header : Header object (optional)
output_verify : str
clobber : bool (optional) checksum : bool (optional)
|
Append the header/data to FITS file if filename exists, create if not.
If only data is supplied, a minimal header is created.
Parameters: | |
---|---|
filename : file path, file object, or file like object
data : array, table, or group data object
header : Header object (optional)
checksum : bool (optional)
verify: bool (optional) : kwargs :
|
Update the specified extension with the input data/header.
Parameters: | |
---|---|
filename : file path, file object, or file like object
data : array, table, or group data object
header : Header object (optional)
ext, extname, extver :
kwargs :
|
Print the summary information on a FITS file.
This includes the name, type, length of header, data shape and type for each extension.
Parameters: | |
---|---|
filename : file path, file object, or file like object
output : file, bool (optional)
kwargs :
|