-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for build powerplants (#1432)
* code: add unit test for add_custom_powerplants * remove unnecessary file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * code: add test parametrization * code: pre-commit fix * code: unit test for build_powerplants.py, modify Makefile and test.yaml * code: include requested comments to PR * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * code: new reformatting --------- Co-authored-by: Fabrizio Finozzi <fabriziofinozzi@Mac.homenet.telecomitalia.it> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
98d387c
commit 17628e9
Showing
9 changed files
with
340 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors | ||
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# coding: utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors | ||
# | ||
# SPDX-License-Identifier: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# coding: utf-8 | ||
|
||
import pathlib | ||
|
||
import pypsa | ||
import pytest | ||
import yaml | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def scigrid_network(): | ||
return pypsa.examples.scigrid_de(from_master=True) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def ac_dc_network(): | ||
return pypsa.examples.ac_dc_meshed(from_master=True) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def config(): | ||
path_config = pathlib.Path(pathlib.Path.cwd(), "config", "config.default.yaml") | ||
with open(path_config, "r") as file: | ||
config_dict = yaml.safe_load(file) | ||
return config_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# -*- coding: utf-8 -*- | ||
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# coding: utf-8 | ||
""" | ||
Tests the functionalities of scripts/build_powerplants.py. | ||
""" | ||
|
||
import pathlib | ||
import sys | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
||
sys.path.append("./scripts") | ||
|
||
from build_powerplants import ( | ||
add_custom_powerplants, | ||
replace_natural_gas_fueltype, | ||
replace_natural_gas_technology, | ||
) | ||
|
||
path_cwd = pathlib.Path.cwd() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"query_value,expected", | ||
[(False, (131, 18)), (True, (137, 18))], | ||
) | ||
def test_add_custom_powerplants(config, query_value, expected): | ||
""" | ||
Verify what returned by add_custom_powerplants. | ||
""" | ||
config_dict = config | ||
config_dict["electricity"]["custom_powerplants"] = query_value | ||
custom_powerplants_path = pathlib.Path( | ||
path_cwd, "test", "test_data", "custom_powerplants_DE.csv" | ||
) | ||
ppl_path = pathlib.Path(path_cwd, "test", "test_data", "powerplants_DE.csv") | ||
ppl_df = pd.read_csv(ppl_path) | ||
ppl_final = add_custom_powerplants( | ||
ppl_df, | ||
custom_powerplants_path, | ||
config_dict["electricity"]["custom_powerplants"], | ||
) | ||
assert ppl_df.shape == (131, 18) | ||
assert ppl_final.shape == expected | ||
|
||
|
||
def test_replace_natural_gas_technology(): | ||
""" | ||
Verify what returned by replace_natural_gas_technology. | ||
""" | ||
input_df = pd.DataFrame( | ||
{ | ||
"Name": [ | ||
"plant_hydro", | ||
"plant_ng_1", | ||
"plant_ng_2", | ||
"plant_ng_3", | ||
"plant_ng_4", | ||
], | ||
"Fueltype": [ | ||
"Hydro", | ||
"Natural Gas", | ||
"Natural Gas", | ||
"Natural Gas", | ||
"Natural Gas", | ||
], | ||
"Technology": [ | ||
"Run-Of-River", | ||
"Steam Turbine", | ||
"Combustion Engine", | ||
"Not Found", | ||
np.nan, | ||
], | ||
} | ||
) | ||
|
||
reference_df = pd.DataFrame( | ||
{ | ||
"Name": [ | ||
"plant_hydro", | ||
"plant_ng_1", | ||
"plant_ng_2", | ||
"plant_ng_3", | ||
"plant_ng_4", | ||
], | ||
"Fueltype": [ | ||
"Hydro", | ||
"Natural Gas", | ||
"Natural Gas", | ||
"Natural Gas", | ||
"Natural Gas", | ||
], | ||
"Technology": ["Run-Of-River", "CCGT", "OCGT", "CCGT", "CCGT"], | ||
} | ||
) | ||
modified_df = input_df.assign(Technology=replace_natural_gas_technology) | ||
comparison_df = modified_df.compare(reference_df) | ||
assert comparison_df.empty | ||
|
||
|
||
def test_replace_natural_gas_fueltype(): | ||
""" | ||
Verify what returned by replace_natural_gas_fueltype. | ||
""" | ||
input_df = pd.DataFrame( | ||
{ | ||
"Name": [ | ||
"plant_hydro", | ||
"plant_ng_1", | ||
"plant_ng_2", | ||
], | ||
"Fueltype": [ | ||
"Hydro", | ||
"Gas", | ||
"Natural", | ||
], | ||
"Technology": [ | ||
"Run-Of-River", | ||
"CCGT", | ||
"OCGT", | ||
], | ||
} | ||
) | ||
|
||
reference_df = pd.DataFrame( | ||
{ | ||
"Name": [ | ||
"plant_hydro", | ||
"plant_ng_1", | ||
"plant_ng_2", | ||
], | ||
"Fueltype": [ | ||
"Hydro", | ||
"Natural Gas", | ||
"Natural Gas", | ||
], | ||
"Technology": [ | ||
"Run-Of-River", | ||
"CCGT", | ||
"OCGT", | ||
], | ||
} | ||
) | ||
modified_df = input_df.assign(Fueltype=replace_natural_gas_fueltype) | ||
comparison_df = modified_df.compare(reference_df) | ||
assert comparison_df.empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Name,Fueltype,Technology,Set,Country,Capacity,Efficiency,DateIn,DateRetrofit,DateOut,lat,lon,Duration,Volume_Mm3,DamHeight_m,StorageCapacity_MWh,EIC,projectID | ||
Eichenkofen,Hydro,Run-Of-River,PP,DE,0.05,,1955.5420560747664,1955.5420560747664,2055.542056074766,48.345217,11.921901,,0.0,0.0,0.0,{},{'JRC': {'JRC-H3173'}} | ||
Isenkraftwerk Generator,Hydro,Run-Of-River,PP,DE,3.15,,1955.5420560747664,1955.5420560747664,2055.542056074766,48.26,12.634,,0.0,0.0,0.0,{},"{'JRC': {'JRC-H2724', 'JRC-H2725', 'JRC-H2719', 'JRC-H2723', 'JRC-H2727', 'JRC-H2720', 'JRC-H2721', 'JRC-H2726', 'JRC-H2722'}}" | ||
Wasserkraftwerk Dietldorf,Hydro,Run-Of-River,PP,DE,0.108,,1955.5420560747664,1955.5420560747664,2055.542056074766,49.205998,11.943661,,0.0,0.0,0.0,{},{'JRC': {'JRC-H2963'}} | ||
Bmkw Konigs Wusterhausen,Bioenergy,Steam Turbine,PP,DE,17.1,0.38,2003.0,2003.0,2023.0,52.30479,13.636029999999998,,0.0,0.0,0.0,{},{'OPSD': {'BNA0549'}} | ||
Datteln,Hard Coal,Steam Turbine,CHP,DE,1014.1306522194916,,1964.0,1964.0,2038.0,51.6293,7.3307,,0.0,0.0,0.0,{},"{'BEYONDCOAL': {'BEYOND-DE-501'}, 'GEM': {'G100000102255', 'G100000102253', 'G100000102254', 'G100000102252'}, 'GEO': {'GEO-44321'}}" | ||
Irsching,Natural Gas,CCGT,PP,DE,1822.0,0.5867942430703624,2010.0,2011.0,2051.0,48.767,11.58,,0.0,0.0,0.0,{'11WD2IRSC000179N'},"{'ENTSOE': {'11WD2IRSC000179N'}, 'GEM': {'L100000400188'}, 'OPSD': {'BNA0995', 'BNA0994'}, 'GEO': {'GEO-44306'}}" |
Oops, something went wrong.