forked from Vic-Flore/Warpx_Sims
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvrcf_plot.py
More file actions
152 lines (112 loc) · 4.2 KB
/
Copy pathvrcf_plot.py
File metadata and controls
152 lines (112 loc) · 4.2 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
import h5py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import use as mpluse
mpluse("Agg", force=True)
from matplotlib import gridspec
from matplotlib import colors
from matplotlib import cm
from scipy import constants
from openpmd_viewer.addons import LpaDiagnostics
import gc
nc = 6.968e27
qe = constants.e
mp = constants.m_p
me = constants.m_e
c = constants.c
l0 = 400e-9
w0 = 2*np.pi*c/l0 #rad/s
T0 = l0/c
t_peak = 90e-15
tzero = 29e-6 / c + t_peak
simroot = "/dfs6/pub/jdlewis2/warpx/CSU_Protons/RZ/hom/t200nm_nc40/"
saveroot = "/dfs6/pub/jdlewis2/warpx/CSU_Protons/RZ/hom/t200nm_nc40/pscan_plots/"
a0s = ["a01/", "a015/", "a040/"]
sls = ["sl5/", "sl20/", "sl100/"]
sds = sum([[sl + a0 for a0 in a0s] for sl in sls], []) # magic~!
sds = ["sl5/a01/", "sl5/a015/", "sl5/a040/", "sl20/a01/", "sl20/a015/", "sl100/a015/"]
plt.rcParams["figure.figsize"] = (18,15) #20
plt.rcParams['xtick.labelsize'] = 12
plt.rcParams['ytick.labelsize'] = 12
## begin plotting loop
for i in range(len(sds)):
if sds[i].split("/")[1] == "a01":
j = -1
else:
j = 10
simdir = simroot + sds[i]
savedir = saveroot + sds[i]
comment = "_4096x12096_az2_48ppc_" + sds[i].replace("/", "_")
Data = simdir + 'diags/diag1/'
try:
ts = LpaDiagnostics(Data)
except FileNotFoundError:
print("skipped " + sds[i])
continue
it = ts.iterations
time = ts.t
## Load particles and do some calculations
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)
x, ux, uy = ts.get_particle(var_list=['x', 'ux', 'uy'], t=time[j], species=spec, plot=False, norm=colors.LogNorm())
mask = uz>0
w = w[0][mask]
x = x[mask]
z = z[mask]
ux = ux[mask]
uz = uz[mask]
uy = uy[mask]
# get gamma and ke
gamma = np.sqrt(1 + ux**2 + uz**2 +uy**2)
ke = (gamma - 1)* mp * c**2 / qe /10**6 # kinetic energy in MeV
#ke = ts.get_mean_gamma(t=time[j], species=spec)
lq = np.quantile(ke,0.955)
nbins=9
ncols = 3
nrows = int(np.ceil(nbins/ncols))
mine = lq
mine = 1
if sds[i].split("/")[1] == "a01":
mine = 0
nbins = 6
maxe = np.max(ke)
emask = np.logical_and(ke>mine, ke<maxe)
uze = uz[emask]
uxe = ux[emask]
uye = uy[emask]
we = w[emask]
kee = ke[emask]
gammae = gamma[emask]
bz = uze/gammae
bx = uxe/gammae
by = uye/gammae
thetax = np.arctan(bx / bz) * 180/np.pi
thetay = np.arctan(by / bz) * 180/np.pi
## make a plot
G = gridspec.GridSpec(nrows, ncols,hspace=0.5,wspace=0.05)
plt.suptitle('Virtual RCF - Even Bins',ha='center', fontsize=20)
cutoff = np.quantile(kee, 0.99)
bw = np.concatenate(([mine + (cutoff-mine)/(nbins-1)*i for i in range(nbins)], [maxe]))
for n in range(nbins):
kmin = bw[n]
kmax = bw[n+1]
#kmin = n*bwidth(0)
#kmax = (n+1)*bwidth(0)
km = np.logical_and(kee>kmin, kee<kmax)
ax = plt.subplot(G[int(np.floor(n/ncols)),n%ncols])
pdose = ax.hist2d(thetax[km], thetay[km], bins=150, weights=we[km], cmap='cubehelix_r') # this returns a tuple
cb = plt.colorbar(pdose[3], ax=ax) # index 3 has the mappable, which is what colorbar needs
cb.set_label('# protons', fontsize=14)
ax.set_xlim(-30, 30)
ax.set_ylim(-30,30)
ax.set_ylabel(r'$\theta\degree$', fontsize=14)
ax.set_xlabel(r'$\theta\degree$', fontsize=14)
ax.set_title('{:.2f}'.format(kmin) + r' $<$ KE $\leq$ ' + '{:.2f}'.format(kmax), fontsize=14)
ax.set_aspect('equal')
plt.savefig(savedir + "vrcf" + comment + str(int(time[j]*1e15)) + "fs.png", dpi=300)
plt.close('all')
del w, x, z, ux, uy, uz, gamma, ke, uze, uxe, uye, we, kee, gammae, bz, bx, by, thetax, thetay, pdose
if j % 1 == 0:
print("garbage collected")
gc.collect()