This repository was archived by the owner on Dec 16, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSlitTableViewer.py
More file actions
Latest commit
180 lines (128 loc) · 5.02 KB
/
Copy pathSlitTableViewer.py
File metadata and controls
180 lines (128 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 20 12:59:00 2023
@author: samos_dev
"""
importtkinterastk
# Used for styling the GUI
#from tkinter import ttk
# import filedialog module
fromtkinterimportfiledialog
fromPILimportImage,ImageTk,ImageOps
importos,sys
importshutil
#from astropy.io import ascii
importtime
importnumpyasnp
importpandasaspd
frompathlibimportPath
path=Path(__file__).parent.absolute()
local_dir=str(path.absolute())
parent_dir=str(path.parent)
sys.path.append(parent_dir)
importtksheet
fromtksheetimportSheet
importginga
fromginga.util.ap_regionimportastropy_region_to_ginga_canvas_objectasr2g
fromginga.util.ap_regionimportginga_canvas_object_to_astropy_regionasg2r
fromginga.canvasimportCompoundMixinasCM
#test plugin
#from ginga import plugin
fromginga.utilimportap_region
fromginga.AstroImageimportAstroImage
img=AstroImage()
fromastropy.ioimportfits
fromPILimportImage,ImageTk,ImageOps
importtkinterastk
fromtkinterimportttk
fromtkinter.filedialogimportaskopenfilename
importregions
fromregionsimportRegions
fromregionsimportPixCoord, RectanglePixelRegion, PointPixelRegion, RegionVisual
fromSAMOS_DMD_dev.CONVERT.CONVERT_classimportCONVERT
convert=CONVERT()
# popup window for Main_V7 that shows the slit setup
# when the user drops a slit somewhere, it will show up here
# user can see the slit parameters in pixel, DMD, and world coordinates.
# when user selects a slit on the canvas, it should highlight that row.
classSlitTableView(tk.Tk):
def__init__(self,): #master):
super().__init__()#master = master)
# changing the title of our master widget
self.title("Slit Table")
#Creation of init_window
self.geometry("700x407")
slitDF=pd.DataFrame(columns=["object","RA","DEC","image_xc","image_yc",
"image_x0", "image_y0", "image_x1",
"image_y1","dmd_xc","dmd_yc","dmd_x0",
"dmd_y0", "dmd_x1", "dmd_y1"])
self.slitDF=slitDF
vbox=tk.Frame(self, background="light gray")
vbox.place(x=4, y=4, anchor="nw", width=700, height=400)
self.vbox=vbox
stab=tksheet.Sheet(vbox,width=700,height=400,)
stab.headers(newheaders=slitDF.columns.values, index=None, reset_col_positions=False,
show_headers_if_not_sheet=True, redraw=False)
stab.grid()
#stab.insert_row(values=list(range(0,15)),redraw=True)
self.stab=stab
defadd_slit_obj(self, obj, viewer):
"""
Parameters
----------
obj : canvas object
Should be a rectangle or box.
image : image canvas view.
Get image for pix2radec conversion.
Returns
-------
None.
"""
obj_num=len(self.slitDF.index.values)+1
x, y=obj.center.x, obj.center.y
width, height=obj.width, obj.height
halfw=width/2
halfh=height/2
x0=x-halfw
x1=x+halfw
y0=y-halfh
y1=y+halfh
fits_x, fits_y=x+1, y+1
fits_x0, fits_y0=x0+1, y0+1
fits_x1, fits_y1=x1+1, y1+1
dmd_x, dmd_y=convert.CCD2DMD(fits_x, fits_y)
dmd_x, dmd_y=int(np.floor(dmd_x)), int(np.floor(dmd_y))
dmd_x0, dmd_y0=convert.CCD2DMD(fits_x0, fits_y0)
dmd_x0, dmd_y0=int(np.floor(dmd_x0)), int(np.floor(dmd_y0))
dmd_x1, dmd_y1=convert.CCD2DMD(fits_x1, fits_y1)
dmd_x1, dmd_y1=int(np.floor(dmd_x1)), int(np.floor(dmd_y1))
# Calculate WCS RA
try:
# NOTE: image function operates on DATA space coords
image=viewer.get_image()
ifimageisNone:
# No image loaded
return
ra, dec=image.pixtoradec(fits_x, fits_y,
format='float', coords='fits')
ra, dec=np.round(ra,6), np.round(dec,6)
exceptExceptionase:
#self.logger.warning("Bad coordinate conversion: %s" % (
# str(e)))
ra=np.nan
dec=np.nan
new_slitrow=pd.Series(np.array([obj_num, ra, dec, x, y, x0, y0,
x1, y1, dmd_x, dmd_y, dmd_x0, dmd_y0,
dmd_x1, dmd_y1]))
self.slitDF.loc[obj_num-1] =new_slitrow
self.stab.insert_row(values=list(new_slitrow.values),redraw=True)
#Root window created.
#Here, that would be the only window, but you can later have windows within windows.
#root = SlitTableView()
#size of the window
#root.geometry("400x330")
#Then we actually create the instance.
#app = Tk.Window(root)
#Finally, show it and begin the mainloop.
#root.mainloop()