本文介绍了如何将两个表与pyfits合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python 2.7.10和pyfits 3.3.之前,我使用以下代码合并两个表.但是,现在我遇到了一些错误
I am using Python 2.7.10 And pyfits 3.3. Earlier, I have used the following code to merge two tables. However, now I am getting some errors
t1 = pyfits.open(table1)[1].columns
t2 = pyfits.open(table2)[1].columns
new_columns = t1 + t2
hdu = pyfits.BinTableHDU.from_columns(new_columns)
hdu.writeto(outtable)
错误是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vvikraman/anaconda2/lib/python2.7/site-packages/pyfits/hdu/table.py", line 116, in from_columns
data = FITS_rec.from_columns(coldefs, nrows=nrows, fill=fill)
File "/home/vvikraman/anaconda2/lib/python2.7/site-packages/pyfits/fitsrec.py", line 315, in from_columns
if arr.hdu.data is None:
ReferenceError: weakly-referenced object no longer exists
推荐答案
是否有不能使用astropy
(即astropy.io.fits
)的原因?
Is there a reason you cannot use astropy
(i.e. astropy.io.fits
)?
在这种情况下,惯用法是:
In that case the idiom would be:
from astropy.table import Table, hstack
t1 = Table.read(table1)
t2 = Table.read(table2)
new = hstack([t1, t2])
new.write(outtable)
在read
和write
调用中,如果表名称扩展名并不暗示它是FITS,则需要提供format='fits'
.
In both the read
and write
calls, you need to provide format='fits'
if the table name extension(s) do not imply that it is FITS.
这篇关于如何将两个表与pyfits合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!