forked from Michael-Gong/visualization-script-for-LPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap_novel_trace_rotate_worky.py
207 lines (163 loc) · 6.49 KB
/
wrap_novel_trace_rotate_worky.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
import sdf
import matplotlib
matplotlib.use('agg')
#%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
#from numpy import ma
from matplotlib import colors, ticker, cm
from matplotlib.mlab import bivariate_normal
from optparse import OptionParser
import os
import matplotlib.colors as mcolors
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import matplotlib.gridspec as gridspec
from numpy import ma
from matplotlib import colors, ticker, cm
from matplotlib.mlab import bivariate_normal
import matplotlib.colors as mcolors
import scipy.ndimage as ndimage
######## 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*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
print('electric field unit: '+str(exunit))
print('magnetic field unit: '+str(bxunit))
print('density unit nc: '+str(denunit))
font = {'family' : 'monospace',
'style' : 'normal',
'color' : 'black',
'weight' : 'normal',
'size' : 20,
}
font2 = {'family' : 'monospace',
'style' : 'normal',
'color' : 'black',
'weight' : 'normal',
'size' : 20,
}
directory = './txt_1300/'
px = np.loadtxt(directory+'px2d_x.txt')
py = np.loadtxt(directory+'py2d_x.txt')
xx = np.loadtxt(directory+'xx2d_x.txt')
yy = np.loadtxt(directory+'yy2d_x.txt')
workx2d = np.loadtxt(directory+'workx2d_x.txt')
worky2d = np.loadtxt(directory+'worky2d_x.txt')
fieldex = np.loadtxt(directory+'fieldex2d_x.txt')/4.0
fieldey = np.loadtxt(directory+'fieldey2d_x.txt')/4.0
fieldbz = np.loadtxt(directory+'fieldbz2d_x.txt')/4.0
ey_averaged = -8.0/3.2*yy
bz_averaged = -8.0/3.2*yy
laser_ey = fieldey-ey_averaged
laser_bz = fieldbz-bz_averaged
gg = (px**2+py**2+1)**0.5
R = gg-px
theta = np.arctan2(py,px)
number=400
plt.subplot(2,1,1)
#axin1 = inset_axes(ax, width='15%', height='5%', loc='upper left')
#axin2 = inset_axes(ax, width='15%', height='5%', loc='upper center')
grid_t = np.zeros(130)
grid_y = np.linspace(-3.5,3.5,140)
grid_data = np.zeros([130,140])
index=68
for n in range(5,130,1):
data = sdf.read("./Data_a20_130_2/"+str(n).zfill(4)+".sdf",dict=True)
header=data['Header']
grid_t[n]=header['time']/1e-15
x = data['Grid/Grid_mid'].data[0]/1.0e-6
y = data['Grid/Grid_mid'].data[1]/1.0e-6
name = 'ey'
ex = data['Electric Field/'+str.capitalize(name)].data/exunit
xi=np.min(np.where(xx[index,(n-5)*10] < x))
print(np.shape(ex[xi, 380:520]))
grid_data[n,:] = (ex[xi, 380:520] + ex[xi-1, 380:520])*0.5
X, Y = np.meshgrid(grid_t, grid_y)
levels = np.linspace(-28.1, 28.1, 50)
grid_data[grid_data < -28]=-28
grid_data[grid_data > 28]= 28
plt.contourf((Y).T, X.T, grid_data, levels=levels, norm=mcolors.Normalize(vmin=levels.min(), vmax=levels.max()), cmap=cm.jet)
cbar=plt.colorbar(ticks=np.linspace(-28,28,5))#,orientation="horizontal")
cbar.set_label('$E_y$ [$m_ec\omega_0/e$]', fontdict=font2)
norm_x = matplotlib.colors.Normalize(vmin=np.min(worky2d[index,0:1299:20]),vmax=np.max(worky2d[index,0:1299:20]))
print(np.shape(grid_t),np.shape(xx[index,0:1299:10]-(n-15)))
plt.scatter(yy[index,0:1299:20], grid_t[5::2], c=worky2d[index,0:1299:20], norm=norm_x, s=60, cmap='hot', edgecolors='black')
cbar=plt.colorbar()#orientation="horizontal")
cbar.set_label('Work$_y$ [$m_ec^2$]', fontdict=font2)
#plt.xlabel('Energy [MeV]',fontdict=font)
plt.ylabel('time [fs]',fontdict=font)
plt.xlabel('y [$\mu$m]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20)
plt.text(1,350,'LDA',fontdict=font)
#plt.yscale('log')
plt.xlim(-3.4,3.4)
plt.ylim(10,430)
#plt.legend(loc='best',fontsize=20,framealpha=0.5)
directory = './txt_1300/'
px = np.loadtxt(directory+'px2d_y.txt')
py = np.loadtxt(directory+'py2d_y.txt')
xx = np.loadtxt(directory+'xx2d_y.txt')
yy = np.loadtxt(directory+'yy2d_y.txt')
workx2d = np.loadtxt(directory+'workx2d_y.txt')
worky2d = np.loadtxt(directory+'worky2d_y.txt')
fieldex = np.loadtxt(directory+'fieldex2d_y.txt')/4.0
fieldey = np.loadtxt(directory+'fieldey2d_y.txt')/4.0
fieldbz = np.loadtxt(directory+'fieldbz2d_y.txt')/4.0
ey_averaged = -8.0/3.2*yy
bz_averaged = -8.0/3.2*yy
laser_ey = fieldey-ey_averaged
laser_bz = fieldbz-bz_averaged
gg = (px**2+py**2+1)**0.5
R = gg-px
theta = np.arctan2(py,px)
plt.subplot(2,1,2)
grid_t = np.zeros(130)
grid_y = np.linspace(-3.5,3.5,140)
grid_data = np.zeros([130,140])
index=3
for n in range(5,130,1):
data = sdf.read("./Data_a20_130_2/"+str(n).zfill(4)+".sdf",dict=True)
header=data['Header']
grid_t[n]=header['time']/1e-15
x = data['Grid/Grid_mid'].data[0]/1.0e-6
y = data['Grid/Grid_mid'].data[1]/1.0e-6
name = 'ey'
ex = data['Electric Field/'+str.capitalize(name)].data/exunit
xi=np.min(np.where(xx[index,(n-5)*10] < x))
print(np.shape(ex[xi, 380:520]))
grid_data[n,:] = (ex[xi, 380:520] + ex[xi-1, 380:520])*0.5
X, Y = np.meshgrid(grid_t, grid_y)
levels = np.linspace(-28.1, 28.1, 50)
grid_data[grid_data < -28]=-28
grid_data[grid_data > 28]= 28
plt.contourf((Y).T, X.T, grid_data, levels=levels, norm=mcolors.Normalize(vmin=levels.min(), vmax=levels.max()), cmap=cm.jet)
cbar=plt.colorbar(ticks=np.linspace(-28,28,5))#,orientation="horizontal")
cbar.set_label('$E_y$ [$m_ec\omega_0/e$]', fontdict=font2)
norm_x = matplotlib.colors.Normalize(vmin=np.min(worky2d[index,0:1299:20]),vmax=np.max(worky2d[index,0:1299:20]))
plt.scatter(yy[index,0:1299:20], grid_t[5::2], c=worky2d[index,0:1299:20], norm=norm_x, s=60, cmap='hot', edgecolors='black')
cbar=plt.colorbar()#orientation="horizontal")
cbar.set_label('Work$_y$ [$m_ec^2$]', fontdict=font2)
#plt.scatter(grid_t[5:], xx[index,0:1299:10]-(grid_t[5:]/3.3333333-15), c=workx2d[index,0:1299:10], norm=norm_x, s=30, cmap='hot', edgecolors='black')
#plt.xlabel('Energy [MeV]',fontdict=font)
plt.ylabel('time [fs]',fontdict=font)
plt.xlabel('y [$\mu$m]',fontdict=font)
plt.xticks(fontsize=20); plt.yticks(fontsize=20);
#plt.yscale('log')
plt.xlim(-3.4,3.4)
plt.ylim(10,430)
plt.text(1,350,'TDA',fontdict=font)
#plt.legend(loc='best',fontsize=20,framealpha=0.5)
fig = plt.gcf()
fig.set_size_inches(11.2, 13.3)
fig.savefig('./figure_wrap_up/'+'move_window_rotate_ey_worky.png',format='png',dpi=160)
plt.close("all")