[AstroPy] How to change fits table header to another name

Vinu Vikram vvinuv at gmail.com
Thu Jun 25 15:20:17 EDT 2015


Thank you Yannick and Erik! It works now,
vinu

On 25 June 2015 at 13:53, Erik Bray <embray at stsci.edu> wrote:
> On 06/25/2015 02:07 PM, Yannick Roehlly wrote:
>> Hi Vinu,
>>
>> The easiest way is to use Table:
>>
>> from astropy.table import Table
>> t = Table.read("foo.fits")
>> t['RA'].name = 'RA_1'
>> t.write("bar.fits")
>>
>> But if your FITS file has other extensions you may loose them when saving back
>> the table. In that case, you must use io.fits but you must know the position of
>> the column you want to rename:
>>
>> from astropy.io <http://astropy.io> import fits
>> hdu_list = fits.open("foo.fits")
>> hdu_list[1].columns[1].name = "RA_1"  # The column index starts at 0
>> hdu_list.writeto("bar.fits")
>
> By the way, in the current dev version, columns['RA'].name = 'RA_1' will work.
> I don't think it works in any released version though.
>
> Erik
>
>>
>> 2015-06-25 19:06 GMT+02:00 Vinu Vikram <vvinuv at gmail.com <mailto:vvinuv at gmail.com>>:
>>
>>     Hi All
>>     I would like to change a fits binary table column name to another
>>     name. E.g. if the fits table has the header column RA and I need to
>>     change that to RA_1.
>>     Thanks
>>     Vinu
>>     _______________________________________________
>>     AstroPy mailing list
>>     AstroPy at scipy.org <mailto:AstroPy at scipy.org>
>>     http://mail.scipy.org/mailman/listinfo/astropy
>>
>>
>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> http://mail.scipy.org/mailman/listinfo/astropy
>>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy



-- 
Vinu Vikraman
http://www.sas.upenn.edu/~vinu/



More information about the AstroPy mailing list