0

I'm trying to convert a simple Matlab signal processing code into Python. I'm trying to use CWT on a Daubechies 4 (db4) using SciPy, but I receive the error 'numpy.ndarray' object is not callable. I tried converting the np arrays to lists, but received TypeError: 'list' object is not callable.

I also tried packages other than SciPy (as suggested on similar StackOverlow question here) but ran into a couple issues. Based on errors I received in my code, I researched and found that pywt doesn't allow Daubechies wavelets for cwt (see related Github thread here). Matlab does allow this, and my source code that I am converting uses cwt with db4.

Here is the example using SciPy. How can I fix it so that it doesn't throw the np error? Using Python 3.8.3 and scipy 1.3.2

import numpy as np
from scipy import signal

x = np. array([5.0000e-03, 2.5500e-01, 5.0500e-01, 7.5500e-01, 1.0050e+00,
       1.2550e+00, 1.5050e+00, 1.7550e+00, 2.0050e+00, 2.2550e+00,
       2.5050e+00, 2.7550e+00, 3.0050e+00, 3.2550e+00, 3.5050e+00,
       3.7550e+00, 4.0050e+00, 4.2550e+00, 4.5050e+00, 4.7550e+00,
       5.0050e+00, 5.2550e+00, 5.5050e+00, 5.7550e+00, 6.0050e+00,
       6.2550e+00, 6.5050e+00, 6.7550e+00, 7.0050e+00, 7.2550e+00,
       7.5050e+00, 7.7550e+00, 8.0050e+00, 8.2550e+00, 8.5050e+00,
       8.7550e+00, 9.0050e+00, 9.2550e+00, 9.5050e+00, 9.7550e+00,
       1.0005e+01, 1.0255e+01, 1.0505e+01, 1.0755e+01, 1.1005e+01,
       1.1255e+01, 1.1505e+01, 1.1755e+01, 1.2005e+01, 1.2255e+01,
       1.2505e+01, 1.2755e+01, 1.3005e+01, 1.3255e+01, 1.3505e+01,
       1.3755e+01, 1.4005e+01, 1.4255e+01, 1.4505e+01, 1.4755e+01,
       1.5005e+01, 1.5255e+01, 1.5505e+01, 1.5755e+01, 1.6005e+01,
       1.6255e+01, 1.6505e+01, 1.6755e+01, 1.7005e+01, 1.7255e+01,
       1.7505e+01, 1.7755e+01, 1.8005e+01, 1.8255e+01, 1.8505e+01,
       1.8755e+01, 1.9005e+01, 1.9255e+01, 1.9505e+01, 1.9755e+01,
       2.0005e+01, 2.0255e+01, 2.0505e+01, 2.0755e+01, 2.1005e+01,
       2.1255e+01, 2.1505e+01, 2.1755e+01, 2.2005e+01, 2.2255e+01,
       2.2505e+01, 2.2755e+01, 2.3005e+01, 2.3255e+01, 2.3505e+01,
       2.3755e+01, 2.4005e+01, 2.4255e+01, 2.4505e+01, 2.4755e+01,
       2.5005e+01, 2.5255e+01, 2.5505e+01, 2.5755e+01, 2.6005e+01,
       2.6255e+01, 2.6505e+01, 2.6755e+01, 2.7005e+01, 2.7255e+01,
       2.7505e+01, 2.7755e+01, 2.8005e+01, 2.8255e+01, 2.8505e+01,
       2.8755e+01, 2.9005e+01, 2.9255e+01, 2.9505e+01, 2.9755e+01,
       3.0005e+01, 3.0255e+01, 3.0505e+01, 3.0755e+01, 3.1005e+01,
       3.1255e+01, 3.1505e+01, 3.1755e+01, 3.2005e+01, 3.2255e+01,
       3.2505e+01, 3.2755e+01, 3.3005e+01, 3.3255e+01, 3.3505e+01,
       3.3755e+01, 3.4005e+01, 3.4255e+01, 3.4505e+01, 3.4755e+01,
       3.5005e+01, 3.5255e+01, 3.5505e+01, 3.5755e+01, 3.6005e+01,
       3.6255e+01, 3.6505e+01, 3.6755e+01, 3.7005e+01, 3.7255e+01,
       3.7505e+01, 3.7755e+01, 3.8005e+01, 3.8255e+01, 3.8505e+01,
       3.8755e+01, 3.9005e+01])

y = np.array([-2.90025342e-03, -6.40420148e-02, -5.14428368e-02, -5.24396156e-02,
       -2.36905934e-02, -7.33774047e-02,  6.96917443e-01,  1.10640628e+00,
        2.14842575e+00,  3.59673555e+00,  4.73432960e+00,  6.49741055e+00,
        7.29974071e+00,  1.01759353e+01,  1.02030717e+01,  1.36557766e+01,
        1.41826988e+01,  7.76774453e+00,  3.82632036e+00, -2.70456335e+00,
       -1.96618648e+01, -3.66985195e+01,  2.99333347e+01,  2.36009095e+01,
        1.10220943e+01, -2.95258984e+00,  6.80386136e+00, -2.70166763e+01,
       -3.76209305e+01, -1.35082003e+01,  4.60503863e+00, -9.60422448e+00,
       -1.43916205e+01, -1.26012282e+01, -2.13207866e+01, -3.26687352e+01,
       -2.41891688e+01, -2.97832448e+00, -2.80885014e+00,  7.05782776e+00,
        7.75577641e+00,  7.42433815e+00,  1.71676749e+00,  1.79335514e+00,
        3.37780022e+00,  9.75024672e+00,  1.03110319e+01,  1.42435904e+00,
        2.48130497e+00,  6.72502952e+00,  5.29311955e+00,  1.02966186e+01,
        1.28654499e+01,  1.27711678e+01,  7.34488122e+00,  4.24580786e+00,
        3.43792737e+00,  7.14184919e+00,  5.87025700e+00,  2.82831733e+00,
        1.41092267e+00, -2.62424149e+00, -6.35504810e+00, -4.29696255e+00,
       -5.27593166e+00, -6.70304826e+00, -7.73215169e+00, -1.06058497e+01,
       -1.11609626e+01, -5.82899263e+00, -3.14857074e+00, -1.82479856e+00,
        1.73553141e+00,  4.10008240e+00,  1.95158521e+00,  6.46081039e-02,
        6.19934053e-01,  3.59542159e+00,  7.38641899e+00,  8.35768231e+00,
        8.65572196e+00,  7.42586536e+00,  5.86887591e+00,  5.36210626e+00,
        3.56410283e+00, -2.27375587e-01, -2.05785024e+00, -2.41085077e+00,
       -2.47258719e+00, -1.92065302e+00, -2.33531757e+00, -3.78717114e+00,
       -5.43768739e+00, -6.22146733e+00, -6.32672517e+00, -8.74872401e+00,
       -9.63365954e+00, -8.04706703e+00, -3.42860196e+00, -2.38901992e-02,
        2.16031975e+00,  4.84801654e+00,  6.73393543e+00,  7.56246002e+00,
        5.51142721e+00,  3.96078924e+00,  1.00253884e+00, -2.56086766e+00,
       -3.32289364e+00, -7.95432505e-01,  8.01013095e-01,  2.44769438e+00,
        2.83964569e+00,  4.17925704e+00,  4.31245244e+00,  2.89684591e+00,
        1.03658591e+00, -8.09516543e-01, -4.15390067e+00, -5.43798992e+00,
       -7.62820752e+00, -7.27063191e+00, -5.52509620e+00, -3.71587359e+00,
       -1.26491743e+00, -1.49203623e+00, -9.37770362e-01,  1.55140704e+00,
        1.88526353e+00,  2.98912902e+00,  4.35663676e+00,  4.36104650e+00,
        3.58104564e+00,  3.55686396e+00,  1.47853154e+00,  2.06093445e-01,
        5.86736552e-01,  1.26966443e+00,  6.73485660e-01,  1.17591023e+00,
        1.96013272e+00,  1.18115362e+00, -4.55632643e-01, -2.13888010e+00,
       -2.23202762e+00, -2.03038079e+00, -1.05057577e+00, -3.30290779e-01,
       -4.42753086e-01, -1.94528619e-01,  2.85416068e-01,  1.88951595e-01,
        9.65445495e-02, -5.39501681e-02, -1.04898435e-01, -9.69066588e-02,
       -2.98158805e-02])


t = x
data = y
wavelet = signal.daub(4)
scales = np.arange(35,2186,43)

coeffs = signal.cwt(data, wavelet, scales)
# coeffs = signal.cwt(data.tolist(), wavelet.tolist(), scales.tolist())

And here is the full traceback:

TypeError                                 Traceback (most recent call last)
<ipython-input-12-2b5f3768f808> in <module>
     82 scales = np.arange(35,2186,43)
     83 
---> 84 coeffs = signal.cwt(data, signal.daub(4), scales.tolist())
     85 
     86 

~\anaconda3\envs\gp\lib\site-packages\scipy\signal\wavelets.py in cwt(data, wavelet, widths)
    360     output = np.zeros([len(widths), len(data)])
    361     for ind, width in enumerate(widths):
--> 362         wavelet_data = wavelet(min(10 * width, len(data)), width)
    363         output[ind, :] = convolve(data, wavelet_data,
    364                                   mode='same')

TypeError: 'numpy.ndarray' object is not callable
a11
  • 3,122
  • 4
  • 27
  • 66
  • When you report a Python error, it is helpful to include the *complete* traceback (i.e. the complete error message) in the question. There is useful information in there, including the line that generated the error. – Warren Weckesser Feb 05 '22 at 23:28
  • 1
    Take another look at the [`cwt` docstring](https://scipy.github.io/devdocs/reference/generated/scipy.signal.cwt.html). The second argument, `wavelet`, must be a callable function, not an array. – Warren Weckesser Feb 05 '22 at 23:33
  • @WarrenWeckesser Using `coeffs = signal.cwt(data, signal.daub(4), scales)` results in the same error. Based on the example in the [docs](https://scipy.github.io/devdocs/reference/generated/scipy.signal.cwt.html), using `wavelet = signal.ricker` and `cwtmatr = signal.cwt(data, wavelet, scales)` and is fine and works for me without error. I think the issue is related to using cwt on Daubechies – a11 Feb 05 '22 at 23:58
  • I am also running into this problem. It seems the ```ricker``` and ```daub``` functions are not made equal. – Jerrit Feb 18 '22 at 12:50

0 Answers0