diff --git a/doc/release_notes.rst b/doc/release_notes.rst index c394cb06..b2aac457 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -64,6 +64,8 @@ Upcoming Release * The ``highs`` solver was added to the default environment file. +* Various minor bugfixes to the perfect foresight workflow, though perfect foresight must still be considered experimental. + * It is now possible to determine the directory for shared resources by setting `shared_resources` to a string. * A ``test.sh`` script was added to the repository to run the tests locally. diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 0586ec01..a8f419c3 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -730,6 +730,40 @@ rule build_district_heat_share: "../scripts/build_district_heat_share.py" +rule build_existing_heating_distribution: + params: + baseyear=config["scenario"]["planning_horizons"][0], + sector=config["sector"], + existing_capacities=config["existing_capacities"], + input: + existing_heating="data/existing_infrastructure/existing_heating_raw.csv", + clustered_pop_layout=RESOURCES + "pop_layout_elec_s{simpl}_{clusters}.csv", + clustered_pop_energy_layout=RESOURCES + + "pop_weighted_energy_totals_s{simpl}_{clusters}.csv", + district_heat_share=RESOURCES + + "district_heat_share_elec_s{simpl}_{clusters}_{planning_horizons}.csv", + output: + existing_heating_distribution=RESOURCES + + "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv", + wildcard_constraints: + planning_horizons=config["scenario"]["planning_horizons"][0], #only applies to baseyear + threads: 1 + resources: + mem_mb=2000, + log: + LOGS + + "build_existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.log", + benchmark: + ( + BENCHMARKS + + "build_existing_heating_distribution/elec_s{simpl}_{clusters}_{planning_horizons}" + ) + conda: + "../envs/environment.yaml" + script: + "../scripts/build_existing_heating_distribution.py" + + rule prepare_sector_network: params: co2_budget=config["co2_budget"], diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index 75334073..94e75a5d 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -3,40 +3,6 @@ # SPDX-License-Identifier: MIT -rule build_existing_heating_distribution: - params: - baseyear=config["scenario"]["planning_horizons"][0], - sector=config["sector"], - existing_capacities=config["existing_capacities"], - input: - existing_heating="data/existing_infrastructure/existing_heating_raw.csv", - clustered_pop_layout=RESOURCES + "pop_layout_elec_s{simpl}_{clusters}.csv", - clustered_pop_energy_layout=RESOURCES - + "pop_weighted_energy_totals_s{simpl}_{clusters}.csv", - district_heat_share=RESOURCES - + "district_heat_share_elec_s{simpl}_{clusters}_{planning_horizons}.csv", - output: - existing_heating_distribution=RESOURCES - + "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv", - wildcard_constraints: - planning_horizons=config["scenario"]["planning_horizons"][0], #only applies to baseyear - threads: 1 - resources: - mem_mb=2000, - log: - LOGS - + "build_existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.log", - benchmark: - ( - BENCHMARKS - + "build_existing_heating_distribution/elec_s{simpl}_{clusters}_{planning_horizons}" - ) - conda: - "../envs/environment.yaml" - script: - "../scripts/build_existing_heating_distribution.py" - - rule add_existing_baseyear: params: baseyear=config["scenario"]["planning_horizons"][0], diff --git a/rules/solve_perfect.smk b/rules/solve_perfect.smk index 76051976..9e164a16 100644 --- a/rules/solve_perfect.smk +++ b/rules/solve_perfect.smk @@ -45,38 +45,6 @@ rule add_existing_baseyear: "../scripts/add_existing_baseyear.py" -rule add_brownfield: - params: - H2_retrofit=config["sector"]["H2_retrofit"], - H2_retrofit_capacity_per_CH4=config["sector"]["H2_retrofit_capacity_per_CH4"], - threshold_capacity=config["existing_capacities"]["threshold_capacity"], - input: - network=RESULTS - + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", - network_p=solved_previous_horizon, #solved network at previous time step - costs="data/costs_{planning_horizons}.csv", - cop_soil_total=RESOURCES + "cop_soil_total_elec_s{simpl}_{clusters}.nc", - cop_air_total=RESOURCES + "cop_air_total_elec_s{simpl}_{clusters}.nc", - output: - RESULTS - + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", - threads: 4 - resources: - mem_mb=10000, - log: - LOGS - + "add_brownfield_elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.log", - benchmark: - ( - BENCHMARKS - + "add_brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" - ) - conda: - "../envs/environment.yaml" - script: - "../scripts/add_brownfield.py" - - rule prepare_perfect_foresight: input: **{ @@ -192,6 +160,3 @@ rule make_summary_perfect: "../envs/environment.yaml" script: "../scripts/make_summary_perfect.py" - - -ruleorder: add_existing_baseyear > add_brownfield diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index f5ae3919..278472f6 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -162,15 +162,17 @@ def concat_networks(years): add_build_year_to_new_assets(network, year) # static ---------------------------------- - # (1) add buses and carriers - for component in network.iterate_components(["Bus", "Carrier"]): - df_year = component.df - # get missing assets - missing = get_missing(df_year, n, component.list_name) - import_components_from_dataframe(n, missing, component.name) - # (2) add generators, links, stores and loads for component in network.iterate_components( - ["Generator", "Link", "Store", "Load", "Line", "StorageUnit"] + [ + "Bus", + "Carrier", + "Generator", + "Link", + "Store", + "Load", + "Line", + "StorageUnit", + ] ): df_year = component.df.copy() missing = get_missing(df_year, n, component.list_name) @@ -199,8 +201,13 @@ def concat_networks(years): pnl[k].loc[pnl_year.index, pnl_year.columns] = pnl_year else: - # this is to avoid adding multiple times assets with - # infinite lifetime as ror + # For components that aren't new, we just extend + # time-varying data from the previous investment + # period. + if i > 0: + pnl[k].loc[(year,)] = pnl[k].loc[(years[i - 1],)].values + + # Now, add time-varying data for new components. cols = pnl_year.columns.difference(pnl[k].columns) pnl[k] = pd.concat([pnl[k], pnl_year[cols]], axis=1)