Release of sentinelhub Python Package 2.0

Matej Aleksandrov
Sentinel Hub Blog
Published in
4 min readApr 27, 2018

Good news, we have recently released version 2.0 of Sentinel Hub’s main open-source Python package for Earth observation research.

In case you haven’t yet heard about sentinelhub Python package - it contains a collection of tools for downloading, managing and transforming satellite data. It primarily supports Sentinel Hub Services, however it also provides data from other sources and has a wide range of useful utilities. The code is available at GitHub repository.

Since the previous blog post about sentinelhub a lot has happened. We have been constantly improving, bug fixing and expanding the package according to users’ wishes and internal demands. Here are the main changes of sentinelhub package in the last 3 months:

More Data Sources

In order to fully support Sentinel Hub Services the package was upgraded to work with more satellite sources. Besides Sentinel-2 L1C the package now also provides an easy access to Sentinel-2 L2A, Sentinel 1, Landsat 8, MODIS and Mapzen DEM data. This enables you to analyze and combine data not only from different locations and times but also from different satellite sources. Detailed examples are a part of documentation.

Images of Eyjafjallajökull volcano in August 2017 obtained by the package using Sentinel-2 L1C, Sentinel-2 L2A, Landsat 8, Sentinel-1 IW, MODIS and Mapzen DEM data sources.

Custom URL Parameters

Besides service-specific request parameters Sentinel Hub Services support various custom parameters documented at Sentinel Hub website. Most of these custom parameters are now also supported through the Python package as well. Following the examples it is possible to specify atmospheric correction, interpolation types, obtain transparency layer, etc. It is even possible to use a custom JavaScript code as a parameter of data request class in the Python package.

Images obtained with the package by evaluating 3 different custom scripts over an image of fields in Brasil. The left one shows Braaten-Cohen-Young cloud detection, the middle one shows results of NDVI script and the right one shows moisture index.

Easier Package Configuration

The package installation contains a config.json file with various configurable parameters. From now on you don’t have to manually seek and edit this file but instead can examine and edit it in command line:

$ sentinelhub.config --show
{
"instance_id": "<here goes your Sentinel Hub instance id>",
"aws_access_key_id": "<here goes your AWS access id>",
"aws_secret_access_key": "<here goes your AWS access key>",
"ogc_base_url": "https://services.sentinel-hub.com/ogc/",
"gpd_base_url": "http://service.geopedia.world/",
"aws_base_url": "http://sentinel-s2-l1c.s3.amazonaws.com/",
"aws_s3_l2a_bucket": "sentinel-s2-l2a",
"opensearch_url": "http://opensearch.sentinel-hub.com/resto/api/collections/Sentinel2/",
"max_wfs_records_per_query": 100,
"max_opensearch_records_per_query": 500,
"default_start_date": "1985-01-01",
"max_download_attempts": 4,
"download_sleep_time": 5,
"download_timeout_seconds": 120
}

Instead of writing your Sentinel Hub instance id in the code you can simply set it in the configuration file:

$ sentinelhub.config --instance_id <your instance id>

More in the documentation.

Download Sentinel-2 L2A Products in .SAFE Format From AWS

Since the initial release the package enabled downloading Sentinel-2 L1C data from AWS into .SAFE format defined by ESA. As this turned out to be a popular feature in the community the package now also supports download of Sentinel-2 L2A data into .SAFE format. The same as before this can be simply done in command line

$ sentinelhub.aws --product S2A_MSIL2A_20180402T151801_N0207_R068_T33XWJ_20180402T202222

or within Python code. Check examples for more.

However, because L2A data is only available at s3 Requester Pays Bucket you first have to set your AWS credentials in package’s config.json file:

$ sentinelhub.config --aws_access_key_id <your access id> --aws_secret_access_key <your access key>

Soon even access to L1C data at AWS will become limited to Requester Pays Bucket therefore the next update of sentinelhub will already allow you to choose between http and s3 download source.

A simple schema of Sentinel-2 L2A folder structure of .SAFE format.

Utilities For Large Areas

Many times the final phase of a research project is upscaling the processing over a large geographical area. In order to support this process sentinelhub now works with shapely Python package for geometrical manipulations. The new version of sentinelhub also contains tools for dividing polygons into smaller bounding boxes for which data can be obtained separately using WMS/WCS requests. These are described in examples and more such functionalities are planned to be added in the future.

The package supports multiple methods for dividing polygons into smaller bounding boxes. These are two ways how to divide polygons of Hawaiian Islands.

Reversed Coordinate Order

Beware, there is also one code-breaking change in sentinelhub Python package version 2.0. In previous versions you had to specify bounding box coordinates in order latitude-longitude while working in WGS84. That was in accordance with OGC standard 1.3.0 for WMS requests. However after a lot of consideration the order in new version was reversed into longitude-latitude. It is now in accordance with commonly used projection library PROJ which will remain the standard for coordinate order or sentinelhub package in the future. Hopefully the order will now be compatible with the majority of geographical data standards.

The order of coordinates remains the same in any other coordinate reference system supported by the package.

A nice blog post describing general lon-lat, lat-lon confusion:

Thanks For Support

Many thanks to users who contributed to the package or provided their feedback. Many improvements were done because of your effort.

Our team will continue to expand Sentinel Hub open-source Python codebase and keep you posted. If you have any questions or feedback in the meantime, feel free to contact us.

--

--