aws

Module for obtaining data from Amazon Web Service

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

Bases: abc.ABC

Amazon Web Service (AWS) base class

Parameters:
  • parent_folder (str) – Folder where the fetched data will be saved.
  • bands (list(str) or None) – List of Sentinel-2 bands for request. If parameter is set to None all bands will be used.
  • metafiles (list(str) or None) – 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.
get_requests()[source]

Abstract class for joining together download requests

get_base_url(force_http=False)[source]

Creates base URL path

Parameters:force_http (str) – 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
Return type:constants.EsaSafeType
Raises:ValueError
get_baseline()[source]

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

Returns:baseline number
Return type:str
Raises:ValueError
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:(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).

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
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 (constants.MimeType or 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.AwsProduct(product_id, tile_list=None, **kwargs)[source]

Bases: sentinelhub.aws.AwsService

Service class for Sentinel-2 product on AWS

Parameters:
  • product_id (str) – ESA ID of the product
  • tile_list (list(str) or None) – list of tile names
  • parent_folder (str) – location of the directory where the fetched data will be saved.
  • bands (list(str) or None) – List of Sentinel-2 bands for request. If parameter is set to None all bands will be used.
  • metafiles (list(str) or None) – 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.
static parse_tile_list(tile_input)[source]

Parses class input and verifies band names.

Parameters:tile_input (str or list(str)) – class input parameter tile_list
Returns:parsed list of tiles
Return type:list(str) or 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:(list(download.DownloadRequest), list(str))
get_data_source()[source]

The method determines data source from product ID.

Returns:Data source of the product
Return type:DataSource
Raises:ValueError
get_date()[source]

Collects sensing date of the product.

Returns:Sensing date
Return type:str
get_url(filename, data_format=None)[source]

Creates url of file location on AWS.

Parameters:
  • filename (str) – name of file
  • data_format (constants.MimeType or 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 (str) – 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.AwsTile(tile_name, time, aws_index=None, data_source=<DataSource.SENTINEL2_L1C: (<_Source.SENTINEL2: 'Sentinel-2'>, <_ProcessingLevel.L1C: 'L1C'>)>, **kwargs)[source]

Bases: sentinelhub.aws.AwsService

Service class for Sentinel-2 product on AWS

Parameters:
  • tile (str) – Tile name (e.g. ‘T10UEV’)
  • time (str) – Tile sensing time in ISO8601 format
  • aws_index (int or None) – 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_source (constants.DataSource) – Source of requested AWS data. Supported sources are Sentinel-2 L1C and Sentinel-2 L2A, default is Sentinel-2 L1C data.
  • parent_folder (str) – folder where the fetched data will be saved.
  • bands (list(str) or None) – List of Sentinel-2 bands for request. If parameter is set to None all bands will be used.
  • metafiles (list(str) or None) – 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.
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
static parse_datetime(time)[source]

Parses and verifies tile sensing time.

Parameters:time (str) – tile sensing time
Returns:tile sensing time in ISO8601 format
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:(list(download.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 (str) – 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_gml_url(qi_type, band='B00')[source]
Parameters:
  • qi_type (str) – type of quality indicator
  • band (str) – band name
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 :return:

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:(str, str, int)