Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
markushal committed Sep 16, 2024
1 parent 0e458fb commit 26346d8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ def network_green_iron(api) -> Tuple[pypsa.Network, dict, dict]:

@pytest.mark.xfail
def test_issue_564(network_green_iron, api):
# calculate costs from optimization tab:
n, metadata, settings = network_green_iron
res_opt = calc_aggregate_statistics(n, include_debugging_output=True)

# get costs from costs tab:
res_costs = api.calculate(**settings)
res_costs_agg = (
res_costs[0]
Expand Down Expand Up @@ -282,14 +285,19 @@ def test_issue_564(network_green_iron, api):
res_costs_agg["total_opt"] - res_costs_agg["total"]
).fillna(0)

# call optimize function directly:
res_optimize = optimize(metadata["opt_input_data"])[0]

# write costs data to excel, and metadata to json:
if not os.path.exists("tests/out"):
os.makedirs("tests/out")
res_costs_agg.to_excel("tests/out/test_issue_564.xlsx")
with open("tests/out/issue_564_metadata.json", "w") as f:
with open("tests/out/issue_564_metadata_optimize_input.json", "w") as f:
dump(metadata, f)
with open("tests/out/issue_564_metadata_optimize_output.json", "w") as f:
dump(res_optimize, f)

# extract input data:
# extract DRI input data:
input_data = api.get_input_data(scenario=settings["scenario"])
input_data_dri = input_data.loc[
input_data["process_code"] == "Green iron reduction"
Expand All @@ -309,6 +317,11 @@ def test_issue_564(network_green_iron, api):
# annuized capex should match:
assert capex_ann_input + opex_fix == pytest.approx(capex_ann_opt)

# FLH from optimization tab and optimize function output should match:
flh_opt_tab = res_opt.at["Derivative production", "Full load hours (h)"]
flh_opt_function = res_optimize["DERIV"]["FLH"] * 8760
assert flh_opt_tab == pytest.approx(flh_opt_function)

# assert that differences between costs and opt tab are zero:
# this currently fails
for i in res_costs_agg["diff"]:
Expand Down

0 comments on commit 26346d8

Please sign in to comment.