Skip to main content

Create a STAC from local S2 data.

Project description

s2stac

Easily access many Sentinel-2 safe folders from a convenient xarray DataArray.

Purpose

The purpose of this library is to create on-the-fly STAC from a list Sentinel-2 products in the form of SAFE folders and provide a xarray DataArray to easily access the main Sentinel-2 bands and more!

Accessible information includes:

  • all bands from the IMG_DATA folder (B01, B02, ..., B11)
  • all viewing/sun zenith/azimuth angles.
  • all detector footprints (for each band)
  • ECMWF data (msl, tco3, ...)

How it works

s2stac uses the stackstac library internally to interogate a static STAC database created on the fly with pystac. The database can be persisted so the user does not need to build it everytime.

Installation

This library requires Python 3.10 or higher.

This library also requires the eccodes library (version 2.16.0) to be able to parse the GRIB ECMWF DataArray containing the meteorological data associated with each tile. You can install it on Ubuntu with the following command:

sudo apt-get install libeccodes-dev

On MacOs you will need to do:

brew install eccodes

Now you can simply install s2stac with:

pip install s2stac

On MacOs you will also need to install ecmfwlibs:

pip install ecmwflibs

Usage

It is very easy to load some SAFE folders into a DataArray. Here we import 5 SAFE folders of imagery taken over the south of Finland.

from pathlib import Path
from s2stac import stacify

safe_folders = list(Path("/path/to/your/safe/folders").glob("*.SAFE"))

stack = stacify(safe_folders)
stack

DataArray

To preview the result, you can use the preview function from the s2stac module:

from s2stac import preview

preview(stack)

Preview

This preview function only displays a small collage of bands B04, B03 and B02 (RGB).

Many other bands are available, here are a few more:

Preview

From there, you can use all the convenient methods offered by xarray to manipulate DataArrays.

stack.sel(band=["B02", "B08", "B11"]).loc[:,:,::4,::4].mean("time").plot.imshow(col="band")

Plot a few bands per columns

Extra

A few extra more options have been added to s2stac that are not considered to be part of the expected functionnalities.

One of them is the ability to retrieve DEM (digital elevation models) data from USGS (United States Geological Survey).

The SRTM asset can be downloaded by specifying in the stacify function the intent to download such imagery as well as username and password.

Here's a small demo of it in action, using imagery taken over Guadeloupe:

from s2stac import stacify,preview
from pathlib import Path
import matplotlib.pyplot as plt
    

safe_folders = list(
    Path("/path/to/safe/folders").glob("*.SAFE")
)[:2]

usgs_username = "<your USGS username>"
usgs_password = "<your USGS password>"

stack = stacify(
    safe_folders,
    include_aux_data=False,
    include_ecmwf=False,
    include_footprint=False,
    include_mtd_tl=False,
    include_qi_data=False,
    include_srtm=True,
    usgs_password=usgs_password,
    usgs_username=usgs_username,
    catalog_folder=Path("./out"),
)


fig,ax = plt.subplots(1, 2)

stack.sel(band="srtm").mean("time").plot.imshow(ax=ax[0])
(stack.sel(band=["B04", "B03", "B02"]).loc[:,:,::4,::4].mean("time") / 10_000).plot.imshow(ax=ax[1])
ax[0].set_aspect("equal")
ax[1].set_aspect("equal")

SRTM preview

License

MIT

Author

Pierre Louvart - plouvart@argans.eu

Credit

gjoseph92, the creator of https://stackstac.readthedocs.io/en/latest/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s2stac-0.1.3.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

s2stac-0.1.3-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file s2stac-0.1.3.tar.gz.

File metadata

  • Download URL: s2stac-0.1.3.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.8.10 Linux/5.15.0-75-generic

File hashes

Hashes for s2stac-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3809f6b51a7c329ebf5641d043a1245860f3ad8714fa8e66bb7a7ac7c7e57220
MD5 3483d1352e828968909eabf587f62941
BLAKE2b-256 620adb840546a2b465f6f11ab50ab28d2abd2f1c1e2c0950a4ba8f3159a6af1b

See more details on using hashes here.

File details

Details for the file s2stac-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: s2stac-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.8.10 Linux/5.15.0-75-generic

File hashes

Hashes for s2stac-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c6d7f530dc2a988658adc34aac4228dc70b67d9432d5d538cfb02bf9b4f0cbe9
MD5 b717922778449b8ef70beccac29d451d
BLAKE2b-256 a6cf8bc9bcb4aa4f075201b139370a9bade98b1ee845c0b541c4f74292086c26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page