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 | #from pygolem_lite import Shot
import numpy as np
import os, sys
import urllib
import matplotlib
matplotlib.rcParams['backend'] = 'Agg'
matplotlib.rc('font', size='10')
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
from scipy.ndimage import median_filter
from matplotlib.pyplot import axvline
def download(url, fileData, pap_name = "Papouch_Ko"):
"""
download
"""
print("ahoj")
def downloadCam(fileData,shotno):
try:
url = "http://golem.fjfi.cvut.cz/shots/%s/diagnostics/Radiation/0211FastCamera.ON/1/CorrectedRGB.png" %shotno
urllib.request.urlretrieve(url, fileData)
return 1
except:
print("can not get fast camera picture")
return 0
#urllib.request.urlretrieve("http://golem.fjfi.cvut.cz/shots/%s/diagnostics/Radiation/0211FastCamera.ON/1/CorrectedRGB.png" %shotno, soubor)
def download_value(url, valueName):
"""
Download and returns single value
"""
try:
with urllib.request.urlopen(url) as response:
val = response.read().splitlines()
val = float(val[0].decode(encoding="utf-8", errors="strict"))
return val
except:
print("can not get %s" %valueName)
return -1
def downloadBasics(shotno):
url_shotno = "http://golem.fjfi.cvut.cz/utils/data/%s/shotno" %(shotno)
url_start = "http://golem.fjfi.cvut.cz/utils/data/%s/plasma_start" %(shotno)
url_end = "http://golem.fjfi.cvut.cz/utils/data/%s/plasma_end" %(shotno)
start = download_value(url_start, "plasma start")
end = download_value(url_end, "plasma end")
shotNum = int(download_value(url_shotno, "shot number"))
return start,end,shotNum #if shotno was "0" then returns last shot number
#try:
#with urllib.request.urlopen(url_start) as response:
#start = response.read().splitlines()
#start = float(start[0].decode(encoding="utf-8", errors="strict"))
#except:
#print("can not get plasma start")
#return -1
#try:
#with urllib.request.urlopen(url_end) as response:
#end = response.read().splitlines()
#end = float(end[0].decode(encoding="utf-8", errors="strict"))
#except:
#print("can not get plasma end")
#return -1
def downloadUloop(fileData, shotno):
"""
Download papouch data to given file
"""
try:
url = "http://golem.fjfi.cvut.cz/utils/data/%s/loop_voltage" %(shotno)
urllib.request.urlretrieve(url, fileData)
except:
print("can not get data")
return -1
def downloadData(fileData, shotno, pap_name):
"""
Download papouch data to given file
"""
try:
url = "http://golem.fjfi.cvut.cz/shots/%s//DAS/%s.ON/Papouch_All.npz" %(shotno,pap_name)
urllib.request.urlretrieve(url, fileData)
except:
print("can not get data")
return -1
def make_img(data, fname, interpolation, start, end,shotno, label,title):
plt.figure(figsize=[20, 8]) #size in inches
plt.imshow(data,
aspect='auto',
extent = [start * 1e3, end * 1e3, #time extents in ms
20, 1,], #channel idx
interpolation=interpolation,
cmap=plt.cm.hot,
)
hx = plt.colorbar()
hx.set_label(label)
plt.xlabel('time [ms]')
plt.ylabel('AXUV1 CHANNEL NUMBER')
plt.text(1, 2, 'TOP', backgroundcolor = "w") #TODO white background of the text - same for bottom
plt.text(1, 18, 'BOTTOM', backgroundcolor = "w")
#cx = axvline(x = 16,linewidth=5, color='black')
#cx.set_label('16 ms')
plt.title(title)
plt.yticks(np.arange(1, 19+1))
plt.savefig(fname)
plt.close() #close this figure
def make_multiplot(data,dataUloop, fname, interpolation, start, end,shotno, label,title1, cam):
"""
plot bolo and fast camera image
"""
plot_num = 3
if not cam:
plot_num =plot_num-1
plot_numAct = 1
fig = plt.figure(figsize=[20, 15])
ax=fig.add_subplot(plot_num,1,1)
#plt.figure(figsize=[100, 20]) #TODO size in inches try to change text size,...
imgplot = plt.imshow(data,
aspect='auto',
extent = [start * 1e3, end * 1e3, #time extents in ms
20, 1,], #channel idx
interpolation=interpolation,
cmap=plt.cm.hot,
)
ax.set_title('Before')
hx = plt.colorbar()
hx.set_label(label)
plt.xlabel('time [ms]')
plt.ylabel('CHANNEL NUMBER')
plt.text(1, 2, 'TOP', backgroundcolor = "w") #white background of the text - same for bottom
plt.text(1, 18, 'BOTTOM', backgroundcolor = "w")
#cx = axvline(x = 16,linewidth=5, color='black')
#cx.set_label('16 ms')
plt.title(title1)
plt.yticks(np.arange(1, 19+1))
fig.subplots_adjust(hspace=0.40)
plot_numAct +=1
if cam:
ax=fig.add_subplot(plot_num,1,plot_numAct)
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
print("data directory is: %s" %os.getcwd())
img2 = mpimg.imread('PLOTS/0211FastCamera.png')
imgplot = plt.imshow(img2,aspect='auto',extent = [start * 1e3, end * 1e3, 20, 1,]) #need to be extended same way as bolo pic
ax.set_title('Fast Camera - corrected image')
plt.axis("off")
plot_numAct +=1
index_min = np.where(0.1 <= dataUloop)[0][0]
index_max = np.where(dataUloop >= 0.1)[0][-1]
dataUloop = dataUloop[index_min:index_max]
x = index_min/1e3 + np.arange(len(dataUloop))/1000
ax=fig.add_subplot(plot_num,1,plot_numAct)
ax.set_title('Uloop - SHOT: %s' %shotno)
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
plt.ylim((0,np.max(dataUloop)))
#plt.xlim(index_min,index_max)
plt.plot(x,dataUloop, "r-")
plt.axvline(start*1e3, color = "black", linestyle = "dashed")
plt.axvline(end*1e3, color = "black", linestyle = "dashed")
plt.xlabel("time [ms]")
plt.ylabel("U [V]")
plt.savefig(fname)
plt.close() #close this figure
def plot_cut(data, fname,shotno):
plt.plot(data[:,5000],'r+',markersize = 10)
plt.savefig(fname)
plt.xlabel('CHANNEL NUMBER')
plt.ylabel('P[W/sr/m$^2$]')
plt.title('SHOT NUMBER ' '%d'%shotno)
def make_plots(fileData,filePlots, shotno,start,end, cam = False):
#shot = Shot()
#t, data_ko = shot['papouch_ko']
#t, data_ja = shot['papouch_ja']
data_ko = np.load(fileData + "Papouch_Ko_All.npz")["data"]
data_ja = np.load(fileData + "Papouch_Ja_All.npz")["data"]
dataUloop = np.loadtxt(fileData + "Uloop_%s" %shotno)[:,1]
#t = np.load(fileData + "Papouch_Ja_All.npz")["data"][:,0]
#start = np.load("Papouch_Ja_All.npz")["t_start"]
#end = np.load("Papouch_Ja_All.npz")["t_end"]
t = np.linspace(0,len(data_ko[:,0])/1e6, len(data_ko[:,0]))
#vector_coef = np.genfromtxt('coeficients_AXUV2.txt') #TODO set after calibration is done
start_idx = np.where(start <= t)[0][0]
end_idx = np.where(t <= end)[0][-1]
print("plasma start= %f ,start index = %f" %(start,start_idx))
print("plasma end= %f, end index %f" %(end,end_idx))
data = np.hstack([data_ko,data_ja]) # NOTE: make sure this is the right order #spoji dohromady za sebou dve pole
data = data[start_idx:end_idx,0:21] #NOTE: osetrit, aby to nebralo ten sedmy kanal - -nejaka fce na vyhozeni
#dataUloop = dataUloop[start_idx:end_idx]
#only for changed channels in shots 24749-55
#data = np.delete(data,18,axis = 1)
#data[:,0:5] = data[:,0:5][:,::-1]
#data[:,5:10] = data[:,5:10][:,::-1]
#data[:,10:15] = data[:,10:15][:,::-1]
#data[:,15:20] = data[:,0:5][:,::-1]
print("data max is: %f" %np.max(data))
#for i in range(18):
#data[:,i] = data[:,i]*vector_coef[i]
print(np.max(data))
data = data.T#/100*np.max(data) # transpose to have time as x axis;
data_calib = data
print(len(data[12,:]))
#plt.hold(False)
plt.plot(data[12,:])
plt.savefig(filePlots + 'dvanacty_kanal.png')
#for i in range(18):
#data_calib[i,:] = data_calib[i,:]*vector_coef[i]
#plot_cut(data, filePlots + 'AXUV1_timecut.png',shotno)
#make_img(data, filePlots+ 'AXUV1.png', 'none', start, end,shotno, 'U[V]')
#if cam: #Fast camera picture available
#make_multiplot(median_filter(data, size=(3, 333)),dataUloop, filePlots+ 'AXUV1_medfilt-bicube_interp.png', 'bicubic', start, end,shotno, 'Amplified signal filtered [V]',
#'AXUV1 data - hot, median_filter (3,333), SHOT NUMBER: %d' %shotno, cam)
#make_multiplot(data,dataUloop, filePlots+ 'AXUV1.png', 'none', start, end,shotno, 'Amplified signal [V]','AXUV1 data - hot, without filter, SHOT NUMBER: %d' %shotno, cam)
make_multiplot(median_filter(data, size=(3, 333)),dataUloop, filePlots+ 'AXUV1_medfilt-bicube_interp.png', 'bicubic', start, end,shotno, 'Amplified signal filtered [V]',
'AXUV1 data - hot, median_filter (3,333), SHOT NUMBER: %d' %shotno, cam)
make_multiplot(data,dataUloop, filePlots+ 'AXUV1.png', 'none', start, end,shotno, 'Amplified signal [V]','AXUV1 data - hot, without filter, SHOT NUMBER: %d' %shotno, cam)
make_img(data_calib,filePlots+ 'AXUV1.png', 'none', start, end,shotno, 'U[V]', "AXUV1 - raw data, SHOT NUMBER: %d" %shotno)
make_img(median_filter(data, size=(3, 333)),filePlots+ 'AXUV1_medfit-bicubic.png', 'bicubic', start, end,shotno, 'U[V]', "AXUV1_medfit")
#make_multiplot(median_filter(data_calib, size=(3, 333)),filePlots+ 'AXUV1_calib_medfit.png', 'bicubic', start, end,shotno, 'P[W/sr/m$^2$]')
#TODO pridat obrazek z foto
#TODO to wiki: raw signal, median_filter, bicubic, compare to 0211FastCamera
def print_shotno(shotno):
print(shotno)
if __name__ == '__main__':
shotno = sys.argv[1]
#shotno = "0" #je treba zjistit cislo shotu
start,end,shotNum = downloadBasics(shotno)
shotno = str(shotNum)
fileData = "DATA/" #TODO presun dat na servru pro nove slozky
filePlots = "PLOTS/"
#try:
#os.mkdir(shotno)
#except: pass
try:
os.mkdir("DATA/")
except: pass
try:
os.mkdir("PLOTS/")
except: pass
print_shotno(shotno)
print("data directory is: %s" %os.getcwd())
downloadData(fileData + "Papouch_Ko_All.npz", shotno, "1113Papouch_Ko")
downloadData(fileData + "Papouch_Ja_All.npz", shotno, "0314Papouch_Ja")
downloadUloop(fileData + "Uloop_%s" %shotno, shotno)
cam = downloadCam(filePlots + "0211FastCamera.png",shotno)
make_plots(fileData,filePlots, shotNum,start,end, cam)
#TODO vyplot jen cast dat odpovidajici casu
#TODO vyplot spolecne s fotoaparatem snimkovani fotaku je 1200 snimku za 1s
|