FITSio mini reference guide

FITSio is a Python module which provides a few easy to use high level FITS access routines. It uses and requires pCFITSIO. This should be viewed a a set of sample functions using the wrapped CFITSIO library pcFitsio and not as a final polished product. Set verbose=1 when calling these functions to have a little bit more information reported.

Available functions

  • get_number_extensions(filename, verbose=0)
    Returns the number of extension in the file filename.
  • read_data(filename, hdu = -1, verbose=0)
    Open and reads the image out of a FITS file filename and using the extension number hdu. This functions an N-dimensional Numeric Python array of the form data[...][col][row]
  • write_data(filename, data, bitpix = -1, hdu = -1, append=0, verbose=0)
    Open, or initializes if needed, a FITS file filename and write the data contained in the N-dimensional Python array data into extension hdu. The BITPIX value is set automatically by default but a particular value of BITPIX can be specified is required. If append is set to 1, then trying to write an image into a non-existing extension number will result into a new extension being created and appended to the existing FITS file.
  • read_keys(filename, keys, hdu = -1, verbose = 0)
    Given a list of keys (case insensitive), this function returns a Python dictionary. This dictionary's keys are the requested keyword and each entry contains the value (properly cast to double, integer, or string) and the comment field.
  • write_keys(filename, keys, hdu = -1, verbose = 0, add = 0)
    Given a list of record, this functions updates existing keywords or add new ones if they do not already exists. Set add=1 to force addition of keywords (no update will be made). A record here consists of 2 or 3 elements in the following order (key name, value, optional comment)

    Examples

        
    Python 2.3.2 (#19, Oct 27 2003, 09:09:35) 
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from numarray import *
    >>> import fitsio
    >>> data = fitsio.read_data("test.fits")
    >>> shape(data) 
    (10, 10)
    >>> 
    
    For further examples, please see N. Pirzkal. and R. N. Hook 1999, in ASP Conf. Ser., Vol. 172, Astronomical Data Analysis Software and Systems VIII, eds. D. M. Mehringer, R. L. Plante, & D. A. Roberts (San Francisco: ASP), 479
    .
    For comments, bug reports, etc.. please send email to
    Nor Pirzkal
    Disclaimer:

    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

    Last modified: Tue Jul 6 18:06:57 MET DST 1999