假设我有一个只有一个扩展名的 fits 文件,数据由一个包含两列的表格组成,每列有 100 个元素
data = pyfits.open('path2myfile')[1].data
head = pyfits.open('path2myfile')[1].header
print data['field1'] # print an array with 100 elements
print data['field2'] # print another array with 100 elements
现在我想在我的表中添加一个新列,假设是 data['field3'],这是另一个包含 100 个元素的数组。
我该怎么做?
最佳答案
正如 Iguananaut 指出的那样,可以在这里找到答案:http://pyfits.readthedocs.org/en/latest/users_guide/users_table.html#merging-tables 但只是为了将这个问题标记为已回答:
cols = []
cols.append(
pyfits.Column(name='field3', format='D', array= arrayContainingTheData)
)
orig_cols = data.columns
new_cols = pyfits.ColDefs(cols)
hdu = pyfits.BinTableHDU.from_columns(orig_cols + new_cols)
hdu.writeto('newtable.fits')
关于python - 使用 PyFITS 向 FITS 表添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25204612/