-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathantennaArray.py
More file actions
163 lines (145 loc) · 4.91 KB
/
Copy pathantennaArray.py
File metadata and controls
163 lines (145 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import numpy as np
from scipy.spatial import KDTree
from patchAntenna import PatchAntenna
from dipoleAntenna import DipoleAntenna
from spiralAntenna import SpiralAntenna
class AntennaArray():
'''
Class to represent an antenna array
'''
def __init__(self):
self.elements = []
self.excite_idx = None
return
def circ_count(self,len_d, count=0):
count = 6+(2*len_d) + count
if len_d <=0:
return count
len_d = len_d-1
return circ_count(len_d,count)
def rps(self,fmax,r,N):
d0 = (3e8/fmax)/2
d0 = d0*1000
if r >=1:
xi = 1
else:
xi = 1/((N**r) - (N-1)**r)
d= np.zeros(N+1)
for n in range(N+1):
d[n] = d0*xi*(n+1)**r
return d
def circ_positions(self,d):
self.xs = []
self.ys = []
for n,dn in enumerate(d):
n_layer = (2*n) + 6
wd = (2*np.pi/n_layer)
for w in np.arange(0,(2*np.pi),wd):
self.xs.append(dn*np.cos(w))
self.ys.append(dn*np.sin(w))
self.xs = np.insert(self.xs,0,0)
self.ys = np.insert(self.ys,0,0)
def rotate_positions(self,rot_angles):
theta = rot_angles * np.pi / 180
rotmat = np.array([[np.cos(theta), -1*np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
for n,t in enumerate(theta):
if n==0: b=0
else: b = self.circ_count(n-1)
if n>0: b+=1
e = self.circ_count(n) +1
[self.xs[b:e],self.ys[b:e]] = np.matmul(rotmat[:,:,n],[self.xs[b:e],self.ys[b:e]])
def generateRPSPositions(self,fmax,r=1,Nrps=3,rotations=None):
self.circ_positions(self.rps(fmax,r,Nrps))
self.N = len(self.xs)
if rotations is not None:
self.rotate_positions(rotations)
self.xmax = np.max(np.abs(self.xs))
self.ymax = np.max(np.abs(self.ys))
self.xmin = np.min(self.xs)
self.ymin = np.min(self.ys)
self.zmax = 0
def generateSingle(self):
self.N = 1
self.xs = [0.0]
self.ys = [0.0]
self.xmax = np.max(np.abs(self.xs))
self.ymax = np.max(np.abs(self.ys))
self.xmin = np.min(self.xs)
self.ymin = np.min(self.ys)
self.zmax = 0
def getNearestNeighborSA(self,idx,Nr):
'''
generates the nearest neighbor subarray object
'''
points = list(zip(self.xs.ravel(),self.ys.ravel()))
tree = KDTree(points)
ds,idxes = tree.query([self.xs[idx],self.ys[idx]],k=(Nr+1))
return self.generateSubarray(idxes)
def generateSubarray(self,ids):
'''
generates a new array object with a subset of the elements for use in subarray simulations.
'''
new_elements = []
for idx in ids:
new_elements.append(self.elements[idx])
ta = AntennaArray()
ta.elements = new_elements
ta.xs = []
ta.ys = []
for idx in ids:
ta.xs.append(self.elements[idx].x)
ta.ys.append(self.elements[idx].y)
ta.xmax = np.max(ta.xs)
ta.xmin = np.min(ta.xs)
ta.ymax = np.max(ta.ys)
ta.ymin = np.min(ta.ys)
ta.zmax = self.zmax
for idx in range(len(ta.elements)):
ta.elements[idx].x -= (ta.xmax-ta.xmin)/2 +ta.xmin
ta.elements[idx].y -= (ta.ymax-ta.ymin)/2 +ta.ymin
ta.xs[idx] -=(ta.xmax-ta.xmin)/2 +ta.xmin
ta.ys[idx] -=(ta.ymax-ta.ymin)/2 +ta.ymin
return ta
def initPatchElements(self):
for id in range(len(self.xs)):
self.elements.append(PatchAntenna(
id,
L_=10.2,
W_=15.5,
x_=self.xs[id],
y_=self.ys[id],
hs_=1.5,
epsr_=4.2))
self.zmax = 10
def initDipoleElements(self,f0,orientation='x'):
for id in range(len(self.xs)):
excite=False
if id == self.excite_idx: excite = True
self.elements.append(DipoleAntenna(
id,
f0,
x_=self.xs[id],
y_=self.ys[id],
orientation_=orientation,
excite_=excite
))
if orientation== 'z': self.zmax = 30
def initSpiralElements(self,r0,rmax,h,hs=0.5,epsr=4.5,alpha=0.32):
self.xmax = np.max(np.abs(self.xs)) + rmax
self.ymax = np.max(np.abs(self.ys)) + rmax
self.zmax = 3*h
for id in range(len(self.xs)):
excite = False
if id == self.excite_idx: excite = True
self.elements.append(SpiralAntenna(
id,
x_=self.xs[id],
y_=self.ys[id],
r0_=r0,
rmax_=rmax,
alpha_=alpha,
h_=h,
hs_=hs,
epsr_=epsr
))