{ "cells": [ { "cell_type": "markdown", "id": "5e77d77863e143dd", "metadata": {}, "source": [ "### Example notebook" ] }, { "cell_type": "code", "execution_count": null, "id": "initial_id", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:04.883797Z", "iopub.status.busy": "2024-11-20T13:52:04.883797Z", "iopub.status.idle": "2024-11-20T13:52:17.812517Z", "shell.execute_reply": "2024-11-20T13:52:17.812517Z" } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "from pommes import test_case_path\n", "from pommes.io.build_input_dataset import (\n", " build_input_parameters,\n", " read_config_file,\n", ")\n", "from pommes.io.save_solution import save_solution\n", "from pommes.model.build_model import build_model\n", "from pommes.model.data_validation.dataset_check import check_inputs" ] }, { "cell_type": "code", "execution_count": null, "id": "e708071b2053cc74", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:17.815503Z", "iopub.status.busy": "2024-11-20T13:52:17.814508Z", "iopub.status.idle": "2024-11-20T13:52:17.818912Z", "shell.execute_reply": "2024-11-20T13:52:17.818912Z" } }, "outputs": [], "source": [ "scenario = \"ref\"\n", "suffix = \"_02161113\"\n", "\n", "output_folder = f\"{test_case_path}/output/{scenario}{suffix}\"\n", "solver = \"highs\" # [\"gurobi\", \"xpress\", \"highs\", \"mosek\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "20ac9edf3ab575d1", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:17.821776Z", "iopub.status.busy": "2024-11-20T13:52:17.821776Z", "iopub.status.idle": "2024-11-20T13:52:19.313319Z", "shell.execute_reply": "2024-11-20T13:52:19.313319Z" } }, "outputs": [], "source": [ "config = read_config_file(file_path=test_case_path / \"config.yaml\")\n", "\n", "model_parameters = build_input_parameters(config)\n", "model_parameters = check_inputs(model_parameters)" ] }, { "cell_type": "code", "execution_count": null, "id": "fb042d2e", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:19.316349Z", "iopub.status.busy": "2024-11-20T13:52:19.315312Z", "iopub.status.idle": "2024-11-20T13:52:21.695271Z", "shell.execute_reply": "2024-11-20T13:52:21.695271Z" } }, "outputs": [], "source": [ "model = build_model(model_parameters)" ] }, { "cell_type": "code", "execution_count": null, "id": "4a4117f4", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:21.698259Z", "iopub.status.busy": "2024-11-20T13:52:21.698259Z", "iopub.status.idle": "2024-11-20T13:52:26.381975Z", "shell.execute_reply": "2024-11-20T13:52:26.381975Z" } }, "outputs": [], "source": [ "model.solve(solver_name=solver)\n", "\n", "save_solution(\n", " model=model,\n", " output_folder=output_folder,\n", " model_parameters=model_parameters,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "964d2da4", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:26.383973Z", "iopub.status.busy": "2024-11-20T13:52:26.383973Z", "iopub.status.idle": "2024-11-20T13:52:26.447766Z", "shell.execute_reply": "2024-11-20T13:52:26.447766Z" } }, "outputs": [], "source": [ "solution = model.solution\n", "print(model.solution)" ] }, { "cell_type": "code", "execution_count": null, "id": "bdb98cb9", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:26.450753Z", "iopub.status.busy": "2024-11-20T13:52:26.449757Z", "iopub.status.idle": "2024-11-20T13:52:26.491117Z", "shell.execute_reply": "2024-11-20T13:52:26.491117Z" } }, "outputs": [], "source": [ "dual = model.dual\n", "print(dual)" ] }, { "cell_type": "code", "execution_count": null, "id": "fd516824", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:26.493216Z", "iopub.status.busy": "2024-11-20T13:52:26.493216Z", "iopub.status.idle": "2024-11-20T13:52:26.510717Z", "shell.execute_reply": "2024-11-20T13:52:26.510717Z" } }, "outputs": [], "source": [ "prices = dual.operation_adequacy_constraint\n", "df = prices.to_dataframe(name=\"value\").reset_index()\n", "print(df)" ] }, { "cell_type": "code", "execution_count": null, "id": "c7860470", "metadata": { "execution": { "iopub.execute_input": "2024-11-20T13:52:26.512712Z", "iopub.status.busy": "2024-11-20T13:52:26.512712Z", "iopub.status.idle": "2024-11-20T13:52:28.187469Z", "shell.execute_reply": "2024-11-20T13:52:28.187469Z" } }, "outputs": [], "source": [ "unique_resources = df[\"resource\"].unique()\n", "unique_years = df[\"year_op\"].unique()\n", "unique_areas = df[\"area\"].unique()\n", "colors = plt.cm.tab10(range(len(unique_areas)))\n", "area_color_map = {area: colors[i] for i, area in enumerate(unique_areas)}\n", "\n", "fig, axes = plt.subplots(\n", " len(unique_resources),\n", " len(unique_years),\n", " figsize=(15, 10),\n", " sharex=True,\n", " sharey=\"row\",\n", ")\n", "\n", "for i, resource in enumerate(unique_resources):\n", " for j, year in enumerate(unique_years):\n", " ax = axes[i, j]\n", " subset = df[(df[\"resource\"] == resource) & (df[\"year_op\"] == year)]\n", "\n", " for area in unique_areas:\n", " area_data = subset[subset[\"area\"] == area]\n", " if not area_data.empty:\n", " ax.plot(\n", " area_data[\"hour\"],\n", " area_data[\"value\"],\n", " marker=\"o\",\n", " color=area_color_map[area],\n", " )\n", " if i == 0:\n", " ax.set_title(f\"Year: {year}\")\n", " if j == 0:\n", " ax.set_ylabel(f\"Resource: {resource}\")\n", " if i == len(unique_resources) - 1:\n", " ax.set_xlabel(\"Hour\")\n", "\n", "legend_elements = [\n", " plt.Line2D(\n", " [0],\n", " [0],\n", " marker=\"o\",\n", " color=color,\n", " linestyle=\"\",\n", " markersize=8,\n", " label=area,\n", " )\n", " for area, color in area_color_map.items()\n", "]\n", "fig.legend(\n", " handles=legend_elements,\n", " loc=\"upper center\",\n", " ncol=len(unique_areas),\n", " title=\"Area\",\n", ")\n", "\n", "plt.tight_layout(rect=(0, 0, 1, 0.95))\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "d70d7024", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "", "language": "python", "name": "" }, "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.10" } }, "nbformat": 4, "nbformat_minor": 5 }