我想学习如何从 FITS 文件头中获取信息并将该信息传输到 ascii 表。例如,这就是我获取信息的方式:
import pyfits
a = pyfits.open('data.fits')
header = a[0].header # Which should return something like this (It is BinHDUlist)
SIMPLE = T / conforms to FITS standards
/ institution responsible for creating this file
TELESCOP= 'Kepler ' / telescope
INSTRUME= 'Kepler Photometer' / detector type
OBJECT = 'KIC 8631743' / string version of KEPLERID
RA_OBJ = 294.466516 / [deg] right ascension
DEC_OBJ = 44.751131 / [deg] declination
如何创建包含 RA_OBJ 和 DEC_OBJ 的 ASCII 表?
编辑:我想创建一个 .dat 文件,其中包含标题中的两列(RA 和 DEC)。这是我正在尝试的示例:
import asciitable
import asciidata
import pyfits
import numpy as np
# Here I have taken all the fits files in my current directory and did the following:
# ls > z.txt so that all the fits files are in one place.
a = asciidata.open('z.txt')
i = 0 #There are 371 fits files in z.txt
while i<=370:
b = pyfits.open(a[0][i])
h = b[0].header
RA = np.array([h['RA_OBJ']])
DEC = np.array(h['DEC_OBJ']])
asciitable.write({'RA': RA, 'DEC': DEC}, 'coordinates.dat', names=['RA', 'DEC'])
i = i+1
我想为此编写一个 .dat 文件,其中包含以下内容:
RA DEC
### ###
... ...
... ...
... ...
相反,我的代码只是覆盖了以前文件的键。有任何想法吗?