Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .jinja suffix; reorganise template rules #409

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* **UPDATED** structure of YAML templates and parametrisation:
* Parametrisation moved to eurocalliopelib.
* Rules to parametrise split into smaller technology-specific rules, to ensure inputs are directly relevant to the files being parametrised.
* YAML templates restructured to match structure of final model (see `Updated (models) above`);
* YAML templates restructured to match structure of final model (see `Updated (models) above`) and given `.jinja` suffix to allow for IDE syntax highlighting (#404);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use a plug-in for that? My VSCode seems to understand it's jinja (the icon is jinja), but I don't get any syntax highlighting or problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, found the answer myself, haha.

* **UPDATE** cluster sync infrastructure to retain file permission defaults on the cluster. This change improves team collaboration, as default group settings will apply to the files on the cluster (#214).
* **UPDATE** the declaration of required cluster resources. Moving away from a mechanism that is deprecated in Snakemake (#211).
* **UPDATE** default Snakemake profile to be activated automatically, for convenience (#264, #268).
Expand Down
30 changes: 13 additions & 17 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ localrules: all, clean
wildcard_constraints:
resolution = "continental|national|regional|ehighways"

ruleorder: area_to_capacity_limits > hydro_capacities > biofuels > nuclear_regional_capacity > dummy_tech_locations_template
ruleorder: bio_techs_and_locations_template > techs_and_locations_template
ruleorder: create_controlled_road_transport_annual_demand_and_installed_capacities > dummy_tech_locations_template
ruleorder: techs_and_locations_template > dummy_tech_locations_template

ALL_CF_TECHNOLOGIES = [
"wind-onshore", "wind-offshore", "open-field-pv",
Expand Down Expand Up @@ -96,30 +94,28 @@ rule all_tests:
)


rule dummy_tech_locations_template: # needed to provide `techs_and_locations_template` with a locational CSV linked to each technology that has no location-specific data to define.
message: "Create empty {wildcards.resolution} location-specific data file for the {wildcards.tech_group} tech `{wildcards.tech}`." # Update ruleorder at the top of the file if you instead want the techs_and_locations_template rule to be used to generate a file
input: rules.locations_template.output.csv
output: "build/data/{resolution}/{tech_group}/{tech}.csv"
conda: "envs/shell.yaml"
shell: "cp {input} {output}"


rule techs_and_locations_template:
message: "Create {wildcards.resolution} definition file for the {wildcards.tech_group} tech `{wildcards.tech}`."
message: "Create {wildcards.resolution} definition file for {wildcards.tech_and_group}."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider naming this "group_and_tech", highlighting that groups comes first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a workflow-wide wildcard_constraint that requires this wildcard to contain / could be useful, right?

input:
template = techs_template_dir + "{tech_group}/{tech}.yaml",
locations = "build/data/{resolution}/{tech_group}/{tech}.csv"
template = techs_template_dir + "{tech_and_group}.yaml.jinja",
locations = "build/data/{resolution}/{tech_and_group}.csv"
params:
scaling_factors = config["scaling-factors"],
capacity_factors = config["capacity-factors"]["average"],
max_power_densities = config["parameters"]["maximum-installable-power-density"],
heat_pump_shares = config["parameters"]["heat-pump"]["heat-pump-shares"],
wildcard_constraints:
tech_group = "(?!transmission).*" # i.e. all but transmission
# Exclude all outputs that have their own `techs_and_locations_template` implementation
tech_and_group = "(?!transmission\/|supply\/biofuel).*"
conda: "envs/default.yaml"
output: "build/models/{resolution}/techs/{tech_group}/{tech}.yaml"
output: "build/models/{resolution}/techs/{tech_and_group}.yaml"
script: "scripts/template_techs.py"

use rule techs_and_locations_template as dummy_tech_locations_template with:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistent naming would be "dummy_techs_and_locations_template".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyways, maybe different names would be more helpful in communicating the difference. I don't really understand why this is called a "dummy". Is it maybe: "tech_and_locations_template_with(out)_location_specific_data"? That seems the be the differentiating factor to me.

Or even more radical and better in my opinion: "model_component_with(out)_location_specific_data". We don't have a clear rule, but typically rules are named by (1) what they do or (2) what they produce, not by their inputs (here: template).

Or: "module_with(out)_location_specific_data". That's how we call these files in the documentation. My favourite right now.

# For all cases where we don't have any location-specific data that we want to supply to the template
input:
template = techs_template_dir + "{tech_and_group}.yaml.jinja",
locations = rules.locations_template.output.csv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR: Should this rule be called locations instead of locations_template? I was misled into thinking this was a template, but it isn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locations_from_template? I still like the link to templates in the rule name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or locations_calliope_input?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I like locations_module best. We already call these files modules and this would be most consistent. I am fine with renaming these files to something else, but I'd be consistent -- including in the docs.


rule no_params_model_template:
message: "Create {wildcards.resolution} configuration files from templates where no parameterisation is required."
Expand All @@ -146,7 +142,7 @@ rule no_params_template:
rule model_template:
message: "Generate top-level {wildcards.resolution} model configuration file from template"
input:
template = model_template_dir + "example-model.yaml",
template = model_template_dir + "example-model.yaml.jinja",
non_model_files = expand(
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
"build/models/{template}", template=["environment.yaml", "README.md"]
),
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 1 addition & 2 deletions rules/biofuels.smk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Rules related to biofuels."""


rule download_biofuel_potentials_and_costs:
message: "Download raw biofuel potential and cost data."
params: url = config["data-sources"]["biofuel-potentials-and-costs"]
Expand Down Expand Up @@ -55,7 +54,7 @@ rule biofuels:
rule bio_techs_and_locations_template:
message: "Create biofuel tech definition file from template."
input:
template = techs_template_dir + "supply/biofuel.yaml",
template = techs_template_dir + "supply/biofuel.yaml.jinja",
biofuel_cost = "build/data/regional/biofuel/{scenario}/costs-eur-per-mwh.csv".format(
scenario=config["parameters"]["jrc-biofuel"]["scenario"]
),
Expand Down
2 changes: 1 addition & 1 deletion rules/shapes.smk
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ rule eez:
rule locations_template:
message: "Generate locations configuration file for {wildcards.resolution} resolution from template."
input:
template = model_template_dir + "locations.yaml",
template = model_template_dir + "locations.yaml.jinja",
shapes = rules.units.output[0]
output:
yaml = "build/models/{resolution}/locations.yaml",
Expand Down
8 changes: 4 additions & 4 deletions rules/transmission.smk
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ rule entsoe_tyndp_xlsx:
shell: "unzip -o {input} 'TYNDP-2020-Scenario-Datafile.xlsx' -d build/data/national"


rule transmission_entsoe_tyndp_template:
rule transmission_entsoe_tyndp_techs_and_locations_template:
message: "Create YAML file of national-scale links with ENTSO-E TYNDP net-transfer capacities"
input:
template = techs_template_dir + "transmission/electricity-transmission.yaml",
template = techs_template_dir + "transmission/electricity-transmission.yaml.jinja",
locations = rules.locations_template.output.csv,
entsoe_tyndp = rules.entsoe_tyndp_xlsx.output[0]
params:
Expand All @@ -39,10 +39,10 @@ rule transmission_entsoe_tyndp_template:
script: "../scripts/transmission/template_transmission_entsoe_tyndp.py"


rule link_locations_with_transmission_techs_template:
rule transmission_techs_and_locations_template:
message: "Link {wildcards.resolution} direct neighbours and neighbours with sea connections with transmission techs from template."
input:
template = techs_template_dir + "transmission/electricity-transmission.yaml",
template = techs_template_dir + "transmission/electricity-transmission.yaml.jinja",
units = rules.units.output[0]
params:
scaling_factors = config["scaling-factors"],
Expand Down
File renamed without changes.
Loading