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: IOTask

Base abstract class for raster IO tasks

Parameters:
  • feature (Tuple[Literal[<FeatureType.BBOX: 'bbox'>, <FeatureType.TIMESTAMPS: 'timestamps'>], None] | ~typing.Tuple[~eolearn.core.constants.FeatureType, str] | ~typing.Tuple[~typing.Literal[<FeatureType.BBOX: 'bbox'>, <FeatureType.TIMESTAMPS: 'timestamps'>], None, None] | ~typing.Tuple[~eolearn.core.constants.FeatureType, str, str]) – 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 (FS | None) – An existing filesystem object. If not given it will be initialized according to folder parameter.

  • image_dtype (dtype | type | None) – A data type of data in exported images or data imported from images.

  • no_data_value (float | None) – 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 (SHConfig | None) – 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: 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 (Tuple[Literal[<FeatureType.BBOX: 'bbox'>, <FeatureType.TIMESTAMPS: 'timestamps'>], None] | ~typing.Tuple[~eolearn.core.constants.FeatureType, str] | ~typing.Tuple[~typing.Literal[<FeatureType.BBOX: 'bbox'>, <FeatureType.TIMESTAMPS: 'timestamps'>], None, None] | ~typing.Tuple[~eolearn.core.constants.FeatureType, str, str]) – 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 (List[int] | Tuple[int, int] | Tuple[datetime, datetime] | Tuple[str, str] | None) – 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 (List[int] | Tuple[int, int] | None) – 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 (CRS | int | str | None) – 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 (str | None) – 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 (EOPatch) – An input EOPatch

  • filename (str | List[str] | None) – 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:

EOPatch

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

Bases: 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 (Tuple[Literal[<FeatureType.BBOX: 'bbox'>, <FeatureType.TIMESTAMPS: 'timestamps'>], None] | ~typing.Tuple[~eolearn.core.constants.FeatureType, str] | ~typing.Tuple[~typing.Literal[<FeatureType.BBOX: 'bbox'>, <FeatureType.TIMESTAMPS: 'timestamps'>], None, None] | ~typing.Tuple[~eolearn.core.constants.FeatureType, str, str]) – 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 (int | None) – 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 the FeatureType.TIMESTAMPS feature. If FeatureType.TIMESTAMPS does not exist this value 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 | None) – input EOPatch or None if a new EOPatch should be created

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

Return type:

EOPatch