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
101
102
103
104
105
106
107
108
109
110
111
112
|
#!/usr/bin/python -OO
# -*- coding: utf-8 -*-
import numpy as np
import pylab, sys, os, re
if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]):
sys.exit(1)
measurements={}
def autom(panelid, u, i):
""" Add Measurments to dict
@param panelid id of solarcell panel
@param u measured voltage in volts
@param i remasured current in milli ampere
"""
global measurements
panelid = int(panelid)
if not panelid in measurements:
measurements[panelid]=[]
measurements[panelid].append( (float(u), float(i) * 1e-3) )
def getm_ui(panelid, limit_voltage=100):
""" get measurements load over power
@param subject name of solarpanelcells series
@returns tuple of lists: (list(r values), list(p values))
"""
global measurements
return zip(* sorted(list(set(filter(lambda (u,i): i > 0.0 and u < limit_voltage, measurements[panelid]) ))))
def getm_rp(panelid, limit_voltage=100):
""" get measurements load over power
@param subject name of solarpanelcells series
@returns tuple of lists: (list(r values), list(p values))
"""
global measurements
return zip(* sorted(list(set(map( lambda (u,i): (int(u/i), u*i), filter(lambda (u,i): i > 0.0 and u < limit_voltage, measurements[panelid]) )))))
def get_matched_impedance(panelids, limit_voltage=100):
""" get measurements load over power
@param subject name of solarpanelcells series
@returns tuple of lists: (list(r values), list(p values))
"""
global measurements
r_panel_dict = {}
for id in panelids:
try:
(rl,pl) = getm_rp(id, limit_voltage)
except ValueError:
continue
for (r,p) in zip(rl, pl):
r = r / 5 * 5
if not r in r_panel_dict:
r_panel_dict[r] = {}
if id in r_panel_dict[r]:
r_panel_dict[r][id] = max(p, r_panel_dict[r][id])
else:
r_panel_dict[r][id] = p
return reduce(lambda (r1,p1),(r2,p2): (r1,p1) if p1 > p2 else (r2,p2) ,map(lambda (r,d): (r, sum(d.values())), r_panel_dict.items()))
lre = re.compile(r"(\d)\s+([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)")
#lre = re.compile(r"(\d)\s+([+-]?\d+.\d+)\s+([+-]?\d+\.\d+)")
with open(sys.argv[1], "rb") as fh:
for line in fh:
m = lre.match(line)
if m:
autom(*m.group(1,2,3))
#print measurements
panelids = range(0,8)
pylab.figure(0)
pylab.xlabel('Spannung [V]')
pylab.ylabel('Strom [A]')
pylab.xscale('linear')
pylab.yscale('linear')
pylab.title("U/I Plot\nFile: %s" % sys.argv[1])
pylab.grid(True)
for id in panelids:
try:
(u, i) = getm_ui(id, limit_voltage=9)
except ValueError:
continue
pylab.plot(u,i, label=str(id))
pylab.hold(True)
pylab.legend()
pylab.figure(1)
pylab.xlabel('Widerstand [Ohm]')
pylab.ylabel('Leistung [W]')
(r_mi, p_mi) = get_matched_impedance(panelids, limit_voltage=9)
pylab.xscale('log', basex=10)
pylab.yscale('log', basey=10)
pylab.title("Leistungsanpassung: %.1f mW @ %d Ohm: \nFile: %s" % (p_mi*1e3, r_mi,sys.argv[1]))
pylab.hold(True)
pylab.grid(True)
for id in panelids:
try:
(r, p) = getm_rp(id, limit_voltage=9)
except ValueError:
continue
pylab.plot(r,p, label=str(id))
pylab.hold(True)
pylab.stem([r_mi], [p_mi])
(ymin, ymax) = pylab.ylim()
pylab.axvline(r_mi, ymin, ymax)
pylab.legend()
pylab.show()
|