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

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


Hello Phil,

that did the trick. Thank you.

I wrote a function to encapsulate this task:

def select_by_key(fits_data, key, val):
    column = fits_data.field(key)
    selected = (column == val)
    return fits_data[selected]

selected_data = select_by_key(fits_data, 'OBJECT', 18_Sco')


Cheers, Steffen


On 31.08.2015 15:43, Phil Hodge wrote:
> 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
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
> 


-- 
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/99a3aa70/attachment.key>


More information about the AstroPy mailing list