{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "e5e9ca3f-6a7e-4003-952e-d455ea750b79", "metadata": {}, "outputs": [], "source": [ "import grass.jupyter as gj\n", "from grass.tools import Tools\n", "\n", "tools = Tools(overwrite=True)\n", "\n", "m = gj.Map(width=500)\n", "\n", "# Add a raster map to the map object\n", "m.d_rast(map=\"elevation\")\n", "\n", "# Add a vector map to the map object\n", "m.d_vect(map=\"streets\", color=\"black\")\n", "\n", "# Display the map\n", "m.show()\n", "m.save(\"./man/mkdocs/docs/jupyter_map.png\")" ] }, { "cell_type": "code", "execution_count": null, "id": "19bc23a5-f724-4c53-9a6d-0f1e439e5995", "metadata": {}, "outputs": [], "source": [ "!pngnq -n 128 -s 3 ./man/mkdocs/docs/jupyter_map.png\n", "\n", "# shuffle original and quantitized image names\n", "!mv ./man/mkdocs/docs/jupyter_map-nq8.png ./man/mkdocs/docs/jupyter_map.png\n", "\n", "# compress better (lossless)\n", "!optipng -o5 ./man/mkdocs/docs/jupyter_map.png" ] }, { "cell_type": "code", "execution_count": null, "id": "ff690750-3e97-42ec-8738-daaa291f915c", "metadata": {}, "outputs": [], "source": [ "tools.r_relief(input=\"elevation\", output=\"relief\")\n", "m = gj.Map(width=500)\n", "\n", "# Add a shaded relief map\n", "m.d_shade(color=\"elevation\", shade=\"relief\", brighten=50)\n", "\n", "# Add a raster legend\n", "m.d_legend(\n", " raster=\"elevation\",\n", " at=(1, 50, 1, 8),\n", " title=\"Elevation (m)\",\n", " border_color=\"none\",\n", " flags=\"bt\",\n", ")\n", "\n", "# Add a scale bar to the map\n", "m.d_barscale(at=(53, 5), flags=\"n\")\n", "\n", "# Display the map\n", "m.show()\n", "m.save(\"./man/mkdocs/docs/jupyter_map.webp\")" ] }, { "cell_type": "code", "execution_count": null, "id": "15c2932d-c828-42b0-a9f7-bd2d659ca081", "metadata": {}, "outputs": [], "source": [ "!pngnq -n 200 -s 3 ./man/mkdocs/docs/jupyter_map.png\n", "\n", "# shuffle original and quantitized image names\n", "!mv ./man/mkdocs/docs/jupyter_map-nq8.png ./man/mkdocs/docs/jupyter_map.png\n", "\n", "# compress better (lossless)\n", "!optipng -o5 ./man/mkdocs/docs/jupyter_map.png" ] }, { "cell_type": "code", "execution_count": null, "id": "6893df42-23e2-4649-9794-c1c4238aa3f0", "metadata": {}, "outputs": [], "source": [ "m = gj.InteractiveMap(width=500)\n", "m.add_raster(\"elevation\", opacity=0.7)\n", "m.add_vector(\"roadsmajor\")\n", "m.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "f18bab5c-c852-4f9e-8953-9c6c2532b490", "metadata": {}, "outputs": [], "source": [ "!pngnq -n 200 -s 3 ./man/mkdocs/docs/jupyter_interactive_map.png\n", "\n", "# shuffle original and quantitized image names\n", "!mv ./man/mkdocs/docs/jupyter_interactive_map-nq8.png ./man/mkdocs/docs/jupyter_interactive_map.png\n", "\n", "# compress better (lossless)\n", "!optipng -o5 ./man/mkdocs/docs/jupyter_interactive_map.png" ] }, { "cell_type": "code", "execution_count": null, "id": "8ec4dd7e-c197-472e-bb6e-26e3a1e904ea", "metadata": {}, "outputs": [], "source": [ "from PIL import Image\n", "\n", "elevation_3dmap = gj.Map3D()\n", "elevation_3dmap.render(\n", " elevation_map=\"elevation\",\n", " color_map=\"landuse\",\n", " position=[0.5, 1],\n", " perspective=10,\n", " height=5000,\n", " resolution_fine=1,\n", " zexag=5,\n", ")\n", "elevation_3dmap.overlay.d_legend(\n", " raster=\"landuse\", at=(0, 30, 87, 100), flags=\"b\", border_color=\"none\"\n", ")\n", "elevation_3dmap.show()\n", "\n", "im = Image.open(elevation_3dmap._filename)\n", "im.save(\"./man/mkdocs/docs/jupyter_3d_map.png\", \"PNG\")" ] }, { "cell_type": "code", "execution_count": null, "id": "1f57da59-eb53-45f7-9675-8f8ce2f1f899", "metadata": {}, "outputs": [], "source": [ "!pngnq -n 128 -s 3 ./man/mkdocs/docs/jupyter_3d_map.png\n", "\n", "# shuffle original and quantitized image names\n", "!mv ./man/mkdocs/docs/jupyter_3d_map-nq8.png ./man/mkdocs/docs/jupyter_3d_map.png\n", "\n", "# compress better (lossless)\n", "!optipng -o5 ./man/mkdocs/docs/jupyter_3d_map.png" ] }, { "cell_type": "code", "execution_count": null, "id": "d29ce273-ff43-4640-accf-7565a008a87d", "metadata": {}, "outputs": [], "source": [ "directions = [0, 90, 180, 270]\n", "for azimuth in directions:\n", " tools.r_relief(\n", " input=\"elevation\",\n", " output=f\"relief_{azimuth}\",\n", " azimuth=azimuth,\n", " zscale=2,\n", " )\n", "maps = [f\"relief_{azimuth}\" for azimuth in directions]" ] }, { "cell_type": "code", "execution_count": null, "id": "00f47fc2-5202-4b86-b300-24327c56561e", "metadata": {}, "outputs": [], "source": [ "m = gj.SeriesMap(width=500)\n", "m.add_rasters(maps)\n", "m.d_vect(map=\"streets\", color=\"black\")\n", "m.d_barscale(at=(53, 5), flags=\"n\")\n", "m.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "034c54a3-94b3-4f07-b46e-9b5c25a0eb20", "metadata": {}, "outputs": [], "source": [ "!pngnq -n 32 -s 3 ./man/mkdocs/docs/jupyter_series_map.png\n", "\n", "# shuffle original and quantitized image names\n", "!mv ./man/mkdocs/docs/jupyter_series_map-nq8.png ./man/mkdocs/docs/jupyter_series_map.png\n", "\n", "# compress better (lossless)\n", "!optipng -o5 ./man/mkdocs/docs/jupyter_series_map.png" ] }, { "cell_type": "code", "execution_count": null, "id": "b8b9ef9e-9eba-468d-ae06-924ade46c277", "metadata": {}, "outputs": [], "source": [ "tools.g_region(n=226040, s=223780, e=639170, w=636190)\n", "tools.r_slope_aspect(elevation=\"elevation\", dx=\"dx\", dy=\"dy\")\n", "tools.r_sim_water(\n", " flags=\"t\",\n", " elevation=\"elevation\",\n", " dx=\"dx\",\n", " dy=\"dy\",\n", " depth=\"depth\",\n", " niterations=30,\n", " overwrite=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "7c9ae833-cd63-49a6-bd61-4049e6cff7fc", "metadata": {}, "outputs": [], "source": [ "tools.t_create(\n", " output=\"depth\",\n", " temporaltype=\"relative\",\n", " title=\"Overland flow depth\",\n", " description=\"Overland flow depth\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "ca2998db-1355-45ec-974c-5077acd04789", "metadata": {}, "outputs": [], "source": [ "maps = [\n", " item[\"fullname\"]\n", " for item in tools.g_list(type=\"raster\", pattern=\"depth*\", format=\"json\")\n", "]\n", "tools.t_register(input=\"depth\", maps=maps)" ] }, { "cell_type": "code", "execution_count": null, "id": "a96270e2-b65e-4e93-94bb-2b3e32dfaa26", "metadata": {}, "outputs": [], "source": [ "flow_map = gj.TimeSeriesMap()\n", "\n", "# Add the time series data\n", "flow_map.d_rast(map=\"elevation\")\n", "flow_map.add_raster_series(\"depth\", values=\"0.025-1.25\")\n", "flow_map.d_vect(map=\"streets\")\n", "\n", "# Add map features\n", "flow_map.d_legend(\n", " raster=\"depth.30\",\n", " title=\"Depth [m]\",\n", " flags=\"bt\",\n", " border_color=\"none\",\n", " at=(1, 50, 0, 5),\n", ")\n", "\n", "# Display the map\n", "flow_map.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "8d7c615c-6ad5-4f95-a9ba-1fff682774f9", "metadata": {}, "outputs": [], "source": [ "!pngnq -n 256 -s 3 ./man/mkdocs/docs/jupyter_timeseries_map.png\n", "\n", "# shuffle original and quantitized image names\n", "!mv ./man/mkdocs/docs/jupyter_timeseries_map-nq8.png ./man/mkdocs/docs/jupyter_timeseries_map.png\n", "\n", "# compress better (lossless)\n", "!optipng -o5 ./man/mkdocs/docs/jupyter_timeseries_map.png" ] }, { "cell_type": "code", "execution_count": null, "id": "9148b304", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }