Repository: obspy/obspy

Issue:
Trace remove_response() method raises exception when used with numpy 1.17.0
numpy version 1.17 has replaced the internal fftpack module with pocketfft (see release notes here: https://github.com/numpy/numpy/blob/master/doc/release/1.17.0-notes.rst)

This causes an exception to be raised in the following line of code:

https://github.com/obspy/obspy/blob/e97fe91ae99df0154664933102f03405940b86d6/obspy/core/util/misc.py#L614

which has the effect of breaking the remove_response() method of the Trace object, as demonstrated in the test script I've attached (renamed to .txt to make github happy).

The error is:

`AttributeError: module 'numpy.fft' has no attribute 'fftpack'`

[testresp.txt](https://github.com/obspy/obspy/files/3463112/testresp.txt)

OS Version: OSX 10.13.6
Python:  3.6.7
numpy: 1.17.0
obspy: 1.1.1

I created a test environment with conda:
conda create -n testfft python=3.6 obspy

The workaround, I suppose is to not use numpy 1.17 or higher until this is patched in obspy.





Discussion:
It is surprising to me that numpy removed fftpack without a deprecation cycle. It will certainly break mores codes than just obspy.  
@mhearne-usgs conda-forge repository is updated, so this should not hit people anymore installing new environments or updating theirs.. at least when obspy 1.1.1 is selected, i.e. when people don't **force** numpy >= 1.17 or some other dependencies to high version that pull in numpy 1.17, conda will pull older obspy packages unfortunately, nothing we can do.

Thanks for reporting this, this should help minimize people getting affected by a lot.
Is the fix for this as simple as wrapping the `limit_numpy_fft_cache()` in a version check?

```python
if np.__version__ < '1.17.0':
    limit_numpy_fft_cache()
```

https://github.com/obspy/obspy/blob/0c214da22eed6bd587a317eaa9aaa305373512aa/obspy/core/trace.py#L2745

Or is there a reason this would be a bit of a hacked solution?  I didn't see an equivalent to `fft_cache_()` in pocketfft.

Can't say @aringler-usgs, didn't have time to look into it yet..
Yes.

I actually contributed this fix to numpy a while ago so it should not be necessary anymore. But now with fftpack gone it is fully obsolete.


Am 6. Aug. 2019, 19:15, um 19:15, aringler-usgs <notifications@github.com> schrieb:
>Is the fix for this as simple as wrapping the `limit_numpy_fft_cache()`
>in a version check?
>
>```python
>if np.__version__ < '1.17.0':
>    limit_numpy_fft_cache()
>```
>
>https://github.com/obspy/obspy/blob/0c214da22eed6bd587a317eaa9aaa305373512aa/obspy/core/trace.py#L2745
>
>Or is there a reason this would be a bit of a hacked solution?  I
>didn't see an equivalent to `fft_cache_()` in pocketfft.
>
>
>-- 
>You are receiving this because you are subscribed to this thread.
>Reply to this email directly or view it on GitHub:
>https://github.com/obspy/obspy/issues/2434#issuecomment-518739630

So I guess the answer would be yes @aringler-usgs, I think that's what we should do.

Resolving patch:
diff --git a/obspy/core/trace.py b/obspy/core/trace.py
--- a/obspy/core/trace.py
+++ b/obspy/core/trace.py
@@ -23,7 +23,7 @@
 
 from obspy.core import compatibility
 from obspy.core.utcdatetime import UTCDateTime
-from obspy.core.util import AttribDict, create_empty_data_chunk
+from obspy.core.util import AttribDict, create_empty_data_chunk, NUMPY_VERSION
 from obspy.core.util.base import _get_function_from_entry_point
 from obspy.core.util.decorator import raise_if_masked, skip_if_no_data
 from obspy.core.util.misc import (flat_not_masked_contiguous, get_window_times,
@@ -2742,7 +2742,8 @@ def remove_response(self, inventory=None, output="VEL", water_level=60,
             plot is saved to file (filename must have a valid image suffix
             recognizable by matplotlib e.g. '.png').
         """
-        limit_numpy_fft_cache()
+        if NUMPY_VERSION < [1, 17]:
+            limit_numpy_fft_cache()
 
         from obspy.core.inventory import PolynomialResponseStage
         from obspy.signal.invsim import (cosine_taper, cosine_sac_taper,


Test patch: