From 830019a6e5d5ced3403bd4d5d9e28e2d66fe621b Mon Sep 17 00:00:00 2001 From: Tom Brown Date: Fri, 15 Dec 2023 09:50:47 +0100 Subject: [PATCH] add rule that allows cost data to be modified --- rules/build_sector.smk | 4 ++-- rules/retrieve.smk | 14 ++++++++++++++ scripts/modify_cost_data.py | 12 ++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 scripts/modify_cost_data.py diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 5a9e8646d..596c0305d 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -743,9 +743,9 @@ rule prepare_sector_network: else RESOURCES + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", heat_profile="data/heat_load_profile_BDEW.csv", - costs="data/costs_{}.csv".format(config["costs"]["year"]) + costs="data/costs_{}-modified.csv".format(config["costs"]["year"]) if config["foresight"] == "overnight" - else "data/costs_{planning_horizons}.csv", + else "data/costs_{planning_horizons}-modified.csv", profile_offwind_ac=RESOURCES + "profile_offwind-ac.nc", profile_offwind_dc=RESOURCES + "profile_offwind-dc.nc", h2_cavern=RESOURCES + "salt_cavern_potentials_s{simpl}_{clusters}.csv", diff --git a/rules/retrieve.smk b/rules/retrieve.smk index b830be251..18b424ff7 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -259,3 +259,17 @@ if config["enable"]["retrieve"]: "../envs/environment.yaml" script: "../scripts/retrieve_monthly_fuel_prices.py" + + +rule modify_cost_data: + input: + costs="data/costs_{year}.csv", + output: + "data/costs_{year}-modified.csv" + log: + LOGS + "modify_cost_data_{year}.log", + resources: + mem_mb=1000, + retries: 2 + script: + "../scripts/modify_cost_data.py" diff --git a/scripts/modify_cost_data.py b/scripts/modify_cost_data.py new file mode 100644 index 000000000..3e1f12f47 --- /dev/null +++ b/scripts/modify_cost_data.py @@ -0,0 +1,12 @@ + +import pandas as pd + +costs = pd.read_csv(snakemake.input.costs, index_col=[0, 1]).sort_index() + +if "modifications" in snakemake.input.keys(): + modifications = pd.read_csv(snakemake.input.modifications, index_col=[0, 1]).sort_index() + costs.loc[modifications.index] = modifications + print(modifications) + print( costs.loc[modifications.index]) + +costs.to_csv(snakemake.output[0])