Skip to content

Commit 2b3d1f6

Browse files
authored
Merge pull request #15 from SWIFTSIM/add_titles
Adds titles and disabled scripts in comparisons
2 parents e776ade + 10be9b6 commit 2b3d1f6

File tree

6 files changed

+82
-10
lines changed

6 files changed

+82
-10
lines changed

CHANGELOG.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
Changelog for the ``swiftpipeline`` repository.
22

3+
Version 0.2.0
4+
-------------
5+
6+
Titles update!
7+
8+
+ Adds ability to overwrite run names in output, to enable easier comparisons.
9+
+ Adds by default a redshift tag to each simulation name when comparing different
10+
snapshots that have different redshifts.
11+
+ Adds ability to disable scripts for comparisons (`use_for_comparison: false` in
12+
yaml file).
13+
314
Version 0.1.8
415
-------------
516

example/config/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ scripts:
2828
output_file: density_temperature.png
2929
section: Density-Temperature
3030
title: Density-Temperature
31+
use_for_comparison: false
3132
additional_arguments:
3233
quantity_type: hydro

swift-pipeline

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ parser.add_argument(
9999
),
100100
)
101101

102+
parser.add_argument(
103+
"-n",
104+
"--run-names",
105+
required=False,
106+
default=None,
107+
nargs="*",
108+
help=(
109+
"Overwrite the names given to each run? If not present, the default names "
110+
"from the snapshots are used, and in the case where there are multiple "
111+
"redshifts, we append the redshift."
112+
),
113+
)
114+
102115

103116
if __name__ == "__main__":
104117
# Parse our lovely arguments and pass them to the velociraptor library
@@ -158,13 +171,32 @@ if __name__ == "__main__":
158171
load_snapshot(f"{input}/{snapshot}")
159172
for input, snapshot in zip(args.input, args.snapshots)
160173
]
161-
run_names = [data.metadata.run_name for data in snapshots]
174+
if args.run_names is not None:
175+
run_names = args.run_names
176+
print_if_debug("Using custom run names:")
177+
print_if_debug(" ".join(run_names))
178+
else:
179+
# First, check if the snapshots are all at the same redshift
180+
redshifts = {data.metadata.redshift for data in snapshots}
181+
if len(redshifts) == len(snapshots):
182+
# All different redshifts!
183+
run_names = [data.metadata.run_name for data in snapshots]
184+
else:
185+
# Need to append appropriate redshifts to names.
186+
run_names = [
187+
f"{data.metadata.run_name} (z={data.metadata.redshift:1.3f})"
188+
for data in snapshots
189+
]
190+
print_if_debug("Using default run names from snapshot:")
191+
print_if_debug(" ".join(run_names))
162192

163193
observational_data_path = (
164194
f"{config.config_directory}/{config.observational_data_directory}/data"
165195
)
166196

167-
if len(args.snapshots) == 1:
197+
is_comparison = len(args.snapshots) > 1
198+
199+
if not is_comparison:
168200
# Run the pipeline based on the arguments if only a single simulation is
169201
# included and generate the metadata yaml file.
170202
print_if_debug(
@@ -213,7 +245,7 @@ if __name__ == "__main__":
213245
f"{args.input[0]}/{args.metadata}_{args.snapshots[0][-9:-5]}.yml"
214246
)
215247
print_if_debug(f"Creating and writing metadata to {metadata_filename}")
216-
248+
217249
try:
218250
auto_plotter_metadata.write_metadata(metadata_filename)
219251
except (OSError, PermissionError) as e:
@@ -283,7 +315,9 @@ if __name__ == "__main__":
283315
if args.debug:
284316
config.scripts = tqdm(config.scripts, desc="Running Scripts")
285317

286-
for script in config.scripts:
318+
scripts_to_use = config.comparison_scripts if is_comparison else config.scripts
319+
320+
for script in scripts_to_use:
287321
full_script_path = f"{config.config_directory}/{script.filename}"
288322

289323
run(
@@ -310,7 +344,7 @@ if __name__ == "__main__":
310344
print_if_debug("Creating webpage.")
311345
webpage = WebpageCreator()
312346
webpage.add_auto_plotter_metadata(auto_plotter_metadata=auto_plotter_metadata)
313-
webpage.add_config_metadata(config=config)
347+
webpage.add_config_metadata(config=config, is_comparison=is_comparison)
314348
webpage.add_metadata(page_name=" | ".join(run_names))
315349
webpage.add_run_metadata(config=config, snapshots=snapshots)
316350
webpage.render_webpage()

swiftpipeline/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.8"
1+
__version__ = "0.2.0"

swiftpipeline/config.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class Script(object):
3838
show_on_webpage: bool
3939
# additional arguments to be fed to a given script
4040
additional_arguments: dict
41+
# Use in the case where we have comparisons? The scripts may be disabled
42+
# in comparison cases for performance reasons.
43+
use_for_comparison: bool
4144

4245
def __init__(self, script_dict: dict):
4346
"""
@@ -51,6 +54,7 @@ def __init__(self, script_dict: dict):
5154
self.title = script_dict.get("title", "")
5255
self.show_on_webpage = script_dict.get("show_on_webpage", True)
5356
self.additional_arguments = script_dict.get("additional_arguments", {})
57+
self.use_for_comparison = script_dict.get("use_for_comparison", True)
5458
return
5559

5660
def __str__(self):
@@ -85,7 +89,7 @@ class Config(object):
8589

8690
# Raw config read directly from the file, before processing.
8791
raw_config: dict
88-
scripts: List[Script]
92+
raw_scripts: List[Script]
8993

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

145149
raw_scripts = self.raw_config.get("scripts", [])
146-
self.scripts = [Script(script_dict=script_dict) for script_dict in raw_scripts]
150+
self.raw_scripts = [
151+
Script(script_dict=script_dict) for script_dict in raw_scripts
152+
]
147153

148154
return
155+
156+
@property
157+
def scripts(self):
158+
"""
159+
Gets all of the scripts defined in the parameter file.
160+
"""
161+
return self.raw_scripts
162+
163+
@property
164+
def comparison_scripts(self):
165+
"""
166+
Gets the scripts only to be used in comparisons from the parameter
167+
file.
168+
"""
169+
return [script for script in self.raw_scripts if script.use_for_comparison]

swiftpipeline/html.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def add_auto_plotter_metadata(self, auto_plotter_metadata: AutoPlotterMetadata):
196196

197197
return
198198

199-
def add_config_metadata(self, config: Config):
199+
def add_config_metadata(self, config: Config, is_comparison: bool = False):
200200
"""
201201
Adds the section metadata from the additional plots
202202
defined under ``config.yml::scripts``.
@@ -206,13 +206,18 @@ def add_config_metadata(self, config: Config):
206206
207207
config: Config
208208
Configuration object from ``swift-pipeline``.
209+
210+
is_comparison: bool, optional
211+
Is this webpage being created for a comparison? Default: False.
209212
"""
210213

211214
self.config = config
212215

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

219+
scripts_to_use = config.comparison_scripts if is_comparison else config.scripts
220+
216221
for section in sections:
217222
plots = [
218223
dict(
@@ -221,7 +226,7 @@ def add_config_metadata(self, config: Config):
221226
caption=script.caption,
222227
hash=abs(hash(script.caption + script.title)),
223228
)
224-
for script in config.scripts
229+
for script in scripts_to_use
225230
if script.section == section and script.show_on_webpage
226231
]
227232

0 commit comments

Comments
 (0)