eolearn.io.raster_io

Module containing tasks used for reading and writing to disk

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

Bases: IOTask

Base abstract class for raster IO tasks

Parameters:
  • feature (Feature) – Feature which will be exported or imported

  • path (str) – Path pointing to an image file or to a directory of image files. If filesystem is not defined, absolute paths should be provided.

  • filesystem (FS | None) – A filesystem object. If not given it will be initialized according to folder parameter.

  • image_dtype (np.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.

  • folder (str | None) –

class eolearn.io.raster_io.ExportToTiffTask(feature, path=Ellipsis, *, date_indices=None, band_indices=None, crs=None, fail_on_missing=True, compress=None, filesystem=None, image_dtype=None, no_data_value=None, config=None, folder=None)[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 (Feature) – A feature to be exported.

  • path (str) – Path pointing to an image file or to a directory of image files to be exported. If filesystem is not defined, absolute paths should be provided.

  • date_indices (list[int] | tuple[int, int] | tuple[dt.datetime, dt.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.

  • filesystem (FS | None) – A filesystem object. If not given it will be initialized according to folder parameter.

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

  • no_data_value (float | None) – The NoData value of pixels in exported images.

  • 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.

  • folder (str | None) –

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, path=Ellipsis, *, use_vsi=None, timestamp_size=None, filesystem=None, image_dtype=None, no_data_value=None, config=None, folder=None)[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 (Feature) – EOPatch feature into which data will be imported

  • path (str) – Path pointing to an image file or to a directory of image files to be imported. If filesystem is not defined, absolute paths should be provided.

  • use_vsi (bool | None) – Deprecated.

  • 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 timestamps attribute. If timestamps do 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.

  • filesystem (FS | None) – A filesystem object. If not given it will be initialized according to folder parameter.

  • image_dtype (np.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.

  • 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.

  • folder (str | None) –

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