1
0
Fork 0
mirror of https://github.com/cosmo-sims/cosmICweb-music.git synced 2024-09-19 16:53:43 +02:00

Merge pull request #3 from cosmo-sims/output-type

Add saved output type and options in config
This commit is contained in:
Lukas Winkler 2024-04-23 13:11:49 +02:00 committed by GitHub
commit f00726063d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 103 additions and 48 deletions

View file

@ -193,7 +193,7 @@ def music_config_to_template(config: DownloadConfig) -> str:
"[setup]\n" + music_config["setup"] + "\n\n<ELLIPSOID_TEMPLATE>\n\n" "[setup]\n" + music_config["setup"] + "\n\n<ELLIPSOID_TEMPLATE>\n\n"
"[cosmology]\n" + music_config["cosmology"] + "\n\n" "[cosmology]\n" + music_config["cosmology"] + "\n\n"
"[random]\n" + music_config["random"] + "\n\n" "[random]\n" + music_config["random"] + "\n\n"
"[poisson]\n" + music_config["poisson"] "[poisson]\n" + music_config["poisson"] + "\n\n"
) )
if settings: if settings:
config = apply_config_parameter( config = apply_config_parameter(
@ -205,6 +205,18 @@ def music_config_to_template(config: DownloadConfig) -> str:
"zstart": settings["startRedshift"], "zstart": settings["startRedshift"],
}, },
) )
if settings["outputType"]:
config += f"""
[output]
format = {settings["outputType"]}
filename = {settings["outputFilename"]}
""".strip()
config += "\n"
for k, v in settings["outputOptions"]:
config += f"{k} = {v}\n"
if not settings or not settings["outputType"]:
# TODO: allow specifying output format via cli argument
config += "[output]\n# TODO: add output options"
return config return config

View file

@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
from datetime import datetime from datetime import datetime
from typing import NamedTuple, Any, List, Dict, TypedDict from typing import NamedTuple, Any, List, Dict, TypedDict, Tuple
class Ellipsoid(NamedTuple): class Ellipsoid(NamedTuple):
@ -19,10 +19,10 @@ class Resolution(TypedDict):
class Configuration(TypedDict): class Configuration(TypedDict):
outputType: str outputType: str
resolution: Resolution resolution: Resolution
outputOptions: List[Any] outputOptions: List[Tuple[str, str]]
startRedshift: int startRedshift: int
outputFilename: str outputFilename: str
separateFolders: bool seperateFolders: bool
tracebackRadius: int | float | str tracebackRadius: int | float | str

View file

@ -7,7 +7,7 @@ from cosmicweb_music.cosmICweb import (
DEFAULT_URL, DEFAULT_URL,
compose_template, compose_template,
) )
from cosmicweb_music.data_types import DownloadConfig, Args, Ellipsoid from cosmicweb_music.data_types import DownloadConfig, Args, Ellipsoid, Configuration
some_config = """ some_config = """
[setup] [setup]
@ -40,7 +40,31 @@ baryons = no # switch on for baryon runs
use_2LPT = no use_2LPT = no
use_LLA = no # AMR codes might want to enable this use_LLA = no # AMR codes might want to enable this
""".strip() """.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( config = DownloadConfig(
simulation_name="test", simulation_name="test",
project_name="project", project_name="project",
@ -50,7 +74,7 @@ config = DownloadConfig(
traceback_radius=10, traceback_radius=10,
api_token="...", api_token="...",
MUSIC={"cosmology": "", "poisson": "", "random": "", "setup": ""}, MUSIC={"cosmology": "", "poisson": "", "random": "", "setup": ""},
settings=None, settings=settings,
accessed_at=datetime.now(), accessed_at=datetime.now(),
) )
@ -93,6 +117,14 @@ region_ellipsoid_center = 0.42174551551333334, 0.42890526632, 0.2797593877600
[poisson] [poisson]
[output]
format = grafic2
filename = ics.dat
ramses_nml = yes
ramses_old_nml = no
ramses_pvar_idx = 43
""".lstrip() """.lstrip()

View file

@ -1,65 +1,73 @@
import re import re
from datetime import datetime
from cosmicweb_music.cosmICweb import ( from cosmicweb_music.cosmICweb import (
apply_config_parameter,
music_config_to_template,
process_config,
DEFAULT_URL, DEFAULT_URL,
compose_template,
downloadstore_mode, downloadstore_mode,
publication_mode, publication_mode,
) )
from cosmicweb_music.data_types import DownloadConfig, Args, Ellipsoid from cosmicweb_music.data_types import Args
reference_output = """ reference_output = """
# Zoom Initial Conditions for halo 208416759 (halo_208416759) in simulation 150MPC (CosmOCA project) # 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/150MPC/halo/208416759 # Details on this halo can be found on https://cosmicweb.eu/simulation/AGORA/halo/25401888
# This file has been generated by CosmICweb @2024-04-20T22:26:13.916577 # This file has been generated by CosmICweb @2024-04-23T12:56:20.876162
[setup] [setup]
boxlength = 150 boxlength = 60
zstart = 99 zstart = 100
levelmin = 8 levelmin = 7
levelmin_TF = 8 levelmin_TF = 7
levelmax = 12 levelmax = 11
padding = 16 # try reduce it at your own risk padding = 16 # try reduce it at your own risk
overlap = 4 overlap = 4
align_top = no align_top = no
baryons = no # switch on for baryon runs baryons = no # switch on for baryon runs
use_2LPT = no use_2LPT = no
use_LLA = no # AMR codes might want to enable this use_LLA = no # AMR codes might want to enable this
# Ellipsoidal refinement region defined on unity cube # Ellipsoidal refinement region defined on unity cube
# This minimum bounding ellipsoid has been obtained from # This minimum bounding ellipsoid has been obtained from
# particles within 10.0 Rvir of the halo center # particles within 4.0 Rvir of the halo center
region = ellipsoid region = ellipsoid
region_ellipsoid_matrix[0] = 872.2886068575001, -31.76815629375, 92.22811563824999 region_ellipsoid_matrix[0] = 73.2097934892, 0.7223112927, 6.51459018132
region_ellipsoid_matrix[1] = -31.76815629375, 520.6134379275, 28.34206946775 region_ellipsoid_matrix[1] = 0.7223112927, 41.7248191188, -11.54268986796
region_ellipsoid_matrix[2] = 92.22811563824999, 28.34206946775, 165.70762251300002 region_ellipsoid_matrix[2] = 6.51459018132, -11.54268986796, 82.69775988479999
region_ellipsoid_center = 0.42174551551333334, 0.42890526632, 0.27975938776000003 region_ellipsoid_center = 0.03202272286, 0.7263335608333333, 0.5582005855333333
[cosmology] [cosmology]
Omega_m = 0.309 Omega_m = 0.272
Omega_L = 0.691 Omega_L = 0.728
Omega_b = 0.049 Omega_b = 0.0455
H0 = 67.74 H0 = 70.2
sigma_8 = 0.816 sigma_8 = 0.807
nspec = 0.9667 nspec = 0.961
transfer = eisenstein 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] [random]
cubesize = 256 cubesize = 256
seed[9] = 74927 seed[8] = 95064
seed[10] = 21450 seed[9] = 31415
seed[10] = 27183
# do not add higher seeds!
[poisson] [poisson]
fft_fine = true fft_fine = yes
accuracy = 1e-5 accuracy = 1e-6
grad_order = 4 grad_order = 6
laplace_order = 4 laplace_order = 6
[output]
format = grafic2
filename = ics.dat
ramses_nml = yes
ramses_old_nml = no
ramses_pvar_idx = 43
""".lstrip() """.lstrip()
reference_output_publication=""" reference_output_publication="""
@ -115,18 +123,21 @@ fft_fine = yes
accuracy = 1e-6 accuracy = 1e-6
grad_order = 6 grad_order = 6
laplace_order = 6 laplace_order = 6
[output]
# TODO: add output options
""".lstrip() """.lstrip()
time_fix_regex = re.compile(r"@[\d\-T:.]+") time_fix_regex = re.compile(r"@[\d\-T:.]+")
def test_single_saved(): def test_single_saved():
id = "f5399734-ad67-432b-ba4d-61bc2088136a" id = "50e20c16-45b8-4d0f-b6cd-44e050b76afb"
args = Args(output_path="./", url=DEFAULT_URL, common_directory=True, attempts=1) args = Args(output_path="./", url=DEFAULT_URL, common_directory=True, attempts=1)
output = downloadstore_mode(args, id, store=False) output = downloadstore_mode(args, id, store=False)
assert len(output) == 1 assert len(output) == 1
output = output[0] output = output[0]
assert output[0] == "./cosmICweb-zooms-150MPC/ics_halo_208416759.cfg" assert output[0] == "./cosmICweb-zooms-AGORA/ics_halo_25401888.cfg"
assert time_fix_regex.sub("TIME", output[1]) == time_fix_regex.sub( assert time_fix_regex.sub("TIME", output[1]) == time_fix_regex.sub(
"TIME", reference_output "TIME", reference_output