sentinelhub.decoding

Module for data decoding

sentinelhub.decoding.decode_data(response_content, data_type)[source]

Interprets downloaded data and returns it.

Parameters
  • response_content (bytes) – downloaded data (i.e. json, png, tiff, xml, zip, … file)

  • data_type (MimeType) – expected downloaded data type

Returns

downloaded data

Raises

ValueError

Return type

Any

sentinelhub.decoding.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 a numpy array

Parameters
  • data (bytes) – image in its original format

  • image_type (MimeType) – expected image format

Returns

image as numpy array

Raises

ImageDecodingError

Return type

ndarray

sentinelhub.decoding.decode_image_with_pillow(stream)[source]

Decodes an image using Pillow package and handles potential warnings.

Parameters

stream (Union[IOBase, str]) – A binary stream format or a filename.

Returns

A numpy array representing an image of shape (height, width) or (height, width, channels).

Return type

ndarray

sentinelhub.decoding.decode_jp2_image(stream)[source]

Tries to decode a JPEG2000 image using the Pillow package.

Parameters

stream (IOBase) – A binary stream format.

Returns

A numpy array representing an image of shape (height, width) or (height, width, channels).

Return type

ndarray

sentinelhub.decoding.decode_tar(data)[source]

A decoder to convert response bytes into a dictionary of {filename: value}

Parameters

data (Union[bytes, BytesIO]) – Data to decode

Returns

A dictionary of decoded files from a tar file

Return type

Dict[str, object]

sentinelhub.decoding.decode_sentinelhub_err_msg(response)[source]

Decodes error message from Sentinel Hub service

Parameters

response (Response) – Sentinel Hub service response

Returns

An error message

Return type

str

sentinelhub.decoding.get_jp2_bit_depth(stream)[source]

Reads a bit encoding depth of jpeg2000 file in binary stream format

Parameters

stream (IOBase) – binary stream format

Returns

bit depth

Return type

int

sentinelhub.decoding.fix_jp2_image(image, bit_depth)[source]

Because Pillow library incorrectly reads JPEG 2000 images with 15-bit encoding this function corrects the values in image.

Parameters
  • image (ndarray) – image read by opencv library

  • bit_depth (int) – A bit depth of jp2 image encoding

Returns

corrected image

Return type

ndarray

sentinelhub.decoding.get_data_format(filename)[source]

Util function to guess format from filename extension

Parameters

filename (str) – name of file

Returns

file extension

Return type

MimeType