1
0
Fork 0
mirror of https://github.com/Findus23/collision-analyisis-and-interpolation.git synced 2024-09-19 15:13:50 +02:00
collision-analyisis-and-int.../visualize.py

84 lines
2.9 KiB
Python
Raw Permalink Normal View History

2021-03-08 13:25:11 +01:00
from copy import copy
from pathlib import Path
2019-02-13 15:27:48 +01:00
import numpy as np
2019-08-20 16:17:19 +02:00
from matplotlib import pyplot as plt, cm
2019-02-13 15:27:48 +01:00
2019-05-02 14:12:06 +02:00
from CustomScaler import CustomScaler
2019-08-21 12:54:27 +02:00
from config import water_fraction
2021-10-12 15:45:43 +02:00
from interpolators.griddata import GriddataInterpolator
2019-08-21 12:54:27 +02:00
from interpolators.rbf import RbfInterpolator
2021-10-12 15:45:43 +02:00
from simulation import Simulation
2019-02-13 15:27:48 +01:00
from simulation_list import SimulationList
2021-10-12 15:45:43 +02:00
plt.style.use('dark_background')
2020-11-30 12:02:22 +01:00
2019-05-02 15:30:17 +02:00
def main():
2021-10-12 15:45:43 +02:00
mcode, gamma, wt, wp = [10 ** 22, 0.6, 1e-5, 1e-5]
2021-03-08 13:25:11 +01:00
simlist = SimulationList.jsonlines_load(Path("rsmc_dataset.jsonl"))
2019-07-06 15:50:16 +02:00
# for s in simlist.simlist:
# if s.type!="original":
# continue
# print(s.wpcode,s.projectile_water_fraction)
# exit()
2019-05-02 15:30:17 +02:00
data = simlist.X
2019-07-06 15:50:16 +02:00
print("-----")
print(len(data))
# print(data[0])
# exit()
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)
2020-11-30 12:02:22 +01:00
interpolator = RbfInterpolator(scaled_data, values)
# interpolator = GriddataInterpolator(scaled_data, values)
2019-05-02 15:30:17 +02:00
2021-10-12 15:45:43 +02:00
alpharange = np.linspace(0, 60, 300)
2019-08-06 14:42:15 +02:00
vrange = np.linspace(0.5, 5.5, 300)
2019-05-02 15:30:17 +02:00
grid_alpha, grid_v = np.meshgrid(alpharange, vrange)
parameters = [grid_alpha, grid_v, mcode, gamma, wt, wp]
scaled_parameters = list(scaler.transform_parameters(parameters))
grid_result = interpolator.interpolate(*scaled_parameters)
2019-08-20 16:17:19 +02:00
print("minmax")
print(np.nanmin(grid_result), np.nanmax(grid_result))
2019-05-02 15:30:17 +02:00
2021-03-08 13:25:11 +01:00
plt.title("m={:3.0e}, gamma={:3.1f}, wt={:2.0e}, wp={:2.0e}\n".format(mcode, gamma, wt, wp))
cmap = cm.get_cmap("Blues") if water_fraction else cm.get_cmap("Oranges")
cmap = copy(cmap)
2019-08-20 16:17:19 +02:00
cmap.set_bad('white', 1.) # show nan white
2019-08-06 14:42:15 +02:00
# plt.contourf(grid_alpha, grid_v, grid_result, 100, cmap="Blues", vmin=0, vmax=1)
2019-08-20 16:17:19 +02:00
# plt.pcolormesh(grid_alpha, grid_v, grid_result, cmap="Blues", vmin=0, vmax=1)
plt.imshow(grid_result, interpolation='none', cmap=cmap, aspect="auto", origin="lower", vmin=0, vmax=1,
extent=[grid_alpha.min(), grid_alpha.max(), grid_v.min(), grid_v.max()])
2019-05-02 15:30:17 +02:00
# plt.scatter(data[:, 0], data[:, 1], c=values, cmap="Blues")
2019-08-20 16:17:19 +02:00
plt.xlabel("impact angle $\\alpha$ [$^{\circ}$]")
plt.ylabel("velocity $v$ [$v_{esc}$]")
2021-10-12 15:45:43 +02:00
s: Simulation
xs = []
ys = []
zs = []
for s in simlist.simlist:
# if not (0.4 < s.gamma < 0.6) or not (1e23 < s.total_mass < 5e24):
# continue
# if s.alpha < 60 or s.v > 5 or s.v < 2:
# continue
z = s.output_mass_fraction
zs.append(z)
xs.append(s.alpha)
ys.append(s.v)
print(z, s.runid)
plt.scatter(xs, ys, c=zs, cmap=cmap, vmin=0, vmax=1)
plt.colorbar().set_label("stone retention fraction" if water_fraction else "core mass retention fraction")
2019-05-02 15:30:17 +02:00
plt.tight_layout()
# plt.savefig("vis.png", transparent=True)
2021-10-12 15:45:43 +02:00
plt.savefig("/home/lukas/tmp/test.pdf", transparent=True)
2019-05-02 15:30:17 +02:00
plt.show()
if __name__ == '__main__':
main()