Upload ndarray to new product

This example demonstrates how to create a product in our Catalog and upload an example image.

from descarteslabs.catalog import Product, SpectralBand, Image, properties as p
import uuid

Create a unique product id (to avoid collisions).

product_id = uuid.uuid4().hex

Create a product entry in our Catalog.

product = Product(
    name="Simple Image Upload",
    description="An example of creating a product, adding the visible band range, and ingesting a single scene.",

Add band information to the product. This is a necessary step, and requires the user to know a bit about the data to be ingested.

bands = ["red", "green", "blue"]

for band_index, band in enumerate(bands):
        product=product,  # product this band will belong to
        name=band,  # name of the band
        band_index=band_index,  # 0 based index for storage and retrieval
        data_type="Float64",  # data type for storage
        nodata=0,  # pixel value indicating no data available
        data_range=(0.0, 1.0),  # list of the min and max data values
        display_range=(0.0, 0.4),  # a good default scale for display

As an aside, we can add a writer to this product. The product that we just created doesn’t have any writers.

print("Product writers: {}".format(product.writers))
Product writers: []

However, we can add a writer to this product.

product.writers = ["email:someuser@gmail.com"]

Now, 'email:someuser@gmail.com' is a writer for this product. This user can now change the product metadata, add bands, and add imagery to this product.

print("Changed product writers: {}".format(product.writers))
Changed product writers: ['email:someuser@gmail.com']

Search for Sentinel-2 imagery over an AOI. Define a bounding box around Paris, France.

paris = {
    "type": "Polygon",
    "coordinates": [
            [2.165946315534452, 48.713171120067045],
            [2.5359015712706023, 48.713171120067045],
            [2.5359015712706023, 48.957687975409726],
            [2.165946315534452, 48.957687975409726],
            [2.165946315534452, 48.713171120067045],

search = (
    .filter("2020-06-24" < p.acquired < "2020-06-30")
    .filter(p.cloud_fraction < 0.1)
images = search.collect()

Mosaic the image collection to a single RGB image.

ndarray_mosaic, raster_info = images.mosaic("red green blue", raster_info=True)

Upload the ndarray as a single scene in our new product. Note: It can take several minutes for the image to appear in various interfaces.

image = Image(
    name="Paris", product=product, acquired="2020-06-24", acquired_end="2020-06-30"

upload = image.upload_ndarray(ndarray_mosaic, raster_meta=raster_info)

Now the image exists and can be found by search.

ImageCollection of 1 image
  * Dates: Jun 24, 2020 to Jun 24, 2020
  * Products: descarteslabs:0bb9449943b84b60b8e02a8e345f3423: 1

Delete our product; we don’t need it anymore.

task = product.delete_related_objects()
while task is not None:
    if task.status == "success":
    task = product.delete_related_objects()
print("Product removed.")
Product removed.

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

Gallery generated by Sphinx-Gallery