-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotDensity.py
More file actions
205 lines (189 loc) · 7.21 KB
/
plotDensity.py
File metadata and controls
205 lines (189 loc) · 7.21 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import oneDInteraction as od
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
font={'family':'serif','weight':'normal','size':18}
plt.rc('font',**font)
def plotDenistyHistory(xpts, history, skip=1):
colors = sns.cubehelix_palette(len(history))
colors_b = sns.cubehelix_palette(len(history),start=2,rot=0)
for m in range(0,len(history),skip):
plt.plot(xpts,history[m]['phi_a'],color=colors[m])
plt.plot(xpts,history[m]['phi_b'],color=colors_b[m])
plt.xlabel('r/R')
plt.ylabel('VolumeFraction')
plt.tight_layout()
plt.show()
def plotPhiAPhiB(xpts,phi_a,phi_b):
plt.plot(xpts,phi_a,label='a')
plt.plot(xpts,phi_b,label='b')
plt.plot(xpts,phi_a+phi_b,label='total',color='k')
plt.ylabel('Volume Fraction')
plt.xlabel('r/R')
plt.legend()
plt.tight_layout()
plt.show()
def plotProposed(xpts, history, skip=3,minimum=0, maximum=1000):
npts=min(len(history),maximum)-minimum
colors = sns.cubehelix_palette(npts)
colors_b = sns.cubehelix_palette(npts,start=2,rot=0)
for m in range(minimum,min(len(history),maximum),skip):
plt.plot(xpts,history[m]['phi_a'],color=colors[m-minimum])
plt.plot(xpts,history[m]['phi_b'],color=colors_b[m-minimum])
plt.plot(xpts,history[m]['phi_a_proposed'],color='r')
plt.plot(xpts,history[m]['phi_b_porposed'],color='b')
if params_0['spherical']:
plt.xlabel('r')
else:
plt.xlabel('x')
plt.ylabel('Volume Fraction')
plt.tight_layout()
plt.show()
def plot_phase_progression(params_0, delta_params, samples, xpts, setType):
"""Plot to see where phase transition occure
"""
#----------------
# Unpack energies from samples
#----------------
what_changed = list(delta_params.keys())[0]
e_chi_pp = []
e_chi_aa = []
e_bind = []
fail_to_converg = []
xvals = []
plotparams = params_0.copy()
for idx, sample in enumerate(samples):
for key in delta_params:
plotparams[key] = params_0[key]+idx*delta_params[key]
energy = od.energy_terms(sample['phi_a'], sample['phi_b'],
plotparams['chi_pp'], plotparams['chi_aa'],
plotparams['ubind'], plotparams['rbind'],
xpts, plotparams['spherical'], plotparams['reverse_x'],
plotparams['R'])
e_chi_pp.append(energy['e_chi_pp'])
e_chi_aa.append(energy['e_chi_aa'])
e_bind.append(energy['e_bind'])
fail_to_converg.append(sample['failToConverg'])
xvals.append(sample[what_changed])
e_chi_pp = np.array(e_chi_pp)
e_chi_aa = np.array(e_chi_aa)
e_bind = np.array(e_bind)
fail_to_converg = np.array(fail_to_converg)
#-------------
# Make plot
#-------------
for converge in [True, False]:
if converge:
marker = 'o'
linestyle = '-'
choice = fail_to_converg == False
else:
marker = 'x'
linestyle = ' '
choice = fail_to_converg == True
x = xvals
x_vals = []
for ii, val in enumerate(x):
if fail_to_converg[ii] == converge:
x_vals.append(None)
else:
x_vals.append(val)
plt.plot(x_vals, e_chi_pp, marker=marker, linestyle=linestyle,
color='b', label='e_chi_pp')
plt.plot(x_vals, e_chi_aa, marker=marker, linestyle=linestyle,
color='r', label='e_chi_aa')
plt.plot(x_vals, e_bind, marker=marker, linestyle=linestyle,
color='g', label='e_bind')
plt.xlabel(what_changed)
plt.title(setType)
plt.legend()
plt.tight_layout()
def get_value_matrix(params_0, delta_params,
all_data, xpts, to_get='e_bind'):
#----------------
# Unpack energies from all_data
#----------------
to_get_matrix = []
for idy, [samples, params_n] in enumerate(all_data):
plotparams = params_n.copy()
to_get_seq = []
for idx, sample in enumerate(samples):
for key in delta_params:
plotparams[key] = params_0[key]+idx*delta_params[key]
if to_get in ['e_chi_pp','e_chi_aa','e_bind']:
energy = od.energy_terms(sample['phi_a'], sample['phi_b'],
plotparams['chi_pp'], plotparams['chi_aa'],
plotparams['ubind'], plotparams['rbind'],
xpts, plotparams['spherical'], plotparams['reverse_x'],
plotparams['R'])
to_get_seq.append(energy[to_get])
elif to_get in sample.keys():
to_get_seq.append(sample[to_get])
elif to_get in plotparams.keys():
to_get_seq.append(plotparams[to_get])
else:
raise ValueError(str(to_get)+" not found")
to_get_matrix.append(to_get_seq)
return to_get_matrix
def multi_sweep_plot(params0, delta_params, all_data, xpts, xvar,yvar):
xMatrix = get_value_matrix(params0, delta_params, all_data, xpts,
to_get=xvar)
yMatrix = get_value_matrix(params0, delta_params, all_data, xpts,
to_get=yvar)
fMatrix = get_value_matrix(params0, delta_params, all_data, xpts,
to_get='failToConverg')
colors = sns.cubehelix_palette(len(yMatrix))
for converge in [True, False]:
if converge:
marker = 'o'
linestyle = '-'
else:
marker = 'x'
linestyle = ' '
for isweep in range(len(all_data)):
ymasked = []
for ii, value in enumerate(yMatrix[isweep]):
if fMatrix[isweep][ii] == converge:
ymasked.append(value)
else:
ymasked.append(None)
plt.plot(xMatrix[isweep], ymasked, marker=marker,
linestyle=linestyle, color=colors[isweep])
plt.xlabel(xvar)
plt.ylabel(yvar)
plt.tight_layout()
plt.show()
def plot_a_density_samples(samples,xpts):
colors = sns.cubehelix_palette(len(samples))
for i_sample, sample in enumerate(samples):
if sample['failToConverg']:
linestyle=':'
else:
linestyle='-'
plt.plot(xpts, sample['phi_a'], color=colors[i_sample], linestyle=linestyle)
plt.title('phi_a')
if params_0['spherical']:
plt.xlabel('r')
else:
plt.xlabel('x')
#plt.ylim((0,0.1))
plt.ylabel('Volume Fraction')
plt.tight_layout()
plt.show()
def plot_b_density_samples(samples,xpts):
colors_b = sns.cubehelix_palette(len(samples),start=2,rot=0)
for i_sample, sample in enumerate(samples):
if sample['failToConverg']:
linestyle=':'
else:
linestyle='-'
plt.plot(xpts,sample['phi_b'],color=colors_b[i_sample], linestyle=linestyle)
plt.title('phi_b')
if params_0['spherical']:
plt.xlabel('r')
else:
plt.xlabel('x')
#plt.ylim((0,0.1))
plt.ylabel('Volume Fraction')
plt.tight_layout()
plt.show()