From beefb57c25dd3aa235320d884d74ef846e8571c5 Mon Sep 17 00:00:00 2001 From: Tom Brown Date: Fri, 21 Aug 2020 12:15:01 +0200 Subject: [PATCH] Fix plotting of maps and balances; move log/benchmark to results/ --- Snakefile | 24 ++++++++++++------------ scripts/plot_network.py | 4 +--- scripts/plot_summary.py | 16 ++++++++-------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Snakefile b/Snakefile index 3e4b0425..54b8c241 100644 --- a/Snakefile +++ b/Snakefile @@ -213,7 +213,7 @@ rule prepare_sector_network: output: config['results_dir'] + config['run'] + '/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}.nc' threads: 1 resources: mem_mb=2000 - benchmark: "benchmarks/prepare_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}" + benchmark: config['results_dir'] + config['run'] + "/benchmarks/prepare_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}" script: "scripts/prepare_sector_network.py" @@ -243,8 +243,8 @@ rule make_summary: networks=expand(config['results_dir'] + config['run'] + "/postnetworks/elec_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}.nc", **config['scenario']), costs=config['costs_dir'] + "costs_{}.csv".format(config['scenario']['planning_horizons'][0]), - #plots=expand(config['results_dir'] + config['run'] + "/maps/elec_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}-costs-all_{co2_budget_name}_{planning_horizons}.pdf", - # **config['scenario']) + plots=expand(config['results_dir'] + config['run'] + "/maps/elec_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}-costs-all_{co2_budget_name}_{planning_horizons}.pdf", + **config['scenario']) #heat_demand_name='data/heating/daily_heat_demand.h5' output: nodal_costs=config['summary_dir'] + '/' + config['run'] + '/csvs/nodal_costs.csv', @@ -276,7 +276,7 @@ rule plot_summary: output: costs=config['summary_dir'] + '/' + config['run'] + '/graphs/costs.pdf', energy=config['summary_dir'] + '/' + config['run'] + '/graphs/energy.pdf', - #balances=config['summary_dir'] + '/' + config['run'] + '/graphs/balances-energy.pdf' + balances=config['summary_dir'] + '/' + config['run'] + '/graphs/balances-energy.pdf' threads: 2 resources: mem_mb=10000 script: @@ -292,10 +292,10 @@ if config["foresight"] == "overnight": output: config['results_dir'] + config['run'] + "/postnetworks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}.nc" shadow: "shallow" log: - solver="logs/" + config['run'] + "/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_solver.log", - python="logs/" + config['run'] + "/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_python.log", - memory="logs/" + config['run'] + "/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_memory.log" - benchmark: "benchmarks/solve_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}" + solver=config['results_dir'] + config['run'] + "/logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_solver.log", + python=config['results_dir'] + config['run'] + "/logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_python.log", + memory=config['results_dir'] + config['run'] + "/logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_memory.log" + benchmark: config['results_dir'] + config['run'] + "/benchmarks/solve_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}" threads: 4 resources: mem_mb=config['solving']['mem'] # group: "solve" # with group, threads is ignored https://bitbucket.org/snakemake/snakemake/issues/971/group-job-description-does-not-contain @@ -348,10 +348,10 @@ if config["foresight"] == "myopic": output: config['results_dir'] + config['run'] + "/postnetworks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}.nc" shadow: "shallow" log: - solver="logs/" + config['run'] + "/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_solver.log", - python="logs/" + config['run'] + "/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_python.log", - memory="logs/" + config['run'] + "/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_memory.log" - benchmark: "benchmarks/solve_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}" + solver=config['results_dir'] + config['run'] + "/logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_solver.log", + python=config['results_dir'] + config['run'] + "/logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_python.log", + memory=config['results_dir'] + config['run'] + "/logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}_memory.log" + benchmark: config['results_dir'] + config['run'] + "/benchmarks/solve_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{sector_opts}_{co2_budget_name}_{planning_horizons}" threads: 4 resources: mem_mb=config['solving']['mem'] script: "scripts/solve_network.py" diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 6672c431..707481e7 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -253,9 +253,7 @@ def plot_h2_map(network): elec = n.links.index[n.links.carrier == "H2 Electrolysis"] - bus_sizes = pd.Series(0., index=n.buses.index) - bus_sizes.loc[elec.str.replace(" H2 Electrolysis", "")] = \ - n.links.loc[elec, "p_nom_opt"].values / bus_size_factor + bus_sizes = n.links.loc[elec,"p_nom_opt"].groupby(n.links.loc[elec,"bus0"]).sum() / bus_size_factor # make a fake MultiIndex so that area is correct for legend bus_sizes.index = pd.MultiIndex.from_product( diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 37638f47..caba5f18 100755 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -188,18 +188,18 @@ def plot_balances(): df = df/1e6 #remove trailing link ports - df.index = [i[:-1] if i[-1:] in ["0","1","2","3"] else i for i in df.index] + df.index = [i[:-1] if ((i != "co2") and (i[-1:] in ["0","1","2","3"])) else i for i in df.index] df = df.groupby(df.index.map(rename_techs)).sum() - to_drop = df.index[df.abs().max(axis=1) < snakemake.config['plotting']['energy_threshold']] + to_drop = df.index[df.abs().max(axis=1) < snakemake.config['plotting']['energy_threshold']/10] print("dropping") print(df.loc[to_drop]) df = df.drop(to_drop) - + print(df.sum()) if df.empty: @@ -209,7 +209,7 @@ def plot_balances(): new_columns = df.columns.sort_values() - + fig, ax = plt.subplots() fig.set_size_inches((12,8)) @@ -255,10 +255,10 @@ if __name__ == "__main__": snakemake.output[item] = snakemake.config['summary_dir'] + '/{name}/graphs/{item}.pdf'.format(name=snakemake.config['run'],item=item) snakemake.input["balances"] = snakemake.config['summary_dir'] + '/test/csvs/supply_energy.csv' snakemake.output["balances"] = snakemake.config['summary_dir'] + '/test/graphs/balances-energy.csv' - - n_header = 5 + + n_header = 5 plot_costs() plot_energy() - - #plot_balances() + + plot_balances()