Skip to content

Commit 180137e

Browse files
committed
fix: reduce number of levels in summary files
1 parent 5be0961 commit 180137e

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

scripts/make_cumulative_costs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def calculate_cumulative_cost(costs, planning_horizons):
6060
configure_logging(snakemake)
6161
set_scenario_config(snakemake)
6262

63-
costs = pd.read_csv(snakemake.input.costs, index_col=[0, 1, 2], header=[0, 1, 2])
63+
costs = pd.read_csv(snakemake.input.costs, index_col=[0, 1, 2], header=0)
64+
65+
# clean multiindex: add cluster/opts from scenario & make planning horizons numeric
66+
cluster = str(snakemake.params.scenario["clusters"][0])
67+
sector_opts = snakemake.params.scenario.get("sector_opts", [""])[0]
6468

65-
# clean multiindex: handle empty opts/sector_opts & make planning horizons numeric
6669
costs.columns = pd.MultiIndex.from_tuples(
67-
[
68-
(lvl0, "" if lvl1.startswith("Unnamed:") else lvl1, pd.to_numeric(lvl2))
69-
for lvl0, lvl1, lvl2 in costs.columns
70-
],
70+
[(cluster, sector_opts, pd.to_numeric(horizon)) for horizon in costs.columns],
7171
names=["cluster", "opt", "planning_horizon"],
7272
)
7373

scripts/make_global_summary.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858

5959
summaries = pd.concat(summaries, axis=1, keys=summaries_dict.keys())
6060

61+
# Drop redundant second level from column MultiIndex (original column names)
62+
if (
63+
isinstance(summaries.columns, pd.MultiIndex)
64+
and summaries.columns.nlevels == 2
65+
):
66+
summaries.columns = summaries.columns.droplevel(1)
67+
6168
summaries.sort_index().to_csv(snakemake.output[kind])
6269

6370
del summaries

scripts/plot_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def plot_carbon_budget_distribution(input_eurostat, options):
496496
configure_logging(snakemake)
497497
set_scenario_config(snakemake)
498498

499-
n_header = 3
499+
n_header = 1
500500

501501
plot_costs()
502502

0 commit comments

Comments
 (0)