Skip to main content

Simple FITS files I/O package

Project description

pycfitsio: Python ctypes wrapper for cfitsio


* read binary tables using hdu and column names into simple dictionaries of arrays
* write FITS files incrementally 1 HDU at a time


pycfitsio requires the dynamic library cfitsio, in linux it usually packaged as libcfitsio-dev


pip install pycfitsio #stable version

# for development version clone from github and run
python install



>>> f ="debug/data.fits")

>>> hdulist = f.HDUs

>>> print(hdulist)
OrderedDict([('DATA', HDU: DATA)])

>>> hdu = f['DATA']

>>> column_array = f['DATA'].read_column('signal')

>>> all_columns = f['DATA'].read_all()
>>> print(all_columns)
OrderedDict([('signal', array([ 0., 1. ....])), 'flag', array([1, 1, ....])])


>>> from collections import OrderedDict
>>> f = pycfitsio.create('file.fits')

3 options to write HDUs:

#. list of (name, array) tuples

>>> f.write_HDU('HDUNAME',
[('firstcolname', np.arange(10)), ('seccolname', np.arange(10)**2)]

#. OrderedDict keys = name values = array

>>> data = OrderedDict()
>>> data['firstcolname'] = np.arange(10)
>>> data['seccolname'] = np.arange(10)**2
>>> f.write_HDU('HDUNAME', data)

#. Compound numpy array

>>> data = np.ones(10, dtype = [('firstcolname', np.long), ('seccolname', np.double)])
>>> f.write_HDU('HDUNAME', data)

>>> f.close()

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pycfitsio, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size pycfitsio-0.3.0.tar.gz (21.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page