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

feat: add query for extraction station groups for each power unit #329

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
10 changes: 10 additions & 0 deletions src/cimsparql/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import datetime as dt
from typing import Self

import pandera as pa

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera" could not be resolved (reportMissingImports)
from pandera.api.pandas.model_config import BaseConfig

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)
from pandera.typing import DataFrame, Index, Series

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.typing" could not be resolved (reportMissingImports)


class CoercingSchema(pa.DataFrameModel):
Expand Down Expand Up @@ -423,3 +423,13 @@


GenUnitAndSyncMachineMridDataFrame = DataFrame[GenUnitAndSyncMachineMridSchema]


class StationGroupForPowerUnitSchema(CoercingSchema):
power_system_model_mrid: str = pa.Field(unique=True)
market_unit_mrid: str = pa.Field(unique=True)
resource_name: str
market_code: str


StationGroupForPowerUnitDataFrame = DataFrame[StationGroupForPowerUnitSchema]
6 changes: 6 additions & 0 deletions src/cimsparql/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
RASEquipmentDataFrame,
RegionsDataFrame,
StationGroupCodeNameDataFrame,
StationGroupForPowerUnitDataFrame,
SubstationVoltageDataFrame,
SvInjectionDataFrame,
SvPowerDeviationDataFrame,
Expand Down Expand Up @@ -697,6 +698,11 @@ def gen_unit_and_sync_machine_mrid(self) -> GenUnitAndSyncMachineMridDataFrame:
query = self.template_to_query(templates.GEN_UNIT_MRID_AND_SYNC_MACHINE)
return GenUnitAndSyncMachineMridDataFrame(self.get_table_and_convert(query))

@time_it
def station_group_for_power_unit(self) -> StationGroupForPowerUnitDataFrame:
query = self.template_to_query(templates.STATION_GROUP_FOR_POWER_UNIT_QUERY)
return StationGroupForPowerUnitDataFrame(self.get_table_and_convert(query))


class SingleClientModel(Model):
def __init__(
Expand Down
13 changes: 13 additions & 0 deletions src/cimsparql/sparql/station_group_for_power_unit.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Name: station group for power resource
PREFIX SN: <${SN}>
PREFIX cim: <${cim}>

select ?power_system_model_mrid ?market_unit_mrid ?resource_name ?market_code where {
?resource SN:ScheduleResource.marketCode ?market_code .
?unit ?p ?resource;
cim:IdentifiedObject.name ?resource_name;
cim:IdentifiedObject.mRID ?market_unit_mrid;
values ?physical_model_predicate {cim:SynchronousMachine.GeneratingUnit cim:NonConformLoad.LoadGroup}
?physical_object ?physical_model_predicate ?unit;
cim:IdentifiedObject.mRID ?power_system_model_mrid .
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ insert {
graph <http://cimsparql/xml-adpator/EQ-modifications> {
_:b0 a SN:GeneratingUnit;
cim:IdentifiedObject.name "GeneratingUnit" .
?machine cim:SynchronousMachine.GeneratingUnit _:b0
?machine cim:SynchronousMachine.GeneratingUnit _:b0 .
_:b0 SN:GeneratingUnit.ScheduleResource _:b1 .
_:b1 SN:ScheduleResource.marketCode "market0001"
}}
where {
?machine a cim:SynchronousMachine
Expand Down
1 change: 1 addition & 0 deletions src/cimsparql/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def _read_template(filename: pathlib.Path) -> Template:
REGIONS_QUERY = _read_template(sparql_folder / "regions.sparql")
SERIES_COMPENSATORS_QUERY = _read_template(sparql_folder / "series_compensators.sparql")
STATION_GROUP_CODE_NAME_QUERY = _read_template(sparql_folder / "station_group_code_and_names.sparql")
STATION_GROUP_FOR_POWER_UNIT_QUERY = _read_template(sparql_folder / "station_group_for_power_unit.sparql")
SUBSTATION_VOLTAGE_LEVEL_QUERY = _read_template(sparql_folder / "substation_voltage_level.sparql")
SV_BRANCH_QUERY = _read_template(sparql_folder / "sv_branch.sparql")
SV_INJECTION_QUERY = _read_template(sparql_folder / "sv_injection.sparql")
Expand Down
1 change: 1 addition & 0 deletions tests/test_graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async def collect_data(model: Model) -> dict[str, pd.DataFrame]:
model.series_compensators,
model.station_group_codes_and_names,
model.substation_voltage_level,
model.station_group_for_power_unit,
model.sv_power_deviation,
model.switches,
model.synchronous_machines,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_micro_t1_nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,12 @@ def test_gen_unit_and_sync_machine_mrid(test_model: t_common.ModelTest) -> None:

gen = test_model.model.gen_unit_and_sync_machine_mrid()
assert len(gen) == 4


@pytest.mark.parametrize("test_model", t_entsoe.micro_models())
def test_station_group_for_power_unit(test_model: t_common.ModelTest) -> None:
t_common.check_model(test_model)
assert test_model.model

group_for_units = test_model.model.station_group_for_power_unit()
assert len(group_for_units) == 4
Loading