|
45 | 45 | "source": [ |
46 | 46 | "# some basic imports\n", |
47 | 47 | "import numpy as np\n", |
48 | | - "import warnings\n", |
49 | | - "\n", |
50 | | - "with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n", |
51 | | - " # suppress warning about pyarrow as future required dependency\n", |
52 | | - " import pandas as pd\n", |
| 48 | + "import pandas as pd\n", |
53 | 49 | "\n", |
54 | 50 | "from power_grid_model import LoadGenType, ComponentType, DatasetType, ComponentAttributeFilterOptions\n", |
55 | 51 | "from power_grid_model import PowerGridModel, CalculationMethod, CalculationType\n", |
|
640 | 636 | }, |
641 | 637 | { |
642 | 638 | "cell_type": "markdown", |
643 | | - "id": "fcc57354", |
| 639 | + "id": "25a3f722", |
644 | 640 | "metadata": {}, |
645 | 641 | "source": [ |
646 | | - "Columnar data is also supported" |
| 642 | + "If you are updating all components of the same type (uniformly) in the same order as in the input data, providing IDs is optional." |
647 | 643 | ] |
648 | 644 | }, |
649 | 645 | { |
650 | 646 | "cell_type": "code", |
651 | 647 | "execution_count": 15, |
| 648 | + "id": "6a4d9802", |
| 649 | + "metadata": {}, |
| 650 | + "outputs": [], |
| 651 | + "source": [ |
| 652 | + "update_sym_load_no_id = initialize_array(DatasetType.update, ComponentType.sym_load, 2)\n", |
| 653 | + "update_sym_load_no_id[\"p_specified\"] = [30e6, 15e6] # change active power for both sym_loads\n", |
| 654 | + "# leave reactive power the same, no need to specify\n", |
| 655 | + "\n", |
| 656 | + "update_line_no_id = initialize_array(DatasetType.update, ComponentType.line, 3)\n", |
| 657 | + "update_line_no_id[\"from_status\"] = [0, 1, 1] # switch off at from side for line #3\n", |
| 658 | + "\n", |
| 659 | + "update_data_no_id = {ComponentType.sym_load: update_sym_load_no_id, ComponentType.line: update_line_no_id}" |
| 660 | + ] |
| 661 | + }, |
| 662 | + { |
| 663 | + "cell_type": "markdown", |
| 664 | + "id": "fcc57354", |
| 665 | + "metadata": {}, |
| 666 | + "source": [ |
| 667 | + "Columnar data is also supported." |
| 668 | + ] |
| 669 | + }, |
| 670 | + { |
| 671 | + "cell_type": "code", |
| 672 | + "execution_count": 16, |
652 | 673 | "id": "aaf8fe64", |
653 | 674 | "metadata": {}, |
654 | 675 | "outputs": [], |
|
660 | 681 | "}\n", |
661 | 682 | "# leave to-side swiching status the same, no need to specify\n", |
662 | 683 | "\n", |
663 | | - "update_data = {ComponentType.sym_load: update_sym_load, ComponentType.line: columnar_update_line}" |
| 684 | + "update_data_col = {ComponentType.sym_load: update_sym_load, ComponentType.line: columnar_update_line}" |
| 685 | + ] |
| 686 | + }, |
| 687 | + { |
| 688 | + "cell_type": "markdown", |
| 689 | + "id": "f5179288", |
| 690 | + "metadata": {}, |
| 691 | + "source": [ |
| 692 | + "Columnar data also supports optional IDs." |
| 693 | + ] |
| 694 | + }, |
| 695 | + { |
| 696 | + "cell_type": "code", |
| 697 | + "execution_count": 17, |
| 698 | + "id": "7eabed0c", |
| 699 | + "metadata": {}, |
| 700 | + "outputs": [], |
| 701 | + "source": [ |
| 702 | + "line_update_dtype = power_grid_meta_data[DatasetType.update][ComponentType.line].dtype\n", |
| 703 | + "columnar_no_ID_update_line = {\n", |
| 704 | + " # Update IDs are not specified\n", |
| 705 | + " \"from_status\": np.array(\n", |
| 706 | + " [0, 1, 1], dtype=line_update_dtype[\"from_status\"]\n", |
| 707 | + " ), # The update for the whole column needs to be specified\n", |
| 708 | + "}\n", |
| 709 | + "# leave to-side swiching status the same, no need to specify\n", |
| 710 | + "\n", |
| 711 | + "update_data_col_no_id = {ComponentType.sym_load: update_sym_load, ComponentType.line: columnar_no_ID_update_line}" |
664 | 712 | ] |
665 | 713 | }, |
666 | 714 | { |
|
676 | 724 | }, |
677 | 725 | { |
678 | 726 | "cell_type": "code", |
679 | | - "execution_count": 16, |
| 727 | + "execution_count": 18, |
680 | 728 | "id": "63ea4cc3", |
681 | 729 | "metadata": {}, |
682 | 730 | "outputs": [], |
683 | 731 | "source": [ |
684 | 732 | "from power_grid_model.validation import assert_valid_batch_data\n", |
685 | 733 | "\n", |
686 | | - "assert_valid_batch_data(input_data=input_data, update_data=update_data, calculation_type=CalculationType.power_flow)" |
| 734 | + "assert_valid_batch_data(input_data=input_data, update_data=update_data, calculation_type=CalculationType.power_flow)\n", |
| 735 | + "assert_valid_batch_data(\n", |
| 736 | + " input_data=input_data, update_data=update_data_no_id, calculation_type=CalculationType.power_flow\n", |
| 737 | + ")\n", |
| 738 | + "assert_valid_batch_data(input_data=input_data, update_data=update_data_col, calculation_type=CalculationType.power_flow)\n", |
| 739 | + "assert_valid_batch_data(\n", |
| 740 | + " input_data=input_data, update_data=update_data_col_no_id, calculation_type=CalculationType.power_flow\n", |
| 741 | + ")" |
687 | 742 | ] |
688 | 743 | }, |
689 | 744 | { |
|
699 | 754 | }, |
700 | 755 | { |
701 | 756 | "cell_type": "code", |
702 | | - "execution_count": 17, |
| 757 | + "execution_count": 19, |
703 | 758 | "id": "188f6663", |
704 | 759 | "metadata": {}, |
705 | 760 | "outputs": [], |
|
721 | 776 | }, |
722 | 777 | { |
723 | 778 | "cell_type": "code", |
724 | | - "execution_count": 18, |
| 779 | + "execution_count": 20, |
725 | 780 | "id": "a93c1e16", |
726 | 781 | "metadata": {}, |
727 | 782 | "outputs": [ |
|
810 | 865 | }, |
811 | 866 | { |
812 | 867 | "cell_type": "code", |
813 | | - "execution_count": 19, |
| 868 | + "execution_count": 21, |
814 | 869 | "id": "42d5cd8f", |
815 | 870 | "metadata": {}, |
816 | 871 | "outputs": [], |
|
844 | 899 | }, |
845 | 900 | { |
846 | 901 | "cell_type": "code", |
847 | | - "execution_count": 20, |
| 902 | + "execution_count": 22, |
848 | 903 | "id": "4e25006f", |
849 | 904 | "metadata": { |
850 | 905 | "scrolled": true |
|
887 | 942 | }, |
888 | 943 | { |
889 | 944 | "cell_type": "code", |
890 | | - "execution_count": 21, |
| 945 | + "execution_count": 23, |
891 | 946 | "id": "afccf7a2", |
892 | 947 | "metadata": { |
893 | 948 | "scrolled": true |
|
924 | 979 | }, |
925 | 980 | { |
926 | 981 | "cell_type": "code", |
927 | | - "execution_count": 22, |
| 982 | + "execution_count": 24, |
928 | 983 | "id": "9af1be38", |
929 | 984 | "metadata": { |
930 | 985 | "scrolled": true |
|
967 | 1022 | }, |
968 | 1023 | { |
969 | 1024 | "cell_type": "code", |
970 | | - "execution_count": 23, |
| 1025 | + "execution_count": 25, |
971 | 1026 | "id": "041368dc", |
972 | 1027 | "metadata": {}, |
973 | 1028 | "outputs": [], |
|
997 | 1052 | }, |
998 | 1053 | { |
999 | 1054 | "cell_type": "code", |
1000 | | - "execution_count": 24, |
| 1055 | + "execution_count": 26, |
1001 | 1056 | "id": "34338ce3", |
1002 | 1057 | "metadata": {}, |
1003 | 1058 | "outputs": [ |
|
1029 | 1084 | }, |
1030 | 1085 | { |
1031 | 1086 | "cell_type": "code", |
1032 | | - "execution_count": 25, |
| 1087 | + "execution_count": 27, |
1033 | 1088 | "id": "04e56690", |
1034 | 1089 | "metadata": {}, |
1035 | 1090 | "outputs": [], |
|
1061 | 1116 | }, |
1062 | 1117 | { |
1063 | 1118 | "cell_type": "code", |
1064 | | - "execution_count": 26, |
| 1119 | + "execution_count": 28, |
1065 | 1120 | "id": "0d5b94c2", |
1066 | 1121 | "metadata": {}, |
1067 | 1122 | "outputs": [ |
|
1144 | 1199 | }, |
1145 | 1200 | { |
1146 | 1201 | "cell_type": "code", |
1147 | | - "execution_count": 27, |
| 1202 | + "execution_count": 29, |
1148 | 1203 | "id": "b5f10bae", |
1149 | 1204 | "metadata": {}, |
1150 | 1205 | "outputs": [ |
|
1204 | 1259 | }, |
1205 | 1260 | { |
1206 | 1261 | "cell_type": "code", |
1207 | | - "execution_count": 28, |
| 1262 | + "execution_count": 30, |
1208 | 1263 | "id": "1a221507", |
1209 | 1264 | "metadata": {}, |
1210 | 1265 | "outputs": [ |
|
1246 | 1301 | }, |
1247 | 1302 | { |
1248 | 1303 | "cell_type": "code", |
1249 | | - "execution_count": 29, |
| 1304 | + "execution_count": 31, |
1250 | 1305 | "id": "541af620", |
1251 | 1306 | "metadata": {}, |
1252 | 1307 | "outputs": [ |
|
1294 | 1349 | }, |
1295 | 1350 | { |
1296 | 1351 | "cell_type": "code", |
1297 | | - "execution_count": 30, |
| 1352 | + "execution_count": 32, |
1298 | 1353 | "id": "20d8285c", |
1299 | 1354 | "metadata": {}, |
1300 | 1355 | "outputs": [], |
|
1305 | 1360 | }, |
1306 | 1361 | { |
1307 | 1362 | "cell_type": "code", |
1308 | | - "execution_count": 31, |
| 1363 | + "execution_count": 33, |
1309 | 1364 | "id": "b702eb15", |
1310 | 1365 | "metadata": {}, |
1311 | 1366 | "outputs": [ |
|
1340 | 1395 | }, |
1341 | 1396 | { |
1342 | 1397 | "cell_type": "code", |
1343 | | - "execution_count": 32, |
| 1398 | + "execution_count": 34, |
1344 | 1399 | "id": "1ba71901", |
1345 | 1400 | "metadata": {}, |
1346 | 1401 | "outputs": [ |
|
1349 | 1404 | "output_type": "stream", |
1350 | 1405 | "text": [ |
1351 | 1406 | "Node data with invalid results\n", |
1352 | | - "[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n", |
1353 | | - " [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n", |
1354 | | - " [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n", |
1355 | | - " [0.00000000e+000 3.04369633e+101 3.41345331e+241]\n", |
1356 | | - " [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n", |
1357 | | - " [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n", |
1358 | | - " [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n", |
1359 | | - " [1.66994188e-321 3.12878333e-312 9.75772002e+199]\n", |
1360 | | - " [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n", |
1361 | | - " [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n", |
| 1407 | + "[[0.99940117 0.99268579 0.99452137]\n", |
| 1408 | + " [0.99934769 0.98622639 0.98935286]\n", |
| 1409 | + " [0.99928838 0.97965401 0.98409554]\n", |
| 1410 | + " [0. 0. 0. ]\n", |
| 1411 | + " [0.99915138 0.96614948 0.97329879]\n", |
| 1412 | + " [0.99907317 0.95920586 0.96775071]\n", |
| 1413 | + " [0.9989881 0.95212621 0.96209647]\n", |
| 1414 | + " [0. 0. 0. ]\n", |
| 1415 | + " [0.99879613 0.93753005 0.95044796]\n", |
| 1416 | + " [0.9986885 0.92999747 0.94444167]]\n", |
1362 | 1417 | "Node data with only valid results\n", |
1363 | 1418 | "[[0.99940117 0.99268579 0.99452137]\n", |
1364 | 1419 | " [0.99934769 0.98622639 0.98935286]\n", |
|
0 commit comments