-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview_fes_convergence_2d.py
executable file
·166 lines (131 loc) · 4.92 KB
/
view_fes_convergence_2d.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import numpy as np
import os
from functools import reduce
from matplotlib.ticker import MaxNLocator
import matplotlib.pyplot as plt
import re
import glob
import itertools
import matplotlib.gridspec as gridspec
#cutoffs = [-0.005, 0.024, -0.005, 0.024]
cutoffs = [-0.035, 0.035, -0.035, 0.035]
files=list([])
files = ['out_300.FES','out_400.FES','out_500.FES','out_600.FES','out_700.FES','out_800.FES','out_900.FES','out_1000.FES','out_1100.FES']
#files = ['out_1900.FES','out_2000.FES','out_2100.FES','out_2200.FES']
#for i in range(200,900,50):
# files.append('out_' + str(i) + '.FES')
print(files)
plot_levels=range(0,60,2)
#handy function for determining factors don't lose
def factors(n):
return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def format_coord(xt, yt, zt):
xarr = x[0,:]
yarr = y[:,0]
if ((xt > xarr.min()) & (xt <= xarr.max()) &
(yt > yarr.min()) & (yt <= yarr.max())):
col = np.searchsorted(xarr, xt)-1
row = np.searchsorted(yarr, yt)-1
zt = z[row, col]
return f'xt={xt:1.4f}, yt={yt:1.4f}, zt={zt:1.4f}'
#return f'zt={zt:1.4f}'
else:
return f''
#detect files and sort them nicely
#files.sort(key=lambda var:[int(x) if x.isdigit() else x for x in re.findall(r'[^0-9]|[0-9]+', var)])
facts = np.sort(np.array((factors(len(files)))))
print (facts)
print ((len(facts)-1)/2)
#determining rows and cols arrangement, more annoying than you'd think
num_plots_rows=0
num_plots_cols=0
#if a square number we'll have an odd number of factors so set number of rows and cols to the same thing
if (len(facts) % 2) == 0:
num_plots_rows=facts[int(len(facts)/2-1)]
num_plots_cols=facts[int(len(facts)/2)]
else:
num_plots_rows=facts[int((len(facts)-1)/2)]
num_plots_cols=facts[int((len(facts)-1)/2)]
print(num_plots_rows)
print(num_plots_cols)
#make grid for viewing convergence
#plt.figure(figsize=(10,4))
AX=gridspec.GridSpec(num_plots_rows,num_plots_cols)
#AX.update (wspace=0.4,hspace=0.8)
row_arr=range(num_plots_rows)
col_arr=range(num_plots_cols)
row_arr_t=list(itertools.chain.from_iterable(itertools.repeat(x, num_plots_cols) for x in row_arr))
row_arr=row_arr_t
col_arr=list(col_arr)*num_plots_rows
print(row_arr)
print(col_arr)
for i in range(len(files)):
row_place=row_arr[i]
col_place=col_arr[i]
plt.subplot2grid((num_plots_rows,num_plots_cols),(row_place,col_place),colspan=1,rowspan=1)
#need the number of bins in each axis of the grid.
data=np.loadtxt(files[i])
pattern=re.compile('nbins')
grid_dims=[0,0]
ind=0
x_label_text=''
y_label_text=''
for j, line in enumerate(open(files[i])):
if j==0:
temp_line=line
temp_line=line.split(' ')
x_label_text=temp_line[2]
y_label_text=temp_line[3]
x_label_text=x_label_text.split('.')[0]
y_label_text=y_label_text.split('.')[0]
for j, line in enumerate(open(files[i])):
for match in re.finditer(pattern, line):
#print ('Found on line %s: %s' % (i+1, match.group()))
#print(line)
if re.search('nbins',str(line)):
nbin_line=line
nbin_line=nbin_line.split(' ')
nbins=np.int(nbin_line[-1])
grid_dims[ind]=nbins
ind=ind+1
#print(grid_dims)
x,y,z=(data[:,0],data[:,1],data[:,2])
x=np.reshape(x,grid_dims)
y=np.reshape(y,grid_dims)
z=np.reshape(z,grid_dims)
print(np.shape(z))
#print (type(x))
#print ((x))
type(x)
# x and y are bounds, so z should be the value *inside* those bounds.
# Therefore, remove the last value from the z array.
#z = z[:-1, :-1]
#z_min, z_max = np.abs(z).max(), -np.abs(z).min()
#
#fig, ax = plt.subplots()
#c = ax.contourf(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max,rasterized=True)
#levels = MaxNLocator(nbins=15).tick_values(z_min, z_max)
#c = plt.contour(x, y, z)
#levels = MaxNLocator(nbins=15).tick_values(z_min, z_max)
temp_min = 0
for k in range(np.shape(z)[0]):
for l in range(np.shape(z)[1]):
if z[k][l] < temp_min and x[k][l] > cutoffs[0] and x[k][l] < cutoffs[1] and y[k][l] > cutoffs[2] and y[k][l] < cutoffs[3] :
#if z[i][j] < temp_min:
temp_min = z[k][l]
print(temp_min)
z=z-temp_min
#c = ax.contour(x, y, z,levels=plot_levels,cornor_mask=True)
c = plt.contour(x, y, z,levels=plot_levels,colors='k',linewidths=0.6)
c = plt.contourf(x, y, z,levels=plot_levels)
#c = plt.pcolormesh(x, y, z)
plt.title(str(files[i]))
# set the limits of the plot to the limits of the data
plt.xlim([cutoffs[0], cutoffs[1]])
plt.ylim([cutoffs[2], cutoffs[3]])
plt.format_coord = format_coord
#plt.ylabel(y_label_text)
plt.colorbar(c)
#plt.savefig('fig.pdf')
plt.tight_layout()
plt.show()