Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: numpy2 support #66

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pmd_beamphysics/fields/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,7 +43,7 @@ def accelerating_voltage_and_phase(z, Ez, frequency):
fz =Ez*np.exp(-1j*k*z)

# Integrate
Z = np.trapz(fz, z)
Z = trapezoid(fz, z)

# Max voltage at phase
voltage = np.abs(Z)
Expand Down
Loading