AWS#

Let’s read satellite data stored on AWS.

This tutorial is a bit tricky as EOReader uses rasterio and cloudpathlib libraries and they are currently handling S3 buckets differently. That’s why we’ll use the helper context manager temp_s3 from sertit.s3, that will do the right connections for us.

Note: These Sentinel-2 products are not stored in the .SAFE format. Landsat format is howver the same.

Cloud data processed by Element84: Sentinel-2 L2A as COGs#

See this registry (arn:aws:s3:::sentinel-cogs). This registry is open access, so you don’t have to sign-in.

# Imports
import os
import tempenv
import logging

from sertit import logs, s3
from eoreader.reader import Reader
from eoreader.bands import BLUE
with tempenv.TemporaryEnvironment({
    "AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
}):
    with s3.temp_s3(no_sign_request=True):
        logs.init_logger(logging.getLogger("eoreader"), logging.DEBUG)
        path = r"s3://sentinel-cogs/sentinel-s2-l2a-cogs/39/K/ZU/2023/10/S2A_39KZU_20231031_0_L2A"
        prod = Reader().open(path)
        prod.plot()
        blue = prod.load(BLUE)[BLUE]
2023-11-20 13:46:49,201 - [DEBUG] - Loading bands ['BLUE']
2023-11-20 13:46:49,403 - [DEBUG] - Read BLUE
2023-11-20 13:46:50,948 - [DEBUG] - Manage nodata for band BLUE
2023-11-20 13:46:50,949 - [DEBUG] - Converting BLUE to reflectance
../_images/94ae91882c741ea8b903b7efb9ed1efaa77f0287afecadd82cfa91707079db00.png
blue[:, ::10, ::10].plot(cmap="Blues_r")
<matplotlib.collections.QuadMesh at 0x7fdd7c580f10>
../_images/e46873982f72b7bcc5fe915ec768845136eb5cd1ecffd058e9f3f6f14df0ac94.png

Cloud data processed by Sinergise: Sentinel-2 L1C#

See this registry (arn:aws:s3:::sentinel-s2-l1c). This registry needs authentication.

NB: L2A would have been the same (arn:aws:s3:::sentinel-s2-l2a)

Note: Sinergise data are stored as requester pays in AWS. Don’t forget to state this when requesting data!

with tempenv.TemporaryEnvironment({
    "AWS_S3_ENDPOINT": "s3.eu-central-1.amazonaws.com",
    "AWS_SECRET_ACCESS_KEY": os.getenv("AMAZON_AWS_SECRET_ACCESS_KEY"),
    "AWS_ACCESS_KEY_ID": os.getenv("AMAZON_AWS_ACCESS_KEY_ID"),
}):
    with s3.temp_s3(requester_pays=True):
        path = r"s3://sentinel-s2-l1c/tiles/10/S/DG/2022/7/8/0"
        prod = Reader().open(path)
        prod.plot()
        blue = prod.load(BLUE)[BLUE]
2023-11-20 13:49:28,993 - [DEBUG] - Loading bands ['BLUE']
2023-11-20 13:49:29,040 - [DEBUG] - Read BLUE
2023-11-20 13:49:29,887 - [DEBUG] - Manage nodata for band BLUE
2023-11-20 13:49:30,180 - [DEBUG] - Converting BLUE to reflectance
../_images/b48d4e7077275c063e27bbdfe319fac675b6079295cc95892b30f8b7874a2be2.png

Cloud data processed by USGS: Landsat-8#

See this registry (arn:aws:s3:::usgs-landsat). This registry needs authentication.

Note: USGS data are stored as requester pays in AWS. Don’t forget to state this when requesting data!

with tempenv.TemporaryEnvironment({
    "AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
    "AWS_SECRET_ACCESS_KEY": os.getenv("AMAZON_AWS_SECRET_ACCESS_KEY"),
    "AWS_ACCESS_KEY_ID": os.getenv("AMAZON_AWS_ACCESS_KEY_ID"),
}):
    with s3.temp_s3(requester_pays=True):
        path = r"s3://usgs-landsat/collection02/level-1/standard/oli-tirs/2021/016/042/LC08_L1TP_016042_20211027_20211104_02_T1"
        prod = Reader().open(path)
        prod.plot()
../_images/9bb0a02d2b54a868b9f6fc722a9943aac6e86015e32a76b47ffdbf7fdb2fdfb6.png