-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathCDF_python.py
80 lines (61 loc) · 2.07 KB
/
CDF_python.py
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
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 14:12:49 2019
@author: mlin
"""
import numpy as np
import math
import matplotlib.pyplot as plt
class ffd_CDF():
def __init__(self, ffd_file):
self._read(ffd_file)
self._compute()
def _read(self, ffd_file):
with open(ffd_file) as f:
text=f.readlines()
t=[int(i) for i in text[0].split(' ')]
p=[int(i) for i in text[1].split(' ')]
convert=lambda x:math.pi*(x/180)
self.dtheta=convert((t[1]-t[0])/(t[2]-1))
self.dphi=convert((p[1]-p[0])/(p[2]-1))
theta=[convert(t[0])+i*self.dtheta for i in range(t[2])]
phi=[convert(p[0])+i*self.dphi for i in range(p[2])]
E=[]
for i in text[4:]:
E.append([float(j) for j in i.strip().split(' ')])
self.fld=zip(self._duplicate(theta, len(phi)), phi*len(theta),E)
def _duplicate(self, x_list, y):
result=[]
for i in x_list:
for j in range(y):
result.append(i)
return result
def _compute(self):
data=[]
Etotal, stotal=0, 0
Esum=0
for theta, phi, E in self.fld:
Esum=math.sqrt(sum([i*i for i in E]))
ds=abs(self.dtheta*self.dphi*math.sin(theta))
stotal+=ds
Etotal+=Esum#*ds
data.append((ds,Esum))
x, y = [], []
z=0
Eaverage=Etotal/len(data)#/stotal
data_n=[(Esum/Eaverage, ds/stotal) for ds, Esum in data]
data_n.sort()
for i , j in data_n:
x.append(10*math.log(i))
z+=j
y.append(z)
self.CDF=list(zip(x,y))
def plot(self):
x,y=zip(*self.CDF)
plt.plot(x,y)
plt.grid(True)
plt.yticks(np.arange(0, 1.1, 0.1))
plt.xticks(np.arange(-40, 10, 5))
plt.show()
cdf1=ffd_CDF('D:/Customer2019/2019_4_12_5G_CDF/exportfields.ffd')
cdf1.plot()