假设我有一个扩展名为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个元素组成的数组。在
我到底该怎么做?在
@Cehem的回答是正确的。但我只想补充一点,Astropy有一个更好的通用Table接口,您可能会发现它更易于使用(用于在其他用例中插入列)。在
Astropy在astropy.io.fits模块中加入了PyFITS。但是,由于您还可以访问更好的表接口,因此您可以阅读大多数将表放入Astropy Table类,如下所示:
就这样。也可以将表写回FITS文件。诚然,这目前不支持all类型的FITS表,但它将适用于大多数和将来的所有类型。在
正如iguanaut指出的,答案可以在这里找到:http://pyfits.readthedocs.org/en/latest/users_guide/users_table.html#merging-tables 但要把这个问题标记为已回答:
相关问题 更多 >
编程相关推荐