简体   繁体   中英

ifft function gives “'str' object is not callable” error

I am trying to take the inverse Fourier transform of a list, and for some reason I keep getting the following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "simulating_coherent_data.py", line 238, in <module>
    exec('ift%s = np.fft.ifft(nd.array(FTxSQRT_PS%s))'(x,x))
TypeError: 'str' object is not callable

And I can't figure out where I have a string. The part of my code it relates to is as follows

def FTxSQRT_PS(FT,PS):
# Import: The Fourier Transform and the Power Spectrum, both as lists
# Export: The result of FTxsqrt(PS), as a list
# Function:
#     Takes each element in the FT and PS and finds FTxsqrt(PS) for each
#     appends each results to a list called signal
    signal = []
    print type(PS)
    for x in range(len(FT)):
        indiv_signal = np.abs(FT[x])*math.sqrt(PS[x])
        signal.append(indiv_signal)
    return signal

for x in range(1,number_timesteps+1):
    exec('FTxSQRT_PS%s = FTxSQRT_PS(fshift%s,power_spectrum%s)'%(x,x,x))
    exec('ift%s = np.fft.ifft(FTxSQRT_PS%s)'(x,x))

Where FTxSQRT_PS%s are all lists. fshift%s is a np.array and power_spectrum%s is a list. I've also tried setting the type for FTxSQRT_PS%s as a np.array but that did not help. I have very similar code a few lines up that works fine;

for x in range(1,number_timesteps+1):
    exec('fft%s = np.fft.fft(source%s)'%(x,x))

where source%s are all type np.array

The only thing I can think of is that maybe np.fft.ifft is not how I should be taking the inverse Fourier transform for Python 2.7.6 but I also cannot find an alternative.

Let me know if you'd like to see the whole code, there is about 240 lines up to where I'm having trouble, though a lot of that is commenting.

Thanks for any help,

Teresa

You are missing a %

exec('ift%s = np.fft.ifft(FTxSQRT_PS%s)'(x,x))

Should be:

exec('ift%s = np.fft.ifft(FTxSQRT_PS%s)'%(x,x))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM