111 zarr
Visualizing Zarr Data
This notebook demonstrates how to visualize Zarr datasets on interactive maps using leafmap. Zarr is a cloud-optimized format for storing large N-dimensional arrays, making it ideal for geospatial and scientific data.
The add_zarr method uses titiler-xarray for dynamic tile serving from Zarr datasets.
References: - EOPF Sentinel Zarr Explorer - titiler-eopf - EOPF 101 - Zarr Visualization Report
Prerequisites¶
To visualize Zarr data, you need a TiTiler endpoint with titiler-xarray support. The default TiTiler endpoint does NOT support Zarr/xarray datasets.
You have two options:
- Start a local titiler-xarray server (recommended for testing)
- Use a remote titiler-xarray endpoint (if available)
Install required packages¶
1 | |
1 | |
Option 1: Start a Local TiTiler-XArray Server¶
The easiest way to get started is to run a local titiler-xarray server. This requires the titiler.xarray package to be installed.
1 2 3 4 | |
Working with Zarr Metadata¶
Before visualizing, let's explore the Zarr dataset using the helper functions.
Get Available Variables¶
Use the zarr_variables function to list all variables in a Zarr dataset.
1 2 3 4 5 6 | |
Get Dataset Information¶
Use the zarr_info function to get detailed information about a Zarr dataset.
1 2 3 4 | |
Get Dataset Bounds¶
Use the zarr_bounds function to get the geographic bounds of a Zarr dataset.
1 2 | |
Visualizing Zarr Data with ipyleaflet backend¶
The add_zarr method allows you to add Zarr datasets to the map. It requires:
- A URL to the Zarr dataset
- A variable name for multi-variable datasets
- A titiler endpoint with xarray support
Note: For datasets with a time dimension, the time_index parameter specifies which time step to display (default is 0, the first time step).
1 2 3 4 5 6 7 8 9 10 11 | |
Displaying Different Time Steps¶
You can change the time_index parameter to visualize different time steps.
1 2 3 4 5 6 7 8 9 10 11 | |
Visualizing Zarr Data with MapLibre backend¶
The add_zarr method is also available in the MapLibre backend.
1 | |
1 2 3 4 5 6 7 8 9 10 11 | |
Using xarray to Explore Zarr Data¶
You can also use xarray directly to explore Zarr datasets before visualization.
1 2 3 4 5 6 | |
1 2 3 4 | |
1 2 | |
1 2 3 4 | |
Option 2: Using a Remote TiTiler-XArray Endpoint¶
If you have access to a remote titiler-xarray endpoint (e.g., from titiler-eopf), you can use it directly:
1 2 3 4 5 6 7 8 9 10 | |
You can also set the endpoint as an environment variable:
1 2 | |
Summary¶
Key functions for working with Zarr data in leafmap:
leafmap.run_titiler_xarray()- Start a local titiler-xarray servermap.add_zarr()- Add a Zarr dataset to the maptime_indexparameter specifies which time step to display (default: 0)leafmap.zarr_variables()- Get list of variables in a Zarr datasetleafmap.zarr_info()- Get metadata about a Zarr datasetleafmap.zarr_bounds()- Get geographic bounds of a Zarr datasetleafmap.zarr_statistics()- Get statistics for a Zarr variable
Public Zarr Datasets for Testing¶
Here are some publicly available Zarr datasets you can use:
- GPCP Precipitation:
https://ncsa.osn.xsede.org/Pangeo/pangeo-forge/gpcp-feedstock/gpcp.zarr