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

compatibility to new numpy scipy and numexpr versions #281

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 3 additions & 2 deletions postpic/datahandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
ats = self.axes_transform_state[:]
tao = self.transformed_axes_origins[:]
reduceaxis = kwargs.get('axis', 0)
reduceaxis = range(len(axes)) if reduceaxis is None else reduceaxis
if not isinstance(reduceaxis, Iterable):
reduceaxis = (reduceaxis,)
for axis in reversed(sorted(set(reduceaxis))):
Expand Down Expand Up @@ -1742,7 +1743,7 @@ def _integrate_constant(self, axes):
def _integrate_scipy(self, axes, method):
ret = copy.copy(self)
for axis in reversed(sorted(axes)):
ret._matrix = method(ret, ret.axes[axis].grid, axis=axis)
ret._matrix = method(ret, x=ret.axes[axis].grid, axis=axis)
del ret.axes[axis]
del ret.axes_transform_state[axis]
del ret.transformed_axes_origins[axis]
Expand Down Expand Up @@ -1787,7 +1788,7 @@ def _integrate_fast(self, axes):

return ret

def integrate(self, axes=None, method=scipy.integrate.simps):
def integrate(self, axes=None, method=scipy.integrate.simpson):
'''
Calculates the definite integral along the given axes.

Expand Down
2 changes: 1 addition & 1 deletion postpic/datareader/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def simgridpoints(self, axis):

def simextent(self, axis):
g = self.grid(None, axis)
return np.asfarray([g[0], g[-1]])
return np.asarray([g[0], g[-1]], dtype=np.float64)

def gridnode(self, key, axis):
'''
Expand Down
6 changes: 3 additions & 3 deletions postpic/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def _linear_phase(field, dx, phi0=0.0):

# calculate linear phase
# arg = sum([dx[i]*mesh[i] for i in dx.keys()])
arg_expr = '+'.join('({}*k{})'.format(repr(v), i) for i, v in dx.items())
arg_expr = '+'.join('({:}*k{})'.format(v, i) for i, v in dx.items())

if transform_state is True:
exp_ikdx_expr = 'exp(1j * ({arg} + phi0))'.format(arg=arg_expr)
Expand Down Expand Up @@ -1039,7 +1039,7 @@ def _kspace_propagate_generator(kspace, dt, moving_window_vect=None,
raise ValueError("Argument moving_window_vect has the wrong length. "
"Please make sure that len(moving_window_vect) == kspace.dimensions.")

moving_window_vect = np.asfarray(moving_window_vect)
moving_window_vect = np.asarray(moving_window_vect, dtype=np.float64)
moving_window_vect /= npl.norm(moving_window_vect)
moving_window_dict = dict(enumerate([dz*x for x in moving_window_vect]))

Expand All @@ -1057,7 +1057,7 @@ def _kspace_propagate_generator(kspace, dt, moving_window_vect=None,
# m = kspace.matrix.copy()
# m[sum(k*dx for k, dx in zip(kspace.meshgrid(), moving_window_vect)) < 0.0] = 0.0
# kspace = kspace.replace_data(m)
arg_expr = '+'.join('({}*k{})'.format(repr(v), i)
arg_expr = '+'.join('({:}*k{})'.format(v, i)
for i, v
in enumerate(moving_window_vect))
numexpr_vars = dict(kspace=kspace)
Expand Down
4 changes: 2 additions & 2 deletions test/test_datahandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ def test_integrate(self):
print('type(a.matrix)', type(a.matrix))
self.assertTrue(np.isclose(a, b))

b = self.f2d_fine.integrate(method=scipy.integrate.simps)
c = self.f2d_fine.integrate(method=scipy.integrate.trapz)
b = self.f2d_fine.integrate(method=scipy.integrate.simpson)
c = self.f2d_fine.integrate(method=scipy.integrate.trapezoid)

self.assertTrue(np.isclose(b, 0))
self.assertTrue(np.isclose(c, 0))
Expand Down
Loading