Skip to content

Commit

Permalink
Merge pull request #240 from RemiLehe/fix_warpx_script
Browse files Browse the repository at this point in the history
Use more robust calculation of the emittance.
  • Loading branch information
RemiLehe authored Sep 18, 2024
2 parents 88cf936 + 9b2db31 commit fd637e0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/multi_stage/analysis_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
def get_emittance(ts, t):
"""Calculate the beam emittance at the given time step."""
w, x, ux = ts.get_particle(["w", "x", "ux"], t=t)
x2 = np.average(x**2, weights=w)
u2 = np.average(ux**2, weights=w)
xu = np.average(x * ux, weights=w)
return np.sqrt(x2 * u2 - xu**2)
if len(w) <= 2:
return 0
else:
x2 = np.average(x**2, weights=w)
u2 = np.average(ux**2, weights=w)
xu = np.average(x * ux, weights=w)
return np.sqrt(x2 * u2 - xu**2)


def analyze_simulation(simulation_directory, output_params):
Expand Down

0 comments on commit fd637e0

Please sign in to comment.