This repository was archived by the owner on Oct 18, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathGUI_driver.py
More file actions
370 lines (252 loc) · 14.2 KB
/
Copy pathGUI_driver.py
File metadata and controls
370 lines (252 loc) · 14.2 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
## written by Sarah Betti 2019
## updated 5 November 2019
import numpy as np
import os
import tkinter as tk
from tkinter import *
from tkinter import ttk, StringVar, IntVar, BooleanVar
from tkinter.filedialog import askopenfilename, askdirectory
from PIL import ImageTk, Image
class Window:
def __init__(self,window):
self.name = StringVar()
self.instrument = StringVar()
self.signal = StringVar()
self.signalpath = ''
self.weight = StringVar()
self.weightpath = ''
self.sn = StringVar()
self.snpath = ''
self.psf = StringVar()
self.psfpath = ''
self.noisepath = StringVar()
self.temp = StringVar()
self.temppath = ''
self.wcs = self.temp
self.nh2 = StringVar()
self.nh2path = ''
self.yso = StringVar()
self.ysopath = ''
self.racol = IntVar()
self.deccol = IntVar()
self.outbase = StringVar()
self.wave = IntVar()
self.pcdist = IntVar()
self.sn_thresh = IntVar()
self.sim = BooleanVar()
window.title('ImSeg Reduction')
ttk.Style().configure('red.TButton', background='red')
#name
y = 0
ttk.Label(window, text='Name').grid(row=y)
ttk.Entry(window, textvariable=self.name).grid(row=y,column=1, ipadx=3, ipady=5, sticky='W')
y+=1
ttk.Label(window, text='Instrument').grid(row=y)
ttk.Entry(window, textvariable=self.instrument).grid(row=y,column=1, ipadx=3, ipady=5, sticky='W')
y+=1
ttk.Button(window, text='Get signal\nmap', command = lambda : self.load_signal()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.signal, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open fits', command = lambda : self.process_fits(self.signalpath)).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
y+=1
#sn
ttk.Button(window, text='Get S/N\nmap', command = lambda : self.load_sn()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.sn, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open fits', command = lambda : self.process_fits(self.snpath)).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
#weight
y+=1
ttk.Button(window, text='Get weight\nmap', command = lambda : self.load_weight()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.weight, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open fits', command = lambda : self.process_fits(self.weightpath)).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
#psf
y+=1
ttk.Button(window, text='Get psf\nmap', command = lambda : self.load_psf()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.psf, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open fits', command = lambda : self.process_fits(self.psfpath)).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
#noise path
y+=1
ttk.Button(window, text='Get noisepath', command = lambda : self.load_noise_path()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.noisepath, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
y+=1
ttk.Label(window, text='wavelength').grid(row=y)
wavelength = ttk.Entry(window, textvariable=self.wave).grid(row=y, column=1,ipadx=3, ipady=5, sticky='W')
y+=1
ttk.Label(window, text='distance').grid(row=y)
wavelength = ttk.Entry(window, textvariable=self.pcdist).grid(row=y, column=1,ipadx=3, ipady=5, sticky='W')
y+=1
ttk.Label(window, text='S/N threshold').grid(row=y)
wavelength = ttk.Entry(window, textvariable=self.sn_thresh).grid(row=y, column=1,ipadx=3, ipady=5, sticky='W')
y+=1
ttk.Label(window, text='Simulation? (T=1/F=0)').grid(row=y)
wavelength = ttk.Entry(window, textvariable=self.sim).grid(row=y, column=1,ipadx=3, ipady=5, sticky='W')
#temperature
y+=1
ttk.Button(window, text='Get temp', command = lambda : self.load_temp_wcs()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.temp, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open fits', command = lambda : self.process_fits(self.temppath)).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
# NH2
y+=1
ttk.Button(window, text='Get NH2', command = lambda : self.load_NH2()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.nh2, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open fits', command = lambda : self.process_fits(self.nh2path)).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
ttk.Label(window, text='ImSeg Reduction Steps').grid(row=y, column =3, columnspan=2)
# YSO
y+=1
ttk.Button(window, text='Get YSO', command = lambda : self.load_yso()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.yso, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Open text file', command = lambda : self.read_yso()).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
# RUN GET BLOBS
self.getblobs = BooleanVar()
self.getblobs.set(False)
self.run_getblobs = ttk.Checkbutton(window, text="run Image\nSegmenation", var=self.getblobs).grid(row=y, column=3,sticky='W')
# RUN NOISE BLOBS
self.getnoiseblobs = BooleanVar()
self.getnoiseblobs.set(False)
self.run_getnoiseblobs = ttk.Checkbutton(window, text="run noise Image\nSegmentation", var=self.getnoiseblobs).grid(row=y, column=4,sticky='W')
#YSO COLUMNS
y+=1
ttk.Label(window, text='YSO RA column #').grid(row=y)
ttk.Entry(window, textvariable=self.racol).grid(row=y, column=1,ipadx=3, ipady=5, sticky='W')
# RUN CORE SELECTION
self.coresel = BooleanVar()
self.coresel.set(False)
self.run_coreselection = ttk.Checkbutton(window, text="run core\nselection", var=self.coresel).grid(row=y, column=3, sticky='W', rowspan=2)
# # RUN DO CORRECTIONS
# self.docorr = BooleanVar()
# self.docorr.set(False)
# self.do_corrections = ttk.Checkbutton(window, text="do corrections", var=self.docorr).grid(row=y, column=4,sticky='W', rowspan=2)
y+=1
ttk.Label(window, text='YSO Dec column #').grid(row=y, column=0)
ttk.Entry(window, textvariable=self.deccol).grid(row=y, column=1,ipadx=3, ipady=5, sticky='W')
# y+=1
# self.entry_var = StringVar()
# ttk.Entry(window, textvariable=self.entry_var, width=20).grid(row=y,column=0, ipadx=1, ipady=1)
#
# ttk.Button(window, text='print noisepath / yso', command = lambda : self.process_filename(y)).grid(row=y, column=1,ipadx=5, ipady=15)
# OUTBASE
y+=1
ttk.Button(window, text='Get outbase', command = lambda : self.get_outbase()).grid(row=y, ipadx=5, ipady=15, sticky="ew")
ttk.Entry(window, textvariable=self.outbase, width=70).grid(row=y,column=1, ipadx=1, ipady=1,sticky='W')
ttk.Button(window, text='Make outbase', command = lambda : self.make_outbase()).grid(row=y, column=2, ipadx=5, ipady=15, sticky="ew")
y+=1
ttk.Button(window, text='RUN', command = lambda : self.runImseg(), style='red.TButton').grid(row=y, column=3,ipadx=5, ipady=15)
for row in range(y):
window.grid_rowconfigure(row, weight=1)
for col in range(3):
window.grid_columnconfigure(col, weight=1)
ttk.Separator(window, orient=VERTICAL).grid(column=2, row=0, rowspan=y, sticky='ns'+'E')
ttk.Separator(window, orient=VERTICAL).grid(column=3, row=0, rowspan=y, sticky='ns'+'W')
def load_signal(self):
self.signalpath = askopenfilename(filetypes=(("FITS files", "*.fits"), ("All files", "*.*") ))
self.signal.set(self.signalpath)
def load_weight(self):
self.weightpath = askopenfilename(filetypes=(("FITS files", "*.fits"), ("All files", "*.*") ))
self.weight.set(self.weightpath)
def load_sn(self):
self.snpath = askopenfilename(filetypes=(("FITS files", "*.fits"), ("All files", "*.*") ))
self.sn.set(self.snpath)
def load_psf(self):
self.psfpath = askopenfilename(filetypes=(("FITS files", "*.fits"), ("All files", "*.*") ))
self.psf.set(self.psfpath)
def load_noise_path(self):
filename = askdirectory()
self.noisepath.set(filename)
def load_temp_wcs(self):
temp = askopenfilename(filetypes=(("FITS files", "*.fits"), ("All files", "*.*") ))
self.temppath = temp
self.temp.set(self.temppath)
self.wcs.set(self.temppath)
def load_NH2(self):
fil = askopenfilename(filetypes=(("FITS files", "*.fits"), ("All files", "*.*") ))
self.nh2path = fil
self.nh2.set(self.nh2path)
def load_yso(self):
fil = askopenfilename()
self.ysopath = fil
self.yso.set(self.ysopath)
def read_yso(self):
if self.ysopath != 'None':
print(np.loadtxt(self.ysopath))
def get_outbase(self):
filename = askdirectory()
self.outbase.set(filename)
def make_outbase(self):
if not os.path.exists(self.outbase.get()):
os.makedirs(self.outbase.get())
print(f'{self.outbase.get()} folder is made')
else:
print('folder already exists')
def process_fits(self, filename):
os.system(f"ds9 {filename}")
def process_filename(self,y):
if self.entry_var.get() == 'noisepath':
if self.noisepath.get():
ttk.Label(window, text= self.noisepath.get()).grid(row=y, column=2)
else:
ttk.Label(window, text= "must provide path").grid(row=y, column=2)
elif self.entry_var.get() == 'yso':
if self.yso.get():
ttk.Label(window, text= self.yso.get()).grid(row=y, column=2)
else:
ttk.Label(window, text= "must provide file").grid(row=y, column=2)
elif self.entry_var.get() == 'outbase':
if self.outbase.get():
ttk.Label(window, text= self.outbase.get()).grid(row=y, column=2)
else:
ttk.Label(window, text= "must provide path").grid(row=y, column=2)
elif self.entry_var.get() == 'sim':
if self.sim.get() is not None:
if (self.sim.get() == 0) or (self.sim.get() == False):
ttk.Label(window, text= "False").grid(row=y, column=2)
if (self.sim.get() == 1) or (self.sim.get() == True):
ttk.Label(window, text= "True").grid(row=y, column=2)
else:
ttk.Label(window, text= "must provide True or False").grid(row=y, column=2)
else:
ttk.Label(window, text= 'options are:\nnoisepath, yso, outbase, sim').grid(row=y, column=2)
def runImseg(self):
name = self.name.get()
print('------------------- o ---------------------')
print(name)
signal = self.signal.get()
sn = self.sn.get()
weight = self.weight.get()
psf = self.psf.get()
noisepath = self.noisepath.get()
wavelength = int(self.wave.get())
pcdist = int(self.pcdist.get())
sn_thresh = self.sn_thresh.get()
sim = self.sim.get()
temp = self.temp.get()
wcs = self.wcs.get()
coldens = self.nh2.get()
ysoradec = self.yso.get()
outbase = self.outbase.get()
run_getblobs = self.getblobs.get()
run_getnoiseblobs = self.getnoiseblobs.get()
run_coreselection = self.coresel.get()
ysora = self.racol.get()
ysodec = self.deccol.get()
instrument = self.instrument.get()
os.system(f"python driver.py {name} {signal} {sn} {weight} {psf} {noisepath} {wavelength} {pcdist} {sn_thresh} {sim} {temp} {wcs} {coldens} {ysoradec} {outbase} {run_getblobs} {run_getnoiseblobs} {run_coreselection} {ysora} {ysodec} {instrument}")
im = Image.open(f'{self.outbase.get()}/clumpfind_cores.png')
width = 400
height = 200
im = im.resize((width,height), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)
labels = ttk.Label(window, image = photo)
labels.image = photo
labels.grid(row=0, column=3,rowspan=4, columnspan=2)
ttk.Button(window, text='Open blobprint fits', command = lambda : self.process_fits(f'{self.outbase.get()}/cores_blobprints.fits')).grid(row=4, column=3, ipadx=5, ipady=15, columnspan=2)
if run_coreselection == True:
im = Image.open(f'{self.outbase.get()}/histogram_cmf.png')
width = 250
height = 180
im = im.resize((width,height), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)
labels = ttk.Label(window, image = photo)
labels.image = photo
labels.grid(row=5, column=3,rowspan=7, columnspan=2)
window = Tk()
window.geometry("1300x700")
gui=Window(window)
window.mainloop()