GRASS GIS Jupyter notebooks: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
No edit summary
(Remove outdated information)
 
(26 intermediate revisions by 3 users not shown)
Line 1: Line 1:
A Jupyter Notebook is a web application that allows you to create and share documents that contain scripts and code, equations, visualizations and explanatory text, combined.
A Jupyter Notebook is a web application that allows you to create and share documents that contain scripts and code, equations, visualizations and explanatory text, combined.


You can even change the code and explore your modified script(s).
== Get started ==
Read [https://grass.osgeo.org/grass-stable/manuals/jupyter_intro.html GRASS Jupyter Notebooks Introduction].
Try [https://grass-tutorials.osgeo.org/content/tutorials/get_started/fast_track_grass_and_python.html Get started with GRASS & Python in Jupyter Notebooks] official tutorial. Browse additional [https://grass-tutorials.osgeo.org/ tutorials].


== Requirements ==
== List of selected GRASS Jupyter notebooks ==
Note that the following list is community contributed and the notebooks may contain outdated information and old GRASS API usage. For up-to-date notebooks, see GRASS official [https://grass-tutorials.osgeo.org/ tutorial page].


You need to have a working jupyter installation:
<source lang="bash">
pip2 install jupyter
</source>


== How to run GRASS GIS from Jupyter notebook ==
'''Intro notebooks:'''
* [https://github.com/OSGeo/grass/blob/main/doc/notebooks Official notebooks in OSGeo/grass repo] ([https://mybinder.org/v2/gh/OSGeo/grass/main?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fjupyter_example.ipynb jupyter_example.ipynb on Binder])
* [https://github.com/ncsu-geoforall-lab/grass-gis-workshop-foss4g-2022 Unleash the power of GRASS GIS with Jupyter (FOSS4G 2022 workshop)]
* [https://github.com/ncsu-geoforall-lab/grass-gis-workshop-FOSS4G-2021 GRASS GIS: From Beginner to Power User (FOSS4G 2021 workshop)]
* [https://github.com/wenzeslaus/try-grass-in-jupyter-with-bash wenzeslaus/try-grass-in-jupyter-with-bash] (experimental)
* NSF platform: https://wholetale.org/
** GRASS GIS Introduction, by Anna Petrasova: https://dashboard.wholetale.org/run/63d832bab4a0197e9a9ecdad?tab=files


Running GRASS from Jupyter notebook requires that Jupyter notebook is installed on your system, and that you set up the [https://grass.osgeo.org/grass72/manuals/variables.html environment variables] for using GRASS.
'''Windows related:'''
* [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnWindows_standalone_Tutorial.ipynb GRASS GIS Jupyter Notebooks on Windows standalone installer tutorial]
* [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnWindows_OSGeo4W_Tutorial.ipynb GRASS GIS Jupyter Notebooks on Windows with OSGeo4W]


For example you can create a '''script''' called <tt>grass_jupyter.sh</tt> that contains the following lines:
'''Mac related:'''
<source lang="bash">
* [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnMac_Tutorial.ipynb GRASS GIS Jupyter Notebooks on Mac]


# directory where GRASS GIS lives
'''Workbook Collections:'''
export GISBASE=`grass74 --config path`  # or define path to binaries like /usr/local/grass-7.4.svn
* [https://github.com/wenzeslaus/geospatial-modeling-course-jupyter/tree/master/notebooks 14 Jupyter Notebooks for learning geospatial analysis and modeling with GRASS GIS] (Python and command line versions)
echo $GISBASE


# generate GISRC
'''Species Distribution Modeling:'''
# Defines the system wide value while in a GRASS session
* NSF platform: https://wholetale.org/
MYGISDBASE=$HOME/grassdata # Change this path to reflect your own
** Using satellite data for Species Distribution Modeling with GRASS GIS and R, by Veronica Andreo https://dashboard.wholetale.org/run/64388157b3b74e434bd8f1ac?tab=files
MYLOC=MyLoc # Change this location name to reflect your own
MYMAPSET=PERMANENT


# Set the global grassrc file to individual file name
'''Image processing/OBIA:'''
MYGISRC="$HOME/.grassrc.$$"
* [https://github.com/veroandreo/foss4g2022_grass4rs GRASS GIS for remote sensing data processing and analysis]
 
* [https://github.com/neteler/jupyter_sentinel2_grass_gis GRASS GIS 8 and processing of multitemporal EO data]
echo "GISDBASE: $MYGISDBASE" > "$MYGISRC"
* [https://github.com/tgrippa/Opensource_OBIA_processing_chain An open-source semi-automated processing chain for urban OBIA classification]
echo "LOCATION_NAME: $MYLOC" >> "$MYGISRC"
echo "MAPSET: $MYMAPSET" >> "$MYGISRC"
echo "GRASS_GUI: text" >> "$MYGISRC"
 
# path to GRASS settings file
export GISRC=$MYGISRC
 
export LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$GISBASE/etc/python:$PYTHONPATH
export PATH=$GISBASE/bin:$GISBASE/scripts:$PATH
 
# start the notebook in the notebook folder
cd $HOME/notebooks # change to notebooks folder (example; update to your path)
 
nohup jupyter notebook --ip=0.0.0.0 --port=8888 --debug &
</source>
 
To easily use this script, add this line to your <tt>$HOME/.bashrc</tt> file:
 
<source lang="bash">
# update path to script accordingly
alias grass_notebook='sh $HOME/grass_jupyter.sh'
</source>
 
From terminal, in your home directory:
<source lang="bash">
source .bashrc
</source>
 
Now you can start easily your notebook typing in the terminal:
<source lang="bash">
grass_notebook
</source>


=== List of selected GRASS GIS Jupyter notebooks ===
'''Python and PyGRASS:'''
* [https://github.com/zarch/workshop-pygrass Workshop on PyGRASS using IPython notebook]
* [https://github.com/wenzeslaus/foss4g-2022-developing-custom-grass-tools Developing custom GRASS tools (FOSS4G 2022 workshop)]
* [https://github.com/wenzeslaus/python-grass-addon How to write a Python GRASS GIS 7 addon (FOSS4G Europe 2015 workshop)]
* [https://github.com/lucadelu/docker-stacks/tree/geospatial/geospatial-notebook Jupyter Notebook Geospatial Python Stack]


(please expand!)
'''R and GRASS GIS:'''
 
* [https://gist.github.com/joergsteinkamp/43fb13a82aeab9b5c0dcc4433f97f1a6 Simple Opensource GIS examples with GRASS GIS and R]
* https://github.com/wenzeslaus/try-grass-in-jupyter
* https://github.com/wenzeslaus/try-grass-in-jupyter-with-bash
* OSGeoLive-Notebooks: [https://github.com/OSGeo/OSGeoLive-Notebooks/tree/master/GSoC-2015/Introduction%20to%20GRASS%20GIS Introduction to GRASS GIS]
* [https://github.com/zarch/workshop-pygrass Workshop on pygrass using IPython notebook]
* [https://github.com/tgrippa/Opensource_OBIA_processing_chain An open-source semi-automated processing chain for urban OBIA classification]
* [https://github.com/wenzeslaus/python-grass-addon How to write a Python GRASS GIS 7 addon]
* [https://github.com/lucadelu/docker-stacks/tree/geospatial/geospatial-notebook docker-stacks/geospatial-notebook]
* [https://github.com/wenzeslaus/geospatial-modeling-course-jupyter/tree/master/notebooks 14 Jupyter Notebooks for learning geospatial analysis and modeling with GRASS GIS]
* [https://gist.github.com/joergsteinkamp/43fb13a82aeab9b5c0dcc4433f97f1a6 Simple Opensource GIS examples with Grass and R]


==== See also ====
'''Wildfire Modeling:'''
* [https://github.com/acoiman/wildfire_modeling Wildfire Modeling in Yosemite National Park]


* [https://github.com/wenzeslaus/gdoc2py GRASS GIS focused converter from HTML with pre code tags to Jupyter Notebook]


[[Category: Documentation]]
[[Category: Documentation]]
[[Category: Python]]
[[Category: Python]]
[[Category: Tutorial]]

Latest revision as of 17:15, 15 May 2026

A Jupyter Notebook is a web application that allows you to create and share documents that contain scripts and code, equations, visualizations and explanatory text, combined.

Get started

Read GRASS Jupyter Notebooks Introduction. Try Get started with GRASS & Python in Jupyter Notebooks official tutorial. Browse additional tutorials.

List of selected GRASS Jupyter notebooks

Note that the following list is community contributed and the notebooks may contain outdated information and old GRASS API usage. For up-to-date notebooks, see GRASS official tutorial page.


Intro notebooks:

Windows related:

Mac related:

Workbook Collections:

Species Distribution Modeling:

Image processing/OBIA:

Python and PyGRASS:

R and GRASS GIS:

Wildfire Modeling: