2022-05-31 17:22:57 +02:00
|
|
|
from typing import Tuple
|
|
|
|
|
2022-05-25 17:17:24 +02:00
|
|
|
import h5py
|
2022-05-24 17:06:49 +02:00
|
|
|
import numpy as np
|
|
|
|
import pandas as pd
|
|
|
|
from matplotlib import pyplot as plt
|
|
|
|
|
2022-05-25 17:17:24 +02:00
|
|
|
from cic import cic_from_radius
|
2022-06-01 11:31:42 +02:00
|
|
|
from paths import base_dir, vis_datafile
|
|
|
|
from read_vr_files import read_velo_halo_particles
|
2022-05-24 17:06:49 +02:00
|
|
|
from readfiles import read_file
|
|
|
|
|
2022-05-30 19:12:59 +02:00
|
|
|
all_in_area = True
|
2022-05-24 17:06:49 +02:00
|
|
|
|
2022-05-31 17:22:57 +02:00
|
|
|
Coords = Tuple[float, float, float, float] # radius, X, Y, Z
|
|
|
|
|
2022-05-24 17:06:49 +02:00
|
|
|
|
2022-05-31 17:22:57 +02:00
|
|
|
def load_halo_data(waveform: str, resolution: int, halo_id: int, coords: Coords):
|
2022-05-24 17:06:49 +02:00
|
|
|
dir = base_dir / f"{waveform}_{resolution}_100"
|
2022-07-05 15:40:17 +02:00
|
|
|
df, meta = read_file(dir / "output_0004.hdf5")
|
2022-06-10 11:06:32 +02:00
|
|
|
df_halo, halo_lookup, unbound = read_velo_halo_particles(dir, recursivly=False)
|
2022-05-24 17:06:49 +02:00
|
|
|
|
|
|
|
halo = df_halo.loc[halo_id]
|
2022-07-05 15:40:17 +02:00
|
|
|
if coords:
|
|
|
|
radius, X, Y, Z = coords
|
|
|
|
else:
|
|
|
|
radius = halo["R_size"]
|
|
|
|
X = halo["Xc"]
|
|
|
|
Y = halo["Yc"]
|
|
|
|
Z = halo["Zc"]
|
|
|
|
coords: Coords = radius, X, Y, Z
|
2022-05-30 19:12:59 +02:00
|
|
|
if all_in_area:
|
|
|
|
df = df[df["X"].between(X - radius, X + radius)]
|
|
|
|
df = df[df["Y"].between(Y - radius, Y + radius)]
|
|
|
|
halo_particles = df[df["Z"].between(Z - radius, Z + radius)]
|
|
|
|
else:
|
|
|
|
halo_particle_ids = halo_lookup[halo_id]
|
|
|
|
del halo_lookup
|
|
|
|
del unbound
|
|
|
|
halo_particles = df.loc[list(halo_particle_ids)]
|
2022-05-31 17:22:57 +02:00
|
|
|
return halo, halo_particles, meta, coords
|
2022-05-24 17:06:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_comp_id(ref_waveform: str, reference_resolution: int, comp_waveform: str, comp_resolution: int):
|
|
|
|
return f"{ref_waveform}_{reference_resolution}_100_{comp_waveform}_{comp_resolution}_100_velo.csv"
|
|
|
|
|
|
|
|
|
|
|
|
def map_halo_id(halo_id: int, ref_waveform: str, reference_resolution: int, comp_waveform: str, comp_resolution: int):
|
|
|
|
file = base_dir / "comparisons" / get_comp_id(ref_waveform, reference_resolution, comp_waveform, comp_resolution)
|
|
|
|
print("opening", file)
|
|
|
|
df = pd.read_csv(file)
|
|
|
|
mapping = {}
|
|
|
|
for index, line in df.iterrows():
|
|
|
|
mapping[int(line["ref_ID"])] = int(line["comp_ID"])
|
|
|
|
return mapping[halo_id]
|
|
|
|
|
|
|
|
|
2022-05-25 17:17:24 +02:00
|
|
|
def imsave(rho, file_name: str):
|
2022-05-24 17:06:49 +02:00
|
|
|
# ax.scatter(Xs, Ys)
|
|
|
|
# plt.show()
|
|
|
|
cmap = plt.cm.viridis
|
|
|
|
data = np.log(1.001 + rho)
|
|
|
|
norm = plt.Normalize(vmin=data.min(), vmax=data.max())
|
|
|
|
image = cmap(norm(data))
|
|
|
|
print(file_name)
|
|
|
|
plt.imsave(file_name, image)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-07-05 15:40:17 +02:00
|
|
|
waveforms = ["shannon", "DB2", "DB4", "DB8"]
|
|
|
|
initial_halo_id = 1
|
2022-05-24 17:06:49 +02:00
|
|
|
first_halo = True
|
|
|
|
rhos = {}
|
|
|
|
ref_waveform = "shannon"
|
|
|
|
ref_resolution = 128
|
2022-07-05 15:40:17 +02:00
|
|
|
coords = {}
|
|
|
|
for wf in waveforms:
|
|
|
|
coords[wf] = None
|
2022-05-25 17:17:24 +02:00
|
|
|
vmin = np.Inf
|
|
|
|
vmax = -np.Inf
|
2022-06-01 11:31:42 +02:00
|
|
|
if vis_datafile.exists():
|
|
|
|
input("confirm to overwrite file")
|
|
|
|
with h5py.File(vis_datafile, "w") as vis_out:
|
2022-07-05 15:40:17 +02:00
|
|
|
for waveform in waveforms:
|
2022-05-25 17:17:24 +02:00
|
|
|
for resolution in [128, 256, 512]:
|
|
|
|
if first_halo:
|
|
|
|
assert ref_resolution == resolution
|
|
|
|
assert ref_waveform == waveform
|
|
|
|
halo_id = initial_halo_id
|
|
|
|
first_halo = False
|
|
|
|
else:
|
|
|
|
halo_id = map_halo_id(initial_halo_id, ref_waveform, ref_resolution, waveform, resolution)
|
2022-07-05 15:40:17 +02:00
|
|
|
halo, halo_particles, meta, image_coords = load_halo_data(waveform, resolution, halo_id, coords[waveform])
|
|
|
|
if not coords[waveform]:
|
|
|
|
coords[waveform] = image_coords
|
|
|
|
print(coords[waveform])
|
2022-05-30 19:12:59 +02:00
|
|
|
print("mass", halo["Mvir"])
|
|
|
|
# print("sleep")
|
|
|
|
# sleep(100)
|
2022-07-05 15:40:17 +02:00
|
|
|
radius, X, Y, Z = coords[waveform]
|
|
|
|
rho, _ = cic_from_radius(
|
2022-05-25 17:17:24 +02:00
|
|
|
halo_particles.X.to_numpy(), halo_particles.Y.to_numpy(),
|
2022-05-31 17:22:57 +02:00
|
|
|
1000, X, Y, radius, periodic=False)
|
2022-05-25 17:17:24 +02:00
|
|
|
rhos[(waveform, resolution)] = rho
|
|
|
|
vmin = min(rho.min(), vmin)
|
|
|
|
vmax = max(rho.max(), vmax)
|
|
|
|
vis_out.create_dataset(f"{waveform}_{resolution}_rho", data=rho, compression='gzip', compression_opts=5)
|
2022-07-05 15:40:17 +02:00
|
|
|
vis_out.create_dataset(f"{waveform}_{resolution}_coords", data=coords[waveform])
|
2022-05-25 17:17:24 +02:00
|
|
|
vis_out.create_dataset(f"{waveform}_{resolution}_mass", data=meta.particle_mass)
|
2022-06-01 11:31:42 +02:00
|
|
|
vis_out.create_dataset(f"{waveform}_{resolution}_halo_id", data=halo_id)
|
2022-05-25 17:17:24 +02:00
|
|
|
imsave(rho, f"out_halo{initial_halo_id}_{waveform}_{resolution}_{halo_id}.png")
|
|
|
|
vis_out.create_dataset("vmin_vmax", data=[vmin, vmax])
|
2022-05-24 17:06:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|