Skip to content

Commit

Permalink
r.stats.zonal manual: add screenshots (OSGeo#2577)
Browse files Browse the repository at this point in the history
* r.stats.zonal manual: add figure to illustrate module functionality along with jupyter notebook
* r.series: bugfix for labeling
  • Loading branch information
neteler committed Nov 7, 2023
1 parent 8f82fee commit f05755f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
4 changes: 2 additions & 2 deletions raster/r.series/graphics_for_description.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Graphics for Description of r.series\n",
"\n",
"Requires _d.explanation.plot_, _pngquant_, _optipng_ and ImageMagic _mogrify_."
"Requires _d.explanation.plot_ (GRASS GIS addon), _pngquant_, _optipng_ and ImageMagic _mogrify_."
]
},
{
Expand Down Expand Up @@ -56,7 +56,7 @@
" d=\"d\",\n",
" label_a=\"input 1\",\n",
" label_b=\"input 2\",\n",
" label_c=\"input 1\",\n",
" label_c=\"input 3\",\n",
" label_d=\"average\",\n",
" operator_font=\"FreeMono:Regular\",\n",
")\n",
Expand Down
Binary file modified raster/r.series/r_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 110 additions & 0 deletions raster/r.stats.zonal/graphics_for_description.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Graphics for description of r.stats.zonal\n",
"\n",
"To be run in a GRASS GIS session, North Carolina sample dataset.\n",
"\n",
"Requires _d.explanation.plot_ (GRASS GIS addon), _pngquant_, _optipng_ and ImageMagic _mogrify_."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from IPython.display import Image\n",
"\n",
"import grass.script as gs\n",
"import grass.jupyter as gj\n",
"\n",
"gs.set_raise_on_error(True)\n",
"gs.set_capture_stderr(True)\n",
"os.environ[\"GRASS_OVERWRITE\"] = \"1\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# zoom to spatial subset of \"zipcodes\" map (5 x 5 pixels)\n",
"!g.region n=225430 s=225380 w=640250 e=640300 res=10 -p\n",
"\n",
"# average elevation in zipcode areas\n",
"!r.stats.zonal base=zipcodes cover=elevation method=average output=zipcodes_elev_avg\n",
"!r.colors zipcodes_elev_avg color=elevation -g"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot = gj.Map(use_region=True, width=1100, height=1100)\n",
"plot.d_background(color=\"white\")\n",
"plot.run(\n",
" \"d.explanation.plot\",\n",
" a=\"zipcodes\",\n",
" b=\"elevation\",\n",
" c=\"zipcodes_elev_avg\",\n",
" label_a=\"zipcode areas\",\n",
" label_b=\"elevation\",\n",
" label_c=\"Avg elev. / area\",\n",
" operator_font=\"FreeMono:Regular\",\n",
")\n",
"plot.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename = \"r_stats.zonal.png\"\n",
"plot.save(filename)\n",
"!mogrify -trim {filename}\n",
"!pngquant --ext \".png\" -f {filename}\n",
"!optipng -o7 {filename}\n",
"Image(filename)"
]
},
{
"cell_type": "code",
"execution_count": null,
"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.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
14 changes: 14 additions & 0 deletions raster/r.stats.zonal/r.stats.zonal.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ <h2>EXAMPLE</h2>
r.colors zipcodes_elev_avg color=elevation -g
</pre></div>

<p>
<!-- generated with graphics_for_description.ipynb -->
<div align="center" style="margin: 10px">
<a href="r_stats.zonal.png">
<img src="r_stats.zonal.png" alt="Zonal (average) elevation statistics" border="0">
</a>
<br><br>
<i>Figure: ZIP code map on the left shows ZIP code areas,
elevation map the respective values per pixel,
zonal statistics map on the right shows the average elevation per zone
(all maps: spatial subset).</i>
</div>


<h2>SEE ALSO</h2>

<ul>
Expand Down
Binary file added raster/r.stats.zonal/r_stats.zonal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f05755f

Please sign in to comment.