Skip to content

Commit

Permalink
fix: switch to eic code for center nodes and distinguish enstsoe
Browse files Browse the repository at this point in the history
namespaces

enstoe: cim/schemaextension
entsoeSecretariat: secretariat/profilextension
  • Loading branch information
davidkleiven committed Aug 27, 2024
1 parent b4f9520 commit f74dddb
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cimsparql/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BusDataSchema(JsonSchemaOut):
un: Series[float] = pa.Field()
substation_mrid: Series[str] = pa.Field()
bidzone: Series[str] = pa.Field(nullable=True)
sv_voltage: Series[float] = pa.Field(nullable=True)
sv_voltage: Series[float] = pa.Field()
island: Series[str] = pa.Field()
is_swing_bus: Series[bool] = pa.Field()

Expand Down
7 changes: 6 additions & 1 deletion cimsparql/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def bus_data(self, region: str | None = None) -> BusDataFrame:
"""
dfs = [
self.get_table_and_convert(self.bus_data_query(region), index="node"),
self.get_table_and_convert(self.transformer_center_nodes_query(region), index="node"),
self.transformer_center_nodes(region),
]
df = pd.concat(dfs)
return BusDataFrame(df)
Expand All @@ -257,6 +257,11 @@ def loads_query(self, region: str | None = None) -> str:
substitutes = {"region": region or ".*"}
return self.template_to_query(templates.LOADS_QUERY, substitutes)

@time_it
def transformer_center_nodes(self, region: str | None = None) -> BusDataFrame:
df = self.get_table_and_convert(self.transformer_center_nodes_query(region), index="node")
return BusDataFrame(df)

@time_it
def loads(self, region: str | None = None) -> LoadsDataFrame:
"""Query load data.
Expand Down
6 changes: 3 additions & 3 deletions cimsparql/sparql/bus.sparql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Name: Bus
PREFIX cim:<${cim}>
PREFIX SN:<${SN}>
PREFIX entsoe:<${entsoe}>
PREFIX entsoeSecretariat:<${entsoeSecretariat}>
select (?mrid as ?node) ?busname (?substation_name as ?substation) ?un ?substation_mrid ?bidzone ?sv_voltage ?island ?is_swing_bus
where {
# Extract propertoes from the TP/SV/SSH profile for each topological node
Expand All @@ -28,7 +28,7 @@ where {

# Extract the bidzone of each substation if it exists
optional {
?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoe:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone
?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone
}
} .
optional {
Expand All @@ -40,7 +40,7 @@ where {
?_eq_subj2 <http://entsoe.eu/CIM/EquipmentCore/3/1> ?eq_repo2 .
service ?eq_repo2 {
# Collect bidzones from substations connected to the current substation via a ConductingEquipment
?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoe:IdentifiedObject.energyIdentCodeEIC ?connected_bidzone .
?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?connected_bidzone .
}} group by ?top_node}
}
bind(coalesce(?direct_bidzone, ?nearby_bidzone) as ?bidzone)
Expand Down
18 changes: 10 additions & 8 deletions cimsparql/sparql/connectivity_nodes.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PREFIX cim:<${cim}>
PREFIX SN:<${SN}>
PREFIX entsoe:<${entsoe}>
PREFIX entsoeSecretariat:<${entsoeSecretariat}>

select ?mrid (?container_mrid as ?container) ?container_name ?un ?bidzone ?container_type
where {
Expand All @@ -19,19 +19,21 @@ where {
cim:IdentifiedObject.name ?container_name;
cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area .
# Extract the bidzone of each substation if it exists
optional {
?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone
} .
{
?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoe:IdentifiedObject.energyIdentCodeEIC ?bidzone
} union {
filter not exists {?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoe:IdentifiedObject.energyIdentCodeEIC ?non_existent_bz}
filter(!bound(?bidzone))
# When an EIC code does not exist, look for an EIC code in neighbouring nodes
{
select (max(?related_bidzone) as ?bidzone) where {
select (max(?related_bidzone) as ?nearby_bidzone) where {
# Collect bidzones from substations connected to the current substation via a ConductingEquipment
?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoe:IdentifiedObject.energyIdentCodeEIC ?related_bidzone .
?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?related_bidzone .
}
}
}
bind("Substation" as ?container_type)
}
bind("Substation" as ?container_type)
bind(coalesce(?direct_bidzone, ?nearby_bidzone) as ?bidzone)
} union {
?con_node_container cim:Line.Region/cim:IdentifiedObject.name ?area ;
cim:IdentifiedObject.mRID ?container_mrid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
prefix cim:<${cim}>
prefix SN:<${SN}>
prefix entsoe:<${entsoe}>
prefix entsoeSecretariat:<${entsoeSecretariat}>
insert {
graph <http://cimsparql/xml-adpator/EQ-modifications> {
?substation SN:Substation.MarketDeliveryPoint _:b0 .
_:b0 SN:MarketDeliveryPoint.BiddingArea _:b1 .
_:b1 entsoe:IdentifiedObject.energyIdentCodeEIC "10Y1001A1001A48H"
_:b1 entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC "10Y1001A1001A48H"
}}
where {
?substation a cim:Substation
Expand Down
5 changes: 3 additions & 2 deletions cimsparql/sparql/transformer_center_nodes.sparql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Name: Transformer center nodes
PREFIX cim:<${cim}>
PREFIX SN:<${SN}>
select ?node ?busname (?container_name as ?substation) ?un (?container_mrid as ?substation_mrid) ?bidzone ?island (False as ?is_swing_bus) ?connectivity_node
PREFIX entsoeSecretariat:<${entsoeSecretariat}>
select ?node ?busname (?container_name as ?substation) ?un (?container_mrid as ?substation_mrid) ?bidzone ?island (False as ?is_swing_bus) ?connectivity_node (?un as ?sv_voltage)
where
{
optional{
Expand All @@ -23,7 +24,7 @@ where
?con_node cim:IdentifiedObject.mRID ?connectivity_node .
?container cim:IdentifiedObject.mRID ?container_mrid;
cim:IdentifiedObject.name ?container_name.
optional {?container SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/SN:BiddingArea.marketCode ?bidzone}
?container SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?bidzone
optional {?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis}
}
filter(?network_analysis)
Expand Down
3 changes: 2 additions & 1 deletion pkg_data/namespaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"cim": "http://iec.ch/TC57/2013/CIM-schema-cim16#",
"cims": "http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#",
"dc": "http://purl.org/dc/elements/1.1/",
"entsoe": "http://entsoe.eu/Secretariat/ProfileExtension/1#",
"entsoeSecretariat": "http://entsoe.eu/Secretariat/ProfileExtension/1#",
"entsoe": "http://entsoe.eu/CIM/SchemaExtension/3/1#",
"foaf": "http://xmlns.com/foaf/0.1/",
"md": "http://iec.ch/TC57/61970-552/ModelDescription/1#",
"owl": "http://www.w3.org/2002/07/owl#",
Expand Down
1 change: 1 addition & 0 deletions tests/test_graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async def collect_data(model: Model) -> dict[str, pd.DataFrame]:
model.transformer_windings,
model.transformers,
model.transformers_connected_to_converter,
model.transformer_center_nodes,
model.wind_generating_units,
)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_xml_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_add_sv_injection(xml_adaptor: XmlModelAdaptor) -> None:
def test_add_eic_code(xml_adaptor: XmlModelAdaptor) -> None:
query = "select * where {?s a cim:Substation}"
num_substations = len(xml_adaptor.graph.query(query))
assert num_substations > 0
xml_adaptor.add_eic_code()
query = "select * where {?s entsoe:IdentifiedObject.energyIdentCodeEIC ?eic}"
assert len(xml_adaptor.graph.query(query)) == num_substations
query = "select * where {?s entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?eic}"
assert len(xml_adaptor.graph.query(query, initNs=xml_adaptor.namespaces())) == num_substations

0 comments on commit f74dddb

Please sign in to comment.