commit | author | age
|
d2f7b0
|
1 |
from . import trisurf |
SP |
2 |
|
|
3 |
|
|
4 |
def demo(run, **kwargs): |
|
5 |
host=kwargs.get('host', None) |
|
6 |
print("Demo analysis") |
|
7 |
print("Analysis on host "+host['name']+" for run "+run.Dir.fullpath()+" completed") |
|
8 |
print("here comes info on the run variable:") |
|
9 |
print(run) |
|
10 |
print("here comes info on the host variable:") |
|
11 |
print(host) |
|
12 |
print("here comes info on the args variable:") |
|
13 |
print(kwargs.get('args',None)) |
|
14 |
|
|
15 |
|
|
16 |
def plotrunningavginteractive(run, **kwargs): |
|
17 |
import matplotlib.pyplot as plt |
|
18 |
from trisurf import VTKRendering as vtk |
|
19 |
import math |
|
20 |
from multiprocessing import Process |
|
21 |
table=trisurf.Statistics(run.Dir.fullpath(),filename='data_tspoststat.csv').getTable() |
|
22 |
def running_avg(col): |
|
23 |
import numpy as np |
|
24 |
avg=[] |
|
25 |
for i in range(0,len(col)): |
|
26 |
avg.append(np.average(col[:-i])) |
|
27 |
return avg |
|
28 |
def spawned_viewer(n): |
|
29 |
vtk.Renderer(kwargs.get('args', None),kwargs.get('host',None),run, n) |
|
30 |
|
|
31 |
fig=plt.figure(1) |
|
32 |
ra=running_avg(table['hbar']) |
|
33 |
l=len(table['hbar']) |
|
34 |
plt.plot(ra) |
|
35 |
plt.title('Running average') |
|
36 |
plt.ylabel('1/n sum_i=niter^n(hbar_i)') |
|
37 |
plt.xlabel('n') |
|
38 |
def onclick(event): |
|
39 |
#print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (event.button, event.x, event.y, event.xdata, event.ydata)) |
|
40 |
p=Process(target=spawned_viewer, args=(l-math.floor(event.xdata)-1,)) |
|
41 |
p.start() |
|
42 |
cid = fig.canvas.mpl_connect('button_press_event', onclick) |
|
43 |
plt.show() |
|
44 |
plt.close(1) |
|
45 |
|
|
46 |
|
|
47 |
# ------------------------------- |
|
48 |
# these functions should be wrapped |
|
49 |
# ------------------------------- |
|
50 |
|
|
51 |
def plotColumnFromPostProcess(run, filename='data_tspoststat.csv', column='hbar', **kwargs): |
|
52 |
import matplotlib.pyplot as plt |
|
53 |
|
|
54 |
def smooth(y, box_pts): |
|
55 |
import numpy as np |
|
56 |
box = np.ones(box_pts)/box_pts |
|
57 |
y_smooth = np.convolve(y, box, mode='same') |
|
58 |
return y_smooth |
|
59 |
table=trisurf.Statistics(run.Dir.fullpath(),filename=filename).getTable() |
|
60 |
plt.plot(table[column], '.') |
|
61 |
plt.title(run.Dir.fullpath()) |
|
62 |
plt.xlabel('Iteration') |
|
63 |
plt.ylabel(column) |
|
64 |
smooth_window=10 |
|
65 |
smoothed=smooth(table[column],smooth_window) |
|
66 |
plt.plot(tuple(range(int(smooth_window/2),len(smoothed)-int(smooth_window/2))),smoothed[int(smooth_window/2):-int(smooth_window/2)]) |
|
67 |
plt.show() |
|
68 |
print |
|
69 |
#if return False or no return statement, the analysis will continue with next running instance in the list. if return True, the analysis will stop after this run. |
|
70 |
return False |
|
71 |
|
|
72 |
|