Create a multi-extension FITS (MEF) file from scratch

This example demonstrates how to create a multi-extension FITS (MEF) file from scratch using

By: Erik Bray

License: BSD

import os

HDUList objects are used to hold all the HDUs in a FITS file. This HDUList class is a subclass of Python’s builtin list. and can be created from scratch. For example, to create a FITS file with three extensions:

Write out the new file to disk:


Alternatively, the HDU instances can be created first (or read from an existing FITS file).

Create a multi-extension FITS file with two empty IMAGE extensions (a default PRIMARY HDU is prepended automatically if one is not specified; we use overwrite=True to overwrite the file if it already exists):

Finally, we’ll remove the file we created:


Total running time of the script: ( 0 minutes 0.006 seconds)

Gallery generated by Sphinx-Gallery