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

Phil Hodge hodge at stsci.edu
Mon Aug 31 09:43:11 EDT 2015


On 08/31/2015 09:36 AM, Steffen Brinkmann wrote:
> 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')]

You could try this:

column = fits_data.field("OBJECT")
selected = (column == '18_Sco')
selected_data = fits_data[selected]

Phil



More information about the AstroPy mailing list