download

Module for downloading data

exception sentinelhub.download.DownloadFailedException[source]

Bases: Exception

General exception which is raised whenever download fails

exception sentinelhub.download.AwsDownloadFailedException[source]

Bases: sentinelhub.download.DownloadFailedException

This exception is raised when download fails because of a missing file in AWS

exception sentinelhub.download.ImageDecodingError[source]

Bases: Exception

This exception is raised when downloaded image is not properly decoded

class sentinelhub.download.DownloadRequest(*, url=None, data_folder=None, filename=None, headers=None, request_type=<RequestType.GET: 'GET'>, post_values=None, save_response=True, return_data=True, data_type=<MimeType.RAW: 'raw'>, **properties)[source]

Bases: object

Class to manage HTTP requests

Container for all download requests issued by the DataRequests containing url to Sentinel Hub’s services or other sources to data, file names to saved data and other necessary flags needed when the data is downloaded and interpreted.

Parameters:
  • url (str) – url to Sentinel Hub’s services or other sources from where the data is downloaded. Default is None
  • data_folder (str) – folder name where the fetched data will be (or already is) saved. Default is None
  • filename (str) – filename of the file where the fetched data will be (or already is) saved. Default is None
  • headers (dict) – add HTTP headers to request. Default is None
  • request_type (constants.RequestType) – type of request, either GET or POST. Default is constants.RequestType.GET
  • post_values (dict) – form encoded data to send in POST request. Default is None
  • save_response (bool) – flag to turn on/off saving data downloaded by this request to disk. Default is True.
  • return_data (bool) – flag to return or not data downloaded by this request to disk. Default is True.
  • data_type (constants.MimeType) – expected file format of downloaded data. Default is constants.MimeType.RAW
set_filename(filename)[source]

Set filename attribute

Parameters:filename – Name of the file where .
Returns:str
set_data_folder(data_folder)[source]

Set data_folder attribute

Parameters:data_folder – folder name where the fetched data will be (or already is) saved.
Returns:str
get_file_path()[source]

Returns the full filename.

Returns:full filename (data folder + filename)
Return type:str
set_save_response(save_response)[source]

Set save_response attribute

Parameters:save_response – flag to turn on/off saving data downloaded by this request to disk. Default is True.
Returns:bool
set_return_data(return_data)[source]

Set return_data attribute

Parameters:return_data – flag to return or not data downloaded by this request to disk. Default is True.
Returns:bool
is_downloaded()[source]

Checks if data for this request has already been downloaded and is saved to disk.

Returns:returns True if data for this request has already been downloaded and is saved to disk.
Return type:bool
is_aws_s3()[source]

Checks if data has to be downloaded from AWS s3 bucket

Returns:True if url describes location at AWS s3 bucket and False otherwise
Return type:bool
sentinelhub.download.download_data(request_list, redownload=False, max_threads=None)[source]

Download all requested data or read data from disk, if already downloaded and available and redownload is not required.

Parameters:
  • request_list (list of DownloadRequests) – list of DownloadRequests
  • redownload (bool) – if True, download again the data, although it was already downloaded and is available on the disk. Default is False.
  • max_threads (int) – number of threads to use when downloading data; default is max_threads=None which by default uses the number of processors on the system
Returns:

list of Futures holding downloaded data, where each element in the list corresponds to an element in the download request list.

Return type:

list[concurrent.futures.Future]

sentinelhub.download.execute_download_request(request)[source]

Executes download request.

Parameters:request (DownloadRequest) – DownloadRequest to be executed
Returns:downloaded data or None
Return type:numpy array, other possible data type or None
Raises:DownloadFailedException
sentinelhub.download.decode_data(response_content, data_type, entire_response=None)[source]

Interprets downloaded data and returns it.

Parameters:
  • response_content (bytes) – downloaded data (i.e. json, png, tiff, xml, zip, … file)
  • data_type (constants.MimeType) – expected downloaded data type
  • entire_response (requests.Response or dict or None) – A response obtained from execution of download request
Returns:

downloaded data

Return type:

numpy array in case of image data type, or other possible data type

Raises:

ValueError

sentinelhub.download.decode_image(data, image_type)[source]

Decodes the image provided in various formats, i.e. png, 16-bit float tiff, 32-bit float tiff, jp2 and returns it as an numpy array

Parameters:
  • data (any of possible image types) – image in its original format
  • image_type (constants.MimeType) – expected image format
Returns:

image as numpy array

Return type:

numpy array

Raises:

ImageDecodingError

sentinelhub.download.get_json(url, post_values=None, headers=None)[source]

Download request as JSON data type

Parameters:
  • url (str) – url to Sentinel Hub’s services or other sources from where the data is downloaded
  • post_values (dict) – form encoded data to send in POST request. Default is None
  • headers (dict) – add HTTP headers to request. Default is None
Returns:

request response as JSON instance

Return type:

JSON instance or None

Raises:

RunTimeError

sentinelhub.download.get_xml(url)[source]

Download request as XML data type

Parameters:url (str) – url to Sentinel Hub’s services or other sources from where the data is downloaded
Returns:request response as XML instance
Return type:XML instance or None
Raises:RunTimeError