diff --git a/cosmicweb_music/cosmICweb.py b/cosmicweb_music/cosmICweb.py index 7effc67..38c75de 100755 --- a/cosmicweb_music/cosmICweb.py +++ b/cosmicweb_music/cosmICweb.py @@ -4,8 +4,6 @@ import os import sys from typing import Any -from click import Context - from .data_types import Ellipsoid, Args, DownloadConfig import click @@ -34,7 +32,7 @@ def fetch_ellipsoids(url: str, api_token: str, attempts: int) -> list[Ellipsoid] # This will raise an error if not successful r.raise_for_status() except requests.exceptions.HTTPError as e: - logging.warning("Failed fetching (attempt {}/{}) ...".format(i, attempts)) + logging.warning(f"Failed fetching (attempt {i}/{attempts}) ...") logging.warning(e) else: content = r.json() @@ -47,7 +45,7 @@ def fetch_ellipsoids(url: str, api_token: str, attempts: int) -> list[Ellipsoid] ) for e in content ] - logging.error("Unable to download ellipsoids from {}".format(url)) + logging.error(f"Unable to download ellipsoids from {url}") return [] @@ -68,21 +66,19 @@ def fetch_downloadstore(cosmicweb_url: str, target: str) -> DownloadConfig: # This will raise an error if not successful r.raise_for_status() except requests.exceptions.HTTPError as e: - logging.critical(f"Failed downloading from cosmICweb.") + logging.critical("Failed downloading from cosmICweb.") logging.critical(e) sys.exit(1) content = r.json() sim = content["simulation"] halo_urls = [ - "{url}/simulation/{sid}/halo/{hid}".format( - url=sim["api_url"], sid=sim["api_id"], hid=h - ) + f"{sim['api_url']}/simulation/{sim['api_id']}/halo/{h}" for h in content["halos"] ] return DownloadConfig( simulation_name=sim["name"], project_name=sim["project_name"], - halo_names=["halo_{}".format(h) for h in content["halos"]], + halo_names=[f"halo_{h}" for h in content["halos"]], halo_ids=content["halos"], halo_urls=halo_urls, traceback_radius=content["traceback_radius"], @@ -238,7 +234,7 @@ def compose_template( def write_music_file(output_file: str, music_config: str) -> None: dirname = os.path.dirname(output_file) if not os.path.exists(dirname): - logging.debug("Creating directory {}".format(dirname)) + logging.debug(f"Creating directory {dirname}") os.makedirs(dirname) with open(output_file, "w") as f: f.write(music_config) @@ -263,7 +259,6 @@ def process_config(config: DownloadConfig, args: Args) -> None: # Edit template logging.info("Creating MUSIC template") music_template = music_config_to_template(config) - output = [] if click.confirm( "Do you want to edit the MUSIC template before creating the IC files?\n" @@ -278,18 +273,16 @@ def process_config(config: DownloadConfig, args: Args) -> None: config.halo_names, config.halo_ids, ellipsoids ): if ellipsoid is None: - logging.warning( - "Ellipsoid for halo {} not available, skipping".format(halo_name) - ) + logging.warning(f"Ellipsoid for halo {halo_name} not available, skipping") continue - logging.info("Composing MUSIC configuration file for halo {}".format(halo_name)) + logging.info(f"Composing MUSIC configuration file for halo {halo_name}") music_config = compose_template( music_template, ellipsoid, config, halo_name, halo_id ) if args.common_directory and len(ellipsoids) > 1: output_file = os.path.join(args.output_path, str(halo_name), "ics.cfg") else: - output_file = os.path.join(args.output_path, "ics_{}.cfg".format(halo_name)) + output_file = os.path.join(args.output_path, f"ics_{halo_name}.cfg") logging.info( "Storing MUSIC configuration file for halo {} in {}".format( halo_name, output_file diff --git a/cosmicweb_music/data_types.py b/cosmicweb_music/data_types.py index 657c20c..4f06d55 100644 --- a/cosmicweb_music/data_types.py +++ b/cosmicweb_music/data_types.py @@ -1,12 +1,12 @@ from __future__ import annotations from datetime import datetime -from typing import NamedTuple, Any, List, Dict, TypedDict, Tuple +from typing import NamedTuple, TypedDict class Ellipsoid(NamedTuple): - center: List[float] - shape: List[List[float]] + center: list[float] + shape: list[list[float]] traceback_radius: float radius_definition: str @@ -19,7 +19,7 @@ class Resolution(TypedDict): class Configuration(TypedDict): outputType: str resolution: Resolution - outputOptions: List[Tuple[str, str]] + outputOptions: list[tuple[str, str]] startRedshift: int outputFilename: str seperateFolders: bool @@ -36,9 +36,9 @@ class ICSections(TypedDict): class DownloadConfig(NamedTuple): simulation_name: str project_name: str - halo_names: List[str] - halo_ids: List[int] - halo_urls: List[str] + halo_names: list[str] + halo_ids: list[int] + halo_urls: list[str] traceback_radius: float api_token: str MUSIC: ICSections diff --git a/tests/test_config.py b/tests/test_config.py index e5bf6af..12c1c63 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,7 +3,6 @@ from datetime import datetime from cosmicweb_music.cosmICweb import ( apply_config_parameter, music_config_to_template, - process_config, DEFAULT_URL, compose_template, ) @@ -40,31 +39,21 @@ baryons = no # switch on for baryon runs use_2LPT = no use_LLA = no # AMR codes might want to enable this """.strip() -settings:Configuration={ + +settings: Configuration = { "outputType": "grafic2", - "resolution": { - "low": 7, - "high": 11 - }, + "resolution": {"low": 7, "high": 11}, "outputOptions": [ - ( - "ramses_nml", - "yes" - ), - ( - "ramses_old_nml", - "no" - ), - ( - "ramses_pvar_idx", - "43" - ) + ("ramses_nml", "yes"), + ("ramses_old_nml", "no"), + ("ramses_pvar_idx", "43"), ], "startRedshift": 100, "outputFilename": "ics.dat", "seperateFolders": True, - "tracebackRadius": 4 + "tracebackRadius": 4, } + config = DownloadConfig( simulation_name="test", project_name="project", diff --git a/tests/test_e2e.py b/tests/test_e2e.py index cdac8b8..6e51b86 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -1,19 +1,10 @@ import re from pathlib import Path -import click from _pytest.monkeypatch import MonkeyPatch from click.testing import CliRunner -from cosmicweb_music.cosmICweb import ( - DEFAULT_URL, - downloadstore_mode, - publication_mode, - collection_mode, - get, - cli, -) -from cosmicweb_music.data_types import Args +from cosmicweb_music.cosmICweb import cli reference_output = """ # Zoom Initial Conditions for halo 25401888 (halo_25401888) in simulation AGORA (AGORA Project project)