Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

python ctypes wrapper for cfitsio

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 debug
Octocat-spinner-32 pycfitsio
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.rst
Octocat-spinner-32 README.txt
Octocat-spinner-32 setup.py
README.rst

pycfitsio: Python ctypes wrapper for cfitsio

Features

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

Requirements

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

Install

pip install pycfitsio #stable version

# for development version clone from github and run python setup.py install

Examples

Reading

>>> f = pycfitsio.open("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, ....])])

Writing

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

3 options to write HDUs:

  1. list of (name, array) tuples

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

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

    >>> data = np.ones(10, dtype = [('firstcolname', np.long), ('seccolname', np.double)])
    >>> f.write_HDU('HDUNAME', data)
    
    >>> f.close()
    
Something went wrong with that request. Please try again.