0
votes

I have to plot antenna response pattern in a spherical polar plot. I first create the theta(t) and phi(p) values. Then there is F_c and F_s that has to calculated for each theta[i] and phi[i].

t=np.linspace(-math.pi/2, math.pi/2, num=x)
p=np.linspace(-math.pi, math.pi, num=x)

for k in xrange(x):
    for j in xrange(x):
            for i in xrange(n):
                    F_c=F_c_F_s.F_c(theta[i],phi[i],t[j],p[k])
                    F_s=F_c_F_s.F_s(theta[i],phi[i],t[j],p[k])
                    sum_F_c[j][k]=sum_F_c[j][k]+F_c
                    sum_F_s[j][k]=sum_F_s[j][k]+F_s
                    mod_F[j][k]=math.log((math.pow(sum_F_c[j][k],2)+math.pow(sum_F_s[j][k],2)),10)

Now we have a value of mod_F for each t and p. For each value of theta and correspondingly for each value of phi I calculate Cartesian coordinates. Then to make the surface plot I have the following:

fig = p.figure()
ax = Axes3D(fig)
ax.plot_wireframe(x,y,z)
ax.plot_surface(x,y,z,rstride=1,cstride=1,cmap=cm.jet)
p.show()

The problem is, it is incredibly slow! Even for x=10 i.e. a 10 x 10 grid, it take a lot of time. Is there a way to do this in better and faster manner?

1
what are F_c and F_s. It might be possible to vectorize that triple loop. - ev-br
F_c and F_s are two components of the pattern. I have to calculate both for all i and sum them. Finally I need the log of sum of squares of (these summed over i) F_c and F_s. The slower part of the code is the plotting part. - Devansh Agarwal
The time is almost certainly being spend in F_c_F_s.F_c and F_c_F_s.F_s; nothing else in the loop takes all that much time (at least, when only performing it 1000 times). Without seeing the code for those, there's not much we can do. - Gretchen
here is the link for the codes. F_map.py is the main code. - Devansh Agarwal
This question appears to be off-topic because it is about improving working code - Tim

1 Answers

0
votes

Following worked for me:

t=np.linspace(0, np.pi, num=x)
p=np.linspace(-np.pi,np.pi,num=x)
[T,P]=np.meshgrid(t,p)
F_c=0.0
F_s=0.0

for i in xrange(n):
    F_c+=F_c_F_s.F_c(theta[i],phi[i],T,P)
    F_s+=F_c_F_s.F_s(theta[i],phi[i],T,P)
mod_F=(np.log10((np.power(F_c,2)+np.power(F_s,2))))