Skip to content

Commit

Permalink
Merge pull request #15 from SWIFTSIM/add_titles
Browse files Browse the repository at this point in the history
Adds titles and disabled scripts in comparisons
  • Loading branch information
JBorrow authored Nov 8, 2020
2 parents e776ade + 10be9b6 commit 2b3d1f6
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Changelog for the ``swiftpipeline`` repository.

Version 0.2.0
-------------

Titles update!

+ Adds ability to overwrite run names in output, to enable easier comparisons.
+ Adds by default a redshift tag to each simulation name when comparing different
snapshots that have different redshifts.
+ Adds ability to disable scripts for comparisons (`use_for_comparison: false` in
yaml file).

Version 0.1.8
-------------

Expand Down
1 change: 1 addition & 0 deletions example/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ scripts:
output_file: density_temperature.png
section: Density-Temperature
title: Density-Temperature
use_for_comparison: false
additional_arguments:
quantity_type: hydro
44 changes: 39 additions & 5 deletions swift-pipeline
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ parser.add_argument(
),
)

parser.add_argument(
"-n",
"--run-names",
required=False,
default=None,
nargs="*",
help=(
"Overwrite the names given to each run? If not present, the default names "
"from the snapshots are used, and in the case where there are multiple "
"redshifts, we append the redshift."
),
)


if __name__ == "__main__":
# Parse our lovely arguments and pass them to the velociraptor library
Expand Down Expand Up @@ -158,13 +171,32 @@ if __name__ == "__main__":
load_snapshot(f"{input}/{snapshot}")
for input, snapshot in zip(args.input, args.snapshots)
]
run_names = [data.metadata.run_name for data in snapshots]
if args.run_names is not None:
run_names = args.run_names
print_if_debug("Using custom run names:")
print_if_debug(" ".join(run_names))
else:
# First, check if the snapshots are all at the same redshift
redshifts = {data.metadata.redshift for data in snapshots}
if len(redshifts) == len(snapshots):
# All different redshifts!
run_names = [data.metadata.run_name for data in snapshots]
else:
# Need to append appropriate redshifts to names.
run_names = [
f"{data.metadata.run_name} (z={data.metadata.redshift:1.3f})"
for data in snapshots
]
print_if_debug("Using default run names from snapshot:")
print_if_debug(" ".join(run_names))

observational_data_path = (
f"{config.config_directory}/{config.observational_data_directory}/data"
)

if len(args.snapshots) == 1:
is_comparison = len(args.snapshots) > 1

if not is_comparison:
# Run the pipeline based on the arguments if only a single simulation is
# included and generate the metadata yaml file.
print_if_debug(
Expand Down Expand Up @@ -213,7 +245,7 @@ if __name__ == "__main__":
f"{args.input[0]}/{args.metadata}_{args.snapshots[0][-9:-5]}.yml"
)
print_if_debug(f"Creating and writing metadata to {metadata_filename}")

try:
auto_plotter_metadata.write_metadata(metadata_filename)
except (OSError, PermissionError) as e:
Expand Down Expand Up @@ -283,7 +315,9 @@ if __name__ == "__main__":
if args.debug:
config.scripts = tqdm(config.scripts, desc="Running Scripts")

for script in config.scripts:
scripts_to_use = config.comparison_scripts if is_comparison else config.scripts

for script in scripts_to_use:
full_script_path = f"{config.config_directory}/{script.filename}"

run(
Expand All @@ -310,7 +344,7 @@ if __name__ == "__main__":
print_if_debug("Creating webpage.")
webpage = WebpageCreator()
webpage.add_auto_plotter_metadata(auto_plotter_metadata=auto_plotter_metadata)
webpage.add_config_metadata(config=config)
webpage.add_config_metadata(config=config, is_comparison=is_comparison)
webpage.add_metadata(page_name=" | ".join(run_names))
webpage.add_run_metadata(config=config, snapshots=snapshots)
webpage.render_webpage()
Expand Down
2 changes: 1 addition & 1 deletion swiftpipeline/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.8"
__version__ = "0.2.0"
25 changes: 23 additions & 2 deletions swiftpipeline/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Script(object):
show_on_webpage: bool
# additional arguments to be fed to a given script
additional_arguments: dict
# Use in the case where we have comparisons? The scripts may be disabled
# in comparison cases for performance reasons.
use_for_comparison: bool

def __init__(self, script_dict: dict):
"""
Expand All @@ -51,6 +54,7 @@ def __init__(self, script_dict: dict):
self.title = script_dict.get("title", "")
self.show_on_webpage = script_dict.get("show_on_webpage", True)
self.additional_arguments = script_dict.get("additional_arguments", {})
self.use_for_comparison = script_dict.get("use_for_comparison", True)
return

def __str__(self):
Expand Down Expand Up @@ -85,7 +89,7 @@ class Config(object):

# Raw config read directly from the file, before processing.
raw_config: dict
scripts: List[Script]
raw_scripts: List[Script]

# Set up the object.
__slots__ = list(direct_read.keys()) + ["scripts", "config_directory", "raw_config"]
Expand Down Expand Up @@ -143,6 +147,23 @@ def __extract_scripts(self):
"""

raw_scripts = self.raw_config.get("scripts", [])
self.scripts = [Script(script_dict=script_dict) for script_dict in raw_scripts]
self.raw_scripts = [
Script(script_dict=script_dict) for script_dict in raw_scripts
]

return

@property
def scripts(self):
"""
Gets all of the scripts defined in the parameter file.
"""
return self.raw_scripts

@property
def comparison_scripts(self):
"""
Gets the scripts only to be used in comparisons from the parameter
file.
"""
return [script for script in self.raw_scripts if script.use_for_comparison]
9 changes: 7 additions & 2 deletions swiftpipeline/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def add_auto_plotter_metadata(self, auto_plotter_metadata: AutoPlotterMetadata):

return

def add_config_metadata(self, config: Config):
def add_config_metadata(self, config: Config, is_comparison: bool = False):
"""
Adds the section metadata from the additional plots
defined under ``config.yml::scripts``.
Expand All @@ -206,13 +206,18 @@ def add_config_metadata(self, config: Config):
config: Config
Configuration object from ``swift-pipeline``.
is_comparison: bool, optional
Is this webpage being created for a comparison? Default: False.
"""

self.config = config

# Unique sections
sections = {script.section for script in config.scripts}

scripts_to_use = config.comparison_scripts if is_comparison else config.scripts

for section in sections:
plots = [
dict(
Expand All @@ -221,7 +226,7 @@ def add_config_metadata(self, config: Config):
caption=script.caption,
hash=abs(hash(script.caption + script.title)),
)
for script in config.scripts
for script in scripts_to_use
if script.section == section and script.show_on_webpage
]

Expand Down

0 comments on commit 2b3d1f6

Please sign in to comment.