Table Of Contents

Previous topic

Files

Next topic

Header Data Units

This Page

HDU Lists

Inheritance diagram of HDUList

HDUList

class pyfits.core.HDUList(hdus=[], file=None)

Bases: list, pyfits.verify._Verify

HDU list class. This is the top-level FITS object. When a FITS file is opened, a HDUList object is returned.

Construct a HDUList object.

Parameters :
 

hdus : sequence of HDU objects or single HDU, optional

The HDU object(s) to comprise the HDUList. Should be instances of _BaseHDU.

file : file object, optional

The opened physical file associated with the HDUList.

append(*args, **kwargs)

Append a new HDU to the HDUList.

Parameters :
 

hdu : instance of _BaseHDU

HDU to add to the HDUList.

classExtensions : dict

A dictionary that maps pyfits classes to extensions of those classes. When present in the dictionary, the extension class will be constructed in place of the pyfits class.

insert(*args, **kwargs)

Insert an HDU into the HDUList at the given index.

Parameters :
 

index : int

Index before which to insert the new HDU.

hdu : _BaseHDU instance

The HDU object to insert

classExtensions : dict

A dictionary that maps pyfits classes to extensions of those classes. When present in the dictionary, the extension class will be constructed in place of the pyfits class.

close(output_verify='exception', verbose=False, closed=True)

Close the associated FITS file and memmap object, if any.

Parameters :
 

output_verify : str

Output verification option. Must be one of "fix", "silentfix", "ignore", "warn", or "exception". See Verification options for more info.

verbose : bool

When True, print out verbose messages.

closed : bool

When True, close the underlying file object.

flush(*args, **kwargs)

Force a write of the HDUList back to the file (for append and update modes only).

Parameters :
 

output_verify : str

Output verification option. Must be one of "fix", "silentfix", "ignore", "warn", or "exception". See Verification options for more info.

verbose : bool

When True, print verbose messages

classExtensions : dict

A dictionary that maps pyfits classes to extensions of those classes. When present in the dictionary, the extension class will be constructed in place of the pyfits class.

index_of(key)

Get the index of an HDU from the HDUList.

Parameters :
 

key : int, str or tuple of (string, int)

The key identifying the HDU. If key is a tuple, it is of the form (key, ver) where ver is an EXTVER value that must match the HDU being searched for.

Returns :
 

index : int

The index of the HDU in the HDUList.

info(output=None)

Summarize the info of the HDUs in this HDUList.

Note that this function prints its results to the console—it does not return a value.

Parameters :
 

output : file, optional

A file-like object to write the output to. If False, does not output to a file and instead returns a list of tuples representing the HDU info. Writes to sys.stdout by default.

filename()

Return the file name associated with the HDUList object if one exists. Otherwise returns None.

Returns :
 

filename : a string containing the file name associated with the

HDUList object if an association exists. Otherwise returns None.

readall()

Read data of all HDUs into memory.

update_extend()

Make sure that if the primary header needs the keyword EXTEND that it has it and it is correct.

verify(option='warn')

Verify all values in the instance.

Parameters :
 

option : str

Output verification option. Must be one of "fix", "silentfix", "ignore", "warn", or "exception". See Verification options for more info.

writeto(*args, **kwargs)

Write the HDUList to a new file.

Parameters :
 

fileobj : file path, file object or file-like object

File to write to. If a file object, must be opened for append (ab+).

output_verify : str

Output verification option. Must be one of "fix", "silentfix", "ignore", "warn", or "exception". See Verification options for more info.

clobber : bool

When True, overwrite the output file if exists.

checksum : bool

When True adds both DATASUM and CHECKSUM cards to the headers of all HDU’s written to the file.

fileinfo(index)

Returns a dictionary detailing information about the locations of the indexed HDU within any associated file. The values are only valid after a read or write of the associated file with no intervening changes to the HDUList.

Parameters :
 

index : int

Index of HDU for which info is to be returned.

Returns :
 

dictionary or None :

The dictionary details information about the locations of the indexed HDU within an associated file. Returns None when the HDU is not associated with a file.

Dictionary contents:

Key

Value

file

File object associated with the HDU

filename

Name of associated file object

filemode

Mode in which the file was opened (readonly, copyonwrite, update, append, ostream)

resized

Flag that when True indicates that the data has been resized since the last read/write so the returned values may not be valid.

hdrLoc

Starting byte location of header in file

datLoc

Starting byte location of data block in file

datSpan

Data size including padding