-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoscilloscope.py
47 lines (40 loc) · 1.42 KB
/
oscilloscope.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
"""
Author: RedFantom
License: GNU GPLv3
Copyright (c) RedFantom 2019
Convert the results of the oscilloscope utility plain text log files
into a CSV file. The measurements saved to the file are given as plain
read voltages.
"""
import pandas
import os
folder = "INSERT_PATH_TO_OSCILLOSCOPE_LOG_DATA"
os.chdir(folder)
def to_float(v):
return float(v.strip().replace(",", ".").lower())
for file in os.listdir(os.getcwd()):
if not file.endswith(".txt"):
continue
print("Processing {}...".format(file), end=" ", flush=True)
with open(file, "r") as fi:
lines = [l for l in fi.readlines() if l.strip() != ""]
data, delta_t, channel = dict(), 0, ""
for line in lines:
if "waveform" in line:
channel = line.split("\t")[1].strip()
data[channel] = list()
elif "delta t" in line:
delta_t = to_float(line.split("\t")[1])
elif "t0" in line:
# Do something fun with the start time of the measurement
# here if you feel like it
continue
elif "time" in line:
continue
else:
date, measurement = line.split("\t")
measurement = to_float(measurement)
data[channel].append(measurement)
data["time"] = [k * delta_t for k in range(len(data[channel]))]
pandas.DataFrame(data).to_csv("{}_oscilloscope.csv".format(file.split(".")[0]))
print("Done.", flush=True)