pyfits 读取bintable

时间:2021-08-15 12:08:22
import pyfits as pf
import numpy as np
import math
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter #from matplotlib.patches import Ellipse
hdulist = pf.open('ID301_0001.FITS')
image = hdulist[0].data
header = hdulist[0].header
col = hdulist[1].columns
print col
print col.names table = hdulist[1].data
print hdulist.info()
print type(table)
nt = np.array(table)
print nt.shape
tnt = nt.T
print tnt
b = np.array([0,1,0,0,0,0,0])
print (nt[b==1])
a0 = table.field(0)
a1 = table.field(1)
a2 = table.field(2)
a3 = table.field(3)
a4 = table.field(4)
a5 = table.field(5)
a6 = table.field(6)
print ( a0)
print ( a1)
print ( a2)
print ( a3)
print ( a4) print ( a5)
print ( a6)
table2 = table[a1==0]
acd = np.zeros(18)
print acd
b0 = table2.field(0)
b1 = table2.field(1)
b2 = table2.field(2)
b3 = table2.field(3)
b4 = table2.field(4)
b5 = table2.field(5)
b6 = table2.field(6)
ii =0
print b4[0].sum()
while ii<(table2.shape)[0]:
for j in range(0,18):
if b4[ii][j] ==True:
acd[j]=acd[j]+1
# print acd[j]
ii= ii+1 print acd print b4[0].sum()

table读取以后,用field来获得各列数据,为numpy里的array格式。