|
16 | 16 | from power_grid_model._core.dataset_definitions import ComponentTypeVar
|
17 | 17 |
|
18 | 18 | SingleArray: TypeAlias = np.ndarray
|
19 |
| -""" |
20 |
| -A single array is a one-dimensional structured numpy array containing a list of components of the same type. |
21 |
| -
|
22 |
| -- Examples: |
23 |
| -
|
24 |
| - - structure: <1d-array> |
25 |
| - - concrete: array([(0, 10500.0), (0, 10500.0)], dtype=power_grid_meta_data["input"]["node"].dtype) |
26 |
| -""" |
27 | 19 |
|
28 | 20 | AttributeType: TypeAlias = str
|
29 |
| -""" |
30 |
| -An attribute type is a string reprenting the attribute type of a specific component. |
31 |
| -
|
32 |
| -- Examples: |
33 |
| -
|
34 |
| - - "id" |
35 |
| - - "u_rated" |
36 |
| -""" |
37 | 21 |
|
38 | 22 | SingleColumn: TypeAlias = np.ndarray
|
39 |
| -""" |
40 |
| -A single column is a one-dimensional structured numpy array containing a list of the same attribute of |
41 |
| -multiple components of the same type. |
42 |
| -
|
43 |
| -- Examples: |
44 |
| -
|
45 |
| - - structure: <1d-array> |
46 |
| - - concrete: |
47 |
| -
|
48 |
| - - array([0, 1], dtype=power_grid_meta_data["input"]["node"].dtype.fields["id"][0]) |
49 |
| - - array([10500.0, 10500.0], dtype=power_grid_meta_data["input"]["node"].dtype.fields["u_rated"][0]) |
50 |
| -""" |
51 | 23 |
|
52 | 24 | DenseBatchArray: TypeAlias = np.ndarray
|
53 |
| -""" |
54 |
| -A dense batch array is a two-dimensional structured numpy array containing a list of components of |
55 |
| -the same type for each scenario. Otherwise similar to :class:`SingleArray`. |
56 |
| -""" |
57 | 25 |
|
58 | 26 | SingleColumnarData = dict[AttributeType, SingleColumn]
|
59 |
| -""" |
60 |
| -Single columnar data is a dictionary where the keys are the attribute types of the same component |
61 |
| -and the values are :class:`SingleColumn`. |
62 |
| -
|
63 |
| -- Example: {"id": :class:`AttributeType`, "u_rated": :class:`SingleColumn`} |
64 |
| -""" |
65 | 27 |
|
66 | 28 | _SingleComponentData = TypeVar("_SingleComponentData", SingleArray, SingleColumnarData) # deduction helper
|
67 | 29 | SingleComponentData = SingleArray | SingleColumnarData
|
68 |
| -""" |
69 |
| -Single component data can be :class:`SingleArray` or :class:`SingleColumnarData`. |
70 |
| -""" |
71 | 30 |
|
72 | 31 |
|
73 | 32 | SingleDataset = dict[ComponentTypeVar, _SingleComponentData]
|
74 |
| -""" |
75 |
| -A single dataset is a dictionary where the keys are the component types and the values are |
76 |
| -:class:`ComponentData` |
77 |
| -
|
78 |
| -- Example: {"node": :class:`SingleArray`, "line": :class:`SingleColumnarData`} |
79 |
| -""" |
80 | 33 |
|
81 | 34 | BatchList = list[SingleDataset]
|
82 |
| -""" |
83 |
| -A batch list is an alternative representation of a batch. It is a list of single datasets, where each single dataset |
84 |
| -is actually a batch. The batch list is intended as an intermediate data type, during conversions. |
85 |
| -
|
86 |
| -- Example: [:class:`SingleDataset`, {"node": :class:`SingleDataset`}] |
87 |
| -""" |
88 | 35 |
|
89 | 36 | BatchColumn: TypeAlias = np.ndarray
|
90 |
| -""" |
91 |
| -A batch column is a two-dimensional structured numpy array containing a list of the same attribute of |
92 |
| -multiple components of the same type. Otherwise, similar to :class:`SingleColumn`. |
93 |
| -""" |
94 | 37 |
|
95 | 38 | DenseBatchColumnarData = dict[AttributeType, BatchColumn]
|
96 |
| -""" |
97 |
| -Batch columnar data is a dictionary where the keys are the attribute types of the same component |
98 |
| -and the values are :class:`BatchColumn`. |
99 |
| -
|
100 |
| -- Example: {"id": :class:`AttributeType`, "from_status": :class:`BatchColumn`} |
101 |
| -""" |
102 | 39 |
|
103 | 40 | IndexPointer: TypeAlias = np.ndarray
|
104 |
| -""" |
105 |
| -An index pointer is a one-dimensional numpy int64 array containing n+1 elements where n is the amount |
106 |
| -of scenarios, representing the start and end indices for each batch scenario as follows: |
107 |
| -
|
108 |
| - - The elements are the indices in the data that point to the first element of that scenario. |
109 |
| - - The last element is one after the data index of the last element of the last scenario. |
110 |
| - - The first element and last element will therefore be 0 and the size of the data, respectively. |
111 |
| -""" |
112 | 41 |
|
113 | 42 |
|
114 | 43 | class SparseBatchColumnarData(TypedDict):
|
@@ -156,170 +85,48 @@ class SparseBatchArray(TypedDict):
|
156 | 85 |
|
157 | 86 |
|
158 | 87 | SparseBatchData = SparseBatchArray | SparseBatchColumnarData
|
159 |
| -""" |
160 |
| -Sparse batch data can be a :class:`SparseBatchArray` or a :class:`SparseBatchColumnarData`. |
161 |
| -""" |
162 | 88 |
|
163 | 89 | SparseDataComponentType: TypeAlias = str
|
164 |
| -""" |
165 |
| -A string representing the component type of sparse data structures. |
166 |
| -
|
167 |
| -Must be either "data" or "indptr". |
168 |
| -""" |
169 | 90 |
|
170 | 91 | BatchColumnarData = DenseBatchColumnarData | SparseBatchColumnarData
|
171 |
| -""" |
172 |
| -Batch columnar data is either a :class:`DenseBatchColumnarData` or a :class:`SparseBatchColumnarData`. |
173 |
| -""" |
174 | 92 |
|
175 | 93 | ColumnarData = SingleColumnarData | BatchColumnarData
|
176 |
| -""" |
177 |
| -Columnar data can be :class:`SingleColumnarData` or :class:`BatchColumnarData`. |
178 |
| -""" |
179 | 94 | BatchArray = DenseBatchArray | SparseBatchArray
|
180 |
| -""" |
181 |
| -A batch array is a either a :class:`DenseBatchArray` or a :class:`SparseBatchArray`. |
182 |
| -""" |
183 | 95 |
|
184 | 96 |
|
185 | 97 | BatchComponentData = BatchArray | BatchColumnarData
|
186 |
| -""" |
187 |
| -Batch component data can be :class:`BatchArray` or :class:`BatchColumnarData`. |
188 |
| -""" |
189 | 98 |
|
190 | 99 | _BatchComponentData = TypeVar("_BatchComponentData", BatchArray, BatchColumnarData) # deduction helper
|
191 | 100 |
|
192 | 101 |
|
193 | 102 | BatchDataset = dict[ComponentTypeVar, _BatchComponentData]
|
194 |
| -""" |
195 |
| -A batch dataset is a dictionary where the keys are the component types and the values are :class:`BatchComponentData` |
196 |
| -
|
197 |
| -- Example: {"node": :class:`DenseBatchArray`, "line": :class:`SparseBatchArray`, |
198 |
| - "link": :class:`DenseBatchColumnarData`, "transformer": :class:`SparseBatchColumnarData`} |
199 |
| -""" |
200 | 103 |
|
201 | 104 |
|
202 | 105 | DataArray = SingleArray | BatchArray
|
203 |
| -""" |
204 |
| -A data array can be a :class:`SingleArray` or a :class:`BatchArray`. |
205 |
| -""" |
206 | 106 |
|
207 | 107 |
|
208 | 108 | _ComponentData = TypeVar("_ComponentData", SingleComponentData, BatchComponentData) # deduction helper
|
209 | 109 | ComponentData = DataArray | ColumnarData
|
210 |
| -""" |
211 |
| -Component data can be :class:`DataArray` or :class:`ColumnarData`. |
212 |
| -""" |
213 | 110 |
|
214 | 111 | Dataset = dict[ComponentTypeVar, _ComponentData]
|
215 |
| -""" |
216 |
| -A general data set can be a :class:`SingleDataset` or a :class:`BatchDataset`. |
217 |
| -
|
218 |
| -- Examples: |
219 |
| -
|
220 |
| - - single: {"node": :class:`SingleArray`, "line": :class:`SingleColumnarData`} |
221 |
| -
|
222 |
| - - batch: {"node": :class:`DenseBatchArray`, "line": :class:`SparseBatchArray`, |
223 |
| - "link": :class:`DenseBatchColumnarData`, "transformer": :class:`SparseBatchColumnarData`} |
224 |
| -
|
225 |
| -""" |
226 | 112 |
|
227 | 113 |
|
228 | 114 | DenseBatchData = DenseBatchArray | DenseBatchColumnarData
|
229 |
| -""" |
230 |
| -Dense batch data can be a :class:`DenseBatchArray` or a :class:`DenseBatchColumnarData`. |
231 |
| -""" |
232 | 115 |
|
233 | 116 | NominalValue = int
|
234 |
| -""" |
235 |
| -Nominal values can be IDs, booleans, enums, tap pos. |
236 |
| -
|
237 |
| -- Example: 123 |
238 |
| -""" |
239 | 117 |
|
240 | 118 | RealValue = float
|
241 |
| -""" |
242 |
| -Symmetrical values can be anything like cable properties, symmetric loads, etc. |
243 |
| -
|
244 |
| -- Example: 10500.0 |
245 |
| -""" |
246 | 119 |
|
247 | 120 | AsymValue = tuple[RealValue, RealValue, RealValue]
|
248 |
| -""" |
249 |
| -Asymmetrical values are three-phase values like p or u_measured. |
250 |
| -
|
251 |
| -- Example: (10400.0, 10500.0, 10600.0) |
252 |
| -""" |
253 | 121 |
|
254 | 122 | AttributeValue = RealValue | NominalValue | AsymValue
|
255 |
| -""" |
256 |
| -When representing a grid as a native python structure, each attribute (u_rated etc) is either a nominal value, |
257 |
| -a real value, or a tuple of three real values. |
258 |
| -
|
259 |
| -- Examples: |
260 |
| -
|
261 |
| - - real: 10500.0 |
262 |
| - - nominal: 123 |
263 |
| - - asym: (10400.0, 10500.0, 10600.0) |
264 |
| -""" |
265 | 123 |
|
266 | 124 | Component = dict[AttributeType, AttributeValue | str]
|
267 |
| -""" |
268 |
| -A component, when represented in native python format, is a dictionary, where the keys are the attributes and the values |
269 |
| -are the corresponding values. It is allowed to add extra fields, containing either an AttributeValue or a string. |
270 |
| -
|
271 |
| -- Example: {"id": 1, "u_rated": 10500.0, "original_id": "Busbar #1"} |
272 |
| -""" |
273 | 125 |
|
274 | 126 | ComponentList = list[Component]
|
275 |
| -""" |
276 |
| -A component list is a list containing components. In essence it stores the same information as a np.ndarray, |
277 |
| -but in a native python format, without using numpy. |
278 |
| -
|
279 |
| -- Example: [{"id": 1, "u_rated": 10500.0}, {"id": 2, "u_rated": 10500.0}] |
280 |
| -""" |
281 | 127 |
|
282 | 128 | SinglePythonDataset = dict[ComponentTypeVar, ComponentList]
|
283 |
| -""" |
284 |
| -A single dataset in native python representation is a dictionary, where the keys are the component names and the |
285 |
| -values are a list of all the instances of such a component. In essence it stores the same information as a |
286 |
| -SingleDataset, but in a native python format, without using numpy. |
287 |
| -
|
288 |
| -- Example: |
289 |
| -
|
290 |
| - { |
291 |
| - "node": [{"id": 1, "u_rated": 10500.0}, {"id": 2, "u_rated": 10500.0}], |
292 |
| - "line": [{"id": 3, "from_node": 1, "to_node": 2, ...}], |
293 |
| - } |
294 |
| -""" |
295 | 129 |
|
296 | 130 | BatchPythonDataset = list[SinglePythonDataset]
|
297 |
| -""" |
298 |
| -A batch dataset in native python representation is a list of dictionaries, where the keys are the component names and |
299 |
| -the values are a list of all the instances of such a component. In essence it stores the same information as a |
300 |
| -BatchDataset, but in a native python format, without using numpy. Actually it looks more like the BatchList. |
301 |
| -
|
302 |
| -- Example: |
303 |
| -
|
304 |
| - [{"line": [{"id": 3, "from_status": 0, "to_status": 0, ...}],}, |
305 |
| - {"line": [{"id": 3, "from_status": 1, "to_status": 1, ...}],}] |
306 |
| -""" |
307 | 131 |
|
308 | 132 | PythonDataset = SinglePythonDataset | BatchPythonDataset
|
309 |
| -""" |
310 |
| -A general python data set can be a single or a batch python dataset. |
311 |
| -
|
312 |
| -- Examples: |
313 |
| -
|
314 |
| - - single: |
315 |
| -
|
316 |
| - { |
317 |
| - "node": [{"id": 1, "u_rated": 10500.0}, {"id": 2, "u_rated": 10500.0}], |
318 |
| - "line": [{"id": 3, "from_node": 1, "to_node": 2, ...}], |
319 |
| - } |
320 |
| -
|
321 |
| - - batch: |
322 |
| -
|
323 |
| - [{"line": [{"id": 3, "from_status": 0, "to_status": 0, ...}],}, |
324 |
| - {"line": [{"id": 3, "from_status": 1, "to_status": 1, ...}],}] |
325 |
| -""" |
0 commit comments