-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantennapols.py
100 lines (83 loc) · 2.47 KB
/
antennapols.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#python antenna pol translation module
import sys
import subprocess
def callProg(mystring):
#print mystring
p = subprocess.Popen(mystring, stdout=subprocess.PIPE, shell=True)
p.wait()
if(p.returncode):
print "program " + mystring + " returned error"
print p.stdout.read()
sys.exit(1)
return p
def getValidAntennaList():
p = callProg(['fxconf.rb sals'])
line = p.stdout.readline()
while not line.startswith("none"):
line = p.stdout.readline()
validAntennas = line.split()
validAntennas = validAntennas[1:] #first is none, skipping
return validAntennas
def getAntName(apl):
strname=''
if len(apl) > 2:
strname=apl[0:2]
return strname
def isvalidname(antennalist, apl):
if len(apl) < 4:
print("antennapol: " + apl + " -- too short")
return False
pol = apl[2:]
anum = apl[0:2]
if not pol in ['x1','y1']:
print("antennapol: " + apl + " -- bad polarization")
return False
if not anum in antennalist:
print("antennapol: " + apl + " -- bad antenna name")
return False
return True
def getAllAntennas():
validAntennas = getValidAntennaList()
antpols = [];
for ant in validAntennas:
antpols.append(ant + "x1")
antpols.append(ant + "y1")
return validAntennas,antpols
def getAllAntennasStr():
antennasList,antpolList = getAllAntennas()
antstr = ",".join(antennasList);
antpolstr = ",".join(antpolList);
return antstr,antpolstr
def generateAntennasfromAntpolStr(antpolstr):
antennasList,antpolList = generateAntennasfromAntpol(antpolstr)
antstr = ",".join(antennasList);
antpolstr = ",".join(antpolList);
return antstr,antpolstr
def makeAntPolsStr(antennastr):
antennasList,antpolList = makeAntPols(antennastr)
antstr = ",".join(antennasList);
antpolstr = ",".join(antpolList);
return antstr,antpolstr
def makeAntPols(antennastr):
validAntennas = getValidAntennaList()
antennas = set()
antpolsvalid = set()
antennasL = antennastr.split(",")
for ant in antennasL:
apl1 = ant + "x1"
apl2 = ant + "y1"
if(isvalidname(validAntennas,apl1)):
antennas.add(getAntName(apl1))
antpolsvalid.add(apl1)
antpolsvalid.add(apl2)
return antennas,antpolsvalid
def generateAntennasfromAntpol(antpolstr):
validAntennas = getValidAntennaList()
antennas = set()
antpolsvalid = set()
antpols = antpolstr.split(",")
for apl in antpols:
if(isvalidname(validAntennas,apl)):
antennas.add(getAntName(apl))
antpolsvalid.add(apl)
return antennas,antpolsvalid