Skip to content

MS/Ma_def #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
358 changes: 358 additions & 0 deletions input/ma_thesis/szenarien.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,358 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Some jupyter notebook magic to reload modules automaticaally when they change\n",
"# not neccessary for this specific notebook but useful in general\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"# Gives you high resolution images within the notebook\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pypsdm.ma_thesis import *\n",
"from pypsdm.ma_thesis.utils import get_output_path\n",
"\n",
"\n",
"grid_name = \"semiurb-combined-1\"\n",
"result_folder_name = \"Simulationen\"\n",
"result_base_name = \"Szenario\"\n",
"szenarios = [1,2,3,4]\n",
"\n",
"upper_limit = 1.05\n",
"lower_limit = 0.95\n",
"\n",
"dotted = [lower_limit, upper_limit]\n",
"tap_dotted = [2, -2]\n",
"\n",
"def res_out(scenario:str, filename: str, extension: str = \"pdf\"):\n",
" return get_output_path(result_base_name+\"-\"+scenario, filename+\".\"+extension)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-07-31 08:23:09.327\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mpypsdm.models.primary_data\u001b[0m:\u001b[36mfrom_csv\u001b[0m:\u001b[36m266\u001b[0m - \u001b[34m\u001b[1mNo primary data in path C:\\Users\\mariu\\PycharmProjects\\pypsdm\\input\\ma_thesis\\grids\\semiurb-combined-1\u001b[0m\n"
]
}
],
"source": [
"# Read grid and results\n",
"\n",
"grid, results = read_scenarios(grid_name, result_folder_name, result_base_name, szenarios)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Informationen\n",
"from pypsdm.ma_thesis.subgrid import SubGrid\n",
"\n",
"subgrids = SubGrid.build(grid)\n",
"\n",
"transformer_uuids: dict[str, list[str]] = {\n",
" \"1-2\": get_transformers_between(subgrids[1], subgrids[2]),\n",
" \"2-3\": get_transformers_between(subgrids[2], subgrids[3]),\n",
" \"2-4\": get_transformers_between(subgrids[2], subgrids[4]),\n",
" \"2-5\": get_transformers_between(subgrids[2], subgrids[5]),\n",
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"# Erkennung\n",
"\n",
"detection_scenario = \"1\"\n",
"\n",
"detection_results = results[result_base_name+\"-\"+detection_scenario]\n",
"detection_subgrid_info = {nr: SubGridInfo(sub, detection_results) for nr, sub in subgrids.items()}\n",
"detection_gwr = GridWithResults(grid, detection_results)\n",
"\n",
"## Voltage\n",
"\n",
"#congestion_v2 = plot_voltage_with_congestion(detection_subgrid_info[2], detection_results, dotted=dotted)\n",
"#ax_add_vlines(congestion_v2[1], [29, 78])\n",
"\n",
"#congestion_v3 = plot_voltage_with_congestion(detection_subgrid_info[3], detection_results, dotted=dotted)\n",
"#ax_add_vlines(congestion_v3[1], [104, 10, 122, 148])\n",
"\n",
"#congestion_v4 = plot_voltage_with_congestion(detection_subgrid_info[4], detection_results, dotted=dotted)\n",
"#congestion_v5 = plot_voltage_with_congestion(detection_subgrid_info[25], detection_results, dotted=dotted)\n",
"\n",
"\n",
"## Line\n",
"#congestion_l2 = plot_line_utilization_with_congestion(detection_subgrid_info[2], detection_results)\n",
"\n",
"## Transformer\n",
"#congestion_t12 = plot_transformer_utilization_with_congestion(detection_subgrid_info[2], transformer_uuids[\"1-2\"], detection_gwr)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Stufung 1\n",
"\n",
"tapping_results1 = results[result_base_name+\"-\"+\"1\"]\n",
"\n",
"# subgrid 2\n",
"#volt1_2 = plot_voltage_with_tapping(subgrids[2], transformer_uuids[\"1-2\"], tapping_results1, dotted=dotted) \n",
"#line1_2 = plot_line_utilization_with_congestion(SubGridInfo(subgrids[2], tapping_results1), tapping_results1)\n",
"\n",
"#subgrid 3\n",
"#volt1_3 = plot_voltage_with_tapping(subgrids[3], transformer_uuids[\"2-3\"], tapping_results1, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 4\n",
"#volt1_4 = plot_voltage_with_tapping(subgrids[4], transformer_uuids[\"2-4\"], tapping_results1, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 5\n",
"#volt1_5 = plot_voltage_with_tapping(subgrids[5], transformer_uuids[\"2-5\"], tapping_results1, dotted=dotted, tap_dotted=tap_dotted) \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Stufung 2\n",
"\n",
"tapping_results2 = results[result_base_name+\"-\"+\"2\"]\n",
"\n",
"# subgrid 2\n",
"#volt2_2 = plot_voltage_with_tapping(subgrids[2], transformer_uuids[\"1-2\"], tapping_results2, dotted=dotted) \n",
"#line2_2 = plot_line_utilization_with_congestion(SubGridInfo(subgrids[2], tapping_results2), tapping_results2)\n",
"\n",
"#subgrid 3\n",
"#volt2_3 = plot_voltage_with_tapping(subgrids[3], transformer_uuids[\"2-3\"], tapping_results2, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 4\n",
"#volt2_4 = plot_voltage_with_tapping(subgrids[4], transformer_uuids[\"2-4\"], tapping_results2, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 5\n",
"#volt2_5 = plot_voltage_with_tapping(subgrids[5], transformer_uuids[\"2-5\"], tapping_results2, dotted=dotted, tap_dotted=tap_dotted) \n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Stufung 3\n",
"\n",
"tapping_results3 = results[result_base_name+\"-\"+\"3\"]\n",
"\n",
"# subgrid 2\n",
"#volt3_2 = plot_voltage_with_tapping(subgrids[2], transformer_uuids[\"1-2\"], tapping_results3, dotted=dotted) \n",
"#line3_2 = plot_line_utilization_with_congestion(SubGridInfo(subgrids[2], tapping_results3), tapping_results3)\n",
"\n",
"#subgrid 3\n",
"#volt3_3 = plot_voltage_with_tapping(subgrids[3], transformer_uuids[\"2-3\"], tapping_results3, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 4\n",
"#volt3_4 = plot_voltage_with_tapping(subgrids[4], transformer_uuids[\"2-4\"], tapping_results3, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 5\n",
"#volt3_5 = plot_voltage_with_tapping(subgrids[5], transformer_uuids[\"2-5\"], tapping_results3, dotted=dotted, tap_dotted=tap_dotted) \n"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
"# Stufung 4\n",
"\n",
"tapping_results4 = results[result_base_name+\"-\"+\"4\"]\n",
"\n",
"# subgrid 2\n",
"#volt4_2 = plot_voltage_with_tapping(subgrids[2], transformer_uuids[\"1-2\"], tapping_results4, dotted=dotted) \n",
"#line4_2 = plot_line_utilization_with_congestion(SubGridInfo(subgrids[2], tapping_results4), tapping_results4)\n",
"\n",
"#subgrid 3\n",
"#volt2_3 = plot_voltage_with_tapping(subgrids[3], transformer_uuids[\"2-3\"], tapping_results4, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 4\n",
"#volt4_4 = plot_voltage_with_tapping(subgrids[4], transformer_uuids[\"2-4\"], tapping_results4, dotted=dotted, tap_dotted=tap_dotted) \n",
"\n",
"# subgrid 5\n",
"#volt4_5 = plot_voltage_with_tapping(subgrids[5], transformer_uuids[\"2-5\"], tapping_results4, dotted=dotted, tap_dotted=tap_dotted) \n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# Szenario-2 Spannungen\n",
"\n",
"#res_2 = results[result_base_name+\"-\"+\"2\"]\n",
"#s = 3\n",
"#fig, axes = create_fig(nrows=1, width=8, height=2)\n",
"#length = ax_plot_both_voltages(axes, subgrids[s], res_2.nodes, dotted)\n",
"#axes.set_ylabel(\"Spannung in pu\", fontsize=11)\n",
"#format_x_axis(axes, length)\n",
"#fig.savefig(res_out(\"2\", \"voltage-\"+str(s)))\n"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LV3.202 (min) 1.047213\n",
"LV3.202 (max) 1.050146\n",
"Name: 2016-07-30 05:00:00, dtype: float64"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = results[result_base_name+\"-\"+\"1\"]\n",
"\n",
"\n",
"info = SubGridInfo(subgrids[3], res)\n",
"info.node_min_max.loc[\"2016-07-30 05:00:00\"]\n",
"\n",
"\n",
"#df = res.transformers_2w[transformer_uuids[\"1-2\"][0]].data\n",
"#df[df[\"tap_pos\"].values == 2]\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Ohne Engpassmanagement 523.666667\n",
"Zwei Stufungen pro Tag 538.000000\n",
"Stufung zu jedem Zeitpunkt 1014.000000\n",
"dtype: float64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Laufzeit\n",
"\n",
"import pandas as pd\n",
"\n",
"data = {\n",
" \"Ohne Engpassmanagement\": [8*60+47, 8*60+44, 8*60+40],\n",
" \"Zwei Stufungen pro Tag\": [9*60+1, 8*60+57, 8*60+56],\n",
" \"Stufung zu jedem Zeitpunkt\": [16*60+54, 16*60+56, 16*60+52]\n",
"}\n",
"\n",
"df = pd.DataFrame(data)\n",
"\n",
"#ax = df.plot.barh(legend=False)\n",
"#ax.set_xlabel(\"Zeit in Sekunden\")\n",
"\n",
"#df.mean()\n",
"\n",
"df.mean()\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Spannungsvergleich\n",
"from pypsdm.ma_thesis.plots import plot_voltages_with_scenario\n",
"\n",
"\n",
"#_ = plot_voltages_with_scenario(subgrids[2], results, upper_limit=upper_limit, lower_limit=lower_limit).savefig(res_out(\"Spannung-2-all\"))\n",
"#_ = plot_voltages_with_scenario(subgrids[3], results, upper_limit=upper_limit, lower_limit=lower_limit).savefig(res_out(\"Spannung-3-all\"))\n",
"#_ = plot_voltages_with_scenario(subgrids[4], results, upper_limit=upper_limit, lower_limit=lower_limit).savefig(res_out(\"Spannung-4-all\"))\n",
"#_ = plot_voltages_with_scenario(subgrids[5], results, upper_limit=upper_limit, lower_limit=lower_limit).savefig(res_out(\"Spannung-5-all\"))\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"# _ = plot_with_highlights(gwr.grid)\n",
"# _ = plot_voltage_subgrids(subgrids, dotted=[1.03, 0.97], width=30, height=20)\n",
"# _ = plot_voltage_with_tapping(subgrids[1], subgrids[2], gwr.transformers_2_w, gwr.transformers_2_w_res, width=30, height=10, dotted=[1.03, 0.97])\n",
"# _ = plot_line_utilizations(subgrids[4], threshold=0.33, show_legend=False, width=30)\n",
"# _ = plot_line_utilizations(subgrids[2], threshold=0.33, show_legend=False, width=30)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "gui-MypUtHgG-py3.11",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading