Advertisement
Guest User

just some scatter plot

a guest
Aug 5th, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.71 KB | None | 0 0
  1.  
  2. class Source(object):
  3.     def __init__(self, x=None, y=None, amp=None, ngroup=None):
  4.         self.x = x
  5.         self.y = y
  6.         self.amp = amp
  7.         self.ngroup = ngroup
  8.  
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11. import copy as Copy
  12.  
  13. ng0 = [(4,4)]
  14. ng1 = [(3,3), (3,4), (4,5), (5,4), (5,3), (4,3)]
  15. ng2 = [(2,3), (2,4), (2,5), (3,5), (4,6), (5,5),
  16.        (6,5), (6,4), (6,3), (5,2), (4,2), (3,2)]
  17. ng3 = []
  18. ng4 = [(0,2), (0,3), (0,4), (0,5),
  19.        (0,6), (1,6), (2,7), (3,7),
  20.        (4,8), (5,7), (6,7), (7,6),
  21.        (8,6), (8,5), (8,4), (8,3),
  22.        (8,2), (7,1), (6,1), (5,0),
  23.        (4,0), (3,0), (2,1), (1,1)]
  24.  
  25. pi = np.pi
  26. twopi = 2.0 * np.pi
  27.  
  28. j = np.complex(0,1)
  29.  
  30. x = np.linspace(-4, 4, 9)
  31. y = (np.sqrt(3.)/2.) * x
  32. X, Y = np.meshgrid(x, y)
  33. X[1::2] += 0.5
  34.  
  35. sources = []
  36. for p in ng0:
  37.     source = Source(X[p], Y[p], ngroup=0)
  38.     sources.append(source)
  39. for p in ng1:
  40.     source = Source(X[p], Y[p], ngroup=1)
  41.     sources.append(source)
  42. for p in ng2:
  43.     source = Source(X[p], Y[p], ngroup=2)
  44.     sources.append(source)
  45. for p in ng4:
  46.     source = Source(X[p], Y[p], ngroup=4)
  47.     sources.append(source)
  48.  
  49. antenna = Copy.deepcopy(sources)  # save for later
  50.  
  51. count = np.array([sum([s.ngroup == i for s in antenna])
  52.                   for i in range(5)])
  53.  
  54. d = 0.190           # meters spacing estimated from photo with humans
  55. clight = 2.9979E+08 # m/s
  56. freq   = 1.6E+09    # (Hz)  1/s
  57. lam = clight / freq
  58. k0 = twopi / lam
  59.  
  60. nangles = 21
  61. theta_deg = np.linspace(0, 10, nangles)
  62. theta = (pi/180.) * theta_deg
  63. sth = np.sin(theta)
  64.  
  65. E = np.zeros_like(theta, dtype=complex)
  66.  
  67. nst = 20
  68. nstep = 2*nst + 1
  69.  
  70. a2 =  np.logspace(np.log10(0.15), np.log10(0.40), nstep)
  71. a4 = -np.logspace(np.log10(0.10), np.log10(0.16), nstep)
  72. a0 = 4./3.
  73. a1 = 1.0
  74. a3 = 0.0
  75. amplitudes = np.zeros((nstep, nstep, 5))
  76. amplitudes[...,2] = a2[None, :]
  77. amplitudes[...,4] = a4[:, None]
  78. amplitudes[...,0] = a0
  79. amplitudes[...,1] = a1
  80. amplitudes[...,3] = a3
  81.  
  82.  
  83. amps = amplitudes.reshape(-1,5)
  84.  
  85. powers = ((np.abs(amps)**2) * count[None, :]).sum(axis=-1)
  86.  
  87. amps /= np.sqrt(powers)[:, None]   # equalize the total power
  88.  
  89. Ehs, Evs = [], []
  90. Eh = np.zeros_like(theta, dtype=complex)
  91. Ev = Eh.copy()
  92. for amp in amps:
  93.     for s in antenna:
  94.         s.amp = amp[s.ngroup]
  95.     Eh[:], Ev[:] = 0.0, 0.0
  96.     for s in antenna:
  97.         Eh += s.amp * np.exp(j*(d*s.x*sth)*k0)
  98.         Ev += s.amp * np.exp(j*(d*s.y*sth)*k0)
  99.     Ehs.append(Eh.copy())
  100.     Evs.append(Ev.copy())
  101.  
  102. Ehs = np.array(Ehs).reshape(nstep, nstep, -1)
  103. Evs = np.array(Evs).reshape(nstep, nstep, -1)
  104.  
  105. Ihs = np.abs(Ehs)**2
  106. Ivs = np.abs(Evs)**2
  107.  
  108. Ipaper = 1.0 + 1.86*(theta_deg/10.)**2 - 1.82*(theta_deg/10.)**4
  109.            
  110. # ok rankem!
  111.  
  112. if 1 == 1:
  113.     use = theta_deg < 9.5  # don't compare beyond
  114.  
  115.     Ihsflat = Ihs.reshape(-1, nangles)
  116.     Ihsflatzero = Ihsflat[:,0]
  117.     Ihsflatnorm = Ihsflat/Ihsflatzero[:, None]
  118.  
  119.     diffmax = []
  120.     for Ih, Ihn in zip(Ihsflat, Ihsflatnorm):
  121.         diffmax.append( (np.abs(Ihn - Ipaper)/Ipaper)[use].max() )
  122.     diffmax = np.array(diffmax)
  123.  
  124.     consider = (diffmax < 0.05)  *  (Ihsflatzero > 1)
  125.  
  126.     Ihsfzc = Ihsflatzero[consider]
  127.     dmc = diffmax[consider]
  128.     ampsc = amps[consider]
  129.     rankor = Ihsfzc.argsort()[::-1]
  130.     ampscs = ampsc[rankor]
  131.  
  132.  
  133.  
  134.  
  135. if 1 == 1:
  136.     plt.figure()
  137.     plt.scatter(Ihsfzc, dmc)
  138.     plt.xscale('log')
  139.     plt.yscale('log')
  140.     plt.show()
  141.  
  142.     plt.figure()
  143.     data = ampscs.T
  144.     plt.subplot(2,2,1)
  145.     for thing in data:
  146.         plt.plot(thing)
  147.     plt.subplot(2,2,2)
  148.     plt.plot(data[2]/data[1])
  149.     plt.plot(data[4]/data[1])
  150.     plt.subplot(2,1,2)
  151.     data = ampscs[:200].T
  152.     plt.plot(data[2]/data[1])
  153.     plt.plot(data[4]/data[1])
  154.    
  155.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement