Skip to content

Commit

Permalink
Merge branch 'bugfix/workaround_pyfftw_bug' into 'master'
Browse files Browse the repository at this point in the history
Bugfix/workaround pyfftw bug

Closes #71

See merge request danschef/arosics!25
  • Loading branch information
Daniel Scheffler committed Jan 28, 2022
2 parents 4094e1a + e2bd172 commit 89a37b1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
9 changes: 8 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down Expand Up @@ -653,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)
Expand Down
27 changes: 16 additions & 11 deletions arosics/CoReg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matplotlib
numpy
pandas
plotly
pyfftw
pyfftw<0.13.0
pykrige
pyproj>2.2.0
py_tools_ds>=0.18.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/CI_docker/context/environment_arosics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
- numpy
- pandas
- plotly
- pyfftw
- pyfftw<0.13.0
- pykrige
- pyproj>2.2.0
- py-tools-ds>=0.18.0
Expand Down
12 changes: 8 additions & 4 deletions tests/test_COREG.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 89a37b1

Please sign in to comment.