mirror of
https://github.com/cosmo-sims/cosmICweb-music.git
synced 2024-09-19 16:53:43 +02:00
230 lines
6.5 KiB
Python
230 lines
6.5 KiB
Python
import re
|
|
from pathlib import Path
|
|
|
|
from _pytest.monkeypatch import MonkeyPatch
|
|
from click.testing import CliRunner
|
|
|
|
from cosmicweb_music.cosmICweb import cli
|
|
|
|
reference_output = """
|
|
# Zoom Initial Conditions for halo 25401888 (halo_25401888) in simulation AGORA (AGORA Project project)
|
|
# Details on this halo can be found on https://cosmicweb.eu/simulation/AGORA/halo/25401888
|
|
# This file has been generated by CosmICweb @2024-04-23T12:56:20.876162
|
|
|
|
|
|
[setup]
|
|
boxlength = 60
|
|
zstart = 100
|
|
levelmin = 7
|
|
levelmin_TF = 7
|
|
levelmax = 11
|
|
padding = 16 # try reduce it at your own risk
|
|
overlap = 4
|
|
align_top = no
|
|
baryons = no # switch on for baryon runs
|
|
use_2LPT = no
|
|
use_LLA = no # AMR codes might want to enable this
|
|
|
|
# Ellipsoidal refinement region defined on unity cube
|
|
# This minimum bounding ellipsoid has been obtained from
|
|
# particles within 4.0 Rvir of the halo center
|
|
region = ellipsoid
|
|
region_ellipsoid_matrix[0] = 73.2097934892, 0.7223112927, 6.51459018132
|
|
region_ellipsoid_matrix[1] = 0.7223112927, 41.7248191188, -11.54268986796
|
|
region_ellipsoid_matrix[2] = 6.51459018132, -11.54268986796, 82.69775988479999
|
|
region_ellipsoid_center = 0.03202272286, 0.7263335608333333, 0.5582005855333333
|
|
|
|
|
|
[cosmology]
|
|
Omega_m = 0.272
|
|
Omega_L = 0.728
|
|
Omega_b = 0.0455
|
|
H0 = 70.2
|
|
sigma_8 = 0.807
|
|
nspec = 0.961
|
|
transfer = eisenstein
|
|
#below are MUSIC defaults to initialize gas temperature for some codes
|
|
#YHe = 0.248 # primordial He abundance
|
|
#gamma = 1.6667 # adiabatic exponent (=5/3)
|
|
|
|
[random]
|
|
cubesize = 256
|
|
seed[8] = 95064
|
|
seed[9] = 31415
|
|
seed[10] = 27183
|
|
# do not add higher seeds!
|
|
|
|
[poisson]
|
|
fft_fine = yes
|
|
accuracy = 1e-6
|
|
grad_order = 6
|
|
laplace_order = 6
|
|
|
|
[output]
|
|
format = grafic2
|
|
filename = ics.dat
|
|
ramses_nml = yes
|
|
ramses_old_nml = no
|
|
ramses_pvar_idx = 43
|
|
|
|
""".lstrip()
|
|
|
|
reference_output_publication = """
|
|
# Zoom Initial Conditions for halo 25505622 (1e11v) in simulation AGORA (AGORA Project project)
|
|
# Details on this halo can be found on https://cosmicweb.eu/simulation/AGORA/halo/25505622
|
|
# This file has been generated by CosmICweb @2024-04-21T00:03:24.827918
|
|
|
|
|
|
[setup]
|
|
boxlength = 60
|
|
zstart = 100
|
|
levelmin = 9
|
|
levelmin_TF = 9
|
|
levelmax = 9
|
|
padding = 16 # try reduce it at your own risk
|
|
overlap = 4
|
|
align_top = no
|
|
baryons = no # switch on for baryon runs
|
|
use_2LPT = no
|
|
use_LLA = no # AMR codes might want to enable this
|
|
|
|
# Ellipsoidal refinement region defined on unity cube
|
|
# This minimum bounding ellipsoid has been obtained from
|
|
# particles within 2.0 Rvir of the halo center
|
|
region = ellipsoid
|
|
region_ellipsoid_matrix[0] = 1202.685817644, -224.73030332520003, 78.4954201104
|
|
region_ellipsoid_matrix[1] = -224.73030332520003, 1126.675415484, -514.163771388
|
|
region_ellipsoid_matrix[2] = 78.4954201104, -514.163771388, 859.827522564
|
|
region_ellipsoid_center = 0.6253459789833333, 0.47749109738333334, 0.6903304682000001
|
|
|
|
|
|
[cosmology]
|
|
Omega_m = 0.272
|
|
Omega_L = 0.728
|
|
Omega_b = 0.0455
|
|
H0 = 70.2
|
|
sigma_8 = 0.807
|
|
nspec = 0.961
|
|
transfer = eisenstein
|
|
#below are MUSIC defaults to initialize gas temperature for some codes
|
|
#YHe = 0.248 # primordial He abundance
|
|
#gamma = 1.6667 # adiabatic exponent (=5/3)
|
|
|
|
[random]
|
|
cubesize = 256
|
|
seed[8] = 95064
|
|
seed[9] = 31415
|
|
seed[10] = 27183
|
|
# do not add higher seeds!
|
|
|
|
[poisson]
|
|
fft_fine = yes
|
|
accuracy = 1e-6
|
|
grad_order = 6
|
|
laplace_order = 6
|
|
|
|
[output]
|
|
# TODO: add output options
|
|
""".lstrip()
|
|
|
|
reference_output_collection = """
|
|
# Zoom Initial Conditions for halo 20770177 (20770177) in simulation RefL0100N1504 (EAGLE Simulations project)
|
|
# Details on this halo can be found on https://cosmicweb.eu/simulation/RefL0100N1504/halo/20770177
|
|
# This file has been generated by CosmICweb @2024-04-27T19:00:39.574652
|
|
|
|
|
|
[setup]
|
|
boxlength = 67.77
|
|
zstart = 127
|
|
levelmin = 7
|
|
levelmin_TF = 9
|
|
levelmax = 11
|
|
baryons = no
|
|
use_2LPT = no
|
|
use_LLA = no
|
|
padding = 8
|
|
|
|
# Ellipsoidal refinement region defined on unity cube
|
|
# This minimum bounding ellipsoid has been obtained from
|
|
# particles within 2.0 R200c of the halo center
|
|
region = ellipsoid
|
|
region_ellipsoid_matrix[0] = 180.08392, 30.495844, 5.7450113
|
|
region_ellipsoid_matrix[1] = 30.495844, 247.56755, 45.540962
|
|
region_ellipsoid_matrix[2] = 5.7450113, 45.540962, 377.32254
|
|
region_ellipsoid_center = 0.92963797, 0.3582335, 0.9368965
|
|
|
|
|
|
[cosmology]
|
|
Omega_m = 0.307
|
|
Omega_L = 0.693
|
|
Omega_b = 0.04825
|
|
H0 = 67.77
|
|
sigma_8 = 0.8288
|
|
nspec = 0.9611
|
|
ZeroRadiation = true
|
|
transfer = camb_file
|
|
transfer_file = Eagle_camb_file.txt
|
|
|
|
[random]
|
|
generator = PANPHASIA
|
|
descriptor =[Panph1,L16,(31250,23438,39063),S12,CH1050187043,EAGLE_L0100_VOL1]
|
|
|
|
[poisson]
|
|
fft_fine = yes
|
|
accuracy = 1e-6
|
|
grad_order = 6
|
|
laplace_order = 6
|
|
|
|
[output]
|
|
# TODO: add output options
|
|
""".lstrip()
|
|
|
|
time_fix_regex = re.compile(r"@[\d\-T:.]+")
|
|
|
|
|
|
def test_single_saved(tmp_path: Path, monkeypatch: MonkeyPatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
id = "50e20c16-45b8-4d0f-b6cd-44e050b76afb"
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["get", id])
|
|
assert result.exit_code == 0
|
|
subdir = tmp_path / "cosmICweb-zooms-AGORA"
|
|
assert subdir.exists()
|
|
assert len(list(subdir.glob("*"))) == 1
|
|
output_file = subdir / "ics_halo_25401888.cfg"
|
|
assert output_file.exists()
|
|
assert time_fix_regex.sub("TIME", output_file.read_text()) == time_fix_regex.sub(
|
|
"TIME", reference_output
|
|
)
|
|
|
|
|
|
def test_publication(tmp_path: Path, monkeypatch: MonkeyPatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
id = "agora-halos"
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["publication", id])
|
|
assert result.exit_code == 0
|
|
subdir = tmp_path / "agora-halos"
|
|
assert subdir.exists()
|
|
assert len(list(subdir.glob("*"))) == 6
|
|
output_file = subdir / "ics_1e11v.cfg"
|
|
assert output_file.exists()
|
|
assert time_fix_regex.sub("TIME", output_file.read_text()) == time_fix_regex.sub(
|
|
"TIME", reference_output_publication
|
|
)
|
|
|
|
|
|
def test_collection(tmp_path: Path, monkeypatch: MonkeyPatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
id = "c30de0f3-ab4d-48ad-aa26-f20bb4b70bbd"
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["collection", id])
|
|
assert result.exit_code == 0
|
|
subdir = tmp_path / "RefL0100N1504"
|
|
assert subdir.exists()
|
|
assert len(list(subdir.glob("*"))) == 1
|
|
output_file = subdir / "ics_20770177.cfg"
|
|
assert output_file.exists()
|
|
assert time_fix_regex.sub("TIME", output_file.read_text()) == time_fix_regex.sub(
|
|
"TIME", reference_output_collection
|
|
)
|