Using leafmap with actinia in a Jupyter notebook

Logos of actinia and leafmap

This blog post gives an overview of how to easily perform a geodata analysis of an online available dataset (here: a GeoTIFF file) with actinia and display the result in Leafmap browser-based.

First I want to introduce Leafmap and actinia, the two central elements of this notebook:

  • Leafmap is a Python library designed to create interactive maps and perform geospatial analysis with minimal programming, especially in a Jupyter notebook environment. It is easy to use for beginners and offers a range of functionalities for processing geospatial data.
  • The cloud-based geospatial processing engine actinia is a powerful system for analyzing and processing large data sets such as satellite imagery. Actinia provides a REST API for the use of GRASS GIS, GDAL and other software at the core of the system. Processing is done via process chains (JSON files) that are sent to an actinia server for processing.

In the following, a simple example will show how it works, from data import to analysis and visualization of the results. We use the actinia Python client in a Jupyter notebook together with Leafmap.

The Jupyter notebook presented here serves as a practical guide for the integration of Leafmap with actinia. It first shows the installation of the actinia Python client. This client is especially helpful for Python or actinia beginners who are not yet familiar with setting up Python libraries.

The Jupyter notebook then moves on to a practical example, showing step by step how to access, visualize and analyze geodata in actinia.

Jupyter Notebooks (official documentation) are server-client applications that allow code written in a Notebook document to be edited and executed via a web browser. Jupyter Notebooks can be used both on a local computer that does not require Internet access and to control computations on a remote server that is accessible via the Internet. These notebooks are particularly useful for data processing, numerical simulation, statistical modeling, and machine learning. Jupyter supports many programming languages, including Python, R, and Julia. Notebooks can be exported to various formats such as HTML, PDF, Markdown or Python code, and can also be used as an interactive teaching or presentation tool. Jupyter notebooks can be easily shared as documents.

Jupyter Notebooks are

  • convenient for initial code development (prototyping)
  • ideal for code segmentation with the ability to re-run segments
  • able to store values of variables from already executed segments.

The notebook can be saved as an executable Python script in addition to the native .ipynb format, or exported to various documentation formats such as PDF or Sphinx RST with nice styling.

Editing and interactive use

Editing a Jupyter notebook is very easy: in the web browser, you can navigate between text or code blocks (“cells”) using the mouse or keyboard shortcuts (see Menu > Help > Keyboard Shortcuts). You can execute small code segments cell by cell, save the notebook in its current state, or modify and recalculate cells or return them to their previous state. In addition to executable code cells, you can use Markdown in documentation cells to make them presentable to others.

And: there are now many Jupyter notebooks on the Internet for inspiration!

Actinia is an innovative open source cloud platform that provides powerful geoprocessing services. It allows spatial data and geoprocessing algorithms to be made available over the Internet. Actinia can process large amounts of geographic data stored in the cloud and provides an API for executing geoprocessing tasks. This platform leverages the power of GRASS GIS, a robust geographic information system, to perform complex spatial analysis and data processing tasks. Actinia is particularly suited for processing remote sensing data, analyzing environmental data, and creating spatial models.

Leafmap is a free and open source Python package for interactive mapping and spatial analysis of geospatial data. It allows the visualization of geospatial data on a map with minimal programming effort in a Jupyter environment such as Google Colab, Jupyter Notebook, or JupyterLab. Leafmap is based on several open source packages like Folium, ipyleaflet and other components. Leafmap provides a set of interactive tools for loading vector and raster data into a map without programming.

How to launch a Jupyter Notebook?

This can be done either locally with jupyter notebook in the directory in which the notebook is stored (installation instructions). This will open the session in a web browser.

Alternatives are Google Colab, Planetary Computer and other services.
See here on top for the icons to launch the actinia-leafmap notebook directly (some services may ask for user registration).

Screenshot initialization of actinia with leafmap

… please see the full Jupyter notebook here:

https://leafmap.org/notebooks/87_actinia/

Screenshot of actinia and leafmap