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:

In [1]: 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)
   ...:     ),)
   ...: }
   ...: 

Search for Scenes within it:

In [2]: import descarteslabs as dl

In [3]: scenes, ctx = dl.scenes.search(aoi_geometry,
   ...:                                products=["landsat:LC08:PRE:TOAR"],
   ...:                                start_datetime="2013-07-01",
   ...:                                end_datetime="2013-09-01",
   ...:                                limit=10)
   ...: 

In [4]: scenes
Out[4]: 
SceneCollection of 10 scenes
  * Dates: Jul 07, 2013 to Aug 24, 2013
  * Products: landsat:LC08:PRE:TOAR: 10

In [5]: ctx
Out[5]: 
AOI(geometry=<shapely...c00f7110>,
    resolution=15,
    crs=u'EPSG:32615',
    align_pixels=True,
    bounds=(-94.37053769704536, 40.703737, -93.52300099792355, 41.3717716),
    shape=None)

In [6]: ctx_lowres = ctx.assign(resolution=60)

Quickly inspect metadata:

In [7]: scenes = scenes.sorted("properties.date")

In [8]: scenes.each.properties.id
Out[8]: 
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'
...

In [9]: scenes.each.properties.date.month
Out[9]: 
7
7
7
7
7
7
8
8
...

Load and display a scene:

In [10]: scene = scenes[-1]

In [11]: arr = scene.ndarray("red green blue", ctx_lowres)

In [12]: dl.scenes.display(arr)
https://cdn.descarteslabs.com/docs/_images/scene.png

Monthly median composites of NDVI within our area of interest:

In [13]: import numpy as np

In [14]: monthly_composites = {}

In [15]: for month, month_scenes in scenes.groupby("properties.date.month"):
   ....:     stack = month_scenes.stack("red nir", ctx_lowres)
   ....:     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:

In [16]: {month: composite.mean() for month, composite in monthly_composites.items()}
Out[16]: {7: 0.32535368527404873, 8: 0.4119459794034656}

View the NDVI composites:

In [17]: dl.scenes.display(*monthly_composites.values(), title=list(monthly_composites.keys()))
https://cdn.descarteslabs.com/docs/_images/composite.png