From 87ccfe6ef7b63e373e8528db4b08ac3fa79358fa Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 28 Jan 2022 22:08:24 +0100 Subject: [PATCH 1/5] Pin pyFFTW to <0.13.0 for now as a workaround for #71. --- docs/installation.rst | 2 +- requirements.txt | 2 +- setup.py | 2 +- tests/CI_docker/context/environment_arosics.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 3396271..788b98b 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -40,7 +40,7 @@ to resolve the following dependencies before the pip installer is run: * matplotlib * numpy * pandas - * pyfftw + * pyfftw <0.13.0 * pykrige * pyproj >2.2.0 * scikit-image >=0.16.0 diff --git a/requirements.txt b/requirements.txt index eda4876..775e196 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ matplotlib numpy pandas plotly -pyfftw +pyfftw<0.13.0 pykrige pyproj>2.2.0 py_tools_ds>=0.18.0 diff --git a/setup.py b/setup.py index 9720a23..2ccfa3f 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ 'numpy', 'pandas', 'plotly', - 'pyfftw', + 'pyfftw<0.13.0', # https://github.com/pyFFTW/pyFFTW/issues/294 'pykrige', 'pyproj>2.2.0', 'py_tools_ds>=0.18.0', diff --git a/tests/CI_docker/context/environment_arosics.yml b/tests/CI_docker/context/environment_arosics.yml index 9ab3e8d..8041e15 100644 --- a/tests/CI_docker/context/environment_arosics.yml +++ b/tests/CI_docker/context/environment_arosics.yml @@ -18,7 +18,7 @@ dependencies: - numpy - pandas - plotly - - pyfftw + - pyfftw<0.13.0 - pykrige - pyproj>2.2.0 - py-tools-ds>=0.18.0 From 223da345619cfd8ed2ac8bf1ba56bc7efaccd503 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 28 Jan 2022 22:11:07 +0100 Subject: [PATCH 2/5] Revise pyFFTW call and try to catch RuntimeError. --- arosics/CoReg.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arosics/CoReg.py b/arosics/CoReg.py index a21b78f..4eaaebd 100755 --- a/arosics/CoReg.py +++ b/arosics/CoReg.py @@ -1141,23 +1141,28 @@ def _calc_shifted_cross_power_spectrum(self, PLT.subplot_imshow([np.real(in_arr0).astype(np.float32), np.real(in_arr1).astype(np.float32)], ['FFTin ' + self.ref.title, 'FFTin ' + self.shift.title], grid=True) + fft_arr0, fft_arr1 = None, None if pyfftw and self.fftw_works is not False: # if module is installed and working - fft_arr0 = pyfftw.FFTW(in_arr0, np.empty_like(in_arr0), axes=(0, 1))() - fft_arr1 = pyfftw.FFTW(in_arr1, np.empty_like(in_arr1), axes=(0, 1))() + try: + fft_arr0 = pyfftw.FFTW(in_arr0, np.empty_like(in_arr0), axes=(0, 1))() + fft_arr1 = pyfftw.FFTW(in_arr1, np.empty_like(in_arr1), axes=(0, 1))() - # catch empty output arrays (for some reason this happens sometimes..) -> use numpy fft - # => this is caused by the call of pyfftw.FFTW. Exactly in that moment the input array in_arr0 is - # overwritten with zeros (maybe this is a bug in pyFFTW?) - if self.fftw_works in [None, True] and (np.std(fft_arr0) == 0 or np.std(fft_arr1) == 0): + # catch empty output arrays (for some reason this happens sometimes..) -> use numpy fft + # => this is caused by the call of pyfftw.FFTW. Exactly in that moment the input array + # in_arr0 is overwritten with zeros (maybe this is a bug in pyFFTW?) + if np.std(fft_arr0) == 0 or np.std(fft_arr1) == 0: + raise RuntimeError('FFTW result is unexpectedly empty.') + + self.fftw_works = True + + except RuntimeError: self.fftw_works = False + # recreate input arrays and use numpy fft as fallback in_arr0 = im0[ymin:ymax, xmin:xmax].astype(precision) in_arr1 = im1[ymin:ymax, xmin:xmax].astype(precision) - fft_arr0 = np.fft.fft2(in_arr0) - fft_arr1 = np.fft.fft2(in_arr1) - else: - self.fftw_works = True - else: + + if self.fftw_works is False or fft_arr0 is None or fft_arr1 is None: fft_arr0 = np.fft.fft2(in_arr0) fft_arr1 = np.fft.fft2(in_arr1) From b52e3d2133d803c66241a0e1b5626719be191a90 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 28 Jan 2022 22:11:40 +0100 Subject: [PATCH 3/5] Only test interactive functions from IPython. --- tests/test_COREG.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_COREG.py b/tests/test_COREG.py index 9f6e356..d855e0b 100644 --- a/tests/test_COREG.py +++ b/tests/test_COREG.py @@ -324,13 +324,17 @@ def test_plotting_after_shift_calculation(self): # , mock_show): 'ignore', category=UserWarning, message='Matplotlib is currently using agg, ' 'which is a non-GUI backend, so cannot show the figure.') CR.show_cross_power_spectrum() - CR.show_cross_power_spectrum(interactive=True) CR.show_matchWin(interactive=False, after_correction=None) CR.show_matchWin(interactive=False, after_correction=True) CR.show_matchWin(interactive=False, after_correction=False) - CR.show_matchWin(interactive=True, after_correction=None) # only works if test is started with ipython - CR.show_matchWin(interactive=True, after_correction=True) - CR.show_matchWin(interactive=True, after_correction=False) + try: + __IPYTHON__ # noqa + CR.show_cross_power_spectrum(interactive=True) + CR.show_matchWin(interactive=True, after_correction=None) # only works if test is started with ipython + CR.show_matchWin(interactive=True, after_correction=True) + CR.show_matchWin(interactive=True, after_correction=False) + except NameError: + pass CR.show_image_footprints() def test_correct_shifts_without_resampling(self): From 62e879d73e72f5663c1e38058804167eed65b347 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 28 Jan 2022 22:15:34 +0100 Subject: [PATCH 4/5] Updated HISTORY.rst. --- HISTORY.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 81d6e10..f7a8d34 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,13 @@ History ======= +1.7.5 (2021-01-28) +------------------ + +* Implemented a workaround for #71 (pyFFTW RuntimeError: Undefined plan with nthreads. This is a bug). + Pin pyFFTW to <0.13.0. (!25) + + 1.7.4 (2021-12-15) ------------------ From e2bd17221eef9abbd0a02eead0154487d668fcec Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 28 Jan 2022 22:18:10 +0100 Subject: [PATCH 5/5] Fixed dead link. --- HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index f7a8d34..a3ceb5b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -660,7 +660,7 @@ History 0.8.3 (2018-03-07) ------------------ -* Fixed ValueError as reported in https://gitext.gfz-potsdam.de/EnMAP/sicor/issues/22. +* Fixed ValueError as reported in https://git.gfz-potsdam.de/EnMAP/sicor/issues/22. 0.8.2 (2018-01-23)