From 7bcfccbfb69f7fcbbe53e95ba650a509e0feb16c Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Thu, 1 Aug 2024 09:21:21 -0700 Subject: [PATCH 1/4] Use alternative way to define emittance --- examples/multi_stage/analysis_script.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/multi_stage/analysis_script.py b/examples/multi_stage/analysis_script.py index fecc96b8..f8d810d4 100644 --- a/examples/multi_stage/analysis_script.py +++ b/examples/multi_stage/analysis_script.py @@ -9,10 +9,9 @@ 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) + x2 = np.average( x**2, weights=w) xu = np.average(x * ux, weights=w) - return np.sqrt(x2 * u2 - xu**2) + return np.sqrt( x2 * np.average( (ux - xu/x2 * x)**2, weights=w) ) def analyze_simulation(simulation_directory, output_params): From 12b66368d77a28dc6da097585e3f3ca4568327ee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:25:45 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/multi_stage/analysis_script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/multi_stage/analysis_script.py b/examples/multi_stage/analysis_script.py index f8d810d4..91cdc977 100644 --- a/examples/multi_stage/analysis_script.py +++ b/examples/multi_stage/analysis_script.py @@ -9,9 +9,9 @@ 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) + x2 = np.average(x**2, weights=w) xu = np.average(x * ux, weights=w) - return np.sqrt( x2 * np.average( (ux - xu/x2 * x)**2, weights=w) ) + return np.sqrt(x2 * np.average((ux - xu / x2 * x) ** 2, weights=w)) def analyze_simulation(simulation_directory, output_params): From 069fea5f9b68c4d1a8ffd9690e56ed70edea503d Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Thu, 1 Aug 2024 09:50:14 -0700 Subject: [PATCH 3/4] Update calculation --- examples/multi_stage/analysis_script.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/multi_stage/analysis_script.py b/examples/multi_stage/analysis_script.py index 91cdc977..6868f4f9 100644 --- a/examples/multi_stage/analysis_script.py +++ b/examples/multi_stage/analysis_script.py @@ -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) - xu = np.average(x * ux, weights=w) - return np.sqrt(x2 * np.average((ux - xu / x2 * x) ** 2, weights=w)) - + 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): """Analyze the output of the WarpX simulation. From 9b2db31712008e5109cdb5328967d22746312943 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:51:58 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/multi_stage/analysis_script.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/multi_stage/analysis_script.py b/examples/multi_stage/analysis_script.py index 6868f4f9..214c2541 100644 --- a/examples/multi_stage/analysis_script.py +++ b/examples/multi_stage/analysis_script.py @@ -17,6 +17,7 @@ def get_emittance(ts, t): xu = np.average(x * ux, weights=w) return np.sqrt(x2 * u2 - xu**2) + def analyze_simulation(simulation_directory, output_params): """Analyze the output of the WarpX simulation.