Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib: Add load, solar, wind conversion to yaml components #60

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 106 additions & 4 deletions src/andromede/input_converter/src/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,119 @@ def _convert_thermal_to_component_list(
)
return components

def _convert_wind_to_component_list(
self, areas: list[Area]
) -> list[InputComponent]:
components = []

for area in areas:
try:
area.get_wind_matrix()
series_path = (
self.study_path
/ "input"
/ "wind"
/ "series"
/ f"wind_{area.id}.txt"
)

components.append(
InputComponent(
id=area.id,
model="wind",
parameters=[
InputComponentParameter(
name="wind",
type="timeseries",
timeseries=str(series_path),
)
],
)
)
except FileNotFoundError:
pass

return components

def _convert_solar_to_component_list(
self, areas: list[Area]
) -> list[InputComponent]:
components = []

for area in areas:
try:
area.get_solar_matrix()
series_path = (
self.study_path
/ "input"
/ "solar"
/ "series"
/ f"solar_{area.id}.txt"
)
components.extend(
[
InputComponent(
id=area.id,
model="solar",
parameters=[
InputComponentParameter(
name="solar",
type="timeseries",
timeseries=str(series_path),
)
],
)
]
)
except FileNotFoundError:
pass

return components

def _convert_load_to_component_list(
self, areas: list[Area]
) -> list[InputComponent]:
components = []
for area in areas:
try:
area.get_load_matrix()
series_path = (
self.study_path
/ "input"
/ "load"
/ "series"
/ f"load_{area.id}.txt"
)
components.extend(
[
InputComponent(
id=area.id,
model="load",
parameters=[
InputComponentParameter(
name="load",
type="timeseries",
timeseries=str(series_path),
)
],
)
]
)
except FileNotFoundError:
pass

return components

def convert_study_to_input_study(self) -> InputStudy:
areas = self.study.read_areas()
area_components = self._convert_area_to_component_list(areas)
list_components = []
list_components.extend(self._convert_renewable_to_component_list(areas))
list_components.extend(self._convert_thermal_to_component_list(areas))
# loads = convert_load_matrix_to_component_list(areas, root_path)
list_components.extend(self._convert_load_to_component_list(areas))
list_components.extend(self._convert_wind_to_component_list(areas))
list_components.extend(self._convert_solar_to_component_list(areas))

# winds = convert_wind_matrix_to_component_list(areas, root_path)
# solars = convert_solar_matrix_to_component_list(areas, root_path)
# misc_gens = convert_misc_gen_to_component_list(areas, root_path)
return InputStudy(nodes=area_components, components=list_components)

def process_all(self) -> None:
Expand Down
78 changes: 76 additions & 2 deletions tests/input_converter/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_convert_area_to_component(self, local_study_w_areas):
area_components.sort(key=lambda x: x.id)
assert area_components == expected_area_components

def test_convert_renewables_to_input_study(self, local_study_with_renewable):
def test_convert_renewables_to_component(self, local_study_with_renewable):
areas, converter = self._init_area_reading(local_study_with_renewable)
study_path = converter.study_path
renewables_components = converter._convert_renewable_to_component_list(areas)
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_convert_renewables_to_input_study(self, local_study_with_renewable):
]
assert renewables_components == expected_renewable_component

def test_convert_thermals_to_input_study(self, local_study_w_thermal):
def test_convert_thermals_to_component(self, local_study_w_thermal):
areas, converter = self._init_area_reading(local_study_w_thermal)

thermals_components = converter._convert_thermal_to_component_list(areas)
Expand Down Expand Up @@ -406,3 +406,77 @@ def test_convert_area_to_yaml(self, local_study_w_areas):
expected_validated_data.nodes.sort(key=lambda x: x.id)
validated_data.nodes.sort(key=lambda x: x.id)
assert validated_data == expected_validated_data

def test_convert_wind_to_component(self, local_study_w_areas, fr_wind):
areas, converter = self._init_area_reading(local_study_w_areas)

wind_components = converter._convert_wind_to_component_list(areas)
study_path = converter.study_path

wind_timeseries = str(study_path / "input" / "wind" / "series" / f"wind_fr.txt")
expected_wind_components = InputComponent(
id="fr",
model="wind",
scenario_group=None,
parameters=[
InputComponentParameter(
name="wind",
type="timeseries",
scenario_group=None,
value=None,
timeseries=f"{wind_timeseries}",
),
],
)

assert wind_components[0] == expected_wind_components

def test_convert_solar_to_component(self, local_study_w_areas, fr_solar):
areas, converter = self._init_area_reading(local_study_w_areas)

solar_components = converter._convert_solar_to_component_list(areas)
study_path = converter.study_path

solar_timeseries = str(
study_path / "input" / "solar" / "series" / f"solar_fr.txt"
)
expected_solar_components = InputComponent(
id="fr",
model="solar",
scenario_group=None,
parameters=[
InputComponentParameter(
name="solar",
type="timeseries",
scenario_group=None,
value=None,
timeseries=f"{solar_timeseries}",
),
],
)

assert solar_components[0] == expected_solar_components

def test_convert_load_to_component(self, local_study_w_areas, fr_load):
areas, converter = self._init_area_reading(local_study_w_areas)

load_components = converter._convert_load_to_component_list(areas)
study_path = converter.study_path

load_timeseries = str(study_path / "input" / "load" / "series" / f"load_fr.txt")
expected_load_components = InputComponent(
id="fr",
model="load",
scenario_group=None,
parameters=[
InputComponentParameter(
name="load",
type="timeseries",
scenario_group=None,
value=None,
timeseries=f"{load_timeseries}",
),
],
)

assert load_components[0] == expected_load_components
3 changes: 0 additions & 3 deletions tests/unittests/data/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,3 @@ study:
port_1: injection_port
component2: G
port_2: injection_port



Loading