GRASS GIS Jupyter notebooks: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(Section order)
(Replace deprecated source tags by syntaxhighlight)
Line 44: Line 44:
You need to have a working Jupyter installation. If you are using ''pip'', you can install Jupyter using:
You need to have a working Jupyter installation. If you are using ''pip'', you can install Jupyter using:


<source lang="bash">
<syntaxhighlight lang="bash">
pip install jupyter
pip install jupyter
</source>
</syntaxhighlight>


GRASS GIS and the Python you used to install Jupyter need to know about each other.
GRASS GIS and the Python you used to install Jupyter need to know about each other.
Line 56: Line 56:
=== Start Jupyter, then GRASS GIS ===
=== Start Jupyter, then GRASS GIS ===


<source lang="bash">
<syntaxhighlight lang="bash">
jupyter lab
jupyter lab
</source>
</syntaxhighlight>


In a notebook, start the session using the [https://grass.osgeo.org/grass-stable/manuals/libpython/grass.jupyter.html grass.jupyter package].
In a notebook, start the session using the [https://grass.osgeo.org/grass-stable/manuals/libpython/grass.jupyter.html grass.jupyter package].
Line 68: Line 68:
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:
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:


<source lang="bash">
<syntaxhighlight lang="bash">
$ grass ...
$ grass ...
GRASS > jupyter lab
GRASS > jupyter lab
</source>
</syntaxhighlight>


This can be done in one command, avoiding need for an additional step in the GRASS shell:
This can be done in one command, avoiding need for an additional step in the GRASS shell:


<source lang="bash">
<syntaxhighlight lang="bash">
$ grass ... --exec jupyter lab
$ grass ... --exec jupyter lab
</source>
</syntaxhighlight>


For example:
For example:


<source lang="bash">
<syntaxhighlight lang="bash">
$ grass ~/data/world_wgs84/coastal --exec jupyter lab
$ grass ~/data/world_wgs84/coastal --exec jupyter lab
</source>
</syntaxhighlight>


== Tools ==
== Tools ==

Revision as of 14:19, 19 July 2022

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 the intro in the official documentation for grass.jupyter package.

List of selected GRASS GIS Jupyter notebooks

(add yours to the list!)

Intro notebooks:

Collections:

Image processing/OBIA:

Python and PyGRASS:

R and GRASS GIS:

Wildfire Modeling:

Running 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:

pip install jupyter

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 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

jupyter lab

In a notebook, start the session using the 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 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:

$ grass ...
GRASS > jupyter lab

This can be done in one command, avoiding need for an additional step in the GRASS shell:

$ grass ... --exec jupyter lab

For example:

$ grass ~/data/world_wgs84/coastal --exec jupyter lab

Tools