eolearn.io.raster_io

Module containing tasks used for reading and writing to disk

class eolearn.io.raster_io.BaseRasterIoTask(feature, folder, *, filesystem=None, image_dtype=None, no_data_value=None, create=False, config=None)[source]

Bases: eolearn.core.core_tasks.IOTask

Base abstract class for raster IO tasks

Parameters
  • feature – Feature which will be exported or imported

  • folder (str) – A path to a main folder containing all image, potentially in its subfolders. If filesystem parameter is defined, then folder should be a path relative to filesystem object. Otherwise, it should be an absolute path.

  • filesystem (Optional[fs.base.FS]) – An existing filesystem object. If not given it will be initialized according to folder parameter.

  • image_dtype (Optional[Union[numpy.dtype, type]]) – A data type of data in exported images or data imported from images.

  • no_data_value (Optional[float]) – When exporting this is the NoData value of pixels in exported images. When importing this value is assigned to the pixels with NoData.

  • create (bool) – If the filesystem path doesn’t exist this flag indicates to either create it or raise an error.

  • config (Optional[sentinelhub.config.SHConfig]) – A configuration object with AWS credentials. By default, is set to None and in this case the default configuration will be taken.

class eolearn.io.raster_io.ExportToTiffTask(feature, folder, *, date_indices=None, band_indices=None, crs=None, fail_on_missing=True, compress=None, **kwargs)[source]

Bases: eolearn.io.raster_io.BaseRasterIoTask

Task exports specified feature to GeoTIFF.

The task can export also features with sizes of both time and band dimension greater than 1. When exporting only multiple times or only multiple bands, the GeoTIFF channels are in the expected order. However, when exporting multiple times and bands, the order obeys the following pattern:

T(1)B(1), T(1)B(2), …, T(1)B(N), T(2)B(1), T(2)B(2), …, T(2)B(N), …, …, T(M)B(N)

where T and B are the time and band indices of the array, and M and N are the lengths of these indices, respectively.

Parameters
  • feature – A feature to be exported.

  • folder (str) – A path to a main folder containing all image, potentially in its subfolders. If filesystem parameter is defined, then folder should be a path relative to filesystem object. Otherwise, it should be an absolute path.

  • date_indices (Optional[Union[List[int], Tuple[int, int], Tuple[datetime.datetime, datetime.datetime], Tuple[str, str]]]) – Indices of those time frames from the give feature that will be exported to a tiff image. It can be either a list of indices or a tuple of 2 indices defining an interval of indices or a tuple of 2 datetime object also defining a time interval. By default, all time frames will be exported.

  • band_indices (Optional[Union[List[int], Tuple[int, int]]]) – Indices of those bands from the given feature that will be exported to a tiff image. It can be either a list of indices or a tuple of 2 indices defining an interval of indices. By default, all bands will be exported.

  • crs (Optional[Union[sentinelhub.constants.CRS, int, str]]) – A CRS in which to reproject the feature before writing it to GeoTIFF. By default, no reprojection will be done.

  • fail_on_missing (bool) – A flag to specify if the task should fail if a feature is missing or if it should just show a warning.

  • compress (Optional[str]) – A type of compression that rasterio should apply to an exported image.

  • kwargs (Any) – Keyword arguments to be propagated to BaseRasterIoTask.

execute(eopatch, *, filename='')[source]

Execute method

Parameters
  • eopatch (eolearn.core.eodata.EOPatch) – An input EOPatch

  • filename (Optional[Union[str, List[str]]]) – A filename with a path to a tiff file. The path has to be a relative to the filesystem object and path from folder initialization parameter. If the file extension of the image file is not provided, it will default to .tif. If a “*” wildcard or a datetime.strftime substring (e.g. “%Y%m%dT%H%M%S”) is provided in the path, an EOPatch feature will be split over multiple GeoTIFFs where each one will correspond to a single timestamp. Alternatively, a list of paths can be provided, one for each timestamp. Set this parameter to None to disable exporting.

Returns

Unchanged input EOPatch

Return type

eolearn.core.eodata.EOPatch

class eolearn.io.raster_io.ImportFromTiffTask(feature, folder, *, use_vsi=False, timestamp_size=None, **kwargs)[source]

Bases: eolearn.io.raster_io.BaseRasterIoTask

Task for importing data from a GeoTIFF file into an EOPatch

The task can take an existing EOPatch and read the part of GeoTIFF image, which intersects with its bounding box, into a new feature. But if no EOPatch is given it will create a new EOPatch, read entire GeoTIFF image into a feature and set a bounding box of the new EOPatch.

Note that if GeoTIFF file is not completely spatially aligned with location of given EOPatch it will try to fit it as good as possible. However, it will not do any spatial resampling or interpolation on GeoTIFF data.

Parameters
  • feature – EOPatch feature into which data will be imported

  • folder (str) – A directory containing image files or a path of an image file

  • use_vsi (bool) – A flag to define if reading should be done with GDAL/rasterio virtual system (VSI) functionality. The flag only has an effect when the task is used to read an image from a remote storage (i.e. AWS S3 bucket). For a performance improvement it is recommended to set this to True when reading a smaller chunk of a larger image, especially if it is a Cloud-optimized GeoTIFF (COG). In other cases the reading might be faster if the flag remains set to False.

  • timestamp_size (Optional[int]) – In case data will be imported into a time-dependant feature this parameter can be used to specify time dimension. If not specified, time dimension will be the same as size of FeatureType.TIMESTAMP feature. If FeatureType.TIMESTAMP does not exist it will be set to 1. When converting data into a feature channels of given tiff image should be in order T(1)B(1), T(1)B(2), …, T(1)B(N), T(2)B(1), T(2)B(2), …, T(2)B(N), …, …, T(M)B(N) where T and B are the time and band indices.

  • kwargs (Any) – Keyword arguments to be propagated to BaseRasterIoTask.

execute(eopatch=None, *, filename='')[source]

Execute method which adds a new feature to the EOPatch

Parameters
  • eopatch (EOPatch or None) – input EOPatch or None if a new EOPatch should be created

  • filename (str, list of str or None) – filename of tiff file or None if entire path has already been specified in folder parameter of task initialization.

Returns

New EOPatch with added raster layer

Return type

EOPatch