Downloading a GeoTIFF

Imagery stored in the Catalog may be downloaded as a GeoTIFF file via the Raster API

The simplest method for downloading imagery is to use the Scenes submodule which provides a client interface both for searching the Catalog, and downloading the resulting collection of images (scenes) as files, mosaics, or stacked NumPy array. 

The first step is to search the Catalog to find the product IDs you will be searching over. To perform a search, import the descarteslabs module and use the search method on the scenes client.

The platform can mosaic data from multiple products so long as the band names are the same (for example, you can download a simple three band mosaic of Landsat 8 and Sentinel 2 imagery using the red green and blue bands).

import descarteslabs as dl

# Define a GeoJSON region to search
aoi = {"type": "Polygon",
"coordinates": [[[18.19,-34.38],
[18.78,-34.38],
[18.78,-33.85],
[18.19,-33.85],
[18.19,-34.38]
]]
}
scenes, ctx = dl.scenes.search(aoi,
products = 'sentinel-2:L1C',
start_datetime='2020-03-01',
end_datetime='2020-03-31',
limit = None
)

This will return a SceneCollection object representing the scenes found within the search parameters, and a GeoContext object, representing the coordinate system, projection, and resolution of the imagery found. In this case we have scenes retrieved from the Sentinel-2:L1C product, which are in the UTM projection at a resolution of 10 meters per pixel.

To download as GeoTIFF, call the download_mosaic method on the SceneCollection to download a simple mosaic (most recent scenes on top) of the imagery, or the download method to download all scenes as individual files. Pass a list of bands to include in the file(s) and a geocontext to define how the image should be transformed from source. The geocontext can be the original returned from the search (for unmodified data)  or you may assign a different coordinate reference system or resolution.

# Create a 90 meter resolution geocontext from the full resolution source.
ctx_lowres = ctx.assign(resolution=90)

# Download a low resolution simple mosaic of all scenes in the AOI
scenes.download_mosaic('red green blue', ctx_lowres, dest='s2-mosaic.tif')

# Download a full resolution geotiff for each scene into a 's2-scenes' folder
scenes.download('red green blue', ctx, dest="s2-scenes")

Downloading Workflows layers/images

Workflows images and visualization layers may be downloaded as Numpy arrays. The simplest method to convert these to GeoTIFF is via the rasterio Python package. Call the compute method on a Image object to dowload an array that can then be written to a GeoTIFF file via the following code:

# img is a Workflows Image proxy object

result = img.compute(ctx)

# compute an affine transform from gdal transform returned from Workflows
affine_transform = list(
np.array(result.geocontext["gdal_geotrans"])[[1, 2, 0, 4, 5, 3]]
)


arr = result.ndarray

with rasterio.open(fn,
"w",
driver="GTiff",
height=arr.shape[1],
width=arr.shape[2],
count=arr.shape[0],
dtype=arr.dtype,
crs=result.geocontext["crs"],
nodata=arr.nodata,
transform=affine_transform,
) as outraster:
outraster.write(arr)