-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisual.py
executable file
·402 lines (344 loc) · 12.6 KB
/
visual.py
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
try:
import sys
import os
import numpy as np
from astropy.io import fits as pf
import ds9
from Tkinter import *
except ImportError as error:
print "You don't have module {0} installed".format(error.message[16:])
if error.message[16:]=='ds9':
print "See {0} documentation for installation details".format('SAO pyds9')
if error.message[16:]=='fits':
print "See {0} documentation for installation details".format('Astropy fits')
sys.exit(1)
class Stripe82:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="Stripe 82 Title", command=self.onClick1)
self.button1.pack()
self.button2 = Button(frame, text="Radio", command=self.onClick2)
self.button2.pack()
self.button3 = Button(frame, text="FIR", command=self.onClick3)
self.button3.pack()
self.button4 = Button(frame, text="MIR", command=self.onClick4)
self.button4.pack()
self.button5 = Button(frame, text="Op/NIR", command=self.onClick5)
self.button5.pack()
self.button6 = Button(frame, text="UV", command=self.onClick6)
self.button6.pack()
self.button7 = Button(frame, text="X-Ray", command=self.onClick7)
self.button7.pack()
self.button8 = Button(frame, text="Save Image", command=self.onClick8)
self.button8.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
self.rad_exist, self.fir_exist, self.mir_exist, self.op_nir_exist, self.uv_exist, self.xray_exist, self.save_exist = ([None],[None],[None],[None],[None],[None],[None])
def onClick1(self):
d.set('regions stripe82_title.reg')
def onClick2(self):
newWindow("Radio Footprints","300x100+300+300",bands[1],self.rad_exist)
def onClick3(self):
newWindow("Far Infrared Footprints","300x75+300+300",bands[2],self.fir_exist)
def onClick4(self):
newWindow("Mid-Infrared Footprints","300x125+300+300",bands[3],self.mir_exist)
def onClick5(self):
newWindow("Optical/Near Infrared Footprints","300x150+300+300",bands[4],self.op_nir_exist)
def onClick6(self):
newWindow("Ultraviolet Footprints","300x75+300+300",bands[5],self.uv_exist)
def onClick7(self):
newWindow("X-Ray Footprints","300x100+300+300",bands[6],self.xray_exist)
def onClick8(self):
newWindow("Save Image","200x175+300+300",bands[7],self.save_exist)
def onClick0(self):
d.set('regions delete all')
class Radio:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="VLA (Hodge 2011)", command=self.onClick1)
self.button1.pack()
self.button2 = Button(frame, text="CNSS", command=self.onClick2)
self.button2.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
def onClick1(self):
d.set('regions vla_foot.reg')
def onClick2(self):
d.set('regions CNSS_foot.reg')
def onClick0(self):
d.set('regions delete all')
class FIR:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="HeLMS and HeRS", command=self.onClick1)
self.button1.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
def onClick1(self):
d.set('regions HeLMS_and_HeRS_only.reg')
def onClick0(self):
d.set('regions delete all')
class MIR:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="SHELA", command=self.onClick1)
self.button1.pack()
self.button2 = Button(frame, text="SpIES (Ch. 1)", command=self.onClick2)
self.button2.pack()
self.button3 = Button(frame, text="SpIES (Ch. 2)", command=self.onClick3)
self.button3.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
def onClick1(self):
d.set('regions SHELA.reg')
def onClick2(self):
d.set('regions SpIES_regions_ch1.reg')
def onClick3(self):
d.set('regions SpIES_regions_ch2.reg')
def onClick0(self):
d.set('regions delete all')
class Op_NIR:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="SDSS S82", command=self.onClick1)
self.button1.pack()
self.button2 = Button(frame, text="HSC", command=self.onClick2)
self.button2.pack()
self.button3 = Button(frame, text="DES", command=self.onClick3)
self.button3.pack()
self.button4 = Button(frame, text="PRIMUS", command=self.onClick4)
self.button4.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
def onClick1(self):
d.set('regions stripe82.reg')
def onClick2(self):
d.set('regions HSC.reg')
def onClick3(self):
d.set('regions DES.reg')
def onClick4(self):
d.set('regions PRIMUS_stripe82.reg')
d.set('regions PRIMUS_stripe82_masks.reg')
def onClick0(self):
d.set('regions delete all')
class UV:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="GALEX", command=self.onClick1)
self.button1.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
self.im_exist = [None]
self.leg_exist = [None]
def onClick1(self):
if self.im_exist[0] is None:
image = Toplevel()
image.title('GALEX Survey(s)')
image.geometry('+650+300')
entry = Entry(image, bd=3)
image.bind("<Return>", (lambda event, e=entry: self.survey(e,image)))
label = Label(image, text="Please enter 'dis', 'mis', 'ais', or 'all' (separated by commas if multiple) for desired survey(s)")
label.pack(side=LEFT)
entry.pack(side=LEFT)
self.im_exist[0] = 1
image.protocol("WM_DELETE_WINDOW", lambda image=image: existance(image,self.im_exist))
if self.leg_exist[0] is None:
legend = Toplevel()
legend.title('GALEX Survey Legend')
legend.geometry('225x100+1645+300')
legend.configure(background='grey20')
Label(legend, text='AIS', fg='white', bg='grey20', font=('TkDefaultFont',24)).pack()
Label(legend, text='MIS', fg='red', bg='grey20', font=('TkDefaultFont',24)).pack()
Label(legend, text='DIS', fg='blue', bg='grey20', font=('TkDefaultFont',24)).pack()
self.leg_exist[0] = 1
legend.protocol("WM_DELETE_WINDOW", lambda legend=legend: existance(legend,self.leg_exist))
def survey(self, entry, image):
surveylist = ['dis','mis','ais']
surveys = [x.strip() for x in entry.get().split(',')]
if len(surveys)>1:
if all((y in surveys for y in surveylist)):
d.set('regions gr67.reg')
elif all((y in surveys for y in [surveylist[0],surveylist[1]])):
d.set('regions gr67_dis.reg')
d.set('regions gr67_mis.reg')
elif all((y in surveys for y in [surveylist[0],surveylist[2]])):
d.set('regions gr67_dis.reg')
d.set('regions gr67_ais.reg')
elif all((y in surveys for y in [surveylist[2],surveylist[2]])):
d.set('regions gr67_mis.reg')
d.set('regions gr67_ais.reg')
else:
if surveys[0] == 'all':
d.set('regions gr67.reg')
if surveys[0] == surveylist[0]:
d.set('regions gr67_dis.reg')
if surveys[0] == surveylist[1]:
d.set('regions gr67_mis.reg')
if surveys[0] == surveylist[2]:
d.set('regions gr67_ais.reg')
image.destroy()
def onClick0(self):
d.set('regions delete all')
class XRAY:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="Chandra", command=self.onClick1)
self.button1.pack()
self.button2 = Button(frame, text="XMM-Newton", command=self.onClick2)
self.button2.pack()
self.button0 = Button(frame, text="Clear All Footprints", command=self.onClick0)
self.button0.pack()
self.im_exist = [None]
self.leg_exist = [None]
def onClick1(self):
if self.im_exist[0] is None:
image = Toplevel()
image.title('Chandra Camera(s)')
image.geometry('+650+300')
entry = Entry(image, bd=3)
image.bind("<Return>", (lambda event, e=entry: self.camera(e,image)))
label = Label(image, text="Please enter 'acis-s', 'acis-i', 'hrc-s', 'hrc-i', or 'all' (separated by commas if multiple) for desired survey(s)")
label.pack(side=LEFT)
entry.pack(side=LEFT)
self.im_exist[0] = 1
image.protocol("WM_DELETE_WINDOW", lambda image=image: existance(image,self.im_exist))
if self.leg_exist[0] is None:
legend = Toplevel()
legend.title('Chandra Camera Legend')
legend.geometry('225x135+1645+300')
legend.configure(background='grey20')
Label(legend, text='ACIS-S', fg='red', bg='grey20', font=('TkDefaultFont',24)).pack()
Label(legend, text='ACIS-I', fg='blue', bg='grey20', font=('TkDefaultFont',24)).pack()
Label(legend, text='HRC-S', fg='magenta', bg='grey20', font=('TkDefaultFont',24)).pack()
Label(legend, text='HRC-I', fg='green2', bg='grey20', font=('TkDefaultFont',24)).pack()
self.leg_exist[0] = 1
legend.protocol("WM_DELETE_WINDOW", lambda legend=legend: existance(legend,self.leg_exist))
def camera(self, entry, image):
cameralist = ['acis-s','acis-i','hrc-s','hrc-i']
cameras = [x.strip() for x in entry.get().split(',')]
if len(cameras)>1:
if all((y in cameras for y in cameralist)):
d.set('regions chandra_foot.reg')
elif all((y in cameras for y in [cameralist[0],cameralist[1]])):
d.set('regions chandra_acis-s.reg')
d.set('regions chandra_acis-i.reg')
elif all((y in cameras for y in [cameralist[2],cameralist[3]])):
d.set('regions chandra_hrc-s.reg')
d.set('regions chandra_hrc-i.reg')
else:
if cameras[0] == 'all':
d.set('regions chandra_foot.reg')
if cameras[0] == cameralist[0]:
d.set('regions chandra_acis-s.reg')
if cameras[0] == cameralist[1]:
d.set('regions chandra_acis-i.reg')
if cameras[0] == cameralist[2]:
d.set('regions chandra_hrc-s.reg')
if cameras[0] == cameralist[3]:
d.set('regions chandra_hrc-i.reg')
image.destroy()
def onClick2(self):
d.set('regions xmm_archival.reg')
d.set('regions xmm_ao10.reg')
def onClick0(self):
d.set('regions delete all')
class Save:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button1 = Button(frame, text="PNG", command=lambda x=self.onClick0: x('png'))
self.button1.pack()
self.button2 = Button(frame, text="EPS", command=lambda x=self.onClick0: x('eps'))
self.button2.pack()
self.button3 = Button(frame, text="JPEG", command=lambda x=self.onClick0: x('jpeg'))
self.button3.pack()
self.button4 = Button(frame, text="FITS", command=lambda x=self.onClick0: x('fits'))
self.button4.pack()
self.button5 = Button(frame, text="GIF", command=lambda x=self.onClick0: x('gif'))
self.button5.pack()
self.button6 = Button(frame, text="TIFF", command=lambda x=self.onClick0: x('tiff'))
self.button6.pack()
self.im_exist = [None]
def onClick0(self,type):
if self.im_exist[0] is None:
image = Toplevel()
image.title('Save as {0} Image'.format(type.upper()))
image.geometry('+550+300')
entry = Entry(image, bd=3)
image.bind("<Return>", (lambda event, e=entry: self.saveimage(e,image,type)))
label = Label(image, text='.{0}'.format(type))
entry.pack(side=LEFT)
label.pack(side=LEFT)
self.im_exist[0] = 1
image.protocol("WM_DELETE_WINDOW", lambda image=image: existance(image,self.im_exist))
def saveimage(self, entry, image, type):
if def_dir=="D":
d.set('saveimage {0}.{1}'.format(entry.get(),type))
else:
d.set('saveimage {0}/{1}.{2}'.format(def_dir,entry.get(),type))
image.destroy()
def newWindow(Title,geo,band,ex):
if ex[0]==None:
wdw = Toplevel()
wdw.title(Title)
wdw.geometry(geo)
if band=='T':
app = Stripe82(wdw)
if band=='r':
app = Radio(wdw)
if band=='far':
app = FIR(wdw)
if band=='mid':
app = MIR(wdw)
if band=='op':
app = Op_NIR(wdw)
if band=='uv':
app = UV(wdw)
if band=='x':
app = XRAY(wdw)
if band=='save':
app = Save(wdw)
windows.append(wdw)
ex[0]=1
wdw.protocol('WM_DELETE_WINDOW', lambda wdw=wdw: closeWindow(wdw,ex))
def closeWindow(wdw, ex):
ex[0]=None
wdw.destroy()
if wdw in windows: windows.remove(wdw)
if not windows: root.quit()
def existance(wdw,ex):
ex[0] = None
wdw.destroy()
def visual():
global windows,bands,root,d,def_dir
def_dir = raw_input("Name of directory to save images in (Current Working Directory: D): ")
while os.path.isdir(def_dir)==False:
if def_dir=="D":
break
print "{0} does not exist".format(def_dir)
def_dir=raw_input("Try another directory: ")
d = ds9.ds9(wait=10)
d.set('regions delete all')
d.set('mosaic wcs stripe82_60_2.fits')
d.set('mosaic wcs stripe82_300_2.fits')
d.set('zoom to fit')
d.set('grid yes')
d.set('grid axes no')
d.set('wcs skyformat degrees')
d.set('regions stripe82_title.reg')
root = Tk()
root.withdraw()
s82_exist = [None]
windows=[]
bands=['T','r','far','mid','op','uv','x','save']
newWindow("Stripe 82","200x260+50+300",bands[0],s82_exist)
root.mainloop()
if __name__ == '__main__':
visual()