Skip to main content

Sentinel-2 satellite tiles images downloader from Copernicus

Project description

sentinelloader

Sentinel-2 satellite tiles images downloader from Copernicus.

With this utility you can specify the desired polygon, image resolution, band name and aproximate dates and it will do the best effort to find all tiles needed to satisfy your requirement. Then it will download minimal data by selecting just the needed .jp2 files inside Products, combine downloaded tiles, crop the combined tiles image to the polygon and cache the results, returning a GeoTIFF image with raster for the selected area.

All API calls are in ESP:4326 reference.

Background

Granules are packages containing data taken from Sentinel-2 satellite for a region on the globe in a specific time. They contain a lot of data for that area (13 bands in different resolutions and other derived bands and quality data). Level-2A products, for example, have ~1GB of data for a single tile (100km2 x 100km2).

With this utility you can select which bands/resolutions to download. For example, if you need only the TCI band (true color) tile at 60m resolution, you will can use the utility to download just ~3MB of data (instead of 1GB!). For max resolution(10m), each band will have ~120MB. Some caching will be applied to avoid re-downloading of data that is already present in disk.

Usage

Docker example

  • Create docker-compose.yml
version: '3.3'
services:
  sentinelloader:
    image: flaviostutz/sentinelloader
    environment:
      - COPERNICUS_USER=auser
      - COPERNICUS_PASSWORD=apass
    ports:
      - 8686:8888
  • Create an account in Copernicus and change info in docker-compose.yml accordingly

  • Run docker-compose up -d

  • Open your browser at http://localhost:8686/

  • Open Jupyter notebook "example.ipynb" and press "Run"

  • You should see something like this

Python example

pip install git+https://github.com/flaviostutz/sentinelloader
import logging
import os
from osgeo import gdal
import matplotlib.pyplot as plt
from sentinelloader import Sentinel2Loader
from shapely.geometry import Polygon

sl = SentinelLoader('/notebooks/data/output/sentinelcache', 
                    'mycopernicususername', 'mycopernicuspassword',
                    apiUrl='https://scihub.copernicus.eu/apihub/', showProgressbars=True, loglevel=logging.DEBUG)

area = Polygon([(-47.873796, -16.044801), (-47.933796, -16.044801),
        (-47.933796, -15.924801), (-47.873796, -15.924801)])

geoTiffs = sl.getRegionHistory(area, 'TCI', '60m', '2019-01-06', '2019-01-30', daysStep=5)
for geoTiff in geoTiffs:
    print('Desired image was prepared at')
    print(geoTiff)
    os.remove(geoTiff)
)

For a Jupyter example, click here

API

def getRegionHistory(self, geoPolygon, bandOrIndexName, resolution, dateFrom, dateTo, daysStep=5, ignoreMissing=True, minVisibleLand=0, visibleLandPolygon=None, keepVisibleWithCirrus=False, interpolateMissingDates=False):
        """Gets a series of GeoTIFF files for a region for a specific band and resolution in a date range. It will make the best effort to get images near the desired dates and filter out images that have poor land visibility due to cloudy days"""

minVisibleLand - a value from 0 to 1 indicating the percentage of land that must be visible on the image (according to cloud coverage at the time)

sl = SentinelLoader('/notebooks/data/output/sentinelcache', 'mycopernicususername', 'mycopernicuspassword', apiUrl='https://scihub.copernicus.eu/apihub/', showProgressbars=True, loglevel=logging.DEBUG)

desired_region = Polygon([(-47.873796, -16.044801), (-47.933796, -16.044801),(-47.933796, -15.924801), (-47.873796, -15.924801)])

geoTiffs = sl.getRegionHistory(desired_region, 'TCI', '60m', '2019-01-06', '2019-01-30', daysStep=5)

  • In this example, sentinelloader will connect to Coperrnicus with your account and try to get various images in the band "TCI" of the desired region at a resolution of 60m fom 2019-01-06 to 2019-01-30 (if still available in Copernicus Hub) each 5 days (it will try to get the closes image to the days selected, because not every day we have images for every places).

  • Supported band names

    • All bands that are part of Sentinel 2 products at Copernicus Hub (SCL, TCI, B01-08, B1A etc)
    • Sintetic indexes implemented by this tool: NDVI, NDWI, NDWI_MacFeeters or NDMI
    • If you implement a newer one, please send a PR with it!

Publishing package to pypi

python3 -m pip install --upgrade build

python3 -m build

python3 -m twine upload --repository sentinelloader dist/*

https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives

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

sentinelloader-1.1.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

sentinelloader-1.1.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file sentinelloader-1.1.1.tar.gz.

File metadata

  • Download URL: sentinelloader-1.1.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for sentinelloader-1.1.1.tar.gz
Algorithm Hash digest
SHA256 d9ba14f75cbbd981e181b31aa0d444c00d5031b1b8f5ccebd7db2cc4110d907e
MD5 941dd06c4f29b8277b57c7477d65e307
BLAKE2b-256 f25615d5df2617399aa42aeaa85449c984636555c7219b8c6ab3bc6681bad070

See more details on using hashes here.

File details

Details for the file sentinelloader-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: sentinelloader-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for sentinelloader-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 298a1a9c0d4d401321af017e0953ab5ebde197143bfc9a08ef0a6949c73dd0aa
MD5 65592ca1860a6d0930fc07a722902c31
BLAKE2b-256 9a767e73f0f141e59cca03095bdd169baab203ea92376ef1fd801d23dd1d9531

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