|
23 | 23 |
|
24 | 24 | """ |
25 | 25 | import sys |
| 26 | +import warnings |
26 | 27 |
|
27 | 28 | import matplotlib.pyplot as plt |
28 | 29 | import numpy as np |
29 | | -import pyfftw |
30 | 30 |
|
31 | | -# from numba import jit |
| 31 | +with warnings.catch_warnings(): |
| 32 | + warnings.simplefilter("ignore") |
| 33 | + try: |
| 34 | + import pyfftw |
| 35 | + except ImportError: |
| 36 | + pyfftwpresent = False |
| 37 | + else: |
| 38 | + pyfftwpresent = True |
| 39 | + |
32 | 40 | from scipy import fftpack, ndimage, signal |
33 | 41 | from scipy.signal import savgol_filter |
34 | 42 |
|
35 | | -# import warnings |
36 | | - |
| 43 | +if pyfftwpresent: |
| 44 | + fftpack = pyfftw.interfaces.scipy_fftpack |
| 45 | + pyfftw.interfaces.cache.enable() |
37 | 46 |
|
38 | | -# fftpack = pyfftw.interfaces.scipy_fftpack |
39 | | -# pyfftw.interfaces.cache.enable() |
40 | | - |
41 | | -# ---------------------------------------- Global constants ------------------------------------------- |
42 | | -donotusenumba = True |
43 | 47 |
|
44 | 48 | # ----------------------------------------- Conditional imports --------------------------------------- |
45 | 49 | try: |
|
49 | 53 | except ImportError: |
50 | 54 | memprofilerexists = False |
51 | 55 |
|
52 | | - |
53 | | -# ----------------------------------------- Conditional jit handling ---------------------------------- |
54 | | -def conditionaljit(): |
55 | | - def resdec(f): |
56 | | - global donotusenumba |
57 | | - if donotusenumba: |
58 | | - return f |
59 | | - return jit(f, nopython=False) |
60 | | - |
61 | | - return resdec |
62 | | - |
63 | | - |
64 | | -def disablenumba(): |
65 | | - global donotusenumba |
66 | | - donotusenumba = True |
67 | | - |
68 | | - |
69 | 56 | # --------------------------- Filtering functions ------------------------------------------------- |
70 | 57 | # NB: No automatic padding for precalculated filters |
71 | 58 |
|
@@ -177,7 +164,8 @@ def ssmooth(xsize, ysize, zsize, sigma, inputdata): |
177 | 164 |
|
178 | 165 |
|
179 | 166 | # - butterworth filters |
180 | | -@conditionaljit() |
| 167 | + |
| 168 | + |
181 | 169 | def dolpfiltfilt(Fs, upperpass, inputdata, order, padlen=20, cyclic=False, debug=False): |
182 | 170 | r"""Performs a bidirectional (zero phase) Butterworth lowpass filter on an input vector |
183 | 171 | and returns the result. Ends are padded to reduce transients. |
@@ -235,7 +223,6 @@ def dolpfiltfilt(Fs, upperpass, inputdata, order, padlen=20, cyclic=False, debug |
235 | 223 | ).astype(np.float64) |
236 | 224 |
|
237 | 225 |
|
238 | | -@conditionaljit() |
239 | 226 | def dohpfiltfilt(Fs, lowerpass, inputdata, order, padlen=20, cyclic=False, debug=False): |
240 | 227 | r"""Performs a bidirectional (zero phase) Butterworth highpass filter on an input vector |
241 | 228 | and returns the result. Ends are padded to reduce transients. |
@@ -292,7 +279,6 @@ def dohpfiltfilt(Fs, lowerpass, inputdata, order, padlen=20, cyclic=False, debug |
292 | 279 | ) |
293 | 280 |
|
294 | 281 |
|
295 | | -@conditionaljit() |
296 | 282 | def dobpfiltfilt(Fs, lowerpass, upperpass, inputdata, order, padlen=20, cyclic=False, debug=False): |
297 | 283 | r"""Performs a bidirectional (zero phase) Butterworth bandpass filter on an input vector |
298 | 284 | and returns the result. Ends are padded to reduce transients. |
@@ -419,7 +405,6 @@ def getlpfftfunc(Fs, upperpass, inputdata, debug=False): |
419 | 405 | return transferfunc |
420 | 406 |
|
421 | 407 |
|
422 | | -@conditionaljit() |
423 | 408 | def dolpfftfilt(Fs, upperpass, inputdata, padlen=20, cyclic=False, debug=False): |
424 | 409 | r"""Performs an FFT brickwall lowpass filter on an input vector |
425 | 410 | and returns the result. Ends are padded to reduce transients. |
@@ -462,7 +447,6 @@ def dolpfftfilt(Fs, upperpass, inputdata, padlen=20, cyclic=False, debug=False): |
462 | 447 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
463 | 448 |
|
464 | 449 |
|
465 | | -@conditionaljit() |
466 | 450 | def dohpfftfilt(Fs, lowerpass, inputdata, padlen=20, cyclic=False, debug=False): |
467 | 451 | r"""Performs an FFT brickwall highpass filter on an input vector |
468 | 452 | and returns the result. Ends are padded to reduce transients. |
@@ -505,7 +489,6 @@ def dohpfftfilt(Fs, lowerpass, inputdata, padlen=20, cyclic=False, debug=False): |
505 | 489 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
506 | 490 |
|
507 | 491 |
|
508 | | -@conditionaljit() |
509 | 492 | def dobpfftfilt(Fs, lowerpass, upperpass, inputdata, padlen=20, cyclic=False, debug=False): |
510 | 493 | r"""Performs an FFT brickwall bandpass filter on an input vector |
511 | 494 | and returns the result. Ends are padded to reduce transients. |
@@ -555,7 +538,8 @@ def dobpfftfilt(Fs, lowerpass, upperpass, inputdata, padlen=20, cyclic=False, de |
555 | 538 |
|
556 | 539 |
|
557 | 540 | # - fft trapezoidal filters |
558 | | -@conditionaljit() |
| 541 | + |
| 542 | + |
559 | 543 | def getlptrapfftfunc(Fs, upperpass, upperstop, inputdata, debug=False): |
560 | 544 | r"""Generates a trapezoidal lowpass transfer function. |
561 | 545 |
|
@@ -608,7 +592,6 @@ def getlptrapfftfunc(Fs, upperpass, upperstop, inputdata, debug=False): |
608 | 592 | return transferfunc |
609 | 593 |
|
610 | 594 |
|
611 | | -@conditionaljit() |
612 | 595 | def getlptransfunc(Fs, inputdata, upperpass=None, upperstop=None, type="brickwall", debug=False): |
613 | 596 | if upperpass is None: |
614 | 597 | print("getlptransfunc: upperpass must be specified") |
@@ -693,7 +676,6 @@ def gethptransfunc(Fs, inputdata, lowerstop=None, lowerpass=None, type="brickwal |
693 | 676 | return transferfunc |
694 | 677 |
|
695 | 678 |
|
696 | | -@conditionaljit() |
697 | 679 | def dolptransfuncfilt( |
698 | 680 | Fs, |
699 | 681 | inputdata, |
@@ -757,7 +739,6 @@ def dolptransfuncfilt( |
757 | 739 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
758 | 740 |
|
759 | 741 |
|
760 | | -@conditionaljit() |
761 | 742 | def dohptransfuncfilt( |
762 | 743 | Fs, |
763 | 744 | inputdata, |
@@ -827,7 +808,6 @@ def dohptransfuncfilt( |
827 | 808 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
828 | 809 |
|
829 | 810 |
|
830 | | -@conditionaljit() |
831 | 811 | def dobptransfuncfilt( |
832 | 812 | Fs, |
833 | 813 | inputdata, |
@@ -908,7 +888,6 @@ def dobptransfuncfilt( |
908 | 888 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
909 | 889 |
|
910 | 890 |
|
911 | | -@conditionaljit() |
912 | 891 | def dolptrapfftfilt(Fs, upperpass, upperstop, inputdata, padlen=20, cyclic=False, debug=False): |
913 | 892 | r"""Performs an FFT filter with a trapezoidal lowpass transfer |
914 | 893 | function on an input vector and returns the result. Ends are padded to reduce transients. |
@@ -955,7 +934,6 @@ def dolptrapfftfilt(Fs, upperpass, upperstop, inputdata, padlen=20, cyclic=False |
955 | 934 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
956 | 935 |
|
957 | 936 |
|
958 | | -@conditionaljit() |
959 | 937 | def dohptrapfftfilt(Fs, lowerstop, lowerpass, inputdata, padlen=20, cyclic=False, debug=False): |
960 | 938 | r"""Performs an FFT filter with a trapezoidal highpass transfer |
961 | 939 | function on an input vector and returns the result. Ends are padded to reduce transients. |
@@ -1002,7 +980,6 @@ def dohptrapfftfilt(Fs, lowerstop, lowerpass, inputdata, padlen=20, cyclic=False |
1002 | 980 | return unpadvec(fftpack.ifft(inputdata_trans).real, padlen=padlen) |
1003 | 981 |
|
1004 | 982 |
|
1005 | | -@conditionaljit() |
1006 | 983 | def dobptrapfftfilt( |
1007 | 984 | Fs, |
1008 | 985 | lowerstop, |
@@ -1293,7 +1270,6 @@ def csdfilter(obsdata, commondata, padlen=20, cyclic=False, debug=False): |
1293 | 1270 | return unpadvec(fftpack.ifft(obsdata_trans).real, padlen=padlen) |
1294 | 1271 |
|
1295 | 1272 |
|
1296 | | -@conditionaljit() |
1297 | 1273 | def arb_pass( |
1298 | 1274 | Fs, |
1299 | 1275 | inputdata, |
|
0 commit comments