Scenes

The Scenes submodule provides a higher-level, object-based interface that makes most interactions with the Descartes Labs platform easier.

  • Collection: convenience methods for mapping and filtering
  • geocontext: consistent spatial parameters to use when loading a raster
  • Scene: metadata about a single scene
  • SceneCollection: conveniently work with Scenes in aggregate
  • search: search for Scenes
  • display: display ndarrays with matplotlib

It’s available under dl.scenes.

Example

Define our Area of Interest:

>>> aoi_geometry = {
...     'type': 'Polygon',
...     'coordinates': ((
...         (-93.52300099792355, 41.241436141055345),
...         (-93.7138666, 40.703737),
...         (-94.37053769704536, 40.83098709945576),
...         (-94.2036617, 41.3717716),
...         (-93.52300099792355, 41.241436141055345)
...     ),)  # the trailing comma is significant
... }
...

Search for Scenes within it:

>>> import descarteslabs as dl
>>> scenes, ctx = dl.scenes.search(
...     aoi_geometry,
...     products=["landsat:LC08:PRE:TOAR"],
...     start_datetime="2013-07-01",
...     end_datetime="2013-09-01",
...     limit=10
... )
...
>>> scenes
SceneCollection of 10 scenes
  * Dates: Jul 07, 2013 to Aug 24, 2013
  * Products: landsat:LC08:PRE:TOAR: 10
>>>
>>> ctx
AOI(geometry=<shapely...d8276a90>,
    resolution=15,
    crs=u'EPSG:32615',
    align_pixels=True,
    bounds=(-94.37053769704536, 40.703737, -93.52300099792355, 41.3717716),
    bounds_crs='EPSG:4326',
    shape=None)
>>>
>>> ctx_lowres = ctx.assign(resolution=60)

Quickly inspect metadata:

>>> scenes = scenes.sorted("properties.date")
>>>
>>> scenes.each.properties.id
u'landsat:LC08:PRE:TOAR:meta_LC80260312013188_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80260322013188_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80270312013195_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80260312013204_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80260322013204_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80270312013211_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80260312013220_v1'
u'landsat:LC08:PRE:TOAR:meta_LC80260322013220_v1'
...
>>>
>>> scenes.each.properties.date.month
7
7
7
7
7
7
8
8
...

Load and display a scene:

>>> scene = scenes[-1]
>>>
>>> arr = scene.ndarray("red green blue", ctx_lowres)
>>>
>>> dl.scenes.display(arr)
https://cdn.descarteslabs.com/docs/public/_images/init_example_figure8_1.png

Monthly median composites of NDVI within our area of interest:

>>> import numpy as np
>>>
>>> monthly_composites = {}
>>>
>>> for month, month_scenes in scenes.groupby("properties.date.month"):
...     stack = month_scenes.stack("red nir", ctx_lowres)
...     stack = stack.astype(float)  # avoid truncating to uint16
...     red, nir = stack[:, 0], stack[:, 1]
...     ndvi = (nir - red) / (nir + red)
...     ndvi_composite = np.ma.median(ndvi, axis=0)
...     monthly_composites[month] = ndvi_composite
...

And the mean NDVI value of each month’s composite is:

>>> {month: composite.mean() for month, composite in monthly_composites.items()}
{8: 0.3973330207454807, 7: 0.32396951619824726}

View the NDVI composites:

>>> dl.scenes.display(*monthly_composites.values(), title=list(monthly_composites.keys()))
https://cdn.descarteslabs.com/docs/public/_images/init_example_figure11_1.png