Notebooks
Jupyter notebooks that use the Python package on real data. Run them in your browser
below, open one in Google Colab to run it without installing anything, or download it and run it
locally after pip install terrio matplotlib.
In your browser
JupyterLite runs Python and the latest terrio release in your browser, compiled to WebAssembly, with nothing to install: choose Run > Run All Cells. The first run downloads Python and its packages. Edits you save stay in this browser, so download the notebook to keep them elsewhere.
These notebooks are adapted for the browser, where terrio does not open URLs: they download smaller samples first, so they do not show HTTP range reads of remote files. The notebooks below do.
Quickstart notebook
A tour of terrio in Python:
- a USGS 3DEP elevation COG on Amazon S3, read in place: its header, an overview, and a full-resolution window written to a GeoTIFF with statistics;
- hillshade and slope with
terrio.dem, asgdaldemcomputes them; - reprojection to UTM with
terrio.warp; - NDVI from a Landsat 7 image with
terrio.calc; - the world's countries from a GeoJSON URL: filtered with SQL, reprojected, and written as GeoPackage, FlatGeobuf, GeoParquet, Shapefile and KML;
- rasterizing the countries, and transforming coordinates between EPSG CRSs.
xarray notebook
terrio.xarray, rioxarray's API without installing GDAL
(pip install "terrio[xarray]"):
- the USGS 3DEP elevation COG opened lazily as a dask-backed DataArray, with rioxarray's
coordinates, attributes and
spatial_refgrid mapping; - a window clipped by longitude and latitude (only its tiles are fetched), an overview, a reprojection to UTM, a clip to a polygon, two tiles merged;
- a Landsat image through xarray's backend,
xr.open_dataset(url, engine="terrio"); - writing a COG and GeoZarr with
to_raster, and xarray'sto_zarrkeeping the georeferencing; register_rio_accessor(), for code written for rioxarray.
Comparison notebook
The quickstart's workflow written with terrio, GDAL's Python bindings, rasterio and rioxarray, with GeoPandas and pyproj for the vector and coordinate steps. Each step checks that the libraries agree and times them:
- the elevation COG's header, an overview and a window, read over HTTP: the same pixels from all four;
- hillshade and slope: terrio and
gdal.DEMProcessingagree pixel for pixel, and a NumPy slope for rasterio agrees within 0.001°; - reprojection to UTM: terrio and
gdal.Warpproduce the same grid and pixels, while rasterio'scalculate_default_transformchooses a grid one column wider; - NDVI, filtering and reprojecting the countries to GeoPackage, rasterizing them, and transforming a coordinate.
It needs the GDAL Python bindings, which Google Colab includes; locally, install GDAL with conda
(conda install -c conda-forge gdal), then pip install terrio rasterio rioxarray geopandas
matplotlib.