io_utils

Utility functions to read/write image data from/to file

sentinelhub.io_utils.read_data(filename, data_format=None)[source]

Read image data from file

This function reads input data from file. The format of the file can be specified in data_format. If not specified, the format is guessed from the extension of the filename.

Parameters:
  • filename (str) – filename to read data from
  • data_format (MimeType) – format of filename. Default is None
Returns:

data read from filename

Raises:

exception if filename does not exist

sentinelhub.io_utils.read_tiff_image(filename)[source]

Read data from TIFF file

Parameters:filename (str) – name of TIFF file to be read
Returns:data stored in TIFF file
sentinelhub.io_utils.read_jp2_image(filename)[source]

Read data from JPEG2000 file

Parameters:filename (str) – name of JPEG2000 file to be read
Returns:data stored in JPEG2000 file
sentinelhub.io_utils.read_image(filename)[source]

Read data from PNG or JPG file

Parameters:filename (str) – name of PNG or JPG file to be read
Returns:data stored in JPG file
sentinelhub.io_utils.read_text(filename)[source]

Read data from text file

Parameters:filename (str) – name of text file to be read
Returns:data stored in text file
sentinelhub.io_utils.read_csv(filename, delimiter=';')[source]

Read data from CSV file

Parameters:
  • filename (str) – name of CSV file to be read
  • delimiter (str) – type of CSV delimiter. Default is ;
Returns:

data stored in CSV file as list

sentinelhub.io_utils.read_json(filename)[source]

Read data from JSON file

Parameters:filename (str) – name of JSON file to be read
Returns:data stored in JSON file
sentinelhub.io_utils.read_xml(filename)[source]

Read data from XML or GML file

Parameters:filename (str) – name of XML or GML file to be read
Returns:data stored in XML file
sentinelhub.io_utils.read_numpy(filename)[source]

Read data from numpy file

Parameters:filename (str) – name of numpy file to be read
Returns:data stored in file as numpy array
sentinelhub.io_utils.write_data(filename, data, data_format=None, compress=False, add=False)[source]

Write image data to file

Function to write image data to specified file. If file format is not provided explicitly, it is guessed from the filename extension. If format is TIFF, geo information and compression can be optionally added.

Parameters:
  • filename (str) – name of file to write data to
  • data (numpy array) – image data to write to file
  • data_format (MimeType) – format of output file. Default is None
  • compress (bool) – whether to compress data or not. Default is False
  • add (bool) – whether to append to existing text file or not. Default is False
Raises:

exception if numpy format is not supported or file cannot be written

sentinelhub.io_utils.write_tiff_image(filename, image, compress=False)[source]

Write image data to TIFF file

Parameters:
  • filename (str) – name of file to write data to
  • image (numpy array) – image data to write to file
  • compress (bool) – whether to compress data. If True, lzma compression is used. Default is False
sentinelhub.io_utils.write_jp2_image(filename, image)[source]

Write image data to JPEG2000 file

Parameters:
  • filename (str) – name of JPEG2000 file to write data to
  • image (numpy array) – image data to write to file
Returns:

jp2k object

sentinelhub.io_utils.write_image(filename, image)[source]

Write image data to PNG, JPG file

Parameters:
  • filename (str) – name of PNG or JPG file to write data to
  • image (numpy array) – image data to write to file
sentinelhub.io_utils.write_text(filename, data, add=False)[source]

Write image data to text file

Parameters:
  • filename (str) – name of text file to write data to
  • data (numpy array) – image data to write to text file
  • add (bool) – whether to append to existing file or not. Default is False
sentinelhub.io_utils.write_csv(filename, data, delimiter=';')[source]

Write image data to CSV file

Parameters:
  • filename (str) – name of CSV file to write data to
  • data (numpy array) – image data to write to CSV file
  • delimiter (str) – delimiter used in CSV file. Default is ;
sentinelhub.io_utils.write_json(filename, data)[source]

Write data to JSON file

Parameters:
  • filename (str) – name of JSON file to write data to
  • data (list, tuple) – data to write to JSON file
sentinelhub.io_utils.write_xml(filename, element_tree)[source]

Write data to XML or GML file

Parameters:
  • filename (str) – name of XML or GML file to write data to
  • element_tree (xmlElementTree) – data as ElementTree object
sentinelhub.io_utils.write_numpy(filename, data)[source]

Write data as numpy file

Parameters:
  • filename (str) – name of numpy file to write data to
  • data (numpy array) – data to write to numpy file
sentinelhub.io_utils.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
sentinelhub.io_utils.get_jp2_bit_depth(stream)[source]

Reads bit encoding depth of jpeg2000 file in binary stream format

Parameters:stream (Binary I/O (e.g. io.BytesIO, io.BufferedReader, ..)) – binary stream format
Returns:bit depth
Return type:int
sentinelhub.io_utils.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 (numpy array) – image read by opencv library
  • bit_depth (int) – bit depth of jp2 image encoding
Returns:

corrected image

Return type:

numpy array