2021-03-08 13:25:11 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
2019-03-04 19:23:10 +01:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
from matplotlib.collections import QuadMesh
|
2019-05-02 15:30:17 +02:00
|
|
|
from matplotlib.widgets import Slider, Button
|
2019-03-04 19:23:10 +01:00
|
|
|
|
2019-05-02 15:30:17 +02:00
|
|
|
from CustomScaler import CustomScaler
|
2019-08-20 14:27:08 +02:00
|
|
|
from interpolators.rbf import RbfInterpolator
|
2019-03-04 19:23:10 +01:00
|
|
|
from simulation_list import SimulationList
|
|
|
|
|
2021-03-08 13:25:11 +01:00
|
|
|
simlist = SimulationList.jsonlines_load(Path("rsmc_dataset.jsonl"))
|
2021-10-12 15:45:43 +02:00
|
|
|
resolution = 100
|
2019-05-02 15:30:17 +02:00
|
|
|
|
|
|
|
data = simlist.X
|
2021-10-12 15:45:43 +02:00
|
|
|
values = simlist.Y_mass_fraction
|
2019-05-02 15:30:17 +02:00
|
|
|
|
|
|
|
scaler = CustomScaler()
|
|
|
|
scaler.fit(data)
|
|
|
|
scaled_data = scaler.transform_data(data)
|
2019-08-20 14:27:08 +02:00
|
|
|
interpolator = RbfInterpolator(scaled_data, values)
|
2019-05-02 15:30:17 +02:00
|
|
|
|
2021-10-12 15:45:43 +02:00
|
|
|
alpharange = np.linspace(-0.5, 60.5, resolution)
|
|
|
|
vrange = np.linspace(0.5, 5.5, resolution)
|
2019-05-02 15:30:17 +02:00
|
|
|
grid_alpha, grid_v = np.meshgrid(alpharange, vrange)
|
|
|
|
|
2019-03-04 19:23:10 +01:00
|
|
|
fig, ax = plt.subplots()
|
|
|
|
plt.subplots_adjust(bottom=0.35)
|
|
|
|
t = np.arange(0.0, 1.0, 0.001)
|
2019-07-06 15:50:16 +02:00
|
|
|
mcode_default, gamma_default, wt_default, wp_default = [24.0, 1, 15.0, 15.0]
|
2019-03-04 19:23:10 +01:00
|
|
|
|
2019-05-02 15:30:17 +02:00
|
|
|
datagrid = np.zeros_like(grid_alpha)
|
2019-03-04 19:23:10 +01:00
|
|
|
|
2021-10-12 15:45:43 +02:00
|
|
|
mesh = plt.pcolormesh(grid_alpha, grid_v, datagrid, cmap="Blues", vmin=0, vmax=1, shading="nearest") # type:QuadMesh
|
2019-04-18 10:50:57 +02:00
|
|
|
plt.colorbar()
|
2019-03-04 19:23:10 +01:00
|
|
|
|
2021-03-08 13:25:11 +01:00
|
|
|
# axcolor = 'lightgoldenrodyellow'
|
|
|
|
ax_mcode = plt.axes([0.25, 0.1, 0.65, 0.03])
|
|
|
|
ax_gamma = plt.axes([0.25, 0.15, 0.65, 0.03])
|
|
|
|
ax_wt = plt.axes([0.25, 0.20, 0.65, 0.03])
|
|
|
|
ax_wp = plt.axes([0.25, 0.25, 0.65, 0.03])
|
2019-05-02 15:30:17 +02:00
|
|
|
buttonax = plt.axes([0.8, 0.025, 0.1, 0.04])
|
2021-03-08 13:25:11 +01:00
|
|
|
button = Button(buttonax, 'Update', hovercolor='0.975')
|
2019-05-02 15:30:17 +02:00
|
|
|
# thetext = ax.text(-10, 0, "hello", fontsize=12) #type:Text
|
2019-03-04 19:23:10 +01:00
|
|
|
|
2019-04-18 11:54:15 +02:00
|
|
|
s_mcode = Slider(ax_mcode, 'mcode', 21, 25, valinit=mcode_default)
|
|
|
|
s_gamma = Slider(ax_gamma, 'gamma', 0.1, 1, valinit=gamma_default)
|
2021-10-12 15:45:43 +02:00
|
|
|
s_wt = Slider(ax_wt, 'wt', 1e-5, 1e-3, valinit=wt_default)
|
|
|
|
s_wp = Slider(ax_wp, 'wp', 1e-5, 1e-3, valinit=wp_default)
|
2019-03-04 19:23:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
def update(val):
|
2019-04-18 11:54:15 +02:00
|
|
|
print("start updating")
|
2019-05-02 15:30:17 +02:00
|
|
|
# thetext.set_text("updating")
|
|
|
|
# fig.canvas.draw()
|
|
|
|
|
2019-03-04 19:23:10 +01:00
|
|
|
mcode = s_mcode.val
|
|
|
|
gamma = s_gamma.val
|
|
|
|
wt = s_wt.val
|
|
|
|
wp = s_wp.val
|
2021-10-12 15:45:43 +02:00
|
|
|
parameters = [grid_alpha, grid_v, 10 ** mcode, gamma, wt, wp]
|
2019-05-02 15:30:17 +02:00
|
|
|
scaled_parameters = list(scaler.transform_parameters(parameters))
|
|
|
|
|
|
|
|
datagrid = interpolator.interpolate(*scaled_parameters)
|
|
|
|
print(datagrid)
|
2021-10-12 15:45:43 +02:00
|
|
|
print(np.isnan(datagrid).sum() / (resolution * resolution))
|
2019-03-04 19:23:10 +01:00
|
|
|
if not isinstance(datagrid, np.ndarray):
|
|
|
|
return False
|
|
|
|
|
2021-10-12 15:45:43 +02:00
|
|
|
mesh.set_array(datagrid.ravel())
|
2019-04-18 11:54:15 +02:00
|
|
|
print("finished updating")
|
2019-05-02 15:30:17 +02:00
|
|
|
# thetext.set_text("finished")
|
|
|
|
|
2019-03-04 19:23:10 +01:00
|
|
|
fig.canvas.draw_idle()
|
|
|
|
|
|
|
|
|
2021-10-12 15:45:43 +02:00
|
|
|
update(None)
|
|
|
|
|
2019-05-02 15:30:17 +02:00
|
|
|
# s_gamma.on_changed(update)
|
|
|
|
# s_mcode.on_changed(update)
|
|
|
|
# s_wp.on_changed(update)
|
|
|
|
# s_wt.on_changed(update)
|
|
|
|
button.on_clicked(update)
|
2019-03-04 19:23:10 +01:00
|
|
|
|
|
|
|
plt.show()
|