-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
197 lines (154 loc) · 6.96 KB
/
main.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
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
from glob import glob
from os.path import basename, splitext
import numpy as np
import pandas as pd
from bokeh.layouts import column, row
from bokeh.models import Select, ColumnDataSource, ColorBar
from bokeh.palettes import Viridis5, Viridis8
from bokeh.plotting import curdoc, figure
from bokeh.transform import linear_cmap
from bokeh.models.widgets import Slider
# constants
num_ch4_a3 = 2.69015E-05 # from methane-comparison.xlsx
# read data and cleanup
def load_data(path):
print("loading new data from %s" % path)
m = pd.read_csv(path)
m.rename(columns={'a' : 'lattice size',
'atom_sites' : 'num atoms',
'bin12' : 'bin: void fraction',
'bin13' : 'bin: methane loading',
'number_density' : "number density",
'total_epsilon' : "total epsilon",
'epsilon_density' : "epsilon density",
'void_fraction' : "void fraction raspa",
'void_fraction_geo' : "void fraction geo",
'absolute_volumetric_loading' : "absolute volumetric loading",
'absolute_volumetric_loading_error' : "absolute volumetric loading error",
'max_pair_distance' : "max pair distance"
}, inplace=True)
m['volume_plotsize'] = (1/3)*m['volume']**(1/2)
m['num atoms_plotsize'] = m["num atoms"] * 4
m['CH4 / uc'] = m["absolute volumetric loading"] * (num_ch4_a3 * m.volume)
m['epsilon density [log]'] = np.log(m["epsilon density"])
m['number density [log]'] = np.log(m["number density"])
del m['b']
del m['c']
m_source = ColumnDataSource(m)
# atoms = pd.read_csv('atoms.csv')
columns = sorted(m.columns)
columns.remove('volume_plotsize')
columns.remove('num atoms_plotsize')
columns.remove('id')
columns.remove('parent_id')
print(m.head())
print(columns)
return m, m_source, columns
colormap_overrides = {
'num atoms': dict(palette=Viridis8),
'max pair distance': dict(palette=Viridis5, low=0, high=0.5)
# 'epsilon_density': dict(palette=Viridis5, low=0, high=0.5)
}
range_defaults = {
"absolute volumetric loading": (0,800),
"void fraction geo": (0,1)
}
def create_figure(m, m_source, columns):
print("creating figure with x = %s, y = %s, color = %s, size = %s" % (x.value, y.value, color.value, size.value))
tooltips = [
("id", "@id"),
(x.value, "@{%s}" % x.value),
(y.value, "@{%s}" % y.value)
]
if color.value != 'None':
tooltips += [(color.value, "@{%s}" % color.value)]
if size.value != 'None':
tooltips += [(size.value, "@{%s}" % size.value)]
x_range = range_defaults[x.value] if x.value in range_defaults else None
y_range = range_defaults[y.value] if y.value in range_defaults else None
p = figure(plot_height=800, plot_width=800, x_range=x_range, y_range=y_range,
tooltips=tooltips, tools=["tap", "hover", "box_select", "reset", "save"],
title=("%s: %s vs %s" % (data.value, y.value, x.value)))
p.xaxis.axis_label = x.value
p.yaxis.axis_label = y.value
sz = 8
print("size.value = '%s'" % size.value)
if size.value != 'None':
if (size.value + "_plotsize") in m:
sz = size.value + "_plotsize"
else:
sz = size.value
print(sz)
mapper = None
c = "#31AADE"
if color.value != 'None':
if color.value in colormap_overrides:
colormap_args = colormap_overrides[color.value]
else:
colormap_args = dict(palette=Viridis5)
if 'low' not in colormap_args:
colormap_args['low'] = m[color.value].min()
if 'high' not in colormap_args:
colormap_args['high'] = m[color.value].max()
print(color.value, colormap_args)
mapper = linear_cmap(field_name=color.value, **colormap_args)
c = mapper
p.circle(x=x.value, y=y.value, color=c, size=sz, line_color=c, alpha=0.4,
hover_color='white', hover_alpha=0.7,
source=m_source)
fs = "1.3em"
if mapper:
color_bar = ColorBar(color_mapper=mapper['transform'], width=8, location=(0,0))
color_bar.major_label_text_font_size = fs
color_bar.major_label_text_align = "left"
p.add_layout(color_bar, 'right')
p.yaxis.axis_label_text_font_size = fs
p.yaxis.major_label_text_font_size = fs
p.xaxis.axis_label_text_font_size = fs
p.xaxis.major_label_text_font_size = fs
p.title.text_font_size = fs
return p
def slider_on_change(attr, old, gen):
m2 = m[m.generation <= gen]
m2_source = ColumnDataSource(m2)
layout.children[1] = create_figure(m2, m2_source, columns)
print('generation updated')
def update_dataset(attr, old, new):
print("loading dataset: ", new)
data.options = data_files[new]
data.value = default_data_file[new]
print("dataset updated")
def update_data(attr, old, new):
global m, m_source, columns
m, m_source, columns = load_data("./data/%s/%s.csv" % (dataset.value, new))
layout.children[1] = create_figure(m, m_source, columns)
print('data and layout updated')
def update(attr, old, new):
layout.children[1] = create_figure(m, m_source, columns)
print('layout updated')
datasets = ["parameter-explorations", "degrees-of-freedom", "density" ]
data_files = {k:sorted([splitext(basename(f))[0] for f in glob("./data/%s/*.csv" % k)]) for k in datasets}
default_data_file = {
"parameter-explorations": "reference baseline",
"degrees-of-freedom": "IME 1site",
"density": "site-density-random"
}
m, m_source, columns = load_data("./data/parameter-explorations/reference baseline.csv")
dataset = Select(title='Dataset', value="parameter-explorations", options=datasets)
dataset.on_change('value', update_dataset)
data = Select(title='Data source', value=default_data_file['parameter-explorations'], options=data_files['parameter-explorations'])
data.on_change('value', update_data)
x = Select(title='X-Axis', value='void fraction geo', options=columns)
x.on_change('value', update)
y = Select(title='Y-Axis', value='absolute volumetric loading', options=columns)
y.on_change('value', update)
size = Select(title='Size', value='lattice size', options=['None'] + columns)
size.on_change('value', update)
color = Select(title='Color', value='num atoms', options=['None'] + columns)
color.on_change('value', update)
slider = Slider(start=0, end=500, value=500, step=50, title="Generation")
slider.on_change('value', slider_on_change)
controls = column(dataset, data, x, y, color, size, slider, width=200)
layout = row(controls, create_figure(m, m_source, columns))
curdoc().add_root(layout)
curdoc().title = "Pseudomaterial Visualizer"