power-grid-model-io 1.2.13__py3-none-any.whl → 1.2.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of power-grid-model-io might be problematic. Click here for more details.

@@ -29,7 +29,7 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
29
29
 
30
30
  __slots__ = ("pp_input_data", "pgm_input_data", "idx", "idx_lookup", "next_idx", "system_frequency")
31
31
 
32
- def __init__(self, system_frequency: float = 50.0):
32
+ def __init__(self, system_frequency: float = 50.0, trafo_loading: str = "current"):
33
33
  """
34
34
  Prepare some member variables
35
35
 
@@ -37,6 +37,7 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
37
37
  system_frequency: fundamental frequency of the alternating current and voltage in the Network measured in Hz
38
38
  """
39
39
  super().__init__(source=None, destination=None)
40
+ self.trafo_loading = trafo_loading
40
41
  self.system_frequency: float = system_frequency
41
42
  self.pp_input_data: PandaPowerData = {}
42
43
  self.pgm_input_data: SingleDataset = {}
@@ -1060,16 +1061,29 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
1060
1061
  # TODO: create unit tests for the function
1061
1062
  assert "res_trafo" not in self.pp_output_data
1062
1063
 
1063
- if "transformer" not in self.pgm_output_data or self.pgm_output_data["transformer"].size == 0:
1064
+ if ("transformer" not in self.pgm_output_data or self.pgm_output_data["transformer"].size == 0) or (
1065
+ "trafo" not in self.pp_input_data or len(self.pp_input_data["trafo"]) == 0
1066
+ ):
1064
1067
  return
1065
1068
 
1066
1069
  pgm_input_transformers = self.pgm_input_data["transformer"]
1067
-
1070
+ pp_input_transformers = self.pp_input_data["trafo"]
1068
1071
  pgm_output_transformers = self.pgm_output_data["transformer"]
1069
1072
 
1070
1073
  from_nodes = self.pgm_nodes_lookup.loc[pgm_input_transformers["from_node"]]
1071
1074
  to_nodes = self.pgm_nodes_lookup.loc[pgm_input_transformers["to_node"]]
1072
1075
 
1076
+ # Only derating factor used here. Sn is already being multiplied by parallel
1077
+ loading_multiplier = pp_input_transformers["df"]
1078
+ if self.trafo_loading == "current":
1079
+ ui_from = pgm_output_transformers["i_from"] * pgm_input_transformers["u1"]
1080
+ ui_to = pgm_output_transformers["i_to"] * pgm_input_transformers["u2"]
1081
+ loading = np.maximum(ui_from, ui_to) / pgm_input_transformers["sn"] * loading_multiplier * 1e2
1082
+ elif self.trafo_loading == "power":
1083
+ loading = pgm_output_transformers["loading"] * loading_multiplier * 1e2
1084
+ else:
1085
+ raise ValueError(f"Invalid transformer loading type: {str(self.trafo_loading)}")
1086
+
1073
1087
  pp_output_trafos = pd.DataFrame(
1074
1088
  columns=[
1075
1089
  "p_hv_mw",
@@ -1100,7 +1114,7 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
1100
1114
  pp_output_trafos["vm_lv_pu"] = to_nodes["u_pu"].values
1101
1115
  pp_output_trafos["va_hv_degree"] = from_nodes["u_degree"].values
1102
1116
  pp_output_trafos["va_lv_degree"] = to_nodes["u_degree"].values
1103
- pp_output_trafos["loading_percent"] = pgm_output_transformers["loading"] * 1e2
1117
+ pp_output_trafos["loading_percent"] = loading
1104
1118
 
1105
1119
  self.pp_output_data["res_trafo"] = pp_output_trafos
1106
1120
 
@@ -6,7 +6,7 @@ The TabularData class is a wrapper around Dict[str, Union[pd.DataFrame, np.ndarr
6
6
  which supports unit conversions and value substitutions
7
7
  """
8
8
 
9
- from typing import Dict, Iterable, Optional, Tuple, Union
9
+ from typing import Callable, Dict, Generator, Iterable, Optional, Tuple, Union
10
10
 
11
11
  import numpy as np
12
12
  import pandas as pd
@@ -15,6 +15,8 @@ import structlog
15
15
  from power_grid_model_io.mappings.unit_mapping import UnitMapping
16
16
  from power_grid_model_io.mappings.value_mapping import ValueMapping
17
17
 
18
+ LazyDataFrame = Callable[[], pd.DataFrame]
19
+
18
20
 
19
21
  class TabularData:
20
22
  """
@@ -22,7 +24,7 @@ class TabularData:
22
24
  which supports unit conversions and value substitutions
23
25
  """
24
26
 
25
- def __init__(self, **tables: Union[pd.DataFrame, np.ndarray]):
27
+ def __init__(self, **tables: Union[pd.DataFrame, np.ndarray, LazyDataFrame]):
26
28
  """
27
29
  Tabular data can either be a collection of pandas DataFrames and/or numpy structured arrays.
28
30
  The key word arguments will define the keys of the data.
@@ -34,12 +36,12 @@ class TabularData:
34
36
  **tables: A collection of pandas DataFrames and/or numpy structured arrays
35
37
  """
36
38
  for table_name, table_data in tables.items():
37
- if not isinstance(table_data, (pd.DataFrame, np.ndarray)):
39
+ if not isinstance(table_data, (pd.DataFrame, np.ndarray)) and not callable(table_data):
38
40
  raise TypeError(
39
41
  f"Invalid data type for table '{table_name}'; "
40
42
  f"expected a pandas DataFrame or NumPy array, got {type(table_data).__name__}."
41
43
  )
42
- self._data: Dict[str, Union[pd.DataFrame, np.ndarray]] = tables
44
+ self._data: Dict[str, Union[pd.DataFrame, np.ndarray, LazyDataFrame]] = tables
43
45
  self._units: Optional[UnitMapping] = None
44
46
  self._substitution: Optional[ValueMapping] = None
45
47
  self._log = structlog.get_logger(type(self).__name__)
@@ -73,7 +75,7 @@ class TabularData:
73
75
  Returns:
74
76
  The required column, with unit conversions and value substitutions applied
75
77
  """
76
- table_data = self._data[table_name]
78
+ table_data = self[table_name]
77
79
 
78
80
  # If the index 'column' is requested, but no column called 'index' exist,
79
81
  # return the index of the dataframe as if it were an actual column.
@@ -154,6 +156,14 @@ class TabularData:
154
156
 
155
157
  return table_data[pd.MultiIndex.from_tuples([(field, si_unit)])[0]]
156
158
 
159
+ def __len__(self) -> int:
160
+ """
161
+ Return the number of tables (regardless of if they are already loaded or not)
162
+
163
+ Returns: The number of tables
164
+ """
165
+ return len(self._data)
166
+
157
167
  def __contains__(self, table_name: str) -> bool:
158
168
  """
159
169
  Mimic the dictionary 'in' operator
@@ -176,6 +186,8 @@ class TabularData:
176
186
 
177
187
  Returns: The 'raw' table data
178
188
  """
189
+ if callable(self._data[table_name]):
190
+ self._data[table_name] = self._data[table_name]()
179
191
  return self._data[table_name]
180
192
 
181
193
  def keys(self) -> Iterable[str]:
@@ -187,13 +199,14 @@ class TabularData:
187
199
 
188
200
  return self._data.keys()
189
201
 
190
- def items(self) -> Iterable[Tuple[str, Union[pd.DataFrame, np.ndarray]]]:
202
+ def items(self) -> Generator[Tuple[str, Union[pd.DataFrame, np.ndarray]], None, None]:
191
203
  """
192
204
  Mimic the dictionary .items() function
193
205
 
194
- Returns: An iterator over the table names and the raw table data
206
+ Returns: An generator of the table names and the raw table data
195
207
  """
196
208
 
197
209
  # Note: PyCharm complains about the type, but it is correct, as an ItemsView extends from
198
210
  # AbstractSet[Tuple[_KT_co, _VT_co]], which actually is compatible with Iterable[_KT_co, _VT_co]
199
- return self._data.items()
211
+ for key in self._data:
212
+ yield key, self[key]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: power-grid-model-io
3
- Version: 1.2.13
3
+ Version: 1.2.15
4
4
  Summary: Power Grid Model Input/Output
5
5
  Author-email: Alliander Dynamic Grid Calculation <dynamic.grid.calculation@alliander.com>
6
6
  License: MPL-2.0
@@ -67,15 +67,15 @@ SPDX-License-Identifier: MPL-2.0
67
67
  For detailed documentation, see [Read the Docs](https://power-grid-model-io.readthedocs.io/en/stable/index.html).
68
68
 
69
69
  # Examples
70
- * [PGM JSON Example](https://github.com/alliander-opensource/power-grid-model-io/blob/264846040438a8a98396d251853d706c0734e398/docs/examples/pgm_json_example.ipynb)
70
+ * [PGM JSON Example](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/docs/examples/pgm_json_example.ipynb)
71
71
 
72
72
 
73
73
  # License
74
- This project is licensed under the Mozilla Public License, version 2.0 - see [LICENSE](https://github.com/alliander-opensource/power-grid-model-io/blob/264846040438a8a98396d251853d706c0734e398/LICENSE) for details.
74
+ This project is licensed under the Mozilla Public License, version 2.0 - see [LICENSE](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/LICENSE) for details.
75
75
 
76
76
  # Contributing
77
- Please read [CODE_OF_CONDUCT](https://github.com/alliander-opensource/power-grid-model-io/blob/264846040438a8a98396d251853d706c0734e398/CODE_OF_CONDUCT.md) and [CONTRIBUTING](https://github.com/alliander-opensource/power-grid-model-io/blob/264846040438a8a98396d251853d706c0734e398/CONTRIBUTING.md) for details on the process
77
+ Please read [CODE_OF_CONDUCT](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/CODE_OF_CONDUCT.md) and [CONTRIBUTING](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/CONTRIBUTING.md) for details on the process
78
78
  for submitting pull requests to us.
79
79
 
80
80
  # Contact
81
- Please read [SUPPORT](https://github.com/alliander-opensource/power-grid-model-io/blob/264846040438a8a98396d251853d706c0734e398/SUPPORT.md) for how to connect and get into contact with the Power Gird Model IO project.
81
+ Please read [SUPPORT](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/SUPPORT.md) for how to connect and get into contact with the Power Gird Model IO project.
@@ -6,7 +6,7 @@ power_grid_model_io/config/excel/vision_en.yaml,sha256=SqzFUrzd-QQpQtselfWTZOuNO
6
6
  power_grid_model_io/config/excel/vision_nl.yaml,sha256=x_m8nHokSlLT35-xwZrSpZEvUXVjMWsrZ0acV8DLizY,19128
7
7
  power_grid_model_io/converters/__init__.py,sha256=WKvQi375_pb1I4x36aTUvRjAqXHNNlbg2yX8P0fvvsA,424
8
8
  power_grid_model_io/converters/base_converter.py,sha256=HB5hI2g1pD9QNU6RuItHUjke01Xt7B4nBzRlY1gNQk8,4981
9
- power_grid_model_io/converters/pandapower_converter.py,sha256=gDYS43k7yCcL1vznTzN7BKZfYddru4f-L2Cv4R-YIj0,75581
9
+ power_grid_model_io/converters/pandapower_converter.py,sha256=m71hzEKKGpUmtzYRr1o1qrWeDpNv4t-Ui5IkLnNfb8I,76485
10
10
  power_grid_model_io/converters/pgm_json_converter.py,sha256=FPLHuvLmCl9ILLAfUMYmyJ_EifGW0HnzG7ZnI3OrLXE,11846
11
11
  power_grid_model_io/converters/tabular_converter.py,sha256=q4r5apVhZ6N13ZQV0jeAUBPL_6JtcH32wo0XP0CD8Pc,28918
12
12
  power_grid_model_io/converters/vision_excel_converter.py,sha256=EXxFebNiKPLYMU4m1aIf4bccSYCU6EiVUvvlvXc7Gm8,2322
@@ -17,7 +17,7 @@ power_grid_model_io/data_stores/json_file_store.py,sha256=vmo25AiCIy16HDF8S5ZZKu
17
17
  power_grid_model_io/data_stores/vision_excel_file_store.py,sha256=d5J6ClvIpef_JwKcqCilzYU411IR8Zju6R9Dc4j0KXQ,821
18
18
  power_grid_model_io/data_types/__init__.py,sha256=zXc0yGSyNFxpORWjXnejEkvjXFZXXyfEO7PeUtoqWnA,384
19
19
  power_grid_model_io/data_types/_data_types.py,sha256=IRQomW3ecETvIYfIzQRPDOwUY-TAa4g4mV17TvQVeGg,1834
20
- power_grid_model_io/data_types/tabular_data.py,sha256=xpBWKFzQh8U8rFBrn2R03G4piMRtkWLZpLa6TRhhCio,7878
20
+ power_grid_model_io/data_types/tabular_data.py,sha256=BC20WzbV1V03KD_BmfxwDKH4X_X_sbQ97PuUXz2Y7wA,8356
21
21
  power_grid_model_io/functions/__init__.py,sha256=LQKpnYqnZhMHb9QwWTTGiMadwl3e6jMSEzJf6TlIZk0,511
22
22
  power_grid_model_io/functions/_functions.py,sha256=J0KiqU_V3lniwNvYbFhF2_iOz5ug9_KahtlnM1xyeHs,2873
23
23
  power_grid_model_io/functions/phase_to_phase.py,sha256=oaDRoPg6okII0rq8klPM085DF5pSmIDqlSiY9l-L5E8,6296
@@ -33,8 +33,8 @@ power_grid_model_io/utils/dict.py,sha256=Y5fCB22qIwFVHinUq-TO1eXeNWU177sVPyOVVaA
33
33
  power_grid_model_io/utils/json.py,sha256=Fw9GhCiwk4sXw48ljPOkWAR0LaRkdA8ZkUQu-K0z0vU,3343
34
34
  power_grid_model_io/utils/modules.py,sha256=ZB8IIK96VuJk5FkoclrUCuXOSsGeVqT3B01bBAcodeU,944
35
35
  power_grid_model_io/utils/regex.py,sha256=0uJDRSfggmDFu_nip1Oge8NUXBQ_8e-3HTLdB8niAkQ,1728
36
- power_grid_model_io-1.2.13.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
37
- power_grid_model_io-1.2.13.dist-info/METADATA,sha256=XpnYeQrJIjeA9OOx5gw7nIJWQEVj-JoeBBlYDljzWdo,5679
38
- power_grid_model_io-1.2.13.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
39
- power_grid_model_io-1.2.13.dist-info/top_level.txt,sha256=7sq9VveemMm2R0RgTBa4tH8y_xF4_1hxbufmX9OjCTo,20
40
- power_grid_model_io-1.2.13.dist-info/RECORD,,
36
+ power_grid_model_io-1.2.15.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
37
+ power_grid_model_io-1.2.15.dist-info/METADATA,sha256=vehvfqpJuj38lsYHOVfbt79N66zNAjWA3y-rxNCVjJ8,5679
38
+ power_grid_model_io-1.2.15.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
39
+ power_grid_model_io-1.2.15.dist-info/top_level.txt,sha256=7sq9VveemMm2R0RgTBa4tH8y_xF4_1hxbufmX9OjCTo,20
40
+ power_grid_model_io-1.2.15.dist-info/RECORD,,