From 941de04859e15a97a8db3dc464731bf1a5bd96af Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Mon, 18 Mar 2024 10:37:08 +0100 Subject: [PATCH 1/8] Don't use log path function in IRENA retrieval rule The `logs` function returns a path with a {run} wildcard which is not present in the output of the retrieval rule. Follows f50ee2f2. --- rules/retrieve.smk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/retrieve.smk b/rules/retrieve.smk index b2c1e8d6..ac296f79 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -50,7 +50,7 @@ if config["enable"].get("retrieve_irena"): onwind="data/existing_infrastructure/onwind_capacity_IRENA.csv", solar="data/existing_infrastructure/solar_capacity_IRENA.csv", log: - logs("retrieve_irena.log"), + "logs/retrieve_irena.log", resources: mem_mb=1000, retries: 2 From ce549cd9494228998ee6689d095ca06c171fff11 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Mon, 18 Mar 2024 10:00:42 +0100 Subject: [PATCH 2/8] Allow the retrieval of cost data from forks of technology-data --- scripts/retrieve_cost_data.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/retrieve_cost_data.py b/scripts/retrieve_cost_data.py index eb1ef041..39fcab7c 100644 --- a/scripts/retrieve_cost_data.py +++ b/scripts/retrieve_cost_data.py @@ -25,9 +25,10 @@ if __name__ == "__main__": set_scenario_config(snakemake) version = snakemake.params.version - baseurl = ( - f"https://raw.githubusercontent.com/PyPSA/technology-data/{version}/outputs/" - ) + if "/" in version: + baseurl = f"https://raw.githubusercontent.com/{version}/outputs" + else: + baseurl = f"https://raw.githubusercontent.com/PyPSA/technology-data/{version}/outputs/" filepath = Path(snakemake.output[0]) url = baseurl + filepath.name From 1f499eda6ffb20ed81c15a1b6a3a8557a53e18d4 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Mon, 18 Mar 2024 13:31:04 +0100 Subject: [PATCH 3/8] Document new handling of costs version config option --- doc/configtables/costs.csv | 2 +- doc/release_notes.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/configtables/costs.csv b/doc/configtables/costs.csv index b69c0bf9..03933c18 100644 --- a/doc/configtables/costs.csv +++ b/doc/configtables/costs.csv @@ -1,6 +1,6 @@ ,Unit,Values,Description year,--,YYYY; e.g. '2030',Year for which to retrieve cost assumptions of ``resources/costs.csv``. -version,--,vX.X.X; e.g. 'v0.5.0',Version of ``technology-data`` repository to use. +version,--,vX.X.X or //vX.X.X; e.g. 'v0.5.0',Version of ``technology-data`` repository to use. If this string is of the form // then costs are instead retrieved from ``github.com//`` at the tag. rooftop_share,--,float,Share of rooftop PV when calculating capital cost of solar (joint rooftop and utility-scale PV). social_discountrate,p.u.,float,Social discount rate to compare costs in different investment periods. 0.02 corresponds to a social discount rate of 2%. fill_values,--,float,Default values if not specified for a technology in ``resources/costs.csv``. diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 11fd3df7..21094250 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -82,6 +82,8 @@ Upcoming Release * Upgrade default techno-economic assumptions to ``technology-data`` v0.8.1. +* Add possibility to download cost data from custom fork of ``technology-data``. + * Linearly interpolate missing investment periods in year-dependent configuration options. From e03fbf152c88ecff3aca56cc62ca4ac7794d6319 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Mon, 18 Mar 2024 13:37:58 +0000 Subject: [PATCH 4/8] Only sanitize locations when there are buses with a location Fixes an edge case when no buses with a location are added in add_extra_components. --- scripts/add_electricity.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index ac73cb1f..7e60203f 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -184,12 +184,13 @@ def sanitize_carriers(n, config): def sanitize_locations(n): - n.buses["x"] = n.buses.x.where(n.buses.x != 0, n.buses.location.map(n.buses.x)) - n.buses["y"] = n.buses.y.where(n.buses.y != 0, n.buses.location.map(n.buses.y)) - n.buses["country"] = n.buses.country.where( - n.buses.country.ne("") & n.buses.country.notnull(), - n.buses.location.map(n.buses.country), - ) + if "location" in n.buses.columns: + n.buses["x"] = n.buses.x.where(n.buses.x != 0, n.buses.location.map(n.buses.x)) + n.buses["y"] = n.buses.y.where(n.buses.y != 0, n.buses.location.map(n.buses.y)) + n.buses["country"] = n.buses.country.where( + n.buses.country.ne("") & n.buses.country.notnull(), + n.buses.location.map(n.buses.country), + ) def add_co2_emissions(n, costs, carriers): From c983aa7d2dcdee44d805d9c820f416870110e14d Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 7 Mar 2024 10:22:28 +0100 Subject: [PATCH 5/8] prepare_perfect: ensure network.meta assignment --- scripts/prepare_perfect_foresight.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index f7e8495e..fea0cef4 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -537,5 +537,8 @@ if __name__ == "__main__": # set carbon constraints n = set_carbon_constraints(n) + # update meta + n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards))) + # export network n.export_to_netcdf(snakemake.output[0]) From 65af55c22b48e305a6baa30f265054429ba79a55 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Tue, 19 Mar 2024 08:54:58 +0100 Subject: [PATCH 6/8] Fix typos --- scripts/add_brownfield.py | 2 +- scripts/retrieve_cost_data.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 82a40e57..7e49031b 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -145,7 +145,7 @@ def disable_grid_expansion_if_limit_hit(n): for name, glc in glcs.iterrows(): total_expansion = ( ( - n.lines.query("p_nom_extendable") + n.lines.query("s_nom_extendable") .eval(f"s_nom_min * {cols[limit_type]}") .sum() ) diff --git a/scripts/retrieve_cost_data.py b/scripts/retrieve_cost_data.py index 39fcab7c..e236fbfd 100644 --- a/scripts/retrieve_cost_data.py +++ b/scripts/retrieve_cost_data.py @@ -26,7 +26,7 @@ if __name__ == "__main__": version = snakemake.params.version if "/" in version: - baseurl = f"https://raw.githubusercontent.com/{version}/outputs" + baseurl = f"https://raw.githubusercontent.com/{version}/outputs/" else: baseurl = f"https://raw.githubusercontent.com/PyPSA/technology-data/{version}/outputs/" filepath = Path(snakemake.output[0]) From 22d1bf5dd1a35554d476263c91d9bb390881dc2f Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Mon, 18 Mar 2024 11:58:39 +0100 Subject: [PATCH 7/8] Bugfix for missing eia years First, cannot cast pd index to boolean. Second, fix logic error of mistakenly swapped difference in calculating missing years. --- scripts/build_hydro_profile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/build_hydro_profile.py b/scripts/build_hydro_profile.py index b7f270b3..c4e9701e 100644 --- a/scripts/build_hydro_profile.py +++ b/scripts/build_hydro_profile.py @@ -202,9 +202,10 @@ if __name__ == "__main__": contained_years = pd.date_range(freq="YE", **snakemake.params.snapshots).year norm_year = config_hydro.get("eia_norm_year") + missing_years = contained_years.difference(eia_stats.index) if norm_year: eia_stats.loc[contained_years] = eia_stats.loc[norm_year] - elif missing_years := eia_stats.index.difference(contained_years): + elif missing_years.any(): eia_stats.loc[missing_years] = eia_stats.median() inflow = cutout.runoff( From fcf773c003254975740340bb8cb21827aef7fc8b Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Tue, 19 Mar 2024 08:28:14 +0000 Subject: [PATCH 8/8] Copy, don't move natura.tiff to resources Preventing problems when parallel processes attempt to move the same file to different resources directories. --- rules/retrieve.smk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/retrieve.smk b/rules/retrieve.smk index ac296f79..4b244483 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -115,7 +115,7 @@ if config["enable"]["retrieve"] and config["enable"].get( mem_mb=5000, retries: 2 run: - move(input[0], output[0]) + copyfile(input[0], output[0]) validate_checksum(output[0], input[0])