|
@@ -6,7 +6,7 @@
|
|
|
"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",
|
|
|
+ "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 about 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."
|
|
|
]
|
|
@@ -21,8 +21,7 @@
|
|
|
"source": [
|
|
|
"import os\n",
|
|
|
"import subprocess\n",
|
|
|
- "import sys\n",
|
|
|
- "from IPython.display import Image"
|
|
|
+ "import sys"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -63,10 +62,41 @@
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
"# Start GRASS Session\n",
|
|
|
- "gj.init(\"../../data/grassdata\", \"nc_basic_spm_grass7\", \"user1\")\n",
|
|
|
+ "gj.init(\"../../data/grassdata\", \"nc_basic_spm_grass7\", \"user1\")"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# Set computational region to the study area.\n",
|
|
|
+ "gs.run_command(\"g.region\", raster=\"elevation\")"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {
|
|
|
+ "tags": []
|
|
|
+ },
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# Demonstration of GrassRenderer for non-interactive map display\n",
|
|
|
+ "m = gj.GrassRenderer(height=540, filename = \"streams_map.png\")\n",
|
|
|
"\n",
|
|
|
- "# Set default display settings\n",
|
|
|
- "gj.display_settings()"
|
|
|
+ "m.run(\"d.rast\", map=\"elevation\")\n",
|
|
|
+ "m.run(\"d.vect\", map=\"streams\")\n",
|
|
|
+ "\n",
|
|
|
+ "m.show()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "### Let's demonstrate how we can have two instances of GrassRenderer"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -75,18 +105,52 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "# Let's display the DTM of our sample area to ensure all's working\n",
|
|
|
+ "# First, we'll make a second instance. Notice we need a different filename\n",
|
|
|
+ "m2 = gj.GrassRenderer(height=200, width = 220, filename = \"roads_maps.png\")\n",
|
|
|
"\n",
|
|
|
- "# Set computational region to the study area.\n",
|
|
|
- "gs.parse_command(\"g.region\", raster=\"elevation\", flags=\"pg\")\n",
|
|
|
+ "m2.run(\"d.rast\", map=\"elevation_shade\")\n",
|
|
|
+ "m2.run(\"d.vect\", map=\"roadsmajor\")\n",
|
|
|
+ "\n",
|
|
|
+ "m2.show()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# Then, we return to the first instance and continue to modify/display\n",
|
|
|
+ "\n",
|
|
|
+ "m.run(\"d.vect\", map = \"zipcodes\", color=\"red\", fill_color=\"none\")\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\")"
|
|
|
+ "m.show()"
|
|
|
]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "### Error Handling"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# If we pass a non-display related module to GrassRenderer, it returns an error\n",
|
|
|
+ "\n",
|
|
|
+ "m.run(\"r.watershed\", map=\"elevation\")"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": []
|
|
|
}
|
|
|
],
|
|
|
"metadata": {
|