Selecting Collections

This tutorial shows how to select a collection and visualize a cube:

[1]:
import cubo
import xarray as xr

This code creates a cube with an edge size of 64 pixels from Sentinel-2 and apply a cloud coverage filter of 40 percent. Get just the RGB bands:

[2]:
da = cubo.create(
    lat=47.848151988493385,
    lon=13.379491178028564,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2020-01-01",
    end_date="2021-01-01",
    edge_size=64,
    resolution=10,
    query={"eo:cloud_cover": {"lt": 40}}
)
da
[2]:
<xarray.DataArray 'sentinel-2-l2a' (time: 46, band: 3, y: 64, x: 64)>
dask.array<fetch_raster_window, shape=(46, 3, 64, 64), dtype=float64, chunksize=(1, 1, 64, 64), chunktype=numpy.ndarray>
Coordinates: (12/46)
  * time                                     (time) datetime64[ns] 2020-01-01...
    id                                       (time) <U54 'S2B_MSIL2A_20200101...
  * band                                     (band) <U3 'B02' 'B03' 'B04'
  * x                                        (x) float64 3.784e+05 ... 3.791e+05
  * y                                        (y) float64 5.301e+06 ... 5.3e+06
    s2:medium_proba_clouds_percentage        (time) float64 0.3489 ... 4.911
    ...                                       ...
    title                                    (band) <U20 'Band 2 - Blue - 10m...
    proj:transform                           object {0.0, 300000.0, 5400000.0...
    common_name                              (band) <U5 'blue' 'green' 'red'
    center_wavelength                        (band) float64 0.49 0.56 0.665
    full_width_half_max                      (band) float64 0.098 0.045 0.038
    epsg                                     <U10 'EPSG:32633'
Attributes:
    collection:           sentinel-2-l2a
    stac:                 https://planetarycomputer.microsoft.com/api/stac/v1
    epsg:                 EPSG:32633
    resolution:           10
    edge_size:            64
    central_lat:          47.848151988493385
    central_lon:          13.379491178028564
    central_y:            5300694.38448788
    central_x:            378764.6058600877
    time_coverage_start:  2020-01-01
    time_coverage_end:    2021-01-01

However, we can change the collection if we need to. This is an example using Landsat-8 Collection 2 Level 2 from Planetary Computer:

[3]:
da = cubo.create(
    lat=47.848151988493385,
    lon=13.379491178028564,
    collection="landsat-c2-l2",
    bands=["blue","green","red"],
    start_date="2020-01-01",
    end_date="2021-01-01",
    edge_size=32,
    resolution=30,
    query={
        "eo:cloud_cover": {"lt": 50},
        "platform": {"eq": "landsat-8"}
    }
)
da
[3]:
<xarray.DataArray 'landsat-c2-l2' (time: 25, band: 3, y: 32, x: 32)>
dask.array<fetch_raster_window, shape=(25, 3, 32, 32), dtype=float64, chunksize=(1, 1, 32, 32), chunktype=numpy.ndarray>
Coordinates: (12/30)
  * time                         (time) datetime64[ns] 2020-01-11T09:58:09.42...
    id                           (time) <U31 'LC08_L2SP_192027_20200111_02_T1...
  * band                         (band) <U5 'blue' 'green' 'red'
  * x                            (x) float64 3.783e+05 3.783e+05 ... 3.792e+05
  * y                            (y) float64 5.301e+06 5.301e+06 ... 5.3e+06
    landsat:cloud_cover_land     (time) float64 44.67 18.59 ... 44.81 42.77
    ...                           ...
    raster:bands                 object {'scale': 2.75e-05, 'nodata': 0, 'off...
    title                        (band) <U10 'Blue Band' 'Green Band' 'Red Band'
    common_name                  (band) <U5 'blue' 'green' 'red'
    center_wavelength            (band) float64 0.48 0.56 0.65
    full_width_half_max          (band) float64 0.06 0.06 0.04
    epsg                         <U10 'EPSG:32633'
Attributes:
    collection:           landsat-c2-l2
    stac:                 https://planetarycomputer.microsoft.com/api/stac/v1
    epsg:                 EPSG:32633
    resolution:           30
    edge_size:            32
    central_lat:          47.848151988493385
    central_lon:          13.379491178028564
    central_y:            5300694.38448788
    central_x:            378764.6058600877
    time_coverage_start:  2020-01-01
    time_coverage_end:    2021-01-01

Visualize an RGB image per timestep in the cube:

[4]:
da = (da * 0.0000275) - 0.2
(da.sel(band=["red","green","blue"])/0.2).clip(0,1).plot.imshow(col="time",col_wrap = 5)
[4]:
<xarray.plot.facetgrid.FacetGrid at 0x7f6d62250520>
../_images/tutorials_using_collections_8_1.png