Skip to content

Commit ee85132

Browse files
committed
Added ability to disable a script for comparisons
1 parent 00835c0 commit ee85132

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ if __name__ == "__main__":
194194
f"{config.config_directory}/{config.observational_data_directory}/data"
195195
)
196196

197-
if len(args.snapshots) == 1:
197+
is_comparison = len(args.snapshots) > 1
198+
199+
if not is_comparison:
198200
# Run the pipeline based on the arguments if only a single simulation is
199201
# included and generate the metadata yaml file.
200202
print_if_debug(
@@ -313,7 +315,9 @@ if __name__ == "__main__":
313315
if args.debug:
314316
config.scripts = tqdm(config.scripts, desc="Running Scripts")
315317

316-
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:
317321
full_script_path = f"{config.config_directory}/{script.filename}"
318322

319323
run(
@@ -340,7 +344,7 @@ if __name__ == "__main__":
340344
print_if_debug("Creating webpage.")
341345
webpage = WebpageCreator()
342346
webpage.add_auto_plotter_metadata(auto_plotter_metadata=auto_plotter_metadata)
343-
webpage.add_config_metadata(config=config)
347+
webpage.add_config_metadata(config=config, is_comparison=is_comparison)
344348
webpage.add_metadata(page_name=" | ".join(run_names))
345349
webpage.add_run_metadata(config=config, snapshots=snapshots)
346350
webpage.render_webpage()

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)