[AstroPy] Find record(s) with specific key in fits table

Steffen Brinkmann brinkmann at mpia.de
Mon Aug 31 09:36:09 EDT 2015


Currently, after a tedious hour of trying different things, I do the
following to extract records with a specific key from a fits table. In
this case the key name is 'OBJECT' and, say, I am looking for '18_Sco':

$ from astropy.io import fits
$ fits_data = fits.getdata("file.fits")
$ fits_data[list(fits_data['OBJECT']).index('18_Sco')]

The disadvantage is that only the first record with that 'OBJECT' key is

$ fits_data[list(fits_data['OBJECT']) == '18_Sco']

does not work. The output is a different record with another 'OBJECT'
name. No idea why...

I can use a list comprehension of the python built-in filter() but that
lasts minutes. The file has >10⁵ records.

There must be an elegant way to do this right! Right?

Thank you, cheers,


Steffen Brinkmann
Max-Planck-Institut für Astronomie        tel: +49(0)6221-528-458
Königstuhl 17                             fax: +49(0)6221-528-246
69117 Heidelberg                          email: brinkmann at mpia.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0xD969459A.asc
Type: application/pgp-keys
Size: 1727 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20150831/a47c8cb5/attachment.key>

More information about the AstroPy mailing list