summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Arteaga <andyspiros@gmail.com>2012-02-24 18:58:34 +0100
committerAndrea Arteaga <andyspiros@gmail.com>2012-02-24 18:58:34 +0100
commitb92f48b60548d0be057bc9dbe264e00fc186227f (patch)
tree8769044701a15c9223a3b11197fee3b2dbc55d89 /numbench/report.py
parentAdded wildcards and regexp support for skip. Fixed a few bugs. (diff)
downloadauto-numerical-bench-b92f48b60548d0be057bc9dbe264e00fc186227f.tar.gz
auto-numerical-bench-b92f48b60548d0be057bc9dbe264e00fc186227f.tar.bz2
auto-numerical-bench-b92f48b60548d0be057bc9dbe264e00fc186227f.zip
New Plotter class
Diffstat (limited to 'numbench/report.py')
-rw-r--r--numbench/report.py95
1 files changed, 60 insertions, 35 deletions
diff --git a/numbench/report.py b/numbench/report.py
index 901723b..75be5c4 100644
--- a/numbench/report.py
+++ b/numbench/report.py
@@ -16,7 +16,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
from os.path import join as pjoin, basename
-import numpy as np
+import sys, numpy as np
+from shutil import rmtree
import benchconfig as cfg
import benchutils as bu
@@ -24,8 +25,53 @@ from htmlreport import HTMLreport
from testdescr import testdescr
from benchprint import Print
-def saveReport():
+class Plotter:
+ def __init__(self, conf):
+ # Set plot function
+ self.conf = conf
+ if not conf.has_key('type'):
+ self.plotf = plt.plot
+ elif type(conf['type']) == type(''):
+ try:
+ self.plotf = plt.__dict__[conf['type']]
+ except:
+ print >> sys.stderr, \
+ 'Plot function "', conf['type'], '" not found. Using plot'
+ self.plotf = plt.plot
+ return
+ else:
+ self.plot = conf['type']
+
+ # Labels
+ self.xlabel = conf.has_key('xlabel') and conf['xlabel'] or ''
+ self.ylabel = conf.has_key('ylabel') and conf['ylabel'] or ''
+
+ # Initialize markers
+ markers = ('-', '--', 'o', 'v', '^', 's', 'p', 'h', '*', '+', 'x', 'D')
+ colors = ('k', 'r', 'g', 'b')
+ self.linestyles = tuple([c+m for m in markers for c in colors])
+ self.curstyle = 0
+
+ # Open figure
+ plt.figure(figsize=(12,9), dpi=300)
+
+
+ def addPlot(self, x, y, label):
+ style = self.linestyles[self.curstyle]
+ self.curstyle = (self.curstyle+1) % len(self.linestyles)
+ self.plotf(x, y, style, label=label, hold=True)
+
+ def savePlot(self, fname):
+ plt.legend(loc='best')
+ plt.xlabel(self.xlabel)
+ plt.ylabel(self.ylabel)
+ plt.grid(True)
+ plt.savefig(fname, format='png', bbox_inches='tight', transparent=True)
+
+
+
+def saveReport():
# Check whether pyplot is working
try:
plt.figure()
@@ -34,53 +80,32 @@ def saveReport():
Print("Please make sure that X is running and $DISPLAY is set")
return
- # Read configuration
- conf = cfg.mod.reportConf()
-
- if conf['type'] == 'plot':
- plotf = plt.plot
- elif conf['type'] == 'semilogx':
- plotf = plt.semilogx
- elif conf['type'] == 'semilogy':
- plotf = plt.semilogy
- elif conf['type'] == 'loglog':
- plotf = plt.loglog
-
- if conf.has_key('xlabel'):
- xlabel = conf['xlabel']
- else:
- xlabel = ''
-
- if conf.has_key('ylabel'):
- ylabel = conf['ylabel']
- else:
- ylabel = ''
-
+ # Regenerate report in any case
+ rmtree(cfg.reportdir, ignore_errors=True)
# Open HTML file
bu.mkdir(cfg.reportdir)
+ bu.mkdir(pjoin(cfg.reportdir, 'images'))
htmlfname = pjoin(cfg.reportdir, 'index.html')
html = HTMLreport(htmlfname)
for operation in cfg.mod.getTests():
- plt.figure(figsize=(12,9), dpi=300)
-
+
+ # Begin plot
+ p = Plotter(cfg.mod.reportConf())
+
for tid,test in cfg.tests.items():
if test.has_key('implementations'):
for impl in test['implementations']:
if test['results'][impl].has_key(operation):
resultsFile = test['results'][impl][operation]
x,y = np.loadtxt(resultsFile, unpack=True)
- plotf(x, y, label=tid+'/'+impl, hold=True)
+ p.addPlot(x, y, tid+'/'+impl)
- plt.legend(loc='best')
- plt.xlabel(xlabel)
- plt.ylabel(ylabel)
- plt.grid(True)
-
- fname = pjoin(cfg.reportdir, operation+'.png')
- plt.savefig(fname, format='png', bbox_inches='tight', transparent=True)
- html.addFig(testdescr[operation], image=basename(fname))
+ imgpath = pjoin('images', operation+'.png')
+ fname = pjoin(cfg.reportdir, imgpath)
+ p.savePlot(fname)
+ html.addFig(testdescr[operation], image=imgpath)
# Close HTML file
html.close()