Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Source(object):
- def __init__(self, x=None, y=None, amp=None, ngroup=None):
- self.x = x
- self.y = y
- self.amp = amp
- self.ngroup = ngroup
- import numpy as np
- import matplotlib.pyplot as plt
- import copy as Copy
- ng0 = [(4,4)]
- ng1 = [(3,3), (3,4), (4,5), (5,4), (5,3), (4,3)]
- ng2 = [(2,3), (2,4), (2,5), (3,5), (4,6), (5,5),
- (6,5), (6,4), (6,3), (5,2), (4,2), (3,2)]
- ng3 = []
- ng4 = [(0,2), (0,3), (0,4), (0,5),
- (0,6), (1,6), (2,7), (3,7),
- (4,8), (5,7), (6,7), (7,6),
- (8,6), (8,5), (8,4), (8,3),
- (8,2), (7,1), (6,1), (5,0),
- (4,0), (3,0), (2,1), (1,1)]
- pi = np.pi
- twopi = 2.0 * np.pi
- j = np.complex(0,1)
- x = np.linspace(-4, 4, 9)
- y = (np.sqrt(3.)/2.) * x
- X, Y = np.meshgrid(x, y)
- X[1::2] += 0.5
- sources = []
- for p in ng0:
- source = Source(X[p], Y[p], ngroup=0)
- sources.append(source)
- for p in ng1:
- source = Source(X[p], Y[p], ngroup=1)
- sources.append(source)
- for p in ng2:
- source = Source(X[p], Y[p], ngroup=2)
- sources.append(source)
- for p in ng4:
- source = Source(X[p], Y[p], ngroup=4)
- sources.append(source)
- antenna = Copy.deepcopy(sources) # save for later
- count = np.array([sum([s.ngroup == i for s in antenna])
- for i in range(5)])
- d = 0.190 # meters spacing estimated from photo with humans
- clight = 2.9979E+08 # m/s
- freq = 1.6E+09 # (Hz) 1/s
- lam = clight / freq
- k0 = twopi / lam
- nangles = 21
- theta_deg = np.linspace(0, 10, nangles)
- theta = (pi/180.) * theta_deg
- sth = np.sin(theta)
- E = np.zeros_like(theta, dtype=complex)
- nst = 20
- nstep = 2*nst + 1
- a2 = np.logspace(np.log10(0.15), np.log10(0.40), nstep)
- a4 = -np.logspace(np.log10(0.10), np.log10(0.16), nstep)
- a0 = 4./3.
- a1 = 1.0
- a3 = 0.0
- amplitudes = np.zeros((nstep, nstep, 5))
- amplitudes[...,2] = a2[None, :]
- amplitudes[...,4] = a4[:, None]
- amplitudes[...,0] = a0
- amplitudes[...,1] = a1
- amplitudes[...,3] = a3
- amps = amplitudes.reshape(-1,5)
- powers = ((np.abs(amps)**2) * count[None, :]).sum(axis=-1)
- amps /= np.sqrt(powers)[:, None] # equalize the total power
- Ehs, Evs = [], []
- Eh = np.zeros_like(theta, dtype=complex)
- Ev = Eh.copy()
- for amp in amps:
- for s in antenna:
- s.amp = amp[s.ngroup]
- Eh[:], Ev[:] = 0.0, 0.0
- for s in antenna:
- Eh += s.amp * np.exp(j*(d*s.x*sth)*k0)
- Ev += s.amp * np.exp(j*(d*s.y*sth)*k0)
- Ehs.append(Eh.copy())
- Evs.append(Ev.copy())
- Ehs = np.array(Ehs).reshape(nstep, nstep, -1)
- Evs = np.array(Evs).reshape(nstep, nstep, -1)
- Ihs = np.abs(Ehs)**2
- Ivs = np.abs(Evs)**2
- Ipaper = 1.0 + 1.86*(theta_deg/10.)**2 - 1.82*(theta_deg/10.)**4
- # ok rankem!
- if 1 == 1:
- use = theta_deg < 9.5 # don't compare beyond
- Ihsflat = Ihs.reshape(-1, nangles)
- Ihsflatzero = Ihsflat[:,0]
- Ihsflatnorm = Ihsflat/Ihsflatzero[:, None]
- diffmax = []
- for Ih, Ihn in zip(Ihsflat, Ihsflatnorm):
- diffmax.append( (np.abs(Ihn - Ipaper)/Ipaper)[use].max() )
- diffmax = np.array(diffmax)
- consider = (diffmax < 0.05) * (Ihsflatzero > 1)
- Ihsfzc = Ihsflatzero[consider]
- dmc = diffmax[consider]
- ampsc = amps[consider]
- rankor = Ihsfzc.argsort()[::-1]
- ampscs = ampsc[rankor]
- if 1 == 1:
- plt.figure()
- plt.scatter(Ihsfzc, dmc)
- plt.xscale('log')
- plt.yscale('log')
- plt.show()
- plt.figure()
- data = ampscs.T
- plt.subplot(2,2,1)
- for thing in data:
- plt.plot(thing)
- plt.subplot(2,2,2)
- plt.plot(data[2]/data[1])
- plt.plot(data[4]/data[1])
- plt.subplot(2,1,2)
- data = ampscs[:200].T
- plt.plot(data[2]/data[1])
- plt.plot(data[4]/data[1])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement