Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- Add example for Line Results to documentation [#341](https://github.com/ie3-institute/pypsdm/issues/341)
- Add colored Line Trace to plotting [#348](https://github.com/ie3-institute/pypsdm/issues/348)
- Add colored Node Trace to plotting [#349](https://github.com/ie3-institute/pypsdm/issues/349)
- Add functionality to plot line traces without mapbox as vector graphic [#360](https://github.com/ie3-institute/pypsdm/issues/360)

### Changed
- Move `NBVAL` to dev dependencies [#374](https://github.com/ie3-institute/pypsdm/issues/374)
Expand Down
161 changes: 161 additions & 0 deletions docs/nbs/plotting_utilities_trace_vector_graphic.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {},
"outputs": [],
"source": [
"# NBVAL_SKIP\n",
"# Some jupyter notebook magic to reload modules automatically when they change\n",
"# not necessary 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'"
]
},
{
"cell_type": "markdown",
"id": "e5d8cd1a4adf4f11",
"metadata": {},
"source": [
"# Plotting Line traces as Vector Graphic (High Quality)\n",
"Since plotting line and node traces on a map, e.g. OpenStreetMap, using `Scattermapbox` the output will be rendered not as vector graphic.\n",
"\n",
"Setting `use_mapbox = False` allows to use `Scatter` which will output as vector graphic and thus allows to save figures in .svg or .pdf format."
]
},
{
"cell_type": "markdown",
"id": "3ed885bf22427a4a",
"metadata": {},
"source": [
"## Load Data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81678c770f5da613",
"metadata": {},
"outputs": [],
"source": [
"from definitions import ROOT_DIR\n",
"import os\n",
"\n",
"# The PSDM specific input models can be imported from the pypsdm.models.input and\n",
"# pypsdm.models.result. The `GridWithResults` container is located in pypsdm.models.gwr\n",
"from pypsdm.models.gwr import GridWithResults\n",
"\n",
"grid_path = os.path.join(ROOT_DIR, \"tests\", \"resources\", \"simbench\", \"input\")\n",
"result_path = os.path.join(ROOT_DIR, \"tests\", \"resources\", \"simbench\", \"results\")\n",
"\n",
"# IO data models in general have a from_csv method to parse psdm files\n",
"gwr = GridWithResults.from_csv(grid_path, result_path)"
]
},
{
"cell_type": "markdown",
"id": "ca40b9b6b739fa82",
"metadata": {},
"source": [
"## Get Line Results and Calculate Utilisation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "275adf2cb67a9d37",
"metadata": {},
"outputs": [],
"source": [
"# NBVAL_CHECK_OUTPUT\n",
"line_input_data = gwr.lines\n",
"line_utilization = gwr.lines_res.utilisation(line_input_data, side=\"a\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64515d7eab450b23",
"metadata": {},
"outputs": [],
"source": [
"# NBVAL_CHECK_OUTPUT\n",
"import pandas as pd\n",
"\n",
"specific_time = pd.to_datetime(\"2016-01-02 12:00:00\")\n",
"# filter for timestamp\n",
"filtered_data = line_utilization.loc[[specific_time]].to_dict()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d8629a2a57260668",
"metadata": {},
"outputs": [],
"source": [
"from pypsdm.plots.grid import create_zoom_box, grid_plot\n",
"\n",
"# zoom_box allows to focus on certain parts of your plot\n",
"zoom_box = create_zoom_box(53.665, 11.35, 53.62, 11.38)\n",
"\n",
"# to remove the axes and lat / lon grid simply set show_axes = False or remove the parameter\n",
"fig_svg = grid_plot(\n",
" gwr.grid,\n",
" cmap_lines=\"Jet\",\n",
" cmap_line_values=filtered_data,\n",
" cbar_line_title=\"Line Utilisation\",\n",
" zoom_box=zoom_box,\n",
" show_axes=True,\n",
" use_mapbox=False,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b28859b912d9c22c",
"metadata": {},
"outputs": [],
"source": [
"fig_svg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ba2dbff4e8bd18a",
"metadata": {},
"outputs": [],
"source": [
"# Plot can be saved as svg or other vector format\n",
"# fig_svg.write_image('save_as_svg.svg')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading