Skip to content

Commit

Permalink
bugfix [#61]: handling for not received schedules and business type s…
Browse files Browse the repository at this point in the history
…election for different time horizons
  • Loading branch information
m-karo committed Dec 18, 2024
1 parent ca8b59a commit dc79494
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions emf/loadflow_tool/model_merger/model_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ def handle(self, task_object: dict, **kwargs):
# Get aligned schedules
ac_schedules = scaler.query_acnp_schedules(time_horizon=time_horizon, scenario_timestamp=scenario_datetime)
dc_schedules = scaler.query_hvdc_schedules(time_horizon=time_horizon, scenario_timestamp=scenario_datetime)
# Scale balance
solved_model['network'] = scaler.scale_balance(network=solved_model['network'],
ac_schedules=ac_schedules,
dc_schedules=dc_schedules)
# Scale balance if all schedules were received
if all([ac_schedules, dc_schedules]):
solved_model['network'] = scaler.scale_balance(network=solved_model['network'],
ac_schedules=ac_schedules,
dc_schedules=dc_schedules)
else:
logger.warning(f"Schedule reference data not available, skipping model scaling")

merge_end = datetime.datetime.now(datetime.UTC)
logger.info(f"Loadflow status of main island: {solved_model['LOADFLOW_RESULTS'][0]['status_text']}")
Expand Down
15 changes: 9 additions & 6 deletions emf/loadflow_tool/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
def query_hvdc_schedules(time_horizon: str,
scenario_timestamp: str | datetime) -> dict | None:
"""
Method to get HVDC schedules (business type - B63)
:param time_horizon: time horizon of schedules; A01 - Day-ahead, A18 - Intraday
Method to get HVDC schedules (business type - B63 for PEVF, B67 - for CGMA)
:param time_horizon: time horizon of schedules
:param scenario_timestamp: start time in utc. Example: '2023-08-08T23:00:00Z'
:return: DC schedules in dict format
"""
Expand All @@ -72,10 +72,13 @@ def query_hvdc_schedules(time_horizon: str,
utc_start = datetime.fromisoformat(scenario_timestamp) - timedelta(minutes=30)
utc_end = datetime.fromisoformat(scenario_timestamp) + timedelta(minutes=30)

# Define business type by time horizon
business_type = "B63" if time_horizon in ["1D", "ID"] else "B67"

# Define metadata dictionary
metadata = {
"@time_horizon": time_horizon,
"TimeSeries.businessType": "B63",
"TimeSeries.businessType": business_type,
}

# Get HVDC schedules
Expand Down Expand Up @@ -113,7 +116,7 @@ def query_acnp_schedules(time_horizon: str,
scenario_timestamp: str | datetime) -> dict | None:
"""
Method to get ACNP schedules (business type - B64)
:param time_horizon: time horizon of schedules; A01 - Day-ahead, A18 - Intraday
:param time_horizon: time horizon of schedules
:param scenario_timestamp: start time in utc. Example: '2023-08-08T23:00:00Z'
:return: AC schedules in dict format
"""
Expand Down Expand Up @@ -497,8 +500,8 @@ def hvdc_schedule_mapper(row):
network = pp.network.load(model_path, parameters={"iidm.import.cgmes.source-for-iidm-id": "rdfID"})

# Query target schedules
ac_schedules = query_acnp_schedules(process_type="A01", utc_start="2024-12-16T08:00:00Z", utc_end="2024-12-16T09:00:00Z")
dc_schedules = query_hvdc_schedules(process_type="A01", utc_start="2024-12-16T08:00:00Z", utc_end="2024-12-16T09:00:00Z")
ac_schedules = query_acnp_schedules(time_horizon="1D", scenario_timestamp="2024-12-16T08:00:00Z")
dc_schedules = query_hvdc_schedules(time_horizon="1D", scenario_timestamp="2024-12-16T08:00:00Z")

# dc_schedules = [{'value': 350,
# 'in_domain': None,
Expand Down

0 comments on commit dc79494

Please sign in to comment.