#!/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()