Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ template:
name: wind
generator-version-compatibility: X.Y #TODO: find this information
model: antares-historic.renewable
scenario-group: wind_group
template-parameters:
- name: area
description: "Area identifier for the wind component"
Expand Down
60 changes: 46 additions & 14 deletions src/gems/input_converter/src/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
# TODO: Move all global variables in a config class, that is used in AntaresStudyConverter constructor


# TODO: Move all global variables in a config class, that is used in AntaresStudyConverter constructor


class AntaresStudyConverter:
def __init__(
self,
Expand All @@ -70,6 +67,7 @@ def __init__(
period: Optional[int] = None,
lib_paths: Optional[list[str]] = None,
models_to_convert: list[str] = list(MODEL_NAME_TO_FILE_NAME.keys()),
scenario_builder_file: Optional[Path] = None,
):
"""
Initialize processor
Expand All @@ -78,6 +76,7 @@ def __init__(
self.period: int = period if period else 168
self.lib_paths: list[str] = lib_paths if lib_paths else []
self.models_to_convert = models_to_convert
self.scenario_builder_file = scenario_builder_file

try:
self.mode = ConversionMode(mode)
Expand Down Expand Up @@ -129,6 +128,7 @@ def _convert_thermal_to_component_list(
components: list,
connections: list,
area_connections: list,
scenario_group: Optional[str] = None,
) -> tuple[list[InputComponent], list[InputPortConnections]]:
self.logger.info("Converting thermals to component list...")
# Add thermal components for each area
Expand Down Expand Up @@ -211,6 +211,8 @@ def _convert_thermal_to_component_list(
),
tdp.generate_component_parameter("p_max_cluster"),
],
# add scenario-group to each thermal component if provided
scenario_group=scenario_group,
)
)
if self.mode == ConversionMode.FULL:
Expand Down Expand Up @@ -331,19 +333,26 @@ def _iterate_through_model(
area_connections: list,
mp: ModelConversionPreprocessor,
) -> None:
parameters = [
InputComponentParameter(
id=param.id,
time_dependent=bool(param.time_dependent),
scenario_dependent=bool(param.scenario_dependent),
value=mp.convert_param_value(param.id, param.value),
)
for param in resolved_conversion_template.component.parameters
]
scenario_group = getattr(resolved_conversion_template, "scenario_group", None)
kwargs = {}
if scenario_group is not None:
kwargs["scenario_group"] = scenario_group

components.append(
InputComponent(
id=resolved_conversion_template.component.id,
model=resolved_conversion_template.model,
parameters=[
InputComponentParameter(
id=param.id,
time_dependent=bool(param.time_dependent),
scenario_dependent=bool(param.scenario_dependent),
value=mp.convert_param_value(param.id, param.value),
)
for param in resolved_conversion_template.component.parameters
],
parameters=parameters,
**kwargs,
)
)

Expand Down Expand Up @@ -419,13 +428,17 @@ def _convert_model_to_component_list(
)
else:
if conversion_template.name == "thermal":
# Legacy conversion for thermal cluster
# Legacy conversion for thermal cluster.
# Pass scenario_group (if declared in template) into the thermal conversion
self._convert_thermal_to_component_list(
self.get_model_name_among_libs("thermal"),
virtual_objects,
components,
connections,
area_connections,
scenario_group=getattr(
conversion_template, "scenario_group", None
),
)
return components, connections, area_connections
for area in self.areas.values():
Expand Down Expand Up @@ -575,6 +588,8 @@ def _convert_single_model(

def convert_study_to_input_system(self) -> InputSystem:
self._copy_libs_to_model_librairies()
self._copy_scenario_builder()

self._create_dataseries_dir()
model_conversion_templates = self._build_model_conversion_templates()
self._check_converted_models_are_in_libs(model_conversion_templates)
Expand Down Expand Up @@ -630,4 +645,21 @@ def _build_virtual_objects_repo(
def process_all(self) -> None:
system = self.convert_study_to_input_system()
self.logger.info("Dumping input system into yaml file...")
dump_to_yaml(model=system, output_path=self.output_system_path)
dump_to_yaml(model=system, output_path=self.output_path)
# copy modeler-scenariobuilder.dat to input/data-series if provided
# self._copy_scenario_builder()

def _copy_scenario_builder(self) -> None:
if not self.scenario_builder_file:
return

dest = self.output_folder / "input" / "data-series"
dest.mkdir(parents=True, exist_ok=True)

dest_file = dest / "modeler-scenariobuilder.dat" # enforce name

try:
shutil.copy2(self.scenario_builder_file, dest_file)
self.logger.info(f"Copied scenario builder file to {dest_file}")
except Exception as e:
self.logger.warning(f"Failed to copy scenario builder file: {e}")
2 changes: 2 additions & 0 deletions src/gems/input_converter/src/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class ConversionTemplate(ModifiedBaseModel):
legacy_objects_to_delete: list[ReferencedLegacyObjects] = Field(
default_factory=list
)
scenario_group: Optional[str] = None

def resolve_template(
self, template_pattern: str, value: str
Expand Down Expand Up @@ -274,6 +275,7 @@ def resolve_template(
connections=connections,
area_connections=area_connections,
legacy_objects_to_delete=legacy_objects_to_delete,
scenario_group=self.scenario_group, # <-- propagate it!
)

def get_excluded_objects_ids(self) -> VirtualObjectsRepository:
Expand Down
Loading
Loading