Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 25 additions & 1 deletion docs/examples/pgm/basic_pgm_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@
"# Results have been calculated for all 10 scenarios\n",
"display(output[\"line\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create grid from input data example\n",
"\n",
"To create a `Grid` object from `PGM` input data, the `create_grid_from_input_data()` method can be used."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"input_data = core_interface.create_input_from_grid()\n",
"\n",
"core_interface = PowerGridModelInterface(input_data=input_data)\n",
"output = core_interface.create_grid_from_input_data()\n",
"\n",
"print(input_data[\"node\"])\n",
"print(output.node)"
]
}
],
"metadata": {
Expand All @@ -172,7 +196,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down
21 changes: 19 additions & 2 deletions src/power_grid_model_ds/_core/load_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class PowerGridModelInterface:

def __init__(
self,
grid: Grid,
grid: Optional[Grid] = None,
input_data: Optional[Dict] = None,
system_frequency: float = 50.0,
):
self.grid = grid
self.grid = grid or Grid.empty()
self.system_frequency = system_frequency

self.input_data = input_data or {}
Expand All @@ -63,6 +63,23 @@ def create_input_from_grid(self):
self.input_data[array_name] = pgm_array
return self.input_data

def create_grid_from_input_data(
self,
) -> Grid:
"""
Create Grid object from PowerGridModel input.
Note that for some arrays, not all fields are available in the PowerGridModel input.
In this case, the default values are used.

Returns a Grid object with the arrays filled with the PowerGridModel input.
"""
for pgm_name in PGM_ARRAYS:
if pgm_name in self.input_data:
pgm_ds_array_class = getattr(self.grid, pgm_name).__class__
pgm_ds_array = pgm_ds_array_class(self.input_data[pgm_name])
self.grid.append(pgm_ds_array, check_max_id=False)
return self.grid

def calculate_power_flow(
self,
calculation_method: CalculationMethod = CalculationMethod.newton_raphson,
Expand Down
Loading
Loading