Spectral Similarity with the Workflows API

Build an application using the Workflows API to calculate the spectral similarity of ground cover on the fly

The spectral similarity notebook is in the examples subdirectory of example_notebooks. Here, we’ll explore the spectral similarity of minerals and other materials in a remote region of Argentina. Let’s go through the notebook together.


As with all Jupyter notebooks, you can run each cell by using shift & enter on your keyboard. The first thing we need to do is import the necessary packages, including the Descartes Labs Python library.

Define the Sentinel-2 imagery that we'll be using

In this section, we will prepare the Sentinel-2 data that we want to display on our iPyLeaflet map. We will display two different images:

  1. A true color image with cloud-filtered Sentinel-2 optical data
  2. A false-color image with cloud-filtered Sentinel-2 infrared data

In this cell, we’re also defining the bands that we want to use for the similarity search. Specifically, we will use the shortwave infrared 1 (swir1), shortwave infrared 2 (swir2), near infrared (nir), and red (red) bands from Sentinel-2.

Define custom iPyWidget to calculate and display spectral similarity

In the next section, we do two things:

  1. Define and add a Draw Control button to the iPyLeaflet map. This button allows the user to interact with the map by drawing a point or polygon, which then triggers a callback function to run a series of Descartes Labs Platform calls. You can see that the code to draw the rectangle and process the data is fairly straightforward, but we encourage you to dig into this on your own.
  2. Define the spectral similarity function. When a user specifies an area of interest using the widget we just defined, this function calculates the mean spectrum for that AOI, plus the spectral distance between the AOI and all other pixels in the image. Finally, a new layer is generated to display the spectral similarity on the map.

Lastly, we specify the center of the map in latitude/longitude and the map's zoom level. These coordinates can be changed to look at different locations on Earth.

Remember: the notebooks in the example_notebooks directory are effectively read-only. If you want any changes to persist, please copy this notebook into a new directory.

Display and interact with the map


We can toggle between the true and false color images, zoom out or zoom in, and pan around this location. Looking at the false color image, we can see that the geology in this region looks quite interesting. Specifically, we see a large turquoise area that appears to be unique. We can select a few of these pixels using the Draw Control widget, which then triggers the similarity search function. When it’s complete, we see the spectral similarity layer.


Here, brighter colors indicate a greater degree of similarity to our AOI. We can even zoom out to see that function computed on the fly and scaled to larger areas.

Many of the examples in this folder follow a similar pattern: using the Python client and open-source tools to build an application leveraging the Descartes Labs Platform. We hope you find these examples useful and interesting!