-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlay_ver2.py
385 lines (298 loc) · 10.1 KB
/
overlay_ver2.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 14 12:19:54 2019
@author: anshu
"""
import matplotlib.pyplot as plt
from astropy.io import fits
import numpy as np
import tkinter as tk
from tkinter import Tk,Frame,messagebox,Menu
import os
from tkinter import filedialog
import cv2
import os, glob
import random
import math
from os import path
import sys
import subprocess
import pdb
import sunpy
import sunpy.data.sample
import sunpy.map
from sunpy.sun import constants as con
from sunpy.map import header_helper
from astropy.io import fits
import astropy.units as u
from sunpy.coordinates import frames
from astropy.coordinates import SkyCoord
from scipy import ndimage, misc
import matplotlib.pyplot as plt
from matplotlib.backend_bases import key_press_handler
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import math
from tkinter.constants import TOP, BOTH, BOTTOM, LEFT
from tkinter.ttk import *
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
#import pylab
root= tk.Tk()
root.style = Style()
root.style.theme_use("clam")
root.minsize(1200,600)
root.title('Overlay Window')
mainFrame = tk.Frame(root)
mainFrame.grid()
entryFrame = tk.Frame(mainFrame, width=454, height=20)
entryFrame.grid(row=0, column=1)
entryFrame.columnconfigure(0, weight=10)
entryFrame.grid_propagate(False)
def OpenLASCO1():
global LASCO_file1
LASCO_file1=filedialog.askopenfile(initialdir='pwd',title='Select LASCO fits file')
if '.fts' in LASCO_file1.name:
print('You have selected LASCO fits file correctly')
else:
messagebox.showerror('Extension Error','You chose a wrong file!! Please choose a png file')
return None
def OpenLASCO2():
global LASCO_file2
LASCO_file2=filedialog.askopenfile(initialdir='pwd',title='Select LASCO fits file')
if '.fts' in LASCO_file2.name:
print('You have selected LASCO fits file correctly')
else:
messagebox.showerror('Extension Error','You chose a wrong file!! Please choose a png file')
return None
def OpenGRAPH():
global GRAPH_file
GRAPH_file=filedialog.askopenfile(initialdir='pwd',title='Select GRAPH fits file')
if '.fits' in GRAPH_file.name:
print('You have selected GRAPH fits file correctly')
else:
messagebox.showerror('Extension Error','You chose a wrong file!! Please choose a png file')
return None
def plotLASCO():
global LASCO_data1
global LASCO_data2
global LASCO_diff
hdulist = fits.open(LASCO_file1.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
t=hdu.data
LASCO_data1=t*1e12
hdulist = fits.open(LASCO_file2.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
t=hdu.data
LASCO_data2=t*1e12
LASCO_diff=LASCO_data2-LASCO_data1
LASCO_diff = np.flipud(LASCO_diff)
figure = Figure(figsize=(12, 6), dpi=100)
plot = figure.add_subplot(1, 1, 1)
canvas = FigureCanvasTkAgg(figure, root)
canvas.get_tk_widget().grid(row=0, column=0)
plot.imshow(LASCO_diff, cmap = 'gray', interpolation = 'bicubic')
#plot.gca().invert_yaxis()
circle1 = plt.Circle((512, 512), 41*2, color='b', fill=False)
plot.set_title('Whitelight CME LASCO-C2')
plot.set_xlabel('X (pixels)')
plot.set_ylabel('Y (pixels)')
ax = plot.gca()
ax.set_ylim(ax.get_ylim()[::-1])
return LASCO_diff
def plotGRAPH():
global grh
global hdu
global k
global grh_rot
global lev
hdulist = fits.open(GRAPH_file.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
grh1=hdu.data
grh=grh1[0,0,:,:]
lev=np.linspace(10,100,12)*np.max(grh)/100
k=hdu.header['DATE-OBS']
a=sunpy.coordinates.sun.P(k)
print(a.deg)
grh_rot = ndimage.rotate(grh, a.deg, reshape=False)
RA_c=hdu.header['CRVAL1']
DEC_c=hdu.header['CRVAL2']
figure = Figure(figsize=(12, 6), dpi=100)
plot = figure.add_subplot(1, 1, 1)
canvas = FigureCanvasTkAgg(figure, root)
canvas.get_tk_widget().grid(row=0, column=0)
plot.contour(grh_rot, lev, extend='both')
circle1 = plt.Circle((255, 255), 41, color='b', fill=False)
plot.gca().invert_yaxis()
plot.add_artist(circle1)
plot.set_aspect('equal', 'box')
plot.set_title('Radio contours for Type II Burst')
plot.set_xlabel('X (pixels)')
plot.set_ylabel('Y (pixels)')
return grh,k,a,grh_rot
def plotAll():
global LASCO_data1
global LASCO_data2
global LASCO_diff
global grh
global k
global grh_rot
global lev
hdulist = fits.open(LASCO_file1.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
t=hdu.data
LASCO_data1=t*1e12
hdulist = fits.open(LASCO_file2.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
t=hdu.data
LASCO_data2=t*1e12
LASCO_diff=LASCO_data2-LASCO_data1
LASCO_diff = cv2.resize(LASCO_diff, (0,0), fx=0.5, fy=0.5)
LASCO_diff = np.flipud(LASCO_diff)
hdulist = fits.open(GRAPH_file.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
grh1=hdu.data
grh=grh1[0,0,:,:]
lev=np.linspace(10,100,12)*np.max(grh)/100
k=hdu.header['DATE-OBS']
a=sunpy.coordinates.sun.P(k)
grh_rot = ndimage.rotate(grh, a.deg, reshape=False)
figure = Figure(figsize=(12, 6), dpi=100)
plot = figure.add_subplot(1, 1, 1)
canvas = FigureCanvasTkAgg(figure, root)
canvas.get_tk_widget().grid(row=0, column=0)
plot.imshow(LASCO_diff, cmap = 'gray', interpolation = 'bicubic')
plot.contour(grh_rot, lev, extend='both')
circle1 = plt.Circle((255, 255), 41*2, color='b', fill=False)
plot.gca().invert_yaxis()
plot.add_artist(circle1)
plot.set_title('Composite Image of Whitelight CME and Radio contours for Type II Burst')
plot.set_xlabel('X (pixels)')
plot.set_ylabel('Y (pixels)')
plt.ioff()
def LASCO_png():
LASCO_data1 = cv2.imread(LASCO_file1.name,0)
plt.imshow(LASCO_data, cmap = 'gray', interpolation = 'bicubic')
plt.savefig(LASCO_file.name+'new'+'.png')
plt.close()
def LASCO_pdf():
LASCO_data = cv2.imread(LASCO_file.name,0)
plt.imshow(LASCO_data, cmap = 'gray', interpolation = 'bicubic')
plt.savefig(LASCO_file.name+'.pdf')
plt.close()
def GRAPH_png():
hdulist = fits.open(GRAPH_file.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
grh1=hdu.data
grh=grh1[0,0,:,:]
lev=np.linspace(10,100,12)*np.max(grh)/100
k=hdu.header['DATE-OBS']
a=sunpy.coordinates.sun.P(k)
print(a.deg)
grh_rot = ndimage.rotate(grh, a.deg, reshape=False)
plt.contour(grh_rot, lev, extend='both')
plt.savefig(GRAPH_file.name+'.png')
plt.close()
def GRAPH_pdf():
hdulist = fits.open(GRAPH_file.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
grh1=hdu.data
grh=grh1[0,0,:,:]
lev=np.linspace(10,100,12)*np.max(grh)/100
k=hdu.header['DATE-OBS']
a=sunpy.coordinates.sun.P(k)
print(a.deg)
grh_rot = ndimage.rotate(grh, a.deg, reshape=False)
plt.contour(grh_rot, lev, extend='both')
plt.savefig(GRAPH_file.name+'.pdf')
plt.close()
def Composite_png():
LASCO_data = cv2.imread(LASCO_file.name,0)
hdulist = fits.open(GRAPH_file.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
grh1=hdu.data
grh=grh1[0,0,:,:]
lev=np.linspace(10,100,12)*np.max(grh)/100
k=hdu.header['DATE-OBS']
a=sunpy.coordinates.sun.P(k)
grh_rot = ndimage.rotate(grh, a.deg, reshape=False)
plt.imshow(LASCO_data, cmap = 'gray', interpolation = 'bicubic')
plt.contour(grh_rot, lev, extend='both')
plt.savefig(k+'.png')
plt.close()
def Composite_pdf():
LASCO_data1 = cv2.imread(LASCO_file1.name,0)
LASCO_data2 = cv2.imread(LASCO_file2.name,0)
LASCO_diff = LASCO_data2 - LASCO_data1
hdulist = fits.open(GRAPH_file.name)
hdulist.info()
hdu = hdulist[0]
hdu.data.shape
grh1=hdu.data
grh=grh1[0,0,:,:]
lev=np.linspace(10,100,12)*np.max(grh)/100
k=hdu.header['DATE-OBS']
a=sunpy.coordinates.sun.P(k)
grh_rot = ndimage.rotate(grh, a.deg, reshape=False)
plt.imshow(LASCO_data, cmap = 'gray', interpolation = 'bicubic')
plt.contour(grh_rot, lev, extend='both')
plt.savefig(k+'.pdf')
plt.close()
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
def close():
if messagebox.askyesno("Overlay plotting tool","Do you really want to exit?"):
root.destroy()
else:
return None
menu = tk.Menu(root)
mfile = tk.Menu(menu)
mfile.add_command(label="OpenLASCO", command=OpenLASCO1)
mfile.add_command(label="OpenLASCO", command=OpenLASCO2)
mfile.add_command(label="OpenGRAPH", command=OpenGRAPH)
mplot = tk.Menu(menu)
mplot.add_command(label="Plot LASCO", command=plotLASCO)
mplot.add_command(label="Plot GRAPH", command=plotGRAPH)
mplot.add_command(label="Overlay", command=plotAll)
manalysis = tk.Menu(menu)
manalysis.add_command(label="HT_plot", command=plotLASCO)
manalysis.add_command(label="Width", command=plotGRAPH)
manalysis.add_command(label="...")
msave = tk.Menu(menu)
msave.add_command(label="LASCO_png", command=LASCO_png)
msave.add_command(label="LASCO_pdf", command=LASCO_pdf)
msave.add_command(label="GRAPH_png", command=GRAPH_png)
msave.add_command(label="GRAPH_pdf", command=GRAPH_pdf)
msave.add_command(label="Composite_png", command=Composite_png)
msave.add_command(label="Composite_pdf", command=Composite_pdf)
msave.add_command(label="...")
menu.add_cascade(label='File', menu=mfile)
menu.add_cascade(label='Plot', menu=mplot)
menu.add_cascade(label='Analysis',menu=manalysis)
menu.add_cascade(label='Save',menu=msave)
menu.add_command(label="Close", command=close)
root.config(menu=menu)
#root.mainloop()