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

minor cleanup

This commit is contained in:
Lukas Winkler 2022-06-24 16:55:16 +02:00
parent 3222ed19bb
commit 114463853e
Signed by: lukas
GPG key ID: 54DE4D798D244853
2 changed files with 25 additions and 15 deletions

View file

@ -3,7 +3,7 @@ from dataclasses import dataclass
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from pprint import pprint from pprint import pprint
from typing import List from typing import List, Tuple
import h5py import h5py
import numpy as np import numpy as np
@ -15,7 +15,7 @@ from matplotlib.figure import Figure
from cic import cic_from_radius from cic import cic_from_radius
from halo_mass_profile import halo_mass_profile from halo_mass_profile import halo_mass_profile
from nfw import fit_nfw, nfw from nfw import fit_nfw
from paths import auriga_dir, richings_dir from paths import auriga_dir, richings_dir
from readfiles import read_file, read_halo_file, ParticlesMeta from readfiles import read_file, read_halo_file, ParticlesMeta
from utils import read_swift_config from utils import read_swift_config
@ -59,14 +59,17 @@ centers = {}
class Result: class Result:
title: str title: str
rho: np.ndarray rho: np.ndarray
levels: Tuple[int, int, int]
images = [] images = []
vmin = np.Inf vmin = np.Inf
vmax = -np.Inf vmax = -np.Inf
root_dir = auriga_dir if mode == Mode.auriga6 else richings_dir root_dir = auriga_dir if mode == Mode.auriga6 else richings_dir
dirs = [d for d in root_dir.glob("*") if d.is_dir() and "bak" not in d.name] i = 0
for i, dir in enumerate(sorted(dirs)): for dir in sorted(root_dir.glob("*")):
if not dir.is_dir() or "bak" in dir.name:
continue
is_by_adrian = "arj" in dir.name is_by_adrian = "arj" in dir.name
print(dir.name) print(dir.name)
@ -83,7 +86,10 @@ for i, dir in enumerate(sorted(dirs)):
input_file = dir / "output_0000.hdf5" input_file = dir / "output_0000.hdf5"
softening_length = None softening_length = None
else: else:
swift_conf = read_swift_config(dir) try:
swift_conf = read_swift_config(dir)
except FileNotFoundError:
continue
softening_length = swift_conf["Gravity"]["comoving_DM_softening"] softening_length = swift_conf["Gravity"]["comoving_DM_softening"]
assert softening_length == swift_conf["Gravity"]["max_physical_DM_softening"] assert softening_length == swift_conf["Gravity"]["max_physical_DM_softening"]
ideal_softening_length = levelmax_to_softening_length(levelmax) ideal_softening_length = levelmax_to_softening_length(levelmax)
@ -123,11 +129,12 @@ for i, dir in enumerate(sorted(dirs)):
i_max_border = np.argmax(1.5 < log_radial_bins) i_max_border = np.argmax(1.5 < log_radial_bins)
popt = fit_nfw(log_radial_bins[i_min_border:i_max_border], bin_densities[i_min_border:i_max_border]) # = rho_0, r_s popt = fit_nfw(log_radial_bins[i_min_border:i_max_border], bin_densities[i_min_border:i_max_border]) # = rho_0, r_s
print(popt) print(popt)
ax.loglog( # # Plot NFW profile
log_radial_bins[i_min_border:i_max_border], # ax.loglog(
nfw(log_radial_bins[i_min_border:i_max_border], *popt), # log_radial_bins[i_min_border:i_max_border],
linestyle="dotted" # nfw(log_radial_bins[i_min_border:i_max_border], *popt),
) # linestyle="dotted"
# )
centers[dir.name] = center centers[dir.name] = center
if is_by_adrian: if is_by_adrian:
with reference_file.open("wb") as f: with reference_file.open("wb") as f:
@ -168,16 +175,17 @@ for i, dir in enumerate(sorted(dirs)):
Y -= center[1] Y -= center[1]
Z -= center[2] Z -= center[2]
rho, extent = cic_from_radius(X, Z, 5000, 0, 0, 5, periodic=False) rho, extent = cic_from_radius(X, Z, 1000, 0, 0, 5, periodic=False)
vmin = min(vmin, rho.min()) vmin = min(vmin, rho.min())
vmax = max(vmax, rho.max()) vmax = max(vmax, rho.max())
images.append(Result( images.append(Result(
rho=rho, rho=rho,
title=str(dir.name) title=str(dir.name),
levels=(levelmin, levelmin_TF, levelmax) if levelmin else None
)) ))
i += 1
# plot_cic( # plot_cic(
# rho, extent, # rho, extent,
# title=str(dir.name) # title=str(dir.name)
@ -187,8 +195,8 @@ ax2.legend()
# fig3: Figure = plt.figure(figsize=(9, 9)) # fig3: Figure = plt.figure(figsize=(9, 9))
# axes: List[Axes] = fig3.subplots(3, 3, sharex=True, sharey=True).flatten() # axes: List[Axes] = fig3.subplots(3, 3, sharex=True, sharey=True).flatten()
fig3: Figure = plt.figure(figsize=(6, 9)) fig3: Figure = plt.figure(figsize=(9, 9))
axes: List[Axes] = fig3.subplots(3, 2, sharex=True, sharey=True).flatten() axes: List[Axes] = fig3.subplots(3, 3, sharex=True, sharey=True).flatten()
for result, ax in zip(images, axes): for result, ax in zip(images, axes):
data = 1.1 + result.rho data = 1.1 + result.rho

View file

@ -3,3 +3,5 @@ from pathlib import Path
base_dir = Path("/path/to/monofonic_tests/") base_dir = Path("/path/to/monofonic_tests/")
vis_datafile = Path("vis.cache.hdf5") vis_datafile = Path("vis.cache.hdf5")
auriga_dir = Path("/path/to/auriga6/") auriga_dir = Path("/path/to/auriga6/")
richings_dir = Path("path/to/richings21_ics/").expanduser()
spectra_dir = Path("/path/to/git/spectra/build/")