python - TypeError: 'Quantity' object is not callable -
i attempting understand quantity error.
using python version 2.7.1 , numpy quantities package. have posted defined variables , equations , subsequent error. attempting generate array values of teffpv vary theta (th). can explain why creating error?
a = q.quantity(0.2,'au').simplified e = 0.2 r = q.quantity(0.4,'rsun').simplified # radius of blackbody t = q.quantity(3500,'k').simplified #temperature teff of star al = 0.3 n = 100 th = np.linspace(0.,4*np.pi,n) def d(a,e,th): return a*(1-e**2)/(1+e*np.cos(th)) def teffp(al,t,r,d): return ((1.- al)**(1/4))*t*(r/d(a,e,th))**(1/2) teffpv = np.zeros(n) # make arrays store results in range(n-1): teffpv=teffp(al,t,r,d(a,e,th[i])) error message
typeerror traceback (most recent call last) <ipython-input-17-bdcc9550c9ae> in <module>() 14 teffpv = np.zeros(n) # make arrays store results 15 in range (n-1): ---> 16 teffpv=teffp(al,t,r,d(a,e,th[i])) <ipython-input-17-bdcc9550c9ae> in teffp(al, t, r, d) 11 return a*(1-e**2)/(1+e*np.cos(th)) 12 def teffp(al,t,r,d): ---> 13 return ((1.- al)**(1/4))*t*(r/d(a,e,th))**(1/2) 14 teffpv = np.zeros(n) # make arrays store results 15 in range (n-1): typeerror: 'quantity' object not callable
your code has mistakes :
- no need initialize
teffpvnp.zeros(n), use loop. - replace
d(a,e,th)din formula ofteffp-> explains error message - use float rational exponents, in
teffpfunction
this code should want :
import quantities q import numpy np = q.quantity(0.2,'au').simplified e = 0.2 rsun = q.unitquantity('solar radius', q.m*6.9599e8, symbol='rsun') r = q.quantity(0.4,'rsun').simplified # radius of blackbody t = q.quantity(3500.,'k').simplified #temperature teff of star al = 0.3 n = 100 th = np.linspace(0.,4.*np.pi,n) def d(a,e,th): return a*(1-e**2)/(1+e*np.cos(th)) def teffp(al,t,r,d): return ((1.- al)**(0.25))*t*(r/d)**(0.5) teffpv = teffp(al,t,r,d(a,e,th)) print teffpv nb:
i added definition of rsun unit in code otherwise quantities package doesn't recognize it.
i'm not astrophysicist found here ;)
Comments
Post a Comment