forked from Vic-Flore/Warpx_Sims
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_wx.py
More file actions
204 lines (169 loc) · 7.14 KB
/
Copy pathplot_wx.py
File metadata and controls
204 lines (169 loc) · 7.14 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
### imports, constants
import h5py
import numpy as np
import matplotlib.pyplot as plt
import argparse
import sys
import os
from datetime import datetime
from matplotlib import gridspec
from matplotlib import colors
from scipy import constants
from openpmd_viewer import OpenPMDTimeSeries
nc = 6.968e27
qe = constants.e
mp = constants.m_p
c = constants.c
### import h5 data with openPMD
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="warpx PiC sim summary plotter")
parser.add_argument("--simdir", required=True, type=str)
parser.add_argument("--comment", required=False, type=str, default=str(datetime.now()).replace(" ","_"))
args = parser.parse_args()
simdir=args.simdir
comment=args.comment
os.chdir(simdir)
if not os.path.exists('./plots/'):
os.makedirs('./plots/')
Data = './diags/diag2/'
savedir = './plots/'
ts = OpenPMDTimeSeries(Data)
it = ts.iterations
time = ts.t
j = 1 # iteration for plotting
### plot + save E field data
Ey, info_Ey = ts.get_field(t=time[j], field='E', coord='y', plot=False)
Ez = ts.get_field(t=time[j], field='E', coord='z', plot=False)[0]
zmin = info_Ey.zmin*1e6
zmax = info_Ey.zmax*1e6
xmin = info_Ey.xmin*1e6
xmax = info_Ey.xmax*1e6
Z = np.linspace(zmin, zmax, len(Ey))
X = np.linspace(xmin, xmax, len(Ey[0]))
Ey = Ey.T
Ez = Ez.T
res = Ey.shape
plt.rcParams["figure.figsize"] = (15,14)
G = gridspec.GridSpec(2, 2,hspace=0.2,wspace=0.1)
ax0 = plt.subplot(G[0,0:2])
laser_field = ax0.pcolormesh(Z,X,Ey,cmap='jet')
ax0.set_title('Fields at t='+'Time: {:.2e} ps'.format(time[j]*10**12),fontsize=30)
ax0.tick_params('x',labelsize=25)
ax0.tick_params('y',labelsize=25)
ax0.set_ylabel(r'x $\mu$m', fontsize = 25)
ax0.set_xlabel(r'z $\mu$m', fontsize = 25)
cb0 = plt.colorbar(laser_field, ax=ax0)
cb0.set_label('Ey', size=25)
ax1 = plt.subplot(G[1,0:2])
acc_field = ax1.pcolormesh(Z, X, Ez,cmap='jet', norm=colors.LogNorm())
ax1.tick_params('x',labelsize=25)
ax1.tick_params('y',labelsize=25)
ax1.set_ylabel(r'x $\mu$m', fontsize = 25)
ax1.set_xlabel(r'z $\mu$m', fontsize = 25)
cb1 = plt.colorbar(acc_field, ax=ax1)
cb1.set_label('Ez', size=25)
plt.savefig(savedir + 'Efield_'+str(res[0])+'x'+str(res[1])+'_'+comment+'_'+ str(time[j]) +'.png')
plt.close()
j = -1
### plot + save densities
plt.rcParams["figure.figsize"] = (15,16)
rhrs = ts.get_field( t=time[j], field='rho_hydrogen', cmap='inferno_r')[0]
#rhfs = ts.get_field( t=time[j], field='rho_hydrogen_fs', cmap='inferno_r')[0]
re = ts.get_field( t=time[j], field='rho_electrons', cmap='inferno_r')[0]
rd = ts.get_field(t=time[j], field='rho_deuterium',cmap='inferno_r')[0]
rhrs_dens = (rhrs/qe)/nc
#rhfs_dens = (rhfs/qe)/nc
re_dens = (-re/qe)/nc
rd_dens = (rd/qe)/nc
G = gridspec.GridSpec(3, 2,hspace=0.6,wspace=0.1)
ax0 = plt.subplot(G[0,0:2])
charge_bg_dens = ax0.pcolormesh(Z,X,np.log(rhrs_dens.T + 0.00001 ),cmap='seismic', norm=colors.TwoSlopeNorm(vmin=np.log(rhrs_dens.min() + 0.00001), vcenter=0, vmax=np.log(rhrs_dens.max() + 0.00001)))
ax0.set_title('H+ Density, Time: {:.2e} ps'.format(time[j]*10**12),fontsize=30)
ax0.tick_params('x',labelsize=25)
ax0.tick_params('y',labelsize=25)
ax0.set_ylabel(r'x $\mu$m', fontsize = 25)
ax0.set_xlabel(r'z $\mu$m', fontsize = 25)
cb0 = plt.colorbar(charge_bg_dens, ax=ax0)
cb0.ax.tick_params(labelsize=25)
cb0.set_label('log n/n_c',size=25)
ax1 = plt.subplot(G[1,0:2])
proton_dens = ax1.pcolormesh(Z,X,np.log(rd_dens.T + 0.00001 ),cmap='seismic', norm=colors.TwoSlopeNorm(vmin=np.log(rd_dens.min() + 0.00001), vcenter=0, vmax=np.log(rd_dens.max() + 0.00001)))
ax1.tick_params('x',labelsize=25)
ax1.tick_params('y',labelsize=25)
ax1.set_ylabel(r'x $\mu$m', fontsize = 25)
ax1.set_xlabel(r'z $\mu$m', fontsize = 25)
ax1.set_title('D+ Density, Time: {:.2e} ps'.format(time[j]*10**12),fontsize=30)
cb1 = plt.colorbar(proton_dens, ax=ax1)
cb1.ax.tick_params(labelsize=25)
cb1.set_label('log n/n_c',size=25)
ax2 = plt.subplot(G[2,0:2])
proton_dens = ax2.pcolormesh(Z,X,np.log(re_dens.T + 0.00001 ),cmap='seismic', norm=colors.TwoSlopeNorm(vmin=np.log(re_dens.min() + 0.00001), vcenter=0, vmax=np.log(re_dens.max() + 0.00001)))
ax2.tick_params('x',labelsize=25)
ax2.tick_params('y',labelsize=25)
ax2.set_ylabel(r'x $\mu$m', fontsize = 25)
ax2.set_xlabel(r'z $\mu$m', fontsize = 25)
ax2.set_title('e- Density, Time: {:.2e} ps'.format(time[j]*10**12),fontsize=30)
cb2 = plt.colorbar(proton_dens, ax=ax2)
cb2.ax.tick_params(labelsize=25)
cb2.set_label('log n/n_c',size=25)
'''
ax3 = plt.subplot(G[3,0:2])
proton_dens = ax3.pcolormesh(Z,X,np.log(rd_dens.T + 0.00001 ),cmap='seismic')
ax3.tick_params('x',labelsize=25)
ax3.tick_params('y',labelsize=25)
ax3.set_ylabel(r'x $\mu$m', fontsize = 25)
ax3.set_xlabel(r'z $\mu$m', fontsize = 25)
ax3.set_title('D+ Density, Time: {:.2e} ps'.format(time[j]*10**12),fontsize=30)
cb3 = plt.colorbar(proton_dens, ax=ax3)
cb3.ax.tick_params(labelsize=25)
cb3.set_label('log n/n_c',size=25)
'''
#ax0.set_xlim(-6, 12)
#ax1.set_xlim(-6, 12)
#ax2.set_xlim(-6, 12)
plt.savefig(savedir+'Densities_'+str(res[0])+'x'+str(res[1])+'_'+comment+'_'+ str(time[j]) +'.png')
plt.close()
### plot + save spectrum
plt.rcParams["figure.figsize"] = (15,10)
spec = 'hydrogen'
w = ts.get_particle(var_list=['w'], t=time[j], species=spec)
z, uz = ts.get_particle(var_list=['z', 'uz'], t=time[j], species=spec, plot=False, norm=colors.LogNorm())
x, ux = ts.get_particle(var_list=['x', 'ux'], t=time[j], species=spec, plot=False, norm=colors.LogNorm())
gamma = np.sqrt(1 + ux**2 + uz**2)[uz>0]
ke = (gamma - 1)* mp * c**2 / qe /10**6 # kinetic energy in MeV
ebins = plt.hist(ke, bins=100, weights=w[0][uz>0]);
plt.close()
mps = [(ebins[1][i] + ebins[1][i+1]) / 2 for i in range(len(ebins[1])-1)]
fig, ax = plt.subplots(1)
ax.scatter(mps, ebins[0]/mps)
ax.set_title('RS H+ Spectrum',size=30)
ax.set_xlabel('MeV',size=25)
ax.set_ylabel('dN/dE [part/MeV]',size=25)
ax.set_yscale('log')
ax.tick_params('x',labelsize=25)
ax.tick_params('y',labelsize=25)
ax.text(0.8, 0.85, 'Emax='+'{:.2f}'.format(np.max(ke)), horizontalalignment='center',
verticalalignment='center', transform=ax.transAxes,size=25)
plt.savefig(savedir + 'SpectrumH_'+str(res[0])+'x'+str(res[1])+'_'+comment+'_'+ str(time[j]) +'.png')
plt.close('all')
#spec = 'hydrogen_fs'
#w = ts.get_particle(var_list=['w'], t=time[j], species=spec)
#z, uz = ts.get_particle(var_list=['z', 'uz'], t=time[j], species=spec, plot=False, norm=colors.LogNorm())
#x, ux = ts.get_particle(var_list=['x', 'ux'], t=time[j], species=spec, plot=False, norm=colors.LogNorm())
#gamma = np.sqrt(1 + ux**2 + uz**2)[uz>0]
#ke = (gamma - 1)* mp * c**2 / qe /10**6 # kinetic energy in MeV
#ebins = plt.hist(ke, bins=100, weights=w[0][uz>0]);
#plt.close()
#mps = [(ebins[1][i] + ebins[1][i+1]) / 2 for i in range(len(ebins[1])-1)]
#fig, ax = plt.subplots(1)
#ax.scatter(mps, ebins[0]/mps)
#ax.set_title('FS H+ Spectrum',size=30)
#ax.set_xlabel('MeV',size=25)
#ax.set_ylabel('dN/dE [part/MeV]',size=25)
#ax.set_yscale('log')
#ax.tick_params('x',labelsize=25)
#ax.tick_params('y',labelsize=25)
#ax.text(0.8, 0.85, 'Emax='+'{:.2f}'.format(np.max(ke)), horizontalalignment='center',
# verticalalignment='center', transform=ax.transAxes,size=25)
#plt.savefig(simdir + '/plots/SpectrumHFS_'+str(res[0])+'x'+str(res[1])+'_'+comment+'_'+ str(time[j]) +'.png')
#plt.close()