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
|
#!/usr/bin/env python3
import csv
import getopt
import numpy as np
import os
import re
import struct
import sys
import tarfile
import matplotlib.pyplot as plt
from dfatool.loader import MIMOSA
from dfatool.utils import running_mean
opt = dict()
if __name__ == "__main__":
try:
optspec = "export= "
raw_opts, args = getopt.getopt(sys.argv[1:], "", optspec.split())
for option, parameter in raw_opts:
optname = re.sub(r"^--", "", option)
opt[optname] = parameter
if "export" in opt:
opt["export"] = list(map(int, opt["export"].split(":")))
except getopt.GetoptError as err:
print(err)
sys.exit(2)
voltage = float(args[0])
shunt = float(args[1])
mimfile = args[2]
mim = MIMOSA(voltage, shunt)
charges, triggers = mim.load_file(mimfile)
charges = charges[:3000000]
currents = running_mean(mim.charge_to_current_nocal(charges), 10) * 1e-6
powers = currents * voltage
xr = np.arange(len(currents)) * 1e-5
if "export" in opt:
xr = xr[opt["export"][0] : opt["export"][1]]
currents = currents[opt["export"][0] : opt["export"][1]]
powers = powers[opt["export"][0] : opt["export"][1]]
for pair in zip(xr, powers):
print("{} {}".format(*pair))
plt.plot(xr, powers, "r-")
plt.xlabel("Time [s]")
plt.ylabel("Power [W]")
plt.grid(True)
plt.show()
|