sentinelhub.aws.data

Module for defining how satellite data will be collected from AWS and where it will be saved.

class sentinelhub.aws.data.AwsData(parent_folder='', bands=None, metafiles=None, config=None)[source]

Bases: object

A base class for collecting satellite data from AWS.

Parameters:
  • parent_folder (str) – Folder where the fetched data will be saved.

  • bands (None | str | List[str]) – List of Sentinel-2 bands for request. If parameter is set to None all bands will be used.

  • metafiles (None | str | List[str]) – List of additional metafiles available on AWS (e.g. ['metadata', 'tileInfo', 'preview/B01', 'TCI']). If parameter is set to None the list will be set automatically.

  • config (SHConfig | None) – A custom instance of config class to override parameters from the saved configuration.

abstract get_requests()[source]

Abstract class for joining together download requests

Return type:

Tuple[List[DownloadRequest], List[str]]

get_base_url(force_http=False)[source]

Creates base URL path

Parameters:

force_http (bool) – True if HTTP base URL should be used and False otherwise

Returns:

base url string

Return type:

str

get_safe_type()[source]

Determines the type of ESA product.

In 2016 ESA changed structure and naming of data. Therefore, the class must distinguish between old product type and compact (new) product type.

Returns:

type of ESA product

Raises:

ValueError

Return type:

EsaSafeType

get_baseline()[source]

Determines the baseline number (i.e. version) of ESA .SAFE product

Returns:

baseline number

Raises:

ValueError

Return type:

str

static url_to_tile(url)[source]

Extracts tile name, date and AWS index from tile url on AWS.

Parameters:

url (str) – class input parameter ‘metafiles’

Returns:

Name of tile, date and AWS index which uniquely identifies tile on AWS

Return type:

Tuple[str, str, int]

sort_download_list()[source]

Method for sorting the list of download requests. Band images have priority before metadata files. If bands images or metadata files are specified with a list they will be sorted in the same order as in the list. Otherwise, they will be sorted alphabetically (band B8A will be between B08 and B09).

Return type:

None

structure_recursion(struct, folder)[source]

From nested dictionaries representing .SAFE structure it recursively extracts all the files that need to be downloaded and stores them into class attribute download_list.

Parameters:
  • struct (dict) – nested dictionaries representing a part of .SAFE structure

  • folder (str) – name of folder where this structure will be saved

Return type:

None

static add_file_extension(filename, data_format=None, remove_path=False)[source]

Joins filename and corresponding file extension if it has one.

Parameters:
  • filename (str) – Name of the file without extension

  • data_format (MimeType | None) – format of file, if None it will be set automatically

  • remove_path (bool) – True if the path in filename string should be removed

Returns:

Name of the file with extension

Return type:

str

has_reports()[source]

Products created with baseline 2.06 and greater (and some products with baseline 2.05) should have quality report files

Returns:

True if the product has report xml files and False otherwise

Return type:

bool

is_early_compact_l2a()[source]

Check if product is early version of compact L2A product

Returns:

True if product is early version of compact L2A product and False otherwise

Return type:

bool

class sentinelhub.aws.data.AwsProduct(product_id, tile_list=None, **kwargs)[source]

Bases: AwsData

Class for collecting Sentinel-2 products data from AWS.

Parameters:
  • product_id – ESA ID of the product

  • tile_list – list of tile names

  • parent_folder – location of the directory where the fetched data will be saved.

  • bands – List of Sentinel-2 bands for request. If parameter is set to None all bands will be used.

  • metafiles – List of additional metafiles available on AWS (e.g. ['metadata', 'tileInfo', 'preview/B01', 'TCI']). If parameter is set to None the list will be set automatically.

  • config – A custom instance of config class to override parameters from the saved configuration.

static parse_tile_list(tile_input)[source]

Parses class input and verifies band names.

Parameters:

tile_input (None | str | List[str]) – class input parameter tile_list

Returns:

parsed list of tiles

Return type:

List[str] | None

get_requests()[source]

Creates product structure and returns list of files for download.

Returns:

List of download requests and list of empty folders that need to be created

Return type:

Tuple[List[DownloadRequest], List[str]]

get_data_collection()[source]

The method determines data collection from product ID.

Returns:

Data collection of the product

Raises:

ValueError

Return type:

DataCollection

get_date()[source]

Collects sensing date of the product.

Returns:

Sensing date

Return type:

date

get_url(filename, data_format=None)[source]

Creates url of file location on AWS.

Parameters:
  • filename (str) – name of file

  • data_format (MimeType | None) – format of file, if None it will be set automatically

Returns:

url of file location

Return type:

str

get_product_url(force_http=False)[source]

Creates base url of product location on AWS.

Parameters:

force_http (bool) – True if HTTP base URL should be used and False otherwise

Returns:

url of product location

Return type:

str

get_tile_url(tile_info)[source]

Collects tile url from productInfo.json file.

Parameters:

tile_info (dict) – information about tile from productInfo.json

Returns:

url of tile location

Return type:

str

get_filepath(filename)[source]

Creates file path for the file.

Parameters:

filename (str) – name of the file

Returns:

filename with path on disk

Return type:

str

class sentinelhub.aws.data.AwsTile(tile_name, time, aws_index=None, data_collection=DataCollection.SENTINEL2_L1C, **kwargs)[source]

Bases: AwsData

Class for collecting Sentinel-2 tiles data from AWS.

Parameters:
  • tile – Tile name (e.g. ‘T10UEV’)

  • time – Tile sensing time in ISO8601 format

  • aws_index – There exist Sentinel-2 tiles with the same tile and time parameter. Therefore, each tile on AWS also has an index which is visible in their url path. If aws_index is set to None the class will try to find the index automatically. If there will be multiple choices it will choose the lowest index and inform the user.

  • data_collection – A collection of requested AWS data. Supported collections are Sentinel-2 L1C and Sentinel-2 L2A, default is Sentinel-2 L1C data.

  • parent_folder – folder where the fetched data will be saved.

  • bands – List of Sentinel-2 bands for request. If parameter is set to None all bands will be used.

  • metafiles – List of additional metafiles available on AWS (e.g. ['metadata', 'tileInfo', 'preview/B01', 'TCI']). If parameter is set to None the list will be set automatically.

  • config – A custom instance of config class to override parameters from the saved configuration.

static parse_tile_name(name)[source]

Parses and verifies tile name.

Parameters:

name (str) – class input parameter tile_name

Returns:

parsed tile name

Return type:

str

get_requests()[source]

Creates tile structure and returns list of files for download.

Returns:

List of download requests and list of empty folders that need to be created

Return type:

Tuple[List[DownloadRequest], List[str]]

get_aws_index()[source]

Returns tile index on AWS. If tile_index was not set during class initialization it will be determined according to existing tiles on AWS.

Returns:

Index of tile on AWS

Return type:

int

tile_is_valid()[source]

Checks if tile has tile info and valid timestamp

Returns:

True if tile is valid and False otherwise

Return type:

bool

get_tile_info()[source]

Collects basic info about tile from tileInfo.json.

Returns:

dictionary with tile information

Return type:

dict

get_url(filename)[source]

Creates url of file location on AWS.

Parameters:

filename (str) – name of file

Returns:

url of file location

Return type:

str

get_tile_url(force_http=False)[source]

Creates base url of tile location on AWS.

Parameters:

force_http (bool) – True if HTTP base URL should be used and False otherwise

Returns:

url of tile location

Return type:

str

get_qi_url(metafile)[source]

Returns url of tile metadata products

Parameters:

metafile (str) – Name of metadata product at AWS

Returns:

url location of metadata product at AWS

Return type:

str

get_band_qi_url(qi_type, band='B00', data_format=MimeType.GML)[source]
Parameters:
  • qi_type (str) – type of quality indicator

  • band (str) – band name

  • data_format (MimeType) –

Returns:

location of gml file on AWS

Return type:

str

get_preview_url(data_type='L1C')[source]

Returns url location of full resolution L1C preview

Parameters:

data_type (str) –

Return type:

str

get_filepath(filename)[source]

Creates file path for the file.

Parameters:

filename (str) – name of the file

Returns:

filename with path on disk

Return type:

str

get_product_id()[source]

Obtains ESA ID of product which contains the tile.

Returns:

ESA ID of the product

Return type:

str

static tile_id_to_tile(tile_id)[source]
Parameters:

tile_id (str) – original tile identification string provided by ESA (e.g. ‘S2A_OPER_MSI_L1C_TL_SGS__20160109T230542_A002870_T10UEV_N02.01’)

Returns:

tile name, sensing date and AWS index

Return type:

Tuple[str, str, int]