Note
Click here to download the full example code
Composite Multi-Product Imagery¶
Composite imagery from two data sources and display as a single image.
from descarteslabs.catalog import Image, properties as p
from descarteslabs.utils import display
import numpy as np
# Define a bounding box around Taos in a GeoJSON
taos = {
"type": "Polygon",
"coordinates": [
[
[-105.71868896484375, 36.33725319397006],
[-105.2105712890625, 36.33725319397006],
[-105.2105712890625, 36.73668306473141],
[-105.71868896484375, 36.73668306473141],
[-105.71868896484375, 36.33725319397006],
]
],
}
# Create an ImageCollection
search = (
Image.search()
.intersects(taos)
.filter(p.product_id.any_of(["landsat:LC08:01:RT:TOAR", "sentinel-2:L1C"]))
.filter("2018-05-01" <= p.acquired < "2018-06-01")
.filter(p.cloud_fraction < 0.2)
.sort("acquired")
.limit(15)
)
images = search.collect()
See which images we have, and how many per product:
print(images)
Out:
ImageCollection of 4 images
* Dates: May 14, 2018 to May 29, 2018
* Products: sentinel-2:L1C: 3, landsat:LC08:01:RT:TOAR: 1
And if you’re curious, which image IDs:
print(images.each.id)
Out:
'sentinel-2:L1C:2018-05-14_13SDA_99_S2A_v1'
'landsat:LC08:01:RT:TOAR:meta_LC08_L1TP_033035_20180519_20180520_01_RT_v1'
'sentinel-2:L1C:2018-05-24_13SDA_99_S2A_v1'
'sentinel-2:L1C:2018-05-29_13SDA_99_S2B_v1'
Make a median composite of the images
# Request a stack of all the images using the same GeoContext with lower resolution
arr_stack = images.stack("red green blue", resolution=60, data_type="Float64")
# Composite the images based on the median pixel value
composite = np.ma.median(arr_stack, axis=0)
display(composite, title="Taos Composite", size=2)

Total running time of the script: ( 0 minutes 3.246 seconds)