Skip to content

Commit cb5da6f

Browse files
authored
Merge pull request #11 from SOPTIM/fix-iri-handling
Fix IRI handling
2 parents 5906ad2 + 28c2d8c commit cb5da6f

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cgmes2pgm_converter"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Library to convert Common Grid Model Exchange Standard (CGMES) datasets to PowerGridModel (PGM) format"
55
authors = [
66
{ name = "Lars Friedrich, Eduard Fried, Udo Schmitz", email = "powergridmodel@soptim.de" },

src/cgmes2pgm_converter/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
"""
16-
This package provides a library to convert
17-
Common Grid Model Exchange Standard (CGMES) data to PGM format
18-
and apply the State Estimation from
16+
This package provides a library to convert
17+
Common Grid Model Exchange Standard (CGMES) data to PGM format
18+
and apply the State Estimation from
1919
[PowerGridModel](https://github.com/PowerGridModel/power-grid-model).
2020
"""
2121

src/cgmes2pgm_converter/common/cgmes_dataset.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ def mrid_to_urn(self, mrid: str) -> str:
7676
mrid = mrid.replace('"', "")
7777
return f"<urn:uuid:{mrid}>"
7878

79+
def query(
80+
self, query: str, add_prefixes=True, remove_uuid_base_uri=True
81+
) -> pd.DataFrame:
82+
result = super().query(query, add_prefixes)
83+
if remove_uuid_base_uri:
84+
# Remove the base URI from all IRIs (if wanted) -> helps to keep the output clean
85+
prefix = self.base_url + "#"
86+
for col in result.select_dtypes(include="object"):
87+
result[col] = result[col].str.replace(f"^{prefix}", "", regex=True)
88+
return result
89+
7990
def insert_df(
8091
self, df: pd.DataFrame, profile: Profile | str, include_mrid=True
8192
) -> None:

src/cgmes2pgm_converter/components/measurement/reactive_power_sensor_for_shunt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _read_meas_from_default_graph(self):
221221
"$TOPO_ISLAND": self._at_topo_island_node("?tn"),
222222
}
223223
q = self._replace(self._query_meas_in_default, args)
224-
res = self._source.query(q)
224+
res = self._source.query(q, remove_uuid_base_uri=False)
225225
return res
226226

227227
def _read_meas_from_named_graph(self):
@@ -230,7 +230,7 @@ def _read_meas_from_named_graph(self):
230230
"$TOPO_ISLAND": self._at_topo_island_node("?tn"),
231231
}
232232
q = self._replace(self._query_meas_in_graph, args)
233-
res = self._source.query(q)
233+
res = self._source.query(q, remove_uuid_base_uri=False)
234234
return res
235235

236236
def component_name(self) -> ComponentType:

src/cgmes2pgm_converter/components/measurement/voltage_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _read_meas_from_graph(self):
146146
def _read_meas_from_default_graph(self):
147147
args = {"$TOPO_ISLAND": self._at_topo_island_node("?tn")}
148148
q = self._replace(self._query_meas_in_default, args)
149-
res = self._source.query(q)
149+
res = self._source.query(q, remove_uuid_base_uri=False)
150150

151151
meas_by_tn = self._join_measurements_by_node(res)
152152

0 commit comments

Comments
 (0)