mirror of
https://github.com/cosmo-sims/cosmICweb-music.git
synced 2024-09-19 16:53:43 +02:00
136 lines
3.5 KiB
Python
136 lines
3.5 KiB
Python
from datetime import datetime
|
|
|
|
from cosmicweb_music.cosmICweb import (
|
|
apply_config_parameter,
|
|
music_config_to_template,
|
|
DEFAULT_URL,
|
|
compose_template,
|
|
)
|
|
from cosmicweb_music.data_types import DownloadConfig, Args, Ellipsoid, Configuration
|
|
|
|
some_config = """
|
|
[setup]
|
|
boxlength = 150
|
|
zstart = 99
|
|
levelmin = 8
|
|
levelmin_TF = 8
|
|
levelmax = 12
|
|
padding = 16 # try reduce it at your own risk
|
|
overlap = 4
|
|
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
|
|
""".strip()
|
|
|
|
some_config_modified = """
|
|
[setup]
|
|
boxlength = 150
|
|
zstart = 123
|
|
levelmin = 8
|
|
levelmin_TF = 8
|
|
levelmax = 12
|
|
padding = 16 # try reduce it at your own risk
|
|
overlap = 4
|
|
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
|
|
""".strip()
|
|
|
|
settings: Configuration = {
|
|
"outputType": "grafic2",
|
|
"resolution": {"low": 7, "high": 11},
|
|
"outputOptions": [
|
|
("ramses_nml", "yes"),
|
|
("ramses_old_nml", "no"),
|
|
("ramses_pvar_idx", "43"),
|
|
],
|
|
"startRedshift": 100,
|
|
"outputFilename": "ics.dat",
|
|
"seperateFolders": True,
|
|
"tracebackRadius": 4,
|
|
}
|
|
|
|
config = DownloadConfig(
|
|
simulation_name="test",
|
|
project_name="project",
|
|
halo_names=["halo_1"],
|
|
halo_ids=[1],
|
|
halo_urls=["..."],
|
|
traceback_radius=10,
|
|
api_token="...",
|
|
MUSIC={"cosmology": "", "poisson": "", "random": "", "setup": ""},
|
|
settings=settings,
|
|
accessed_at=datetime.now(),
|
|
)
|
|
|
|
args = Args(DEFAULT_URL, ".", False, 1)
|
|
ellipsoid = Ellipsoid(
|
|
radius_definition="Rvir",
|
|
center=[0.42174551551333334, 0.42890526632, 0.27975938776000003],
|
|
shape=[
|
|
[872.2886068575001, -31.76815629375, 92.22811563824999],
|
|
[-31.76815629375, 520.6134379275, 28.34206946775],
|
|
[92.22811563824999, 28.34206946775, 165.70762251300002],
|
|
],
|
|
traceback_radius=10.0,
|
|
)
|
|
|
|
generated_config = """
|
|
# Zoom Initial Conditions for halo 1 (halo_1) in simulation test (project project)
|
|
# Details on this halo can be found on https://cosmicweb.eu/simulation/test/halo/1
|
|
# This file has been generated by CosmICweb @2021-01-01T00:00:00
|
|
|
|
|
|
[setup]
|
|
|
|
|
|
# Ellipsoidal refinement region defined on unity cube
|
|
# This minimum bounding ellipsoid has been obtained from
|
|
# particles within 10.0 Rvir of the halo center
|
|
region = ellipsoid
|
|
region_ellipsoid_matrix[0] = 872.2886068575001, -31.76815629375, 92.22811563824999
|
|
region_ellipsoid_matrix[1] = -31.76815629375, 520.6134379275, 28.34206946775
|
|
region_ellipsoid_matrix[2] = 92.22811563824999, 28.34206946775, 165.70762251300002
|
|
region_ellipsoid_center = 0.42174551551333334, 0.42890526632, 0.27975938776000003
|
|
|
|
|
|
[cosmology]
|
|
|
|
|
|
[random]
|
|
|
|
|
|
[poisson]
|
|
|
|
|
|
[output]
|
|
format = grafic2
|
|
filename = ics.dat
|
|
ramses_nml = yes
|
|
ramses_old_nml = no
|
|
ramses_pvar_idx = 43
|
|
|
|
""".lstrip()
|
|
|
|
|
|
def test_apply_config_parameter_empty():
|
|
assert apply_config_parameter(some_config, {}) == some_config
|
|
|
|
|
|
def test_apply_config_parameter():
|
|
params = {"zstart": 123, "doesn't exist": 1}
|
|
assert apply_config_parameter(some_config, params) == some_config_modified
|
|
|
|
|
|
def test_music_config_to_template():
|
|
halo_name = "halo_1"
|
|
halo_id = 1
|
|
music_template = music_config_to_template(config)
|
|
music_config = compose_template(
|
|
music_template, ellipsoid, config, halo_name, halo_id, now=datetime(2021, 1, 1)
|
|
)
|
|
assert music_config == generated_config
|