Skip to content
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

Noteboook for pypsa distribution #88

Draft
wants to merge 3 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
108 changes: 108 additions & 0 deletions notebooks/distribution/Buildings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import matplotlib.cm as cm\n",
"import matplotlib.patches as mpatches\n",
"import geopandas as gpd\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"import os\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"base_dir = \"C:/Users/margh/Desktop/pypsa/pypsa-distribution\" # Edit this string with the top of the path where you saved the pypsa-distribution folder\n",
"\n",
"buildings_path = base_dir+\"/resources/buildings/microgrid_building.geojson\"\n",
"buildings = gpd.read_file(buildings_path)\n",
"clustered_path = base_dir+\"/resources/buildings/clustered_buildings.geojson\"\n",
"clustered = gpd.read_file(clustered_path)\n",
"shape_path = base_dir+\"/resources/shapes/microgrid_shapes.geojson\"\n",
"shape = gpd.read_file(shape_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(10, 10), subplot_kw={'projection': ccrs.PlateCarree()})\n",
"buildings.plot(ax=ax, legend=False, label=\"buildings\" ,color=\"midnightblue\",markersize=0.005, alpha=1)\n",
"clustered.plot(ax=ax, legend=False, label=\"clustered_buildings\", alpha=1, color='orange')\n",
"shape.plot(ax=ax, legend=False, label=\"shape\", alpha=1, edgecolor=\"slategray\", facecolor=\"none\", linewidth=1)\n",
"ax.set_frame_on(False)\n",
"\n",
"legend_elements = [\n",
" plt.Line2D([0], [0], color='midnightblue', marker='s', linestyle='None', label='Buildings'),\n",
" plt.Line2D([0], [0], color='orange', marker='o', linestyle='None', label='Clustered Buildings'),\n",
" plt.Line2D([0], [0], color='slategrey', marker='_', linestyle='None', label='Shape')\n",
"]\n",
"ax.legend(handles=legend_elements, loc='upper right',bbox_to_anchor=(1.15, 0.96))\n",
"ax.set_title(\"Buildings Cluster and Shape\")\n",
"plt.tight_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(10, 10), subplot_kw={'projection': ccrs.PlateCarree()})\n",
"buildings.plot(ax=ax, legend=False, label=\"buildings\" ,color=\"midnightblue\",markersize=0.005, alpha=1)\n",
"clustered.plot(ax=ax, legend=False, label=\"clustered_buildings\", alpha=1, cmap='tab10')\n",
"shape.plot(ax=ax, legend=False, label=\"shape\", alpha=1, edgecolor=\"slategray\", facecolor=\"none\", linewidth=1)\n",
"\n",
"ax.set_frame_on(False)\n",
"\n",
"cmap = cm.get_cmap('tab10')\n",
"clustered_labels = clustered[\"cluster\"].unique() \n",
"legend_handles = [mpatches.Patch(color=cmap(i), label=f'Cluster {clustered_labels[i]}') for i in range(len(clustered_labels))]\n",
"ax.legend(handles=legend_handles, title='Clustered Buildings', loc='upper left', bbox_to_anchor=(1, 0.96), ncol=1, fancybox=True, shadow=True)\n",
"ax.set_title(\"Buildings with Cluster\")\n",
"plt.tight_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"buildings.explore()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pypsa-earth",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading