GRASS GIS Jupyter notebooks: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(+ Jupyter notebooks for Windows by Caitlin)
(Remove outdated information)
 
(4 intermediate revisions by 2 users not shown)
Line 2: Line 2:


== Get started ==
== 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].


Read the intro in the official documentation for [https://grass.osgeo.org/grass-stable/manuals/libpython/grass.jupyter.html grass.jupyter package].
== 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].


== List of selected GRASS GIS Jupyter notebooks ==
''(add yours to the list!)''


'''Intro notebooks:'''
'''Intro notebooks:'''
Line 18: Line 18:


'''Windows related:'''
'''Windows related:'''
* [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnWindows_standalone_Tutorial.ipynb Jupyter Notebooks on Windows standalone installer tutorial]
* [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 Jupyter Notebooks on Windows with OSGeo4W]
* [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]
 
'''Mac related:'''
* [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnMac_Tutorial.ipynb GRASS GIS Jupyter Notebooks on Mac]


'''Workbook Collections:'''
'''Workbook Collections:'''
Line 45: Line 48:
* [https://github.com/acoiman/wildfire_modeling Wildfire Modeling in Yosemite National Park]
* [https://github.com/acoiman/wildfire_modeling Wildfire Modeling in Yosemite National Park]


== Running GRASS GIS in Jupyter Lab with docker ==
* JupyterGrass: GRASS GIS in Jupyter Lab
** docker-compose file and instructions: https://gist.github.com/manuelep/e56fe90399c44e02e7cb97d5ef95edbd
== Running GRASS GIS in a Jupyter notebook locally ==
Both Jupyter and GRASS GIS have so called environments or sessions which need to be combined. Existing online environments with example notebooks are usually prepared to run right away, but locally, one must prepare the necessary software setup.
=== Software requirements ===
You need to have a working GRASS GIS installation.
You need to have a working Jupyter installation. If you are using ''pip'', you can install Jupyter using:
<syntaxhighlight lang="bash">
pip install jupyter
</syntaxhighlight>
GRASS GIS and the Python you used to install Jupyter need to know about each other.
On Linux, this will be usually true and no special steps are needed. GRASS GIS just uses the system Python and you presumably use pip which uses system Python too.
On Windows, install Jupyter using the Python which is available in GRASS session. There is no system Python on Windows, so, e.g., installing Jupyter in conda and standalone GRASS GIS results in two different and disconnected Python installations. See this [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnWindows_Tutorial.ipynb NCSU GIS714 Jupyter On Windows Tutorial] for installing Jupyter using pip which is linked with Python linked to GRASS GIS.
=== Start Jupyter, then GRASS GIS ===
<syntaxhighlight lang="bash">
jupyter lab
</syntaxhighlight>
In a notebook, start the session using the [https://grass.osgeo.org/grass-stable/manuals/libpython/grass.jupyter.html grass.jupyter package].
On Windows, due to a lack of system Python shared among all applications, it is easiest to start GRASS GIS (to get a command line with Python) and start Jupyter from there, see the [https://github.com/ncsu-geoforall-lab/GIS714-assignments/blob/main/GRASS_GIS_Foundations/JupyterOnWindows_Tutorial.ipynb NCSU GIS714 Jupyter On Windows Tutorial]. (The session in command line will be replaced by a new session in the notebook.)
=== Start GRASS GIS, then GRASS GIS ===
If the above does not work for you or you want your notebooks to not deal with GRASS session at all, start GRASS shell and then start Jupyter from there, for example:
<syntaxhighlight lang="bash">
$ grass ...
GRASS > jupyter lab
</syntaxhighlight>
This can be done in one command, avoiding need for an additional step in the GRASS shell:
<syntaxhighlight lang="bash">
$ grass ... --exec jupyter lab
</syntaxhighlight>
For example:
<syntaxhighlight lang="bash">
$ grass ~/data/world_wgs84/coastal --exec jupyter lab
</syntaxhighlight>
=== Windows tricks ===
If you get the error
<syntaxhighlight lang="python">
FileNotFoundError: [WinError 2] The system cannot find the file specified
</syntaxhighlight>
note that the executable on Windows is '''not called''' <tt>'''grass'''</tt> like on Linux but <tt>'''grass8'''</tt> or <tt>'''grass83'''</tt> (to avoid a strange Python import error).
That should do the trick. If not, try simply providing a full path yourself including the extension (e.g., <tt>C:\...\grass83.bat</tt>), e.g.
<syntaxhighlight lang="python">
# Ask GRASS GIS where its Python packages are.
sys.path.append(
    subprocess.check_output(["C:\GRASS GIS 8.3/grass83.bat", "--config", "python_path"], text=True).strip()
)
</syntaxhighlight>
== Infrastructure ==
* NSF platform: https://wholetale.org/
** Using satellite data for SDM with GRASS GIS and R, by Veronica Andreo https://dashboard.wholetale.org/run/64388157b3b74e434bd8f1ac?tab=files
** GRASS GIS Introduction, by Anna Petrasova: https://dashboard.wholetale.org/run/63d832bab4a0197e9a9ecdad?tab=files
* Colab (Google)
* Binder
== Tools ==
* [https://github.com/wenzeslaus/gdoc2py GRASS GIS focused converter from HTML with pre code tags to Jupyter Notebook]
* RISE: Jupyter/IPython Slideshow Extension, https://rise.readthedocs.io/en/stable/


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

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: