[AstroPy] Convert FITS header into astropy Table entries?

Matthew Craig mcraig at mnstate.edu
Wed Aug 19 11:26:17 EDT 2015

Hi Jason,

I’m late to the party, but ccdproc is about to add an ImageFileCollection obj that does (I think) what you are looking for…given a directory containing FITS files, make a table out of their headers (will not handle multiple extensions in a single file gracefully).

That functionality is available right now from another package, msumastro (http://msum-astro.readthedocs.org/en/latest/image_management.html or https://github.com/mwcraig/msumastro) so if you want it today I would get it from there.

If you decide to give it a try and find issues please report them, either at https://github.com/astropy/ccdproc/issues or at https://github.com/mwcraig/msumastro/issues or by email.

In a nutshell you would do:

>>> from msumastro import ImageFileCollection
>>> my_collection = ImageFileCollection(‘path/to/dir/with/files’, keywords=‘*’)
>>> my_table = my_collection.summary

Matt Craig

schedule:  http://physics.mnstate.edu/craig

Department of Physics and Astronomy
Minnesota State University Moorhead
1104 7th Ave S, Moorhead MN 56563

phone: (218) 477-2439
fax: (218) 477-2290

On Aug 19, 2015, at 9:00 AM, Jason Tumlinson <tumlinson at stsci.edu<mailto:tumlinson at stsci.edu>> wrote:

I am trying to harvest the information from a large number of FITS headers, parse them and do statistics on values, in an efficient manner. I read in each header in the usual fashion:

h = fits.open('lbiy83i0q_x1d.fits’)
h0 = h[0].header

My goal then is to get all the header info into an astropy Table such that the table columns are given by the header keys and the values in the rows are given by the values in each of 100+ headers. I tried this:

In [38]: t = Table(rows=h0.values(), names=h0.keys())
TypeError                                 Traceback (most recent call last)
<ipython-input-38-8a0ece2925d5> in <module>()
----> 1 t = Table(rows=h0.values(), names=h0.keys())

/Users/tumlinson/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc in __init__(self, data, masked, names, dtype, meta, copy, rows)
    240                 data = rows
    241             else:
--> 242                 rec_data = recarray_fromrecords(rows)
    243                 data = [rec_data[name] for name in rec_data.dtype.names]

/Users/tumlinson/Ureka/python/lib/python2.7/site-packages/astropy/table/np_utils.pyc in recarray_fromrecords(rec_list)
    604     # to column arrays in the recarray module; it could be there is a better
    605     # way
--> 606     nfields = len(rec_list[0])
    607     obj = np.array(rec_list, dtype=object)
    608     array_list = [np.array(obj[..., i].tolist()) for i in range(nfields)]

TypeError: object of type 'bool' has no len()

to no avail. Is this possible, easy, or wrongheaded? Advise appreciated.


AstroPy mailing list
AstroPy at scipy.org<mailto:AstroPy at scipy.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150819/23f50876/attachment.html>

More information about the AstroPy mailing list