Getting Started

This tutorial shows some examples of how to use cubo:

[1]:
import cubo

Create a cube with an edge size of 32 pixels and a resolution of 10 m from the Sentinel-2 L2A Collection of Planetary Computer given a pair of coordinates and start and end dates using just the RGB bands:

[3]:
da = cubo.create(
    lat=50,
    lon=10,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-06-01",
    end_date="2021-06-10",
    edge_size=32,
    resolution=10,
)
da
[3]:
<xarray.DataArray 'sentinel-2-l2a' (time: 3, band: 3, y: 32, x: 32)>
dask.array<fetch_raster_window, shape=(3, 3, 32, 32), dtype=float64, chunksize=(1, 1, 32, 32), chunktype=numpy.ndarray>
Coordinates: (12/46)
  * time                                     (time) datetime64[ns] 2021-06-05...
    id                                       (time) <U54 'S2A_MSIL2A_20210605...
  * band                                     (band) <U3 'B02' 'B03' 'B04'
  * x                                        (x) float64 5.715e+05 ... 5.718e+05
  * y                                        (y) float64 5.539e+06 ... 5.539e+06
    s2:datastrip_id                          (time) <U64 'S2A_OPER_MSI_L2A_DS...
    ...                                       ...
    proj:transform                           object {0.0, 5600040.0, 10.0, 49...
    proj:bbox                                object {5490240.0, 5600040.0, 60...
    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:32632'
Attributes:
    collection:           sentinel-2-l2a
    stac:                 https://planetarycomputer.microsoft.com/api/stac/v1
    epsg:                 EPSG:32632
    resolution:           10
    edge_size:            32
    central_lat:          50
    central_lon:          10
    central_y:            5539109.815298798
    central_x:            571666.4475034359
    time_coverage_start:  2021-06-01
    time_coverage_end:    2021-06-10

Create a cube with an edge size of 128 pixels and a resolution of 20 m from the Sentinel-2 L2A Collection of Element84 given a pair of coordinates and start and end dates using just the Red Edge bands:

[5]:
da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-s2-l2a-cogs",
    bands=["B05","B06","B07"],
    start_date="2020-01-01",
    end_date="2020-06-01",
    edge_size=128,
    resolution=20,
    stac="https://earth-search.aws.element84.com/v0"
)
da
[5]:
<xarray.DataArray 'sentinel-s2-l2a-cogs' (time: 31, band: 3, y: 128, x: 128)>
dask.array<fetch_raster_window, shape=(31, 3, 128, 128), dtype=float64, chunksize=(1, 1, 128, 128), chunktype=numpy.ndarray>
Coordinates: (12/26)
  * time                        (time) datetime64[ns] 2020-01-02T15:41:55 ......
    id                          (time) <U24 'S2A_18NUK_20200102_0_L2A' ... 'S...
  * band                        (band) <U3 'B05' 'B06' 'B07'
  * x                           (x) float64 3.656e+05 3.656e+05 ... 3.681e+05
  * y                           (y) float64 4.778e+05 4.778e+05 ... 4.752e+05
    data_coverage               (time) object 77.62 77.37 77.69 ... None None
    ...                          ...
    sentinel:product_id         (time) <U60 'S2A_MSIL2A_20200102T153611_N0213...
    sentinel:latitude_band      <U1 'N'
    proj:shape                  object {5490}
    title                       (band) <U6 'Band 5' 'Band 6' 'Band 7'
    proj:transform              object {0, 300000, 1, 500040, -20, 20}
    epsg                        <U10 'EPSG:32618'
Attributes:
    collection:           sentinel-s2-l2a-cogs
    stac:                 https://earth-search.aws.element84.com/v0
    epsg:                 EPSG:32618
    resolution:           20
    edge_size:            128
    central_lat:          4.31
    central_lon:          -76.2
    central_y:            476498.32356558647
    central_x:            366835.4548862558
    time_coverage_start:  2020-01-01
    time_coverage_end:    2020-06-01

Create a cube with an edge size of 64 pixels and a resolution of 10 m from the Sentinel-2 L2A Collection of Planetary Computer given a pair of coordinates and start and end dates using just the RGB bands. Additionally filter the STAC search by cloud cover values lower than 10 percent:

[ ]:
da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-01-01",
    end_date="2021-06-10",
    edge_size=64,
    resolution=10,
    query={"eo:cloud_cover": {"lt": 10}} # kwarg to pass
)
da