How handle FITS format with PyFITS in Python (2)

Now we look a little more about headers and data attributes in PyFITS objects. We said in a previous post that each HDU has a header minimally and optionally a data section. We also mentioned in each header there are keywords.


We can see this keywords going through HDU header:

for kw in hdulist[1].header:
  print kw

However, the code above shown isn’t the best way to show the keywords, because there are some methods predefined that do it better: we can load the header in a variable using getheader() and show the keywords with ascardlist() and keys() methods. For example, we can show the first ten lines so:

hdr = pyfits.getheader('file.fits', 0)

The main keywords in a header are:

  • BITPIX: number of bits per data pixel
  • NAXIS: number of data axes

Each header contain information, we can access it, via the keywords:

>>> header['SIMPLE']


Show data is very similar to headers:

>>> data = pyfits.getdata('file.fits', 0)
>>> data
array([[38, 43, 35, ..., 45, 43, 41],
       [36, 41, 37, ..., 42, 41, 39],
       [38, 45, 37, ..., 42, 35, 43],
       [49, 52, 49, ..., 41, 35, 39],
       [57, 52, 49, ..., 40, 41, 43],
       [53, 57, 57, ..., 39, 35, 45]], dtype=int16)

We can know

The goal

My goal is use file FITS’s data and find any kind of ROI’s. If I have time I’d like to highlight the stars and somehow get its coordinates.

Get FITS files isn’t trivial thing, nevertheless, there are small banks of images with any examples:


Un comentario sobre “How handle FITS format with PyFITS in Python (2)


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s