sentinelhub.base

Implementation of base interface classes of this package.

class sentinelhub.base.DataRequest(download_client_class, *, data_folder=None, config=None)[source]

Bases: object

A base abstract class for all implementations of data request interface.

Every data request type can write the fetched data to disk and then read it again (and hence avoid the need to download the same data again).

Parameters
  • download_client_class (Callable) – A class implementing a download client

  • data_folder (Optional[str]) – location of the directory where the fetched data will be saved.

  • config (Optional[SHConfig]) – A custom instance of config class to override parameters from the saved configuration.

abstract create_request()[source]

An abstract method for logic of creating download requests

Return type

None

get_download_list()[source]

Returns a list of download requests for requested data.

Returns

List of data to be downloaded

Return type

List[DownloadRequest]

get_filename_list()[source]

Returns a list of file names (or paths relative to data_folder) where the requested data will be saved or read from, if it has already been downloaded and saved.

Returns

A list of filenames

Return type

List[str]

get_url_list()[source]

Returns a list of urls for requested data.

Returns

List of URLs from where data will be downloaded.

Return type

List[Optional[str]]

is_valid_request()[source]

Checks if initialized class instance successfully prepared a list of items to download

Returns

True if request is valid and False otherwise

Return type

bool

get_data(*, save_data=False, redownload=False, data_filter=None, max_threads=None, decode_data=True, raise_download_errors=True, show_progress=False)[source]

Get requested data either by downloading it or by reading it from the disk (if it was previously downloaded and saved).

Parameters
  • save_data (bool) – flag to turn on/off saving of data to disk. Default is False.

  • redownload (bool) – if True, download again the requested data even though it’s already saved to disk. Default is False, do not download if data is already available on disk.

  • data_filter (Optional[List[int]]) – Used to specify which items will be returned by the method and in which order. E.g. with data_filter=[0, 2, -1] the method will return only 1st, 3rd and last item. Default filter is None.

  • max_threads (Optional[int]) – Maximum number of threads to be used for download in parallel. The default is max_threads=None which will use the number of processors on the system multiplied by 5.

  • decode_data (bool) – If True it will return data in a decoded format, e.g. images in form of numpy arrays of values, JSON data in form of Python dictionaries, etc. Otherwise, it will return DownloadResponse objects which contain both encoded data in a binary format and metadata about response, e.g. response headers, status code, elapsed download time, etc.

  • raise_download_errors (bool) – If True any error in download process should be raised as DownloadFailedException. If False failed downloads will only raise warnings and the method will return list with None values in places where the results of failed download requests should be.

  • show_progress (bool) – Whether a progress bar should be displayed while downloading.

Returns

requested images as numpy arrays, where each array corresponds to a single acquisition and has shape [height, width, channels].

Return type

List[Any]

save_data(*, data_filter=None, redownload=False, max_threads=None, raise_download_errors=False, show_progress=False)[source]

Saves data to disk. If redownload=True then the data is redownloaded using max_threads workers.

Parameters
  • data_filter (Optional[List[int]]) – Used to specify which items will be returned by the method and in which order. E.g. with data_filter=[0, 2, -1] the method will return only 1st, 3rd and last item. Default filter is None.

  • redownload (bool) – data is redownloaded if redownload=True. Default is False

  • max_threads (Optional[int]) – Maximum number of threads to be used for download in parallel. The default is max_threads=None which will use the number of processors on the system multiplied by 5.

  • raise_download_errors (bool) – If True any error in download process should be raised as DownloadFailedException. If False failed downloads will only raise warnings.

  • show_progress (bool) – Whether a progress bar should be displayed while downloading.

Return type

None

class sentinelhub.base.FeatureIterator(client, url, params=None)[source]

Bases: Generic[_T]

An implementation of a base feature iteration class

Main functionalities:

  • The iterator will load only as many features as needed at any moment

  • It will keep downloaded features in memory so that iterating over it again will not have to download the same features again.

Parameters
  • client – An instance of a download client object

  • url – A URL where requests will be made

  • params – Parameters to be sent with each request