Skip to content

Commit 287a789

Browse files
authored
Merge pull request #152 from alliander-opensource/feature/doc-example-index
Reading result batches example
2 parents bd02eee + cba3cb3 commit 287a789

File tree

1 file changed

+75
-10
lines changed

1 file changed

+75
-10
lines changed

docs/examples/Power Flow Example.ipynb

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
"execution_count": 14,
524524
"id": "4e25006f",
525525
"metadata": {
526-
"scrolled": true
526+
"scrolled": false
527527
},
528528
"outputs": [
529529
{
@@ -548,6 +548,71 @@
548548
"print(output_data[\"line\"][\"i_from\"])"
549549
]
550550
},
551+
{
552+
"cell_type": "markdown",
553+
"id": "466082fd",
554+
"metadata": {},
555+
"source": [
556+
"#### Accessing batch data\n",
557+
"\n",
558+
"It may be a bit unintuitive to read the `output_data` or `update_data` of a component directly as they are a dictionary of 3 dimension data, ie. $ids \\times batches \\times attributes$. Remember that the `output_data` or `update_data` are a dictionary of numpy structured arrays. Hence the component should be indexed first. The index that follows can be [indexed with numpy structured arrays](https://numpy.org/doc/stable/user/basics.rec.html#indexing-structured-arrays)\n",
559+
"\n",
560+
"To read the result of a single batch, lets say `1st batch`,"
561+
]
562+
},
563+
{
564+
"cell_type": "code",
565+
"execution_count": 15,
566+
"id": "a8ad72d8",
567+
"metadata": {},
568+
"outputs": [
569+
{
570+
"name": "stdout",
571+
"output_type": "stream",
572+
"text": [
573+
" id energized loading p_from q_from i_from \\\n",
574+
"0 3 1 0.212031 29511.239220 3.508895e+06 193.061627 \n",
575+
"1 5 1 0.064924 -1267.160636 -1.172098e+06 64.923606 \n",
576+
"2 8 1 0.156578 19805.345039 2.500724e+06 137.590869 \n",
577+
"\n",
578+
" s_from p_to q_to i_to s_to \n",
579+
"0 3.509019e+06 1267.160636 -3.827902e+06 212.030847 3.827902e+06 \n",
580+
"1 1.172099e+06 3574.919119 8.320006e+05 46.000611 8.320083e+05 \n",
581+
"2 2.500802e+06 -3574.919119 -2.832001e+06 156.577603 2.832003e+06 \n"
582+
]
583+
}
584+
],
585+
"source": [
586+
"print(pd.DataFrame(output_data[\"line\"][0]))"
587+
]
588+
},
589+
{
590+
"cell_type": "markdown",
591+
"id": "e25301da",
592+
"metadata": {},
593+
"source": [
594+
"Or maybe we wish to find result of a single component, (eg. 1st line) in all batches"
595+
]
596+
},
597+
{
598+
"cell_type": "code",
599+
"execution_count": 16,
600+
"id": "7bceccf4",
601+
"metadata": {},
602+
"outputs": [
603+
{
604+
"name": "stdout",
605+
"output_type": "stream",
606+
"text": [
607+
"[ 193.06162675 248.65360093 368.12834615 510.20016036 662.04311447\n",
608+
" 819.63118685 981.46004118 1146.90787963 1315.7236725 1487.83778526]\n"
609+
]
610+
}
611+
],
612+
"source": [
613+
"print(output_data[\"line\"][\"i_from\"][:,0])"
614+
]
615+
},
551616
{
552617
"cell_type": "markdown",
553618
"id": "ac217192",
@@ -562,7 +627,7 @@
562627
},
563628
{
564629
"cell_type": "code",
565-
"execution_count": 15,
630+
"execution_count": 17,
566631
"id": "041368dc",
567632
"metadata": {},
568633
"outputs": [],
@@ -597,7 +662,7 @@
597662
},
598663
{
599664
"cell_type": "code",
600-
"execution_count": 16,
665+
"execution_count": 18,
601666
"id": "34338ce3",
602667
"metadata": {},
603668
"outputs": [
@@ -628,7 +693,7 @@
628693
},
629694
{
630695
"cell_type": "code",
631-
"execution_count": 17,
696+
"execution_count": 19,
632697
"id": "04e56690",
633698
"metadata": {},
634699
"outputs": [],
@@ -655,7 +720,7 @@
655720
},
656721
{
657722
"cell_type": "code",
658-
"execution_count": 18,
723+
"execution_count": 20,
659724
"id": "0d5b94c2",
660725
"metadata": {},
661726
"outputs": [
@@ -732,7 +797,7 @@
732797
},
733798
{
734799
"cell_type": "code",
735-
"execution_count": 19,
800+
"execution_count": 21,
736801
"id": "b5f10bae",
737802
"metadata": {},
738803
"outputs": [
@@ -788,7 +853,7 @@
788853
},
789854
{
790855
"cell_type": "code",
791-
"execution_count": 20,
856+
"execution_count": 22,
792857
"id": "1a221507",
793858
"metadata": {},
794859
"outputs": [
@@ -825,7 +890,7 @@
825890
},
826891
{
827892
"cell_type": "code",
828-
"execution_count": 21,
893+
"execution_count": 23,
829894
"id": "541af620",
830895
"metadata": {},
831896
"outputs": [
@@ -864,7 +929,7 @@
864929
},
865930
{
866931
"cell_type": "code",
867-
"execution_count": 22,
932+
"execution_count": 24,
868933
"id": "b702eb15",
869934
"metadata": {},
870935
"outputs": [
@@ -894,7 +959,7 @@
894959
],
895960
"metadata": {
896961
"kernelspec": {
897-
"display_name": "Python 3.9.13 ('pgm-dev')",
962+
"display_name": "Python 3 (ipykernel)",
898963
"language": "python",
899964
"name": "python3"
900965
},

0 commit comments

Comments
 (0)