0

I want to draw two lines, each works well when separated, but when I draw two at a time, then there's an error:

Traceback (most recent call last): File "2.py", line 99, in fspe2 = [fspe(t2,x) for t2 in t] TypeError: 'list' object is not callable

Full Code:

# -*- coding: utf-8 -*
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import math
from pylab import *

c = 2.998*10**10
hp = 6.626*10**-27
hb = 1.055*10**-27
kb = 1.381*10**-16
g = 6.673*10**-8
me = 9.109*10**-28
mp = 1.673*10**-24
q = 4.803*10**-10
sigT = 6.652*10**-25

p = 2.5
r014 = 1
E53 = 1
g42 = 1
delt12 =1
epsBR2 = 1
epseR1 = 1
DLG = 1 

r0 = r014*10**14
E0 = E53*10**53
g4 = g42*10**2.5
delt0 = delt12*10**12
epseR = epseR1*0.1
epsBR = epsBR2*0.01
n1 = 1.0
k = 0
DL = DLG*3.086*10**27

N0 = E0/(g4*mp*c**2)
SedL = (3*E0/(4*math.pi*n1*mp*c**2))**(1./3)
ttw = delt0/c  
ttn = SedL/(2*c*g4**(3./8))  
Reta = SedL/g4**(2./3)

def Gam3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,(SedL/delt0)**(3./8)*(4*t/ttw)**(-1./4),(SedL/delt0)**(3./8)*(4*ttw/ttw)**(-1./4)*(t/ttw)**(-7./16))
  else:
    return np.where(t<ttn,g4,g4*(t/ttn)**(-2./5))

def n3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,8*Gam3(t)**3*n1/g4,8*Gam3(ttw)**3*n1/g4*(t/ttw)**(-13./16))
  else:
    return np.where(t<ttn,7*n1*g4**2*(t/ttn)**-3,7*n1*g4**2*(t/ttn)**(-6./7))

def e3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,4*Gam3(t)**2*n1*mp*c**2,4*Gam3(ttw)**2*n1*mp*c**2*(t/ttw)**(-13./12))
  else:
    return np.where(t<ttn,4*g4**2*n1*mp*c**2,4*g4**2*n1*mp*c**2*(t/ttn)**(-8./7))

def Ne3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,N0*(t/ttw),N0)
  else:
    return np.where(t<ttn,N0*(t/ttn)**(3./2),N0)

gem = lambda t : epseR*e3(t)/(n3(t)*me*c**2)*(p-2)/(p-1)
BR  = lambda t : np.sqrt(8*math.pi*epsBR*e3(t))
gec = lambda t : 6*math.pi*me*c/(sigT*BR(t)**2*Gam3(t)*t)
num = lambda t : 3*q*BR(t)/(4*math.pi*me*c)*gem(t)**2*Gam3(t)
nuc = lambda t : 3*q*BR(t)/(4*math.pi*me*c)*gec(t)**2*Gam3(t)
Fmax = lambda t : Ne3(t)*math.sqrt(3)*q**3*BR(t)/(me*c**2)*Gam3(t)/(4*math.pi*DL**2)

def fspe(t,u):
  if num(t)<nuc(t):
    return np.where(u<num(t),(u/num(t))**(1./3)*Fmax(t),np.where(u<nuc(t),(u/num(t))**(-(p-1.)/2)*Fmax(t),(u/nuc(t))**(-p/2)*(nuc(t)/num(t))**(-(p-1.)/2)*Fmax(t)))*u
  else:
    return np.where(u<nuc(t),(u/muc(t))**(1./3)*Fmax(t),np.where(u<num(t),(u/nuc(t))**(-1./2)*Fmax(t),(u/num(t))**(-p/2)*(num(t)/nuc(t))**(-1.2)*Fmax(t)))*u

xmin = 2
xmax = 10
i = np.arange(xmin,xmax,0.01)
t = 10**i

plt.figure('God Bless: Lightcure')
plt.title(r'Lightcurve''\n2 Cases')
plt.xlabel(r'log t')
plt.ylabel(r'log Flux')

x = 10**10
fspe = [fspe(t1,x) for t1 in t] 
Lightcurve1 = [math.log10(a5) for a5 in fspe]
plt.plot(i,Lightcurve1,'.',label=r'$\nu=10^{10}$')

########################
## Strange thing happens!The above 4 sentences work well,
## why added the same statements, there's an Error?
x = 10**15
fspe2 = [fspe(t2,x) for t2 in t] 
### This place feedback--Traceback (most recent call last):
#  File "1.py", line 94, in <module>
#    fspe2 = [fspe(t2,x) for t2 in t] 
#TypeError: 'list' object is not callable
Lightcurve2 = [math.log10(a6) for a6 in fspe2]
plt.plot(i,Lightcurve2,'>',label=r'$\nu=10^{15}$')
#######################

plt.legend()
plt.grid(True)
plt.show()  
4
  • also give the full error traceback Commented Jan 27, 2016 at 7:02
  • jesuslove@jesuslove-220s-series:~/matplotlib$ python 2.py Traceback (most recent call last): File "2.py", line 99, in <module> fspe2 = [fspe(t2,x) for t2 in t] TypeError: 'list' object is not callable jesuslove@jesuslove-220s-series:~/matplotlib$ Commented Jan 27, 2016 at 7:04
  • fspe = [fspe(t1,x) for t1 in t] line 91 you assign over your function with a list. How you correct that depends on what you want to do. Commented Jan 27, 2016 at 7:06
  • Thank you very much, God bless my friend! Commented Jan 27, 2016 at 7:41

2 Answers 2

5

Traceback: literally, a way for you to trace a path from the error message back to the line that caused it. Python's error messages are usually very good, so take what it says at face value and follow it back. It'll even describe the path of function calls that produced this result, which serve as breadcrumbs.

  1. fspe2 = [fspe(t2,x) for t2 in t] TypeError: 'list' object is not callable
  2. Where did you call something? The only instance of it in that line is fspe(t2,x).
  3. What did it try to call? A list. Therefore, fspe is a list at that point.
  4. Let's find out where fspe was assigned, searching for that term in your editor or IDE (or within this browser window).
  5. def fspe(t,u): - Nope, that defines a function.
  6. fspe = [fspe(t1,x) for t1 in t] - There's our culprit! You created a list involving the previously-defined fspe function, and then assigned it to the same name fspe, thus masking the function and making it inaccessible (and, if there were no more existing references to it, removed entirely by the garbage collector).
  7. The fix is to give it a unique name, like fspe3 or fspe_calcs or fspe_list.
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, you have explained this pretty well ! I learned very much from this ! Thank you very much, God bless my friend!
2

You assign over the function fspe with a list on line 91.

fspe = [fspe(t1,x) for t1 in t]

I made a simple change

fspe_list = [fspe(t1,x) for t1 in t] 
Lightcurve1 = [math.log10(a5) for a5 in fspe_list]

that at least runs. Whether it does what you want I dont know.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.