Skip to content

Commit fd637e0

Browse files
authored
Merge pull request #240 from RemiLehe/fix_warpx_script
Use more robust calculation of the emittance.
2 parents 88cf936 + 9b2db31 commit fd637e0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

examples/multi_stage/analysis_script.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
def get_emittance(ts, t):
1010
"""Calculate the beam emittance at the given time step."""
1111
w, x, ux = ts.get_particle(["w", "x", "ux"], t=t)
12-
x2 = np.average(x**2, weights=w)
13-
u2 = np.average(ux**2, weights=w)
14-
xu = np.average(x * ux, weights=w)
15-
return np.sqrt(x2 * u2 - xu**2)
12+
if len(w) <= 2:
13+
return 0
14+
else:
15+
x2 = np.average(x**2, weights=w)
16+
u2 = np.average(ux**2, weights=w)
17+
xu = np.average(x * ux, weights=w)
18+
return np.sqrt(x2 * u2 - xu**2)
1619

1720

1821
def analyze_simulation(simulation_directory, output_params):

0 commit comments

Comments
 (0)