From 3c1fc7a28c7470a51ab99b02dd4cd82d6f387f83 Mon Sep 17 00:00:00 2001 From: Ken Lauer <152229072+ken-lauer@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:36:31 -0700 Subject: [PATCH 1/2] FIX: numpy2 support --- pmd_beamphysics/fields/analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd_beamphysics/fields/analysis.py b/pmd_beamphysics/fields/analysis.py index c78d549..e601745 100644 --- a/pmd_beamphysics/fields/analysis.py +++ b/pmd_beamphysics/fields/analysis.py @@ -36,7 +36,7 @@ def accelerating_voltage_and_phase(z, Ez, frequency): fz =Ez*np.exp(-1j*k*z) # Integrate - Z = np.trapz(fz, z) + Z = np.trapezoid(fz, z) # Max voltage at phase voltage = np.abs(Z) From 2a88a4d1c993772854935c9eb99761223d4b4a5d Mon Sep 17 00:00:00 2001 From: Ken Lauer <152229072+ken-lauer@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:04:16 -0700 Subject: [PATCH 2/2] MAINT: numpy 1 and numpy2 support --- pmd_beamphysics/fields/analysis.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pmd_beamphysics/fields/analysis.py b/pmd_beamphysics/fields/analysis.py index e601745..7585d0f 100644 --- a/pmd_beamphysics/fields/analysis.py +++ b/pmd_beamphysics/fields/analysis.py @@ -7,6 +7,13 @@ import numpy as np +# Numpy migration per https://numpy.org/doc/stable/numpy_2_0_migration_guide.html +if np.lib.NumpyVersion(np.__version__) >= '2.0.0': + from numpy import trapezoid +else: + # Support 'trapz' from numpy 1.0 + from numpy import trapz as trapezoid + #---------------------- # Analysis @@ -36,7 +43,7 @@ def accelerating_voltage_and_phase(z, Ez, frequency): fz =Ez*np.exp(-1j*k*z) # Integrate - Z = np.trapezoid(fz, z) + Z = trapezoid(fz, z) # Max voltage at phase voltage = np.abs(Z)