-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotcsv.py
64 lines (48 loc) · 1.67 KB
/
plotcsv.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
import pandas as pd
import plotly.graph_objects as go
import argparse
import plotly.io as pio
sweepmode: bool = False
debug: bool = False
filename: str = ""
outputtype: str = "browser"
pio.kaleido.scope.default_width = 1000
pio.kaleido.scope.default_height = 800
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', help='csv datafile (may contain multiple measurements)')
parser.add_argument('-s', '--sweep', action='store_true', help='file was recorded in sweep mode')
parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
parser.add_argument('-o', '--output', help='output type, default show in browser / browser|png|jpeg')
args = vars(parser.parse_args())
if args['sweep']:
sweepmode = True
if args['verbose']:
debug = True
if args['output']:
outputtype = args['output']
if args['input']:
filename = args["input"]
else:
print("please specify input file name with -i")
exit(1)
fig = go.Figure()
# read csv into dataframe
df = pd.read_csv(filename)
if sweepmode:
df.columns = ["time", "freq", "power", "pass"]
# find unique measurement names in csv
measurements = set(df['pass'])
if debug: print(measurements)
for i in measurements:
df_result = df[df['pass'] == i]
fig.add_trace(go.Scatter(x=df_result['freq'], y=df_result['power'], mode='lines', name=i))
else:
# no sweepmode
df.columns = ["time", "power"]
fig.add_trace(go.Scatter(x = df['time'], y = df['power'], mode='lines', name='dbm over time'))
if outputtype == "browser":
fig.show()
elif outputtype == "png":
fig.write_image(filename+".png")
elif outputtype == "jpeg":
fig.write_image(filename + ".jpg")