-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnapPlay.py
More file actions
308 lines (267 loc) · 6.95 KB
/
SnapPlay.py
File metadata and controls
308 lines (267 loc) · 6.95 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
"""
This is similar to EnhancePlay.py but it is a simplification, focusing on the development of the CIMP Snapshot class and the enhancement methods it calls through the CIMP Enhance class. So, use EnhancePlay.py to assess new possible enhancement algorithms. But, use this to test the algorithms that are already implemented in the Enhance class.
"""
import numpy as np
import matplotlib.pyplot as plt
import sunpy.map
import sunpy.visualization.colormaps as cm
from CIMP import Snapshot as snap
pcase = 18
# dcase = 1: subtract the background
# dcase = 2: take a ratio with the background
dcase = 1
clip = None
scales = None
rmask = None
colormap = 'stereo'
if pcase == 1:
comp = (0,1)
testcase = 1
dcase = 1
pointfilter = True
scales = [(0,1),(0.05,4.0)]
elif pcase == 2:
comp = (0,2)
testcase = 1
dcase = 1
pointfilter = True
scales = [(0,1),(0.0,20.0)]
elif pcase == 3:
comp = (0,3)
testcase = 1
dcase = 1
pointfilter = True
#scales = [(0,1),(-25,400.0)]
colormap = 'lasco'
scales = [(0.01,.12),(0,100.0)]
elif pcase == 4:
comp = (0,4)
testcase = 1
dcase = 1
pointfilter = False
colormap = 'lasco'
rmask = 1.05
clip=(0.01, 0.12)
scales = [(0.01,.12),(0.0,1.0)]
elif pcase == 5:
comp = (0,5)
testcase = 1
dcase = 1
pointfilter = False
colormap = 'lasco'
rmask = 1.05
scales = [(0.01,.12),(0.1,1.0)]
elif pcase == 6:
comp = (0,1)
testcase = 1
dcase = 2
pointfilter = True
colormap = 'lasco'
scales = [(0.005,0.04),(0.1,0.9)]
elif pcase == 7:
# ratio with mgn enhance
comp = (0,4)
testcase = 1
dcase = 2
pointfilter = False
colormap = 'lasco'
rmask = 1.05
clip=(0.0, 0.1)
scales = [(0.005,0.04),(0.2,0.8)]
elif pcase == 8:
# ratio with fnrgf enhance
comp = (0,5)
testcase = 1
dcase = 2
pointfilter = False
colormap = 'lasco'
rmask = 1.05
clip=(0.0, 0.1)
scales = [(0.005,0.04),(0.2,0.9)]
elif pcase == 9:
# just a point filter and adaptive equalization
comp = (0,6)
testcase = 1
dcase = 2
pointfilter = True
colormap = 'lasco'
clip=(0.0, 0.1)
scales = [(0.005,0.04),(0.2,1.0)]
if pcase == 10:
# testcase 2 with just a point filter
comp = (0,1)
testcase = 2
dcase = 1
pointfilter = True
scales = [(0,1),(0.05,4.0)]
if pcase == 11:
# same as pcase 10 but with a ratio instead of a difference
comp = (0,1)
testcase = 2
dcase = 2
pointfilter = True
scales = [(0,.2),(0.05,4.0)]
elif pcase == 12:
# ratio with a point filter and adaptive equalization
comp = (0,6)
testcase = 2
dcase = 2
pointfilter = True
colormap = 'lasco'
clip=(0.0, 0.1)
scales = [(0.005,0.03),(0.2,1.0)]
elif pcase == 13:
# ratio with mgn enhance
comp = (0,4)
testcase = 2
dcase = 2
pointfilter = False
colormap = 'lasco'
rmask = 1.05
clip=(0.0, 0.1)
scales = [(0.005,0.03),(0.1,0.9)]
elif pcase == 14:
# ratio with fnrgf enhance
comp = (0,5)
testcase = 2
dcase = 2
pointfilter = False
colormap = 'lasco'
rmask = 1.05
clip=(0.0, 0.1)
scales = [(0.005,0.03),(0.1,0.9)]
elif pcase == 15:
# testcase 3 (CME model) with an r^2 filter
comp = (0,7)
testcase = 3
dcase = 0
pointfilter = False
scales = [(0,1),(0,1)]
elif pcase == 16:
# testcase 3 (CME model) with adaptive equalization
comp = (0,6)
testcase = 3
dcase = 2
pointfilter = False
colormap = 'lasco'
scales = [(0,1),(0,1.0)]
elif pcase == 17:
# testcase 3 (CME model) with mgn enhance
comp = (0,4)
testcase = 3
dcase = 2
pointfilter = False
colormap = 'lasco'
scales = [(0,1),(0,1.0)]
elif pcase == 18:
# testcase 3 (CME model) with fnrgf enhance
comp = (0,5)
testcase = 3
dcase = 2
pointfilter = False
colormap = 'lasco'
scales = [(0,1),(0,1.0)]
else:
print("specify a valid test case")
exit()
#------------------------------------------------------------------------------
x = snap.snapshot.testcase(testcase)
# set dcase to 0 if there is no background
if dcase == 1:
x.subtract_background()
elif dcase == 2:
x.background_ratio()
#------------------------------------------------------------------------------
# choose your battle
tag = None
images = []
titles = []
# default scales can be overridden
dscales = []
if comp.count(0) > 0:
titles.append("Base image")
images.append(x.data)
dscales.append((0.0,1.0))
if pointfilter:
x.point_filter()
if comp.count(1) > 0:
titles.append("Point filter")
images.append(x.data)
dscales.append((0.0,1.0))
if comp.count(2) > 0:
titles.append("NRGF")
x.nrgf()
images.append(x.data)
dscales.append((0.0,4.0))
if comp.count(3) > 0:
titles.append("FNRGF")
x.fnrgf()
images.append(x.data)
dscales.append((0.0,4.0))
if comp.count(4) > 0:
titles.append("enhance(mgn)")
x.enhance(clip = clip)
images.append(x.data)
dscales.append((0.0,1.0))
if comp.count(5) > 0:
titles.append("enhance(fnrgf)")
x.enhance(detail = 'fnrgf')
images.append(x.data)
dscales.append((0.0,1.0))
if comp.count(6) > 0:
titles.append("Adaptive equalization")
x.equalize()
images.append(x.data)
dscales.append((0.0,1.0))
if comp.count(7) > 0:
titles.append("r^2 filter")
x.powerlaw()
images.append(x.data)
dscales.append((0.0,1.0))
if rmask is not None:
x.mask_annulus(rmax = rmask)
#------------------------------------------------------------------------------
if scales is None:
scales = dscales
else:
if scales[0] is None:
scales[0] = dscales[0]
if scales[1] is None:
scales[1] = dscales[1]
#------------------------------------------------------------------------------
# plot
if colormap == 'stereo':
cmap = plt.get_cmap('stereocor2')
else:
cmap = plt.get_cmap('soholasco2')
fig = plt.figure(figsize=[16,8])
map1 = sunpy.map.Map(images[0],x.header)
print(f"image 1 range: {map1.min()} {map1.max()}")
ax = fig.add_subplot(1,2,1,projection=map1)
if scales[0] is None:
map1.plot(title=titles[0],cmap=cmap)
else:
print(f"image 1 scale: {scales[0][0]} to {scales[0][1]}")
map1.plot(vmin=scales[0][0], vmax=scales[0][1], title=titles[0],cmap=cmap)
map2 = sunpy.map.Map(images[1],x.header)
print(f"image 2 range: {map2.min()} {map2.max()}")
ax = fig.add_subplot(1,2,2,projection=map2)
if scales[1] is None:
map2.plot(title=titles[1],cmap=cmap)
else:
print(f"image 2 scale: {scales[1][0]} to {scales[1][1]}")
map2.plot(vmin=scales[1][0], vmax=scales[1][1], title=titles[1],cmap=cmap)
# ===================
# save to a file
# ===================
dir = '/home/mark.miesch/Products/image_processing/images/Enhance_snap/'
fname = f"Snap_t{testcase}_{comp[0]}_vs_{comp[1]}"
if dcase == 2:
fname += "_rat"
if pointfilter:
fname += "_pf"
if tag is not None:
fname += f"_{tag}"
file = dir + fname + ".png"
plt.savefig(file)
plt.show()