Skip to content

Commit 98f94e4

Browse files
Merge branch 'main' into pypsa-de-merge
2 parents 6c0da03 + 849eced commit 98f94e4

File tree

6 files changed

+20
-50
lines changed

6 files changed

+20
-50
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,3 @@ repos:
5151
rev: v0.11.0
5252
hooks:
5353
- id: snakefmt
54-
55-
56-
- repo: https://github.com/sourcery-ai/sourcery
57-
rev: v1.37.0
58-
hooks:
59-
- id: sourcery
60-
args: [--diff=git diff HEAD, --no-summary]

config/config.at.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ run:
66
prefix: v2025.03
77
name:
88
# - ExPol
9-
# - AT10_KN2040
10-
- KN2045_Mix
9+
- AT10_KN2040
10+
# - KN2045_Mix
1111
# - KN2045_Elek
1212
# - KN2045_H2
1313
# - KN2045_NFniedrig

config/test/config.at10.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
run:
66
prefix: "test-sector-myopic-at10"
77
name:
8-
- KN2045_Mix
8+
- AT10_KN2040
99

1010
# need to include additional neighbor countries, because the
1111
# administrative clustering will not filter lines to connected

evals/plots/sankey.py

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,15 @@
1515
pd.set_option("display.max_columns", 20)
1616

1717

18-
def read_iamc_data_frame():
18+
def read_iamc_data_frame(filepath):
1919
xls = pd.read_excel(
20-
"/IdeaProjects/pypsa-at/results/v2025.02/KN2045_Mix/evaluation/exported_iamc_variables.xlsx",
20+
filepath,
2121
index_col=[0, 1, 2, 3, 4],
2222
)
2323
xls.columns.name = "Year"
2424
return xls.stack()
2525

2626

27-
def main():
28-
year = "2050"
29-
region = "GB0"
30-
31-
df = read_iamc_data_frame()
32-
df = rename_aggregate(df, "TWh", level="Unit").div(1e6)
33-
df = filter_by(df, Year=year, Region=region)
34-
35-
raw_mapping = get_mapping(df)
36-
variables = df.index.unique("Variable")
37-
for k, v in raw_mapping.items():
38-
if k in variables:
39-
clean_mapping[k] = v
40-
else:
41-
print(f"Skipping '{k}' because it does not exist in {region} {year}.")
42-
43-
iamc = pyam.IamDataFrame(df)
44-
fig = iamc.plot.sankey(mapping=clean_mapping)
45-
46-
fig.update_layout(height=600)
47-
48-
plotly.io.show(fig)
49-
50-
5127
def get_mapping(df) -> (dict, set):
5228
mapping = {}
5329
nodes = set()
@@ -147,14 +123,15 @@ def get_xmap(nodes) -> dict:
147123

148124

149125
if __name__ == "__main__":
150-
FILEPATH = "/IdeaProjects/pypsa-at/results/v2025.02/KN2045_Mix/evaluation/exported_iamc_variables.xlsx"
151-
df = read_iamc_data_frame()
126+
df = read_iamc_data_frame(
127+
filepath="/IdeaProjects/pypsa-at/results/v2025.03/AT10_KN2040/evaluation/exported_iamc_variables.xlsx"
128+
)
152129
mapping, nodes = get_mapping(df)
153130
mapping_sorted = {k: mapping[k] for k in sorted(mapping, key=sort_mapping)}
154131
xmap = get_xmap(nodes)
155132
df = rename_aggregate(df, "TWh", level="Unit").div(1e6)
156133
year = "2050"
157-
region = "GB0"
134+
region = "FR0"
158135
df = filter_by(df, Year=year, Region=region)
159136

160137
clean_mapping = {}
@@ -173,8 +150,6 @@ def get_xmap(nodes) -> dict:
173150

174151
node["x"] = [xmap.get(label, 0.2) for label in node["label"]]
175152
node["y"] = [xmap.get(label, 0.4) for label in node["label"]]
176-
# node["y"] = [ymap[label] for label in node["label"]]
177-
# node["color"] = [colormap[label] for label in node["label"]]
178153

179154
new_sankey = Sankey(
180155
node=node,
@@ -184,6 +159,6 @@ def get_xmap(nodes) -> dict:
184159

185160
fig = Figure(data=[new_sankey])
186161

187-
fig.update_layout(height=600)
162+
fig.update_layout(height=800)
188163

189164
plotly.io.show(fig)

scripts/pypsa-at/export_iamc_variables.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ def collect_regional_nh3_loads():
382382
)
383383

384384
# check that imbalances are equal to imbalances in the network
385-
pd.testing.assert_series_equal(imbalances_iamc, imbalances_bus, check_names=False)
385+
pd.testing.assert_series_equal(
386+
imbalances_iamc, imbalances_bus, check_names=False, atol=1e-3
387+
)
386388
if not imbalances_bus.abs().le(1e-3).all():
387389
logger.warning(f"Imbalances detected for bus carrier {bc}:\n{imbalances_bus}.")
388390
var[f"{FINAL}|{BC_ALIAS[bc]}|Agriculture"] = nh3_regional_supply.groupby(IDX).sum()
@@ -1190,9 +1192,9 @@ def calculate_sankey_totals():
11901192
if "snakemake" not in globals():
11911193
snakemake = mock_snakemake(
11921194
"export_iamc_variables",
1193-
run="KN2045_Mix",
1194-
prefix="test-sector-myopic-at10",
1195-
config="config/test/config.at10.yaml",
1195+
run="AT10_KN2040",
1196+
# prefix="test-sector-myopic-at10",
1197+
# config="config/test/config.at10.yaml",
11961198
)
11971199
configure_logging(snakemake)
11981200

@@ -1204,8 +1206,8 @@ def calculate_sankey_totals():
12041206
"drop_zeros": False,
12051207
"drop_unit": False,
12061208
}
1207-
# calculate all statistics and process them to IAMC data model. The idea is to
1208-
# calculate everything once and remove rows from the global statistic. This way
1209+
# Calculate all statistics and process them to IAMC datamodel. The idea is to
1210+
# calculate everything just once and remove rows from the global statistic. This way
12091211
# we make sure that nothing is counted twice or forgotten.
12101212
SUPPLY = collect_myopic_statistics(
12111213
networks, "supply", groupby=groupby, **kwargs

scripts/pypsa-de/build_scenarios.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def write_to_scenario_yaml(input, output, scenarios, df):
178178
for scenario in scenarios:
179179
if config.get(scenario) is None:
180180
logger.warning(
181-
f"Found an empty scenario config for {scenario}. Using default config `pypsa.de.yaml`."
181+
f"Found an empty scenario config for {scenario}. Using default config `pypsa.at.yaml`."
182182
)
183183
config[scenario] = {}
184184
if config[scenario].get("weather_year", False):
@@ -199,7 +199,7 @@ def write_to_scenario_yaml(input, output, scenarios, df):
199199
.get(
200200
"reference_scenario",
201201
snakemake.config["iiasa_database"]["reference_scenario"],
202-
) # Using the default reference scenario from pypsa.de.yaml
202+
) # Using the default reference scenario from pypsa.at.yaml
203203
)
204204

205205
planning_horizons = [

0 commit comments

Comments
 (0)