forked from mdzik/bearded-octo-wookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaportRenderer.py
99 lines (74 loc) · 2.44 KB
/
RaportRenderer.py
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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 13 15:42:05 2015
@author: mdzikowski
"""
import matplotlib.pyplot as plt
import numpy as np
def generic_figure_processor(func):
def f(*args, **kwargs):
func(*args, **kwargs)
plt.figure()
return f
def generic_plot_processor(func):
def f(*args, **kwargs):
func(*args, **kwargs)
plot = args[0]
getattr(plt, plot['fun_name'])(*plot['args'],**plot['kwargs'])
return f
def decorate_with_call(decorator, *args_,**kwargs_):
def fd(func):
def f(*args, **kwargs):
plot = args[0]
if kwargs_.has_key('for_fig') :
if plot['fid'] in kwargs_['for_fig']:
tmp = kwargs_.copy()
tmp.pop('for_fig')
decorator(*args_, **tmp)
else:
decorator(*args_, **kwargs_)
func(*args, **kwargs)
return f
return fd
def decorate_with_alter(decorator, *args_,**kwargs_):
def fd(func):
def f(*args, **kwargs):
plot = args[0]
if kwargs_.has_key('for_fig') :
if plot['fid'] in kwargs_['for_fig']:
tmp = kwargs_.copy()
tmp.pop('for_fig')
decorator(plot, *args_, **tmp)
else:
decorator(plot, *args_, **kwargs_)
func(*args, **kwargs)
return f
return fd
#==============================================================================
#
# @generic_figure_processor
# def pf(*args, **kwargs):
# pass
#
# @decorate_with_call(plt.grid, which='both', for_fig='2')
# @decorate_with_call(plt.xlabel, 'X')
# @generic_plot_processor
# def pp(*args, **kwargs):
# pass
#==============================================================================
def render(fname, processplot, processfigure, **kwargs):
data = np.load(fname)
for fid in data.keys():
figure = data[fid]
print "New figure ", fid
for plot in figure:
plot['fid'] = fid
print "REPLAING: ", plot['fun_name'], plot['kwargs']
#getattr(plt, plot['fun_name'])(*plot['args'],**plot['kwargs'])
processplot(plot)
processfigure({'fid':fid})
if kwargs.has_key('show'):
if kwargs['show']:
plt.show()
else:
plt.show()