Skip to main content
Private Preview
The following content is a read-only preview of an executable Jupyter notebook.To run this notebook interactively:
  1. Go to Wherobots Cloud.
  2. Start a runtime.
  3. Open the notebook.
  4. In the Jupyter Launcher:
    1. Click File > Open Path.
    2. Paste the following path to access this notebook: examples/Analyzing_Data/RasterFlow_Bring_Your_Own_Rasters_NAIP.ipynb
    3. Click Enter.
This notebook demonstrates how to bring your own rasters (BYOR) into RasterFlow by querying a STAC catalog and creating a GTI (GDAL Raster Tile Index). You will learn how to query the NAIP collection, extract Cloud-Optimized GeoTIFF (COG) URLs, and build a mosaic using RasterFlow’s build_gti_mosaics function.

What you will learn

This notebook will teach you to:
  • Query a STAC catalog to discover available imagery for an area of interest
  • Create a GTI (GDAL Raster Tile Index) from STAC items
  • Build a seamless mosaic from multiple image tiles using RasterFlow’s build_gti_mosaics
  • Visualize the resulting mosaic and inference outputs
  • (Optional) Run road detection using the ChesapeakeRSC model

NAIP (National Agriculture Imagery Program)

The National Agriculture Imagery Program (NAIP) acquires aerial imagery during the agricultural growing seasons in the continental United States. Key characteristics:
  • Resolution: 1 meter ground sample distance
  • Bands: 4-band imagery (Red, Green, Blue, NIR) in a single COG file
  • Coverage: Continental United States
  • Update cycle: Typically every 2-3 years per state
We will use the Element84 Earth Search STAC catalog to query NAIP imagery for Montgomery County, Maryland.

Setup and Imports

Selecting an Area of Interest (AOI)

We will use Montgomery County, Maryland as our AOI. This county is well-covered by NAIP imagery and provides a good example for demonstrating the BYOR workflow.

Loading the NAIP STAC collection

We use Wherobots’ built-in STAC reader to load the NAIP collection from Element84’s Earth Search catalog. This catalog provides direct S3 URLs to the imagery files.

Applying spatial and temporal filters

We filter the NAIP collection to only include tiles that:
  • Intersect with our AOI (Montgomery County)
  • Were captured in 2017 (the most recent year with 1-meter resolution NAIP imagery available for Maryland so we can test the ChesapeakeRSC model)

Exploring the STAC asset structure

Before creating the GTI, we need to understand the structure of the STAC assets. NAIP stores all 4 bands (RGBIR) in a single COG file, so we only need one row per tile in our GTI.

Creating the GTI (GDAL Raster Tile Index)

The GTI is a spatial index that maps tile geometries to their corresponding COG URLs. For more information on GTI, see the reference documentation. Since NAIP has a single 4-band COG per tile, we create one row per tile.

Saving the GTI as GeoParquet

We convert the Spark DataFrame to a GeoDataFrame and save it as GeoParquet for use with RasterFlow.

Verifying the GTI

Before building the mosaic, we verify that the GTI was saved correctly and visualize the tile footprints.

Building a mosaic with RasterFlow

Now we use RasterFlow’s build_gti_mosaics function to create a seamless 4-band mosaic from the NAIP tiles.
Note: The naip-analytic S3 bucket is requester-pays, so we set requester_pays=True.
Expected runtime: ~5-10 minutes depending on the number of tiles.

(Optional) Build an optimized Zarr for visualization

RasterFlow writes its outputs as Zarr stores at native resolution. To explore them smoothly with the wherobots_gl.Map() widget, you can build an optimized multiscale Zarr. build_zarr_multiscales adds downsampled overview levels (image pyramids) to the store so the map can stream coarse tiles when zoomed out and full-resolution pixels when zoomed in. This step is optional and can take a few minutes for large outputs, so the code below is commented out by default — uncomment it to run it.

Visualizing outputs

You can visualize the mosaic and inference outputs from this notebook inline with the wherobots_gl.Map() widget — it renders Zarr, GeoParquet, and COG directly in the notebook (as shown above for the AOI and tile footprints), so you can inspect either the mosaic output or the road-probability output without leaving the notebook.

(Optional) Running inference with ChesapeakeRSC

Now that we have built the NAIP mosaic, we can optionally run a semantic segmentation model to detect roads. The ChesapeakeRSC model was trained on NAIP imagery from Maryland and can detect roads even when occluded by tree cover. The model outputs two classes:
  • background
  • road
Expected runtime: ~10-20 minutes depending on the mosaic size.
You can visualize the road-probability output from the inference workflow inline as well — point a wherobots_gl.Map() at the prediction Zarr store (e.g. prediction_store.uri), the same way we mapped the AOI and tile footprints above.