-
Notifications
You must be signed in to change notification settings - Fork 6
/
test2d.py
266 lines (257 loc) · 14 KB
/
test2d.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
#!/public/home/users/bio001/tools/python-2.7.11/bin/python
import sdf
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import numpy as np
import os
from numpy import ma
from matplotlib import colors, ticker, cm
from matplotlib.mlab import bivariate_normal
if __name__ == "__main__":
print ('This is main of module "test2d.py"')
######## Constant defined here ########
pi = 3.1415926535897932384626
q0 = 1.602176565e-19 # C
m0 = 9.10938291e-31 # kg
v0 = 2.99792458e8 # m/s^2
kb = 1.3806488e-23 # J/K
mu0 = 4.0e-7*np.pi # N/A^2
epsilon0 = 8.8541878176203899e-12 # F/m
h_planck = 6.62606957e-34 # J s
wavelength= 1.0e-6
frequency = v0*2*pi/wavelength
exunit = m0*v0*frequency/q0
bxunit = m0*frequency/q0
denunit = frequency**2*epsilon0*m0/q0**2
jalf = 4*np.pi*epsilon0*m0*v0**3/q0/wavelength**2
print 'electric field unit: '+str(exunit)
print 'magnetic field unit: '+str(bxunit)
print 'density unit nc: '+str(denunit)
font = {'family' : 'monospace',
'color' : 'black',
'weight' : 'normal',
'size' : 20,
}
######### Parameter you should set ###########
start = 1 # start time
stop = 52 # end time
step = 1 # the interval or step
youwant = ['electron_x_px','electron_density','electron_en','electron_theta_en','ey'] #,'electron_ekbar']
#youwant = ['jx','jy','bz','ex','ey_averaged','ez','electron_density','carbon_density','photon_density','positron_density','electron_ekbar','photon_ekbar','electron_x_px']
#youwant field ex,ey,ez,bx,by,bz,ex_averaged,bx_averaged...
#youwant Derived electron_density,electron_ekbar...
#youwant dist_fn electron_x_px, electron_py_pz, electron_theta_en...
if (os.path.isdir('jpg') == False):
os.mkdir('jpg')
######### Script code drawing figure ################
for n in range(start,stop+step,step):
#### header data ####
print 'ok'
data = sdf.read("./Data/"+str(n).zfill(4)+".sdf",dict=True)
header=data['Header']
time=header['time']
print 'ok'
x = data['Grid/Grid_mid'].data[0]/1.0e-6
print 'ok'
y = data['Grid/Grid_mid'].data[1]/1.0e-6
X, Y = np.meshgrid(x, y)
for name in youwant:
if (name[0:2] == 'jx') or (name[0:2] == 'jy') or (name[0:2] == 'jz'):
ex = data['Current/'+str.capitalize(name)].data/jalf
if np.min(ex.T) == np.max(ex.T):
continue
eee=np.max([-np.min(ex.T),np.max(ex.T)])
levels = np.linspace(-eee, eee, 40)
plt.contourf(X, Y, ex.T, levels=levels, cmap=cm.PiYG)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=[-eee, -eee/2, 0, eee/2, eee])
cbar.set_label('Normalized current',fontdict=font)
plt.xlabel('X [$\mu m$]',fontdict=font)
plt.ylabel('Y [$\mu m$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
#plt1 = plt.twinx()
#plt1.plot(x,ex[:,y.size/2.0],'-k',linewidth=2.5)
#plt1.set_ylabel('Normalized '+name)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
if (name[0:2] == 'ex') or (name[0:2] == 'ey') or (name[0:2] == 'ez'):
ex = data['Electric Field/'+str.capitalize(name)].data/exunit
if np.min(ex.T) == np.max(ex.T):
continue
eee=np.max([-np.min(ex.T),np.max(ex.T)])
levels = np.linspace(-eee, eee, 40)
plt.contourf(X, Y, ex.T, levels=levels, cmap=cm.seismic)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=[-eee, -eee/2, 0, eee/2, eee])
cbar.set_label('Normalized electric field',fontdict=font)
plt.xlabel('X [$\mu m$]',fontdict=font)
plt.ylabel('Y [$\mu m$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
#plt1 = plt.twinx()
#plt1.plot(x,ex[:,y.size/2.0],'-k',linewidth=2.5)
#plt1.set_ylabel('Normalized '+name)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[0:2] == 'bx') or (name[0:2] == 'by') or (name[0:2] == 'bz'):
ex = data['Magnetic Field/'+str.capitalize(name)].data/bxunit
if np.min(ex.T) == np.max(ex.T):
continue
eee=np.max([-np.min(ex.T),np.max(ex.T)])
levels = np.linspace(-eee, eee, 40)
plt.contourf(X, Y, ex.T, levels=levels, cmap=cm.seismic)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=[-eee, -eee/2, 0, eee/2, eee])
cbar.set_label('Normalized magnetic field',fontdict=font)
plt.xlabel('X [$\mu m$]',fontdict=font)
plt.ylabel('Y [$\mu m$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
#plt1 = plt.twinx()
#plt1.plot(x,ex[:,y.size/2.0],'-k',linewidth=2.5)
#plt1.set_ylabel('Normalized '+name)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-7:] == 'density'):
den = data['Derived/Number_Density/'+name[0:-8]].data/denunit
if np.min(den.T) == np.max(den.T):
continue
levels = np.linspace(np.min(den.T), np.max(den.T), 40)
plt.contourf(X, Y, den.T, levels=levels, cmap=cm.nipy_spectral)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=np.linspace(np.min(den.T), np.max(den.T), 5))
cbar.set_label(name+'[$n_c$]', fontdict=font)
plt.xlabel('X [$\mu m$]',fontdict=font)
plt.ylabel('Y [$\mu m$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-5:] == 'ekbar'):
den = data['Derived/EkBar/'+name[0:-6]].data/(q0*1.0e6)
if np.min(den.T) == np.max(den.T):
continue
levels = np.linspace(np.min(den.T), np.max(den.T), 40)
plt.contourf(X, Y, den.T, levels=levels, cmap=cm.jet)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=np.linspace(np.min(den.T), np.max(den.T), 5))
cbar.set_label(name+'[MeV]', fontdict=font)
plt.xlabel('X [$\mu m$]',fontdict=font)
plt.ylabel('Y [$\mu m$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-4:] == 'x_px'):
den = data['dist_fn/x_px/'+name[0:-5]].data[:,:,0]
den = np.log(den+1.0)
if np.min(den.T) == np.max(den.T):
continue
levels = np.linspace(np.min(den.T), np.max(den.T), 40)
dist_x = data['Grid/x_px/'+name[0:-5]].data[0]/1.0e-6
dist_y = data['Grid/x_px/'+name[0:-5]].data[1]/(m0*v0)
dist_X, dist_Y = np.meshgrid(dist_x, dist_y)
plt.contourf(dist_X, dist_Y, den.T, levels=levels, cmap=cm.nipy_spectral)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=np.linspace(np.min(den.T), np.max(den.T), 5))
cbar.set_label(name+'[$log_{10}(A.U.)$]', fontdict=font)
plt.xlabel('X [$\mu m$]',fontdict=font)
plt.ylabel('$P_x$ [$m_ec$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-4:] == 'y_py'):
den = data['dist_fn/y_py/'+name[0:-5]].data[:,:,0]
den = np.log(den+1.0)
if np.min(den.T) == np.max(den.T):
continue
levels = np.linspace(np.min(den.T), np.max(den.T), 40)
dist_x = data['Grid/y_py/'+name[0:-5]].data[0]/1.0e-6
dist_y = data['Grid/y_py/'+name[0:-5]].data[1]/(m0*v0)
dist_X, dist_Y = np.meshgrid(dist_x, dist_y)
plt.contourf(dist_X, dist_Y, den.T, levels=levels, cmap=cm.nipy_spectral)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=np.linspace(np.min(den.T), np.max(den.T), 5))
cbar.set_label(name+'[$log_{10}(A.U.)$]', fontdict=font)
plt.xlabel('Y [$\mu m$]',fontdict=font)
plt.ylabel('$P_y$ [$m_ec$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-5:] == 'py_pz'):
den = data['dist_fn/py_pz/'+name[0:-6]].data[:,:,0]
den = np.log(den+1.0)
if np.min(den.T) == np.max(den.T):
continue
levels = np.linspace(np.min(den.T), np.max(den.T), 40)
dist_x = data['Grid/py_pz/'+name[0:-6]].data[0]/(m0*v0)
dist_y = data['Grid/py_pz/'+name[0:-6]].data[1]/(m0*v0)
dist_X, dist_Y = np.meshgrid(dist_x, dist_y)
plt.contourf(dist_X, dist_Y, den.T, levels=levels, cmap=cm.nipy_spectral)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=np.linspace(np.min(den.T), np.max(den.T), 5))
cbar.set_label(name+'[$log_{10}(A.U.)$]', fontdict=font)
plt.xlabel('$P_y$ [$m_ec$]',fontdict=font)
plt.ylabel('$P_z$ [$m_ec$]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-8:] == 'theta_en'):
denden = data['dist_fn/theta_en/'+name[0:-9]].data[:,:,0]
den = np.log(denden+1.0)
if np.min(den.T) == np.max(den.T):
continue
levels = np.linspace(np.min(den.T), np.max(den.T), 40)
dist_x = data['Grid/theta_en/'+name[0:-9]].data[0]
dist_y = data['Grid/theta_en/'+name[0:-9]].data[1]/(q0*1.0e6)
dist_X, dist_Y = np.meshgrid(dist_x, dist_y)
plt.contourf(dist_X, dist_Y, den.T, levels=levels, cmap=cm.nipy_spectral)
#### manifesting colorbar, changing label and axis properties ####
cbar=plt.colorbar(ticks=np.linspace(np.min(den.T), np.max(den.T), 5))
cbar.set_label(name+'[$log_{10}(A.U.)$]', fontdict=font)
plt.xlabel('$\Psi$ [rad]',fontdict=font)
plt.ylabel('$Energy$ [MeV]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
plt1 = plt.twinx()
plt1.plot(dist_x,np.sum(denden,axis=1),'-y',linewidth=2.5)
#plt1.set_ylabel('Normalized '+name)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
elif (name[-2:] == 'en'):
den = data['dist_fn/en/'+name[0:-3]].data[:,0,0]
dist_x = data['Grid/en/'+name[0:-3]].data[0]/(q0*1.0e6)
plt.plot(dist_x,den,'-r',linewidth=3)
#### manifesting colorbar, changing label and axis properties ####
plt.xlabel('Energy [MeV]',fontdict=font)
plt.ylabel('dN/dE [A.U.]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
plt.title(name+' at '+str(round(time/1.0e-15,6))+' fs',fontdict=font)
fig = plt.gcf()
fig.set_size_inches(12, 7)
fig.savefig('./jpg/'+name+str(n).zfill(4)+'.png',format='png',dpi=100)
plt.close("all")
print 'finised '+str(round(100.0*(n-start+step)/(stop-start+step),4))+'%'