Add a column to fits file with Astropy

孤人 提交于 2019-12-23 02:48:20

问题


I have a fits files of event data, and I need to modify one of the tables by adding a new column of data derived by the data stored in a preexisting column of the same table. The problem I have is in closing the modified file. This is the code:

data = fits.open(events, extname='events')
t1 = data[1].data.field('time')
table = Table.read(events, format='fits')
t2 = Column(name='T2', data=t1)
table.add_column(t2)

How can I close the file writing on the same file as in input? If I try with table.write(events, format='fits') I receive an error due to the writing on an existing file, while if I try to close data the modifications are not written in the file.


回答1:


They just recently added an overwrite option (similar to the usual clobber):

table.write(events, format='fits', overwrite='True')


来源:https://stackoverflow.com/questions/21620643/add-a-column-to-fits-file-with-astropy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!