eolearn.features.feature_manipulation

Module for basic feature manipulations, i.e. removing a feature from EOPatch, or removing a slice (time-frame) from the time-dependent features.

class eolearn.features.feature_manipulation.SimpleFilterTask(feature, filter_func, filter_features=Ellipsis)[source]

Bases: eolearn.core.eotask.EOTask

Transforms an eopatch of shape [n, w, h, d] into [m, w, h, d] for m <= n. It removes all slices which don’t conform to the filter_func.

A filter_func is a callable which takes a numpy array and returns a bool.

Parameters
execute(eopatch)[source]
Parameters

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

Returns

A new EOPatch with filtered features.

Return type

eolearn.core.eodata.EOPatch

class eolearn.features.feature_manipulation.FilterTimeSeriesTask(start_date, end_date, filter_features=Ellipsis)[source]

Bases: eolearn.features.feature_manipulation.SimpleFilterTask

Removes all frames in the time-series with dates outside the user specified time interval.

Parameters
  • start_date (datetime.datetime) – Start date. All frames within the time-series taken after this date will be kept.

  • end_date (datetime.datetime) – End date. All frames within the time-series taken before this date will be kept.

  • filter_features (dict(FeatureType: set(str))) – A collection of features which will be filtered

class eolearn.features.feature_manipulation.ValueFilloutTask(feature, operations='fb', value=nan, axis=0)[source]

Bases: eolearn.core.eotask.EOTask

Overwrites occurrences of a desired value with their neighbor values in either forward, backward direction or both, along an axis.

Possible fillout operations are ‘f’ (forward), ‘b’ (backward) or both, ‘fb’ or ‘bf’:

‘f’: nan, nan, nan, 8, 5, nan, 1, 0, nan, nan -> nan, nan, nan, 8, 5, 5, 1, 0, 0, 0

‘b’: nan, nan, nan, 8, 5, nan, 1, 0, nan, nan -> 8, 8, 8, 8, 5, 1, 1, 0, nan, nan

‘fb’: nan, nan, nan, 8, 5, nan, 1, 0, nan, nan -> 8, 8, 8, 8, 5, 5, 1, 0, 0, 0

‘bf’: nan, nan, nan, 8, 5, nan, 1, 0, nan, nan -> 8, 8, 8, 8, 5, 1, 1, 0, 0, 0

Parameters
  • feature (an object supported by the FeatureParser) – A feature that must be value-filled.

  • operations (str) – Fill directions, which should be one of [‘f’, ‘b’, ‘fb’, ‘bf’].

  • value (any numpy dtype) – Which value to fill by its neighbors.

  • axis (int) – An axis along which to fill values.

static fill(data, value=nan, operation='f')[source]

Fills occurrences of a desired value in a 2d array with their neighbors in either forward or backward direction.

Parameters
  • data (numpy.ndarray) – A 2d numpy array.

  • value (any numpy dtype) – Which value to fill by its neighbors.

  • operation (str) – Fill directions, which should be either ‘f’ or ‘b’.

Returns

Value-filled numpy array.

Return type

numpy.ndarray

execute(eopatch)[source]
Parameters

eopatch (EOPatch) – Source EOPatch from which to read the feature data.

Returns

An eopatch with the value-filled feature.

Return type

EOPatch

class eolearn.features.feature_manipulation.LinearFunctionTask(input_features, output_features=None, slope=1, intercept=0, dtype=None)[source]

Bases: eolearn.core.core_tasks.MapFeatureTask

Applies a linear function to the values of input features.

Each value in the feature is modified as x -> x * slope + intercept. The dtype of the result can be customized.

Parameters
  • input_features – Feature or features on which the function is used.

  • output_features – Feature or features for saving the result. If not provided the input_features are overwritten.

  • slope (float) – Slope of the function i.e. the multiplication factor.

  • intercept (float) – Intercept of the function i.e. the value added.

  • dtype (Optional[Union[str, type, numpy.dtype]]) – Numpy dtype of the output feature. If not provided the dtype is determined by Numpy, so it is recommended to set manually.

map_method(feature, slope, intercept)[source]

A method where feature is multiplied by a slope

Parameters
  • feature (numpy.ndarray) –

  • slope (float) –

  • intercept (float) –

Return type

numpy.ndarray

class eolearn.features.feature_manipulation.SpatialResizeTask(*, resize_parameters, features=Ellipsis, resize_method=ResizeMethod.LINEAR, resize_library=ResizeLib.PIL)[source]

Bases: eolearn.core.eotask.EOTask

Resizes the specified spatial features of EOPatch.

Parameters
  • features (Any) – The specification of feature for which to perform resizing. Must be supported by the FeatureParser. Features can be renamed, see FeatureParser documentation.

  • new_size – New size of the data (height, width)

  • scale_factors – Factors (f_height, f_width) by which to resize the image

  • resize_method (eolearn.features.utils.ResizeMethod) – Interpolation method used for resizing.

  • resize_library (eolearn.features.utils.ResizeLib) – Which Python library to use for resizing. Default is PIL, as it supports all dtypes and features anti-aliasing. For cases where execution speed is crucial one can use CV2.

  • resize_parameters (Tuple[eolearn.features.utils.ResizeParam, Tuple[float, float]]) –

execute(eopatch)[source]

Override to specify action performed by task.

Parameters

eopatch (eolearn.core.eodata.EOPatch) –

Return type

eolearn.core.eodata.EOPatch