import matplotlib.pyplot as plt
from astropy.io import fits
import os
import numpy as np
from scipy import stats
import tkinter as tk
from tkinter.ttk import Combobox,Button
class fitsGUI():
def __init__(self):
################################################################################################################
"""设置主窗口,主场口大小为1000*1000"""
self.root=tk.Tk()
self.root.geometry('1000x1000')
################################################################################################################
"""设置第一个组合框,用来选择当前目录下的fits文件"""
self.combobox1=Combobox(master=self.root,value=os.listdir(),state="readonly")
self.combobox1.place(relx=0,rely=0,relheight=0.03,relwidth=0.2)
self.combobox1.bind('<<ComboboxSelected>>',self.comboboxSelect1)
################################################################################################################
"""设置一个按钮,组合框3和4选择好数据之后按动按钮,开始以3的数据为x,4的数据为y绘制散点图"""
self.plotButton=Button(master=self.root,text='StartPlot',command=self.plotButtonFunc)
self.plotButton.place(relx=4/10,rely=1/10,relheight=0.5/10,relwidth=2/10)
################################################################################################################
"""主窗口运行"""
self.root.mainloop()
self.hdul.close()
def comboboxSelect1(self,event):
"""第一个组合框对应的函数,用来显示选中的当前目录下的fits"""
fitsName=self.combobox1.get()
self.hdul=fits.open(fitsName)
self.hdul.info()
tableNum=len(self.hdul)
self.tableList=[self.hdul[i].header['EXTNAME'] for i in range(1,tableNum)]
############################################################
"""设置第二个组合框,用来显示所选fits的所有Table"""
# tableList=self.tableList
# tableList.append("PRIMARY")
self.combobox2=Combobox(master=self.root,value=self.tableList,state="readonly")
self.combobox2.place(relx=0.3,rely=0,relheight=0.03,relwidth=0.2)
self.combobox2.bind('<<ComboboxSelected>>',self.comboboxSelect2)
def comboboxSelect2(self,event):
"""第二个组合框对应的函数,第二个组合框是用来选择当前hdul中的tableName的"""
self.tableName=self.combobox2.get()
fieldNameList=self.hdul[self.tableName].columns.names
print(self.hdul[self.tableName].columns)
############################################################
"""设置第三个和第四个组合框,这两个组合框里面都是第二个选出的table中的filedName,然后分别选一个用来画散点图"""
self.combobox3=Combobox(master=self.root,value=fieldNameList,state="readonly")
self.combobox3.place(relx=0.6,rely=0,relheight=0.03,relwidth=0.12)
self.combobox3.bind('<<ComboboxSelected>>',self.comboboxSelect3)
self.combobox4=Combobox(master=self.root,value=fieldNameList,state="readonly")
self.combobox4.place(relx=0.85,rely=0,relheight=0.03,relwidth=0.12)
self.combobox4.bind('<<ComboboxSelected>>',self.comboboxSelect4)
def comboboxSelect3(self,event):
filedNameX=self.combobox3.get()
self.xData=self.hdul[self.tableName].data[filedNameX]
def comboboxSelect4(self,event):
filedNameY = self.combobox4.get()
self.yData=self.hdul[self.tableName].data[filedNameY]
def plotButtonFunc(self):
plt.close()
fig=plt.figure(figsize=(10,10))
ax=plt.axes((0.1,0.1,0.8,0.8))
ax.scatter(self.xData,self.yData,s=2,c='black')
plt.show()
if __name__=="__main__":
fitsGUI()
读fits的tkinter程序
最新推荐文章于 2024-05-14 11:00:23 发布