-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_grasp.py
More file actions
executable file
·267 lines (212 loc) · 7.23 KB
/
Copy pathprocess_grasp.py
File metadata and controls
executable file
·267 lines (212 loc) · 7.23 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import numpy as np
import matplotlib.pyplot as plt
from skrf import Network, Frequency
import pandas as pd
import time
def main():
PA = "F:/Devin/Grasp/LWASandbox/40mLWA/Job_26/"
freq, s11, s11_phase = process_par(PA + "Sparameters.par")
dmax, cut = process_cut(PA + "FieldData.cut", freq)
plot_pair_efficiencies(freq, s11, dmax, "Efficiencies.png", 16)
def process_par(f_name): #Process S parameters document return 1D numpy arrays of frequencies and s11s
f = open(f_name)
f.readline() #ignore header
freq = []
s11 = []
s11_phase = []
for line in f:
line = line.split()
freq.append(float(line[0])*1E3) #grab freq, convert to MHz
s11.append(float(line[1]))
s11_phase.append(float(line[2]))
f.close()
# print("freq = ", freq)
return np.array(freq), np.array(s11), np.array(s11_phase)
def process_cut(f_name, freq, off_axis = False):
# print("freq: ", freq)
print("file name: {}".format(f_name))
f = open(f_name)
line = f.readline()
dmax = []
i = -1 # Frequency Index
cut = pd.DataFrame()
while ("Field data" in line):
line = f.readline()
line = line.split()
line = [float(x) for x in line]
'''
line: Headder defined as per the grasp manual:
0: starting angle
1: angle delta
2: number of angles
3: phi cut
4-6: Various parameters related to polarization and radiation pattern data representation
'''
# print ("Headder = ", line)
phi = line[3] #should be 3 possible values: 0, 45, 90
if (phi == 0):
i += 1
# print(line, i, freq, f_name)
frequency = freq[i]
series_name_co = "f%4.2f:p%4.2f:co" %(frequency, phi)
series_name_cx = "f%4.2f:p%4.2f:cx" %(frequency, phi)
angles = []
dbi_co = []
dbi_cx = []
# record all values from radiation pattern
for ii in range(int(line[2])):
angle= -180. + ii*line[1] ####- 180. #180 used because antenna is technically upside down
angles.append(angle)
fields = [float(x) for x in f.readline().split()]
cx = 10*np.log10(fields[0]**2 + fields[1]**2)
co = 10*np.log10(fields[2]**2 + fields[3]**2)
dbi_co.append(co)
dbi_cx.append(cx)
if (not off_axis):
if ii == 100:
dmax.append(np.max([co, cx]))
#if off axis just take the maximum value here
if (off_axis):
dbi_co_max = np.max(dbi_co)
dbi_cx_max = np.max(dbi_cx)
dmax.append(np.max([dbi_co_max, dbi_cx_max]))
# print("off axis, appending: {}".format(dmax[-1]))
cut[series_name_co] = dbi_co
cut[series_name_cx] = dbi_cx
line = f.readline() #should be Field data... if more data
cut["angles"] = angles
dmax_f = np.zeros(len(freq))
# print(len(freq))
for i in range(len(freq)):
# print(dmax)
dmax_f[i] = np.max(dmax[i*3:(i+1)*3])
return dmax_f, cut
def calc_mismatch(s11):
#s11 in dB
#returns %
return (1-10**(s11/10))
def calc_input_z(s11, s11_phase, z0):
Gamma = 10**(s11/20.0)*np.exp(1.0j*s11_phase*np.pi/180.0) # s11 is in dBs, s11_phase is in deg
return z0*(1.0+Gamma)/(1.0-Gamma) #gives complex input impedance
def calc_refection_coefficient(zin, z0):
return (zin-z0)/(zin+z0)
def calc_app_eff(freq, dmax):
#freq in MHz, dmax in dB
#returns %
c = 2.997E8#meters/sec
r = 20.0#meters
wave_len = c/(freq*1E6)
aphy = np.pi*r**2
dmax_lin = 10**(dmax/10)
return dmax_lin*wave_len**2 /(4*np.pi*aphy)
def plot_smith(freq, s11, s11_phase, location):
plt.figure()
f = Frequency(np.min(freq), np.max(freq), len(freq), 'mhz')
n = Network(freq = f, s = 10**(s11/20)*np.exp(1j*s11_phase*np.pi/180), z0 = 50)
n.plot_s_smith(draw_labels = True)
plt.savefig(location)
def plot_imp(freq, im, title, location):
plt.figure()
plt.plot(freq, np.real(im), label = "real")
plt.plot(freq, np.imag(im), label = "imag")
plt.title(title)
plt.xlabel("Frequency [MHz]")
plt.legend()
plt.ylabel(title)
plt.savefig(location)
def plot_pair_efficiencies(freq, s11, dmax, location, z):
plt.figure()
plt.plot(freq, calc_mismatch(s11), 'b', label= "Mismatch Efficiency")
plt.title("Mismatch and Aperture Efficiencies z = %4.2f" % z)
plt.xlabel("Frequency [MHz]")
plt.ylabel("Efficiency")
plt.ylim([0, 1])
plt.yticks(np.arange(0, 1.01,.1))
plt.plot(freq,calc_app_eff(freq, dmax), 'r', label = "Aperture Efficiency")
# plt.set_ylabel("Aperture Efficiency [%]")
# lns = ms+ap
# labs = [x.get_label() for x in lns]
# plt.legend(lns, labs)
plt.legend()
plt.savefig(location)
def plot_SEFD(freq, dmax, location, z):
plt.figure()
plt.semilogy(freq,SEFD(freq, dmax), 'b', label= "SEFD")
plt.title("SEFD at z = %4.2f" % z)
plt.xlabel("Frequency [MHz]")
plt.ylabel("SEFD [Jy]")
plt.ylim([1, 5E5])
plt.legend()
# print(location)
plt.savefig(location)
def plot_cut(frequency, cut, z, title, feed_pattern = False, max_pattern_dB = 30, plot_cx = False):
#freq is which frequency to use
#
plt.rc('axes', linewidth=2)
fig, ax = plt.subplots(1,3, figsize=(30,10)) #each of the phis
for i, phi in enumerate([0, 45, 90]):
axi = ax[i]
series_name_co = "f%4.2f:p%4.2f:co" %(frequency, phi)
series_name_cx = "f%4.2f:p%4.2f:cx" %(frequency, phi)
half = int(len(cut[series_name_co])/2)
if ((cut[series_name_cx][half] > cut[series_name_co][half]) or
(feed_pattern and (cut[series_name_cx][0] > cut[series_name_co][0])) ):
#swap names if cx has larger boresight gain.
series_name_co, series_name_cx = series_name_cx, series_name_co
data = np.copy(cut[series_name_co])
if feed_pattern:
# For Feed Patterns
temp = np.copy(data[half:])
temp1 = np.copy(data[:half])
data[len(temp):] = temp1
data[:len(temp)] = temp
# print(cut["angles"])
axi.plot(cut["angles"] ,data, 'b', label= "co")
if (plot_cx):
data = np.copy(cut[series_name_cx])
if feed_pattern:
# For Feed Patterns
temp = np.copy(data[half:])
temp1 = np.copy(data[:half])
data[len(temp):] = temp1
data[:len(temp)] = temp
# print(cut["angles"])
axi.plot(cut["angles"] ,data, 'r', label= "cx")
# axi.plot(cut["angles"]-180,cut[series_name_cx], 'r', label= "cx")
axi.set_title("$\phi$ = %4.2f" %phi, fontsize = 20)
axi.legend()
axi.set_ylim([-20,max_pattern_dB])
axi.set_xlim([-180,180])
axi.set_xticks(range(-180, 181, 30))
axi.grid(linewidth = 2, linestyle = '--')
axi.set_yticks(range(-20, max_pattern_dB + 1,5))
fontsize = 14
for tick in axi.xaxis.get_major_ticks():
tick.label1.set_fontsize(fontsize)
# tick.label1.set_fontweight('bold')
for tick in axi.yaxis.get_major_ticks():
tick.label1.set_fontsize(fontsize)
# tick.label1.set_fontweight('bold')
if i == 0:
axi.set_ylabel("Amplitude [dBi]", fontsize = 16)
if i == 1:
axi.set_xlabel("Angle [Degrees]", fontsize = 16)
#axi.set_title()
fig.suptitle(r"Radiation Pattern at z = %4.2f, $\nu$ = %4.2f" % (z,frequency), fontsize=25)
#
# fig.show()
# time.sleep(1)
# print(title)
fig.savefig(title)
plt.close('all')
plt.rc('axes', linewidth=1)
def Tsys(freq):
return 300*(150/freq)**2.5 + 600
def SEFD(freq, dmax):
k = 1.38E3 #jy m^2 s k^-1
r = 20#m
return 2*k*Tsys(freq)/(calc_app_eff(freq,dmax)*np.pi*r**2)
if __name__ == '__main__':
main()
# print(calc_missmatch(-.46))
# print(calc_app_eff(50, 21.32))