2022-08-23 16:36:48 +02:00
|
|
|
import random
|
2022-08-05 16:13:05 +02:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
import h5py
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
from matplotlib.colors import LogNorm
|
|
|
|
from scipy.interpolate import griddata
|
|
|
|
|
2022-08-23 16:36:48 +02:00
|
|
|
from fix_hdf5_masses import calculate_T
|
2022-08-05 16:13:05 +02:00
|
|
|
from utils import create_figure
|
|
|
|
|
|
|
|
|
2022-08-10 16:26:30 +02:00
|
|
|
def create_2d_slice(
|
2022-08-23 16:36:48 +02:00
|
|
|
input_file: Path, center: List[float], property: str, axis="Z", thickness=3, method="nearest"
|
2022-08-10 16:26:30 +02:00
|
|
|
):
|
2022-08-05 16:13:05 +02:00
|
|
|
axis_names = ["X", "Y", "Z"]
|
|
|
|
cut_axis = axis_names.index(axis)
|
2022-08-23 16:36:48 +02:00
|
|
|
limits = {
|
|
|
|
"X": (46, 52),
|
|
|
|
"Y": (54, 60),
|
|
|
|
"Z": (center[cut_axis] - 10, center[cut_axis] + 10)
|
|
|
|
}
|
2022-08-05 16:13:05 +02:00
|
|
|
with h5py.File(input_file) as f:
|
|
|
|
pt0 = f["PartType0"]
|
2022-08-23 16:36:48 +02:00
|
|
|
coords = pt0["Coordinates"][:]
|
|
|
|
energies = pt0["InternalEnergies"][:]
|
|
|
|
entropies = pt0["Entropies"][:]
|
|
|
|
|
2022-08-05 16:13:05 +02:00
|
|
|
print((center[cut_axis] - thickness < coords[::, cut_axis]).shape)
|
|
|
|
# in_slice = (center[cut_axis] - thickness < coords[::, cut_axis]) & (
|
|
|
|
# coords[::, cut_axis] < center[cut_axis] + thickness)
|
|
|
|
# print("got slice")
|
|
|
|
# coords_in_slice = coords[in_slice]
|
|
|
|
# data_in_slice = data[in_slice]
|
2022-08-23 16:36:48 +02:00
|
|
|
filter = (
|
|
|
|
(limits["X"][0] < coords[::, 0]) &
|
|
|
|
(coords[::, 0] < limits["X"][1]) &
|
|
|
|
|
|
|
|
(limits["Y"][0] < coords[::, 1]) &
|
|
|
|
(coords[::, 1] < limits["Y"][1]) &
|
|
|
|
|
|
|
|
(limits["Z"][0] < coords[::, 2]) &
|
|
|
|
(coords[::, 2] < limits["Z"][1])
|
|
|
|
)
|
|
|
|
print("before", coords.shape)
|
|
|
|
energies = energies[filter]
|
|
|
|
entropies = entropies[filter]
|
|
|
|
coords = coords[filter]
|
|
|
|
|
|
|
|
print("after", coords.shape)
|
|
|
|
print("calculating temperatures")
|
|
|
|
print(np.random.choice(energies,10))
|
|
|
|
temperatures = np.array([calculate_T(u) for u in energies])
|
|
|
|
print(temperatures.min(),temperatures.max(),temperatures.mean())
|
|
|
|
print("done")
|
|
|
|
exit()
|
|
|
|
|
2022-08-10 16:26:30 +02:00
|
|
|
other_axis = {"X": ("Y", "Z"), "Y": ("X", "Z"), "Z": ("X", "Y")}
|
2022-08-05 16:13:05 +02:00
|
|
|
x_axis_label, y_axis_label = other_axis[axis]
|
|
|
|
x_axis = axis_names.index(x_axis_label)
|
|
|
|
y_axis = axis_names.index(y_axis_label)
|
|
|
|
xrange = np.linspace(coords[::, x_axis].min(), coords[::, x_axis].max(), 1000)
|
|
|
|
yrange = np.linspace(coords[::, y_axis].min(), coords[::, y_axis].max(), 1000)
|
|
|
|
gx, gy, gz = np.meshgrid(xrange, yrange, center[cut_axis])
|
|
|
|
print("interpolating")
|
2022-08-23 16:36:48 +02:00
|
|
|
grid = griddata(coords, temperatures, (gx, gy, gz), method=method)[::, ::, 0]
|
2022-08-05 16:13:05 +02:00
|
|
|
print(grid.shape)
|
|
|
|
# stats, x_edge, y_edge, _ = binned_statistic_2d(
|
|
|
|
# coords_in_slice[::, x_axis],
|
|
|
|
# coords_in_slice[::, y_axis],
|
|
|
|
# data_in_slice,
|
|
|
|
# bins=500,
|
|
|
|
# statistic="mean"
|
|
|
|
# )
|
|
|
|
fig, ax = create_figure()
|
|
|
|
# stats = np.nan_to_num(stats)
|
|
|
|
print("plotting")
|
|
|
|
img = ax.imshow(
|
2022-08-23 16:36:48 +02:00
|
|
|
grid,
|
2022-08-05 16:13:05 +02:00
|
|
|
norm=LogNorm(),
|
2022-08-10 16:26:30 +02:00
|
|
|
interpolation="nearest",
|
2022-08-23 16:36:48 +02:00
|
|
|
origin="lower",
|
2022-08-10 16:26:30 +02:00
|
|
|
extent=[xrange[0], xrange[-1], yrange[0], yrange[-1]],
|
2022-08-05 16:13:05 +02:00
|
|
|
)
|
|
|
|
ax.set_title(input_file.parent.stem)
|
|
|
|
ax.set_xlabel(x_axis_label)
|
|
|
|
ax.set_ylabel(y_axis_label)
|
2022-08-23 16:36:48 +02:00
|
|
|
ax.set_aspect("equal")
|
|
|
|
fig.colorbar(img, label="Temperatures")
|
2022-08-05 16:13:05 +02:00
|
|
|
fig.tight_layout()
|
2022-08-23 16:36:48 +02:00
|
|
|
fig.savefig(Path("~/tmp/slice.png").expanduser(), dpi=300)
|
2022-08-05 16:13:05 +02:00
|
|
|
plt.show()
|
|
|
|
exit()
|