from astropy.io import fits
from astropy.table import Table
# set memmap=True for large files
with fits.open("my_file.fits", memmap=True):
# select the HDU you want
hdu = hdu_list[1]
# read into an astropy Table object
table = Table(hdu.data)
# write to a CSV file
data.write('path/to/output/my_file.ecsv', delimiter='\t', format='ascii')
@Iguananaut是正确的;以下是作为模板的代码示例:
您当然不希望对图像执行此操作,但对于表,中间CSV格式在某些情况下可能很有用,例如导入数据库
Astropy表已经可以直接写入CSV。无需先将其放入数据帧中。Astropy具有广泛的CSV和ASCII表格功能,适用于天文学中使用的格式。见https://docs.astropy.org/en/stable/io/ascii/write.html#table-or-numpy-structured-array
然而,正如其他人所指出的,将一个非常大的表转储为文本格式可能是不合适的,因为它可能是巨大的,并且对于大多数软件来说很难有效地处理。您应该考虑其他二进制格式(其中几个,例如HD5,也由AtdiPy支持),或者只提取您需要共享的特定数据,或者只共享FITE文件。p>
相关问题 更多 >
编程相关推荐