python - 使用 PyFITS 向 FITS 表添加列

标签 python fits pyfits

假设我有一个只有一个扩展名的 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/

相关文章:

python - 重新装箱时保留 FITS 文件的 WCS 信息

Python,PyFITS,无法打开文件

python - JSON 序列化器在 Django 中不起作用

python - 在 CSV 文件 python 中添加带逗号的字符串

python - astropy.io.fits 从具有多个 HDU 的大型拟合文件中读取行

image - 使用指定边界裁剪非常大的适合文件

python - 如何将等高线图(matplotlib)转换为带标题的 FITS 格式?

python - 更改 FITS 文件 header 中的关键字值

python - pycharm向前或向后移动光标1个字

python - globals() - _frozen_importlib.BuiltinImporter