summaryrefslogtreecommitdiff
path: root/tools/solarmeter/solarmeter_plot.py
blob: 856dd4726a6267b7940e56ab9fefd86af02f3ab9 (plain) (blame)
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
#!/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): (u/i, u*i), filter(lambda (u,i): i > 0.0 and u < limit_voltage, measurements[panelid]) )))))

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")
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]')
pylab.xscale('log', basex=10)
pylab.yscale('log', basey=10)
pylab.title("Leistungsanpassung")
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.legend()

pylab.show()