astropy对fits文件的基础操作
astropy讀取fits文件匯總
from astropy.io import fits
hdu_list = fits.open(image_file)
hdu_list.info()
image_data = hdu_list[0].data
print(type(image_data))
print(image_data.shape)
hdu_list.close() # 關閉,否則占用內存
如果你不需要查看fits頭文件,可以用fits.getdata代替前面的步驟
image_data = fits.getdata(image_file)
print(type(image_data))
print(image_data.shape)
plt.imshow(image_data, cmap=‘gray’) # 不指定顏色,默認為彩色
plt.colorbar()
#打印最大值最小值平均值和標準差
print(‘Min:’, np.min(image_data))
print(‘Max:’, np.max(image_data))
print(‘Mean:’, np.mean(image_data))
print(‘Stdev:’, np.std(image_data))
繪出柱狀圖
NBINS = 1000
histogram = plt.hist(image_data.flatten(), NBINS)
hdu=header data unit
hdul.info()
hdul[0].header
hdul[0].header[‘DATE’]
hdul[0].header.comments[‘fitsver’] #顯示關鍵字的注釋
list(hdul[0].header) # 顯示所有關鍵字
data = hdul[1].data
data.shape
data[0] # 第一行的數據
data.field(0) # 第一列的數據
data.field(‘utobs’)
data.field(‘freq’)
data.field(‘CHAN_BW’)
hdul[1].header
data[2][3] # 訪問第二行第三列數據
data.names # 查看字段,即field
data.field(‘DATA’)
hdr[‘targname’] = (‘NGC121-a’, ‘the observation target’) 為頭文件添加關鍵字,內容和注釋
參考文獻:https://www.cnblogs.com/cuiastro/p/13525114.html
總結
以上是生活随笔為你收集整理的astropy对fits文件的基础操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么淘宝客网站点击商品时候出现商品不存
- 下一篇: Quartz之基本使用