eolearn.core.eodata

The eodata module provides core objects for handling remotely sensing multi-temporal data (such as satellite imagery).

eolearn.core.eodata.LOGGER = <Logger eolearn.core.eodata (WARNING)>
eolearn.core.eodata.MAX_DATA_REPR_LEN = 100
class eolearn.core.eodata.EOPatch(*, data=NOTHING, mask=NOTHING, scalar=NOTHING, label=NOTHING, vector=NOTHING, data_timeless=NOTHING, mask_timeless=NOTHING, scalar_timeless=NOTHING, label_timeless=NOTHING, vector_timeless=NOTHING, meta_info=NOTHING, bbox=None, timestamp=NOTHING)[source]

Bases: object

The basic data object for multi-temporal remotely sensed data, such as satellite imagery and its derivatives.

The EOPatch contains multi-temporal remotely sensed data of a single patch of earth’s surface defined by the bounding box in specific coordinate reference system. The patch can be a rectangle, polygon, or pixel in space. The EOPatch object can also be used to store derived quantities, such as for example means, standard deviations, etc., of a patch. In this case the ‘space’ dimension is equivalent to a pixel.

Primary goal of EOPatch is to store remotely sensed data, usually of a shape n_time x height x width x n_features images, where height and width are the numbers of pixels in y and x, n_features is the number of features (i.e. bands/channels, cloud probability, etc.), and n_time is the number of time-slices (the number of times this patch was recorded by the satellite; can also be a single image)

In addition to that other auxiliary information is also needed and can be stored in additional attributes of the EOPatch (thus extending the functionality of numpy ndarray). These attributes are listed in the FeatureType enum.

Currently the EOPatch object doesn’t enforce that the length of timestamp be equal to n_times dimensions of numpy arrays in other attributes.

remove_feature(feature_type, feature_name)[source]

Removes the feature feature_name from dictionary of feature_type.

Parameters
  • feature_type (FeatureType) – Enum of the attribute we’re about to modify

  • feature_name (str) – Name of the feature of the attribute

add_feature(feature_type, feature_name, value)[source]

Sets EOPatch[feature_type][feature_name] to the given value.

Parameters
  • feature_type (FeatureType) – Type of feature

  • feature_name (str) – Name of the feature

  • value (object) – New value of the feature

rename_feature(feature_type, feature_name, new_feature_name)[source]

Renames the feature feature_name to new_feature_name from dictionary of feature_type.

Parameters
  • feature_type (FeatureType) – Enum of the attribute we’re about to rename

  • feature_name (str) – Name of the feature of the attribute

:param new_feature_name : New Name of the feature of the attribute :type feature_name: str

reset_feature_type(feature_type)[source]

Resets the values of the given feature type.

Parameters

feature_type (FeatureType) – Type of a feature

set_bbox(new_bbox)[source]
Parameters

new_bbox – new bbox

Type

new_bbox: BBox

set_timestamp(new_timestamp)[source]
Parameters

new_timestamp (list(str)) – list of dates

get_feature(feature_type, feature_name=None)[source]

Returns the array of corresponding feature.

Parameters
  • feature_type (FeatureType) – Enum of the attribute

  • feature_name (str) – Name of the feature

get_features()[source]

Returns a dictionary of all non-empty features of EOPatch.

The elements are either sets of feature names or a boolean True in case feature type has no dictionary of feature names.

Returns

A dictionary of features

Return type

dict(FeatureType: str or True)

get_spatial_dimension(feature_type, feature_name)[source]

Returns a tuple of spatial dimension (height, width) of a feature.

The feature has to be spatial or time dependent.

Parameters
  • feature_type (FeatureType) – Enum of the attribute

  • feature_name (str) – Name of the feature

get_feature_list()[source]

Returns a list of all non-empty features of EOPatch.

The elements are either only FeatureType or a pair of FeatureType and feature name.

Returns

list of features

Return type

list(FeatureType or (FeatureType, str))

static concatenate(eopatch1, eopatch2)[source]

Joins all data from two EOPatches and returns a new EOPatch.

If timestamps don’t match it will try to join all time-dependent features with the same name.

Note: In general the data won’t be deep copied. Deep copy will only happen when merging time-dependent features along time

Parameters
  • eopatch1 (EOPatch) – First EOPatch

  • eopatch2 (EOPatch) – First EOPatch

Returns

Joined EOPatch

Return type

EOPatch

static concatenate_data(data1, data2)[source]

A method that concatenates two numpy array along first axis.

Parameters
  • data1 (numpy.ndarray) – Numpy array of shape (times1, height, width, n_features)

  • data2 – Numpy array of shape (times2, height, width, n_features)

Returns

Numpy array of shape (times1 + times2, height, width, n_features)

Return type

numpy.ndarray

save(path, features=Ellipsis, file_format=<FileFormat.NPY: 'npy'>, overwrite_permission=<OverwritePermission.ADD_ONLY: 0>, compress_level=0)[source]

Saves EOPatch to disk.

Parameters
  • path (str) – Location on the disk

  • features – A collection of features types specifying features of which type will be saved. By default

all features will be saved. :type features: list(FeatureType) or list((FeatureType, str)) or … :param file_format: File format :type file_format: FileFormat or str :param overwrite_permission: A level of permission for overwriting an existing EOPatch :type overwrite_permission: OverwritePermission or int :param compress_level: A level of data compression and can be specified with an integer from 0 (no compression)

to 9 (highest compression).

static load(path, features=Ellipsis, lazy_loading=False, mmap=False)[source]

Loads EOPatch from disk.

Parameters
  • path (str) – Location on the disk

  • features (object) – A collection of features to be loaded. By default all features will be loaded.

  • lazy_loading (bool) – If True features will be lazy loaded.

  • mmap (bool) – If True, then memory-map the file. Works only on uncompressed npy files

Returns

Loaded EOPatch

Return type

EOPatch

time_series(ref_date=None, scale_time=1)[source]

Returns a numpy array with seconds passed between the reference date and the timestamp of each image.

An array is constructed as time_series[i] = (timestamp[i] - ref_date).total_seconds(). If reference date is None the first date in the EOPatch’s timestamp is taken. If EOPatch timestamp attribute is empty the method returns None.

Parameters
  • ref_date (datetime object) – reference date relative to which the time is measured

  • scale_time (int) – scale seconds by factor. If 60, time will be in minutes, if 3600 hours

consolidate_timestamps(timestamps)[source]

Removes all frames from the EOPatch with a date not found in the provided timestamps list.

Parameters

timestamps (list of datetime objects) – keep frames with date found in this list

Returns

set of removed frames’ dates

Return type

set of datetime objects

plot(feature, rgb=None, rgb_factor=3.5, vdims=None, timestamp_column='TIMESTAMP', geometry_column='geometry', pixel=False, mask=None)[source]

Plots eopatch features

Parameters
  • feature ((FeatureType, str)) – feature of eopatch

  • rgb ([int, int, int]) – indexes of bands to create rgb image from

  • rgb_factor (float) – factor for rgb bands multiplication

  • vdims (str) – value dimension for vector data

  • timestamp_column (str) – name of the timestamp column, valid for vector data

  • geometry_column (str) – name of the geometry column, valid for vector data

  • pixel (bool) – plot values through time for one pixel

  • mask (str) – where eopatch[FeatureType.MASK] == False, value = 0

Returns

plot

Return type

holovies/bokeh