From 953155d585b60c69f757f6e7861981d60bd0036b Mon Sep 17 00:00:00 2001 From: Stephan Kuschel Date: Mon, 8 Jul 2024 23:09:15 +0200 Subject: [PATCH 1/5] scipy 1.14.0 has removed deprecated functions upate the code accordingly --- postpic/datahandling.py | 4 ++-- test/test_datahandling.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/postpic/datahandling.py b/postpic/datahandling.py index 6d63a53..0b1b9a8 100644 --- a/postpic/datahandling.py +++ b/postpic/datahandling.py @@ -1742,7 +1742,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] @@ -1787,7 +1787,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. diff --git a/test/test_datahandling.py b/test/test_datahandling.py index e0428a9..bbdb25b 100755 --- a/test/test_datahandling.py +++ b/test/test_datahandling.py @@ -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)) From f1d26871c9fa8e78cdb24682c310cdd92a9fc2b8 Mon Sep 17 00:00:00 2001 From: Stephan Kuschel Date: Mon, 8 Jul 2024 23:17:11 +0200 Subject: [PATCH 2/5] numpy __array_ufunc__ changed in numpy 2.0.0 in the kwargs, the argument axis=None may be give when reducing all axis. Handle this case. --- postpic/datahandling.py | 1 + 1 file changed, 1 insertion(+) diff --git a/postpic/datahandling.py b/postpic/datahandling.py index 0b1b9a8..e8f05d8 100644 --- a/postpic/datahandling.py +++ b/postpic/datahandling.py @@ -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))): From b5bbb921d20b657a6973f105063b50d85636bc7e Mon Sep 17 00:00:00 2001 From: Stephan Kuschel Date: Mon, 8 Jul 2024 23:44:15 +0200 Subject: [PATCH 3/5] obey numexpr 2.9 (?) expression sanity check rules otherwise numexpr raises an error "expression xxx has forbidden control characters" --- postpic/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postpic/helper.py b/postpic/helper.py index 55ff655..d7df84d 100644 --- a/postpic/helper.py +++ b/postpic/helper.py @@ -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) @@ -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) From f7171acc1b3d1e1bb4ddacbd6844feea8e2c686c Mon Sep 17 00:00:00 2001 From: Stephan Kuschel Date: Mon, 8 Jul 2024 23:52:17 +0200 Subject: [PATCH 4/5] dont use np.asfarray it has been removed in numpy 2.0 --- postpic/datareader/dummy.py | 2 +- postpic/helper.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/postpic/datareader/dummy.py b/postpic/datareader/dummy.py index c2789b0..61a91e6 100644 --- a/postpic/datareader/dummy.py +++ b/postpic/datareader/dummy.py @@ -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): ''' diff --git a/postpic/helper.py b/postpic/helper.py index d7df84d..aa5141f 100644 --- a/postpic/helper.py +++ b/postpic/helper.py @@ -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])) From c61e85a5105d59c55243a016c63451143aacd11f Mon Sep 17 00:00:00 2001 From: Stephan Kuschel Date: Tue, 9 Jul 2024 00:05:06 +0200 Subject: [PATCH 5/5] remove testing on python 3.9 python 3.9 on github has trouble installing numexpr. --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d60c50a..bd51afb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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