Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys, string, math
- import pygal
- def getFileData2(i_fName):
- lines = open(i_fName).readlines()
- res= {}
- for i in xrange(len(lines)):
- l = lines[i]
- tokens = string.split(l)
- freq = int(tokens[2][:-1]) / 1000000
- power = float(tokens[-1])
- res[freq] = power
- return res
- def listDiff(a, b):
- Len = min(len(a), len(b))
- res = [None] * Len
- for i in xrange(Len):
- res[i] = a[i] - b[i]
- return res
- def ReduceArray(i_arr, maxCount = 30):
- skip = len(i_arr)/(maxCount-1)
- if skip==0:
- skip = 1
- return i_arr[0::skip]
- def PlotLines2d(x_data, y_data, outFile):
- line_chart = pygal.Line(style=pygal.style.DarkSolarizedStyle, logarithmic=True, x_label_rotation=90, height=500, width=1600)
- line_chart.title = ''
- line_chart.x_labels = map(str, ReduceArray(x_data[:], 100))
- line_chart.add('VSWR', ReduceArray(y_data, 100), show_dots=False)
- line_chart.render_to_file(outFile)
- def main():
- pNoAnt = getFileData2(sys.argv[1]) # no antenna connected
- pWithAnt = getFileData2(sys.argv[2]) # antenna connected
- freqs = list(set(pNoAnt.keys()) & set(pWithAnt.keys()))
- freqs = sorted(freqs)
- # leave only samples present in both files
- for k in pNoAnt.keys():
- if k not in freqs:
- del pNoAnt[k]
- for k in pWithAnt.keys():
- if k not in freqs:
- del pWithAnt[k]
- returnLoss = [None] * len(freqs)
- for i in xrange(len(freqs)):
- returnLoss[i] = max( .0001, pNoAnt[freqs[i]] - pWithAnt[freqs[i]] )
- print returnLoss
- vswr = map(lambda x: (pow(10, x/20) + 1)/(pow(10, x/20) - 1), returnLoss)
- print vswr
- PlotLines2d(freqs, vswr, sys.argv[3])
- if __name__ == '__main__':
- if len(sys.argv) < 4:
- print '''Usage:\n \
- VSWR.py noAntennaConnected.csv antenaConnected.csv outputPlot.svg
- '''
- else:
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement