1
0
Fork 0
mirror of https://github.com/Findus23/halo_comparison.git synced 2024-09-19 16:03:50 +02:00

improve halo plots

This commit is contained in:
Lukas Winkler 2023-01-10 17:49:14 +01:00
parent db1d66122c
commit aef59e53e9
Signed by: lukas
GPG key ID: 54DE4D798D244853
2 changed files with 46 additions and 46 deletions

View file

@ -43,10 +43,10 @@ def main():
if has_1024_simulations:
resolutions.append(1024)
fig: Figure = plt.figure(
figsize=figsize_from_page_fraction(columns=2, height_to_width=1 if is_box else 1.2)
figsize=figsize_from_page_fraction(columns=2, height_to_width=1.05), layout="constrained"
)
axes: List[List[Axes]] = fig.subplots(
len(waveforms) if is_box else len(waveforms) * 2, 4, sharex="row", sharey="row"
len(waveforms), 4, sharex="row", sharey="row"
)
with h5py.File(vis_datafile) as vis_out:
halo_group = vis_out[str(initial_halo_id)]
@ -57,11 +57,7 @@ def main():
for j, resolution in enumerate(resolutions):
dir = base_dir / f"{waveform}_{resolution}_100"
halos = read_velo_halos(dir)
if is_box:
ax_both = axes[i][j]
else:
ax_both = axes[i * 2][j]
ax_without = axes[i * 2 + 1][j]
ax = axes[i][j]
dataset_group = halo_group[f"{waveform}_{resolution}"]
rho = np.asarray(dataset_group["rho"])
# radius, X, Y, Z
@ -73,7 +69,6 @@ def main():
vmax_scaled = (vmax + offset) * mass
rho = (rho + offset) * mass
extent = coord_to_2d_extent(coords)
for ax in [ax_both, ax_without] if not is_box else [ax_both]:
img = ax.imshow(
rho.T.T,
norm=LogNorm(vmin=vmin_scaled, vmax=vmax_scaled),
@ -84,8 +79,6 @@ def main():
) # ax.set_axis_off()
ax.set_xticks([])
ax.set_yticks([])
if not is_box:
ax.set_ylim(Y - radius * .5, Y + radius * .5)
if j == 0:
scalebar = AnchoredSizeBar(
ax.transData,
@ -102,29 +95,29 @@ def main():
if not is_box:
found_main_halo = False
for halo_id, halo in halos.iterrows():
if halo["Vmax"] > 75:
if halo["Vmax"] > 50:
if in_area(coords, halo.X, halo.Y, halo.Z):
if halo_id == main_halo_id:
color = "C2"
elif halo["Structuretype"] > 10:
color = "C0"
else:
color = "C1"
else:
color = "C0"
if halo_id == main_halo_id:
found_main_halo = True
print("plotting main halo")
circle = Circle(
(halo.Y - Y + X, halo.X - X + Y),
halo["Rvir"],
halo["R_200crit"],
zorder=10,
linewidth=1,
edgecolor=color,
fill=None,
alpha=0.2,
)
ax_both.add_artist(circle)
assert found_main_halo
ax.add_artist(circle)
print(found_main_halo)
# assert found_main_halo
print(img)
# break

View file

@ -92,12 +92,13 @@ def main():
if has_1024_simulations:
resolutions.append(1024)
coords = {}
radius = None
if argv[1] == "box":
initial_halo_id = 0
first_halo = False
radius = 15
for wf in waveforms:
coords[wf] = (15, 85, 85, 85)
coords[wf] = (radius, 85, 85, 85)
else:
initial_halo_id = int(argv[1])
first_halo = True
@ -136,8 +137,14 @@ def main():
halo, halo_particles, meta, image_coords = load_halo_data(
waveform, resolution, halo_id, coords[waveform]
)
if not radius:
radius = image_coords[0]
if not coords[waveform]:
coords[waveform] = image_coords
tmp=list(image_coords)
tmp[0] = radius
coords[waveform] = tuple(tmp)
print(coords[waveform])
# print("mass", halo["Mvir"])
# print("sleep")
@ -163,10 +170,10 @@ def main():
dataset_group.create_dataset("mass", data=meta.particle_mass)
if halo_id:
dataset_group.create_dataset("halo_id", data=halo_id)
imsave(
rho,
f"out_halo{initial_halo_id}_{waveform}_{resolution}_{halo_id}.png",
)
# imsave(
# rho,
# f"out_halo{initial_halo_id}_{waveform}_{resolution}_{halo_id}.png",
# )
halo_group.create_dataset("vmin_vmax", data=[vmin, vmax])