|
@@ -0,0 +1,113 @@
|
|
|
+{
|
|
|
+ "cells": [
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "# Improved Integration of GRASS and Jupyter\n",
|
|
|
+ "\n",
|
|
|
+ "As part of Google Summer of Code 2021, we've been working to shorten and simplify the launch of GRASS in Jupyter and imporve the map displays. You can find out more abou the project and follow the progress on the [GRASS wiki page](https://trac.osgeo.org/grass/wiki/GSoC/2021/JupyterAndGRASS).\n",
|
|
|
+ "\n",
|
|
|
+ "This notebook is designed to run in binder and demonstrate the usage of `grass.jupyter`, the new module of Jupyter-specific functions for GRASS."
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {
|
|
|
+ "tags": []
|
|
|
+ },
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "import os\n",
|
|
|
+ "import subprocess\n",
|
|
|
+ "import sys\n",
|
|
|
+ "from IPython.display import Image"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "gisbase = subprocess.check_output([\"grass\", \"--config\", \"path\"], text=True).strip()\n",
|
|
|
+ "os.environ[\"GISBASE\"] = gisbase\n",
|
|
|
+ "sys.path.append(os.path.join(gisbase, \"etc\", \"python\"))"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "import grass.script as gs\n",
|
|
|
+ "import grass.jupyter as gj"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# Let's check our import by printing docstring for init()\n",
|
|
|
+ "gj.init?"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# Start GRASS Session\n",
|
|
|
+ "gj.init(\"../../data/grassdata\", \"nc_basic_spm_grass7\", \"user1\")\n",
|
|
|
+ "\n",
|
|
|
+ "# Set default display settings\n",
|
|
|
+ "gj.display_settings()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# Let's display the DTM of our sample area to ensure all's working\n",
|
|
|
+ "\n",
|
|
|
+ "# Set computational region to the study area.\n",
|
|
|
+ "gs.parse_command(\"g.region\", raster=\"elevation\", flags=\"pg\")\n",
|
|
|
+ "\n",
|
|
|
+ "# Draw elevation (DTM) to get an overview of the area.\n",
|
|
|
+ "gs.run_command(\"r.colors\", map=\"elevation\", color=\"elevation\")\n",
|
|
|
+ "gs.run_command(\"d.erase\")\n",
|
|
|
+ "gs.run_command(\"d.rast\", map=\"elevation\")\n",
|
|
|
+ "gs.run_command(\"d.legend\", raster=\"elevation\", at=(65, 90, 85, 90), fontsize=15, flags=\"b\", title=\"DTM\")\n",
|
|
|
+ "Image(filename=\"map.png\")"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "metadata": {
|
|
|
+ "kernelspec": {
|
|
|
+ "display_name": "Python 3",
|
|
|
+ "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.8.5"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "nbformat": 4,
|
|
|
+ "nbformat_minor": 4
|
|
|
+}
|