The utilities module is a collection of classes and functions used across the eolearn package, such as checking whether two objects are deeply equal, padding of an image, etc.

class eolearn.core.utilities.LogFileFilter(thread_name, *args, **kwargs)[source]

Bases: logging.Filter

Filters log messages passed to log file


thread_name (str or None) – Name of the thread by which to filter logs. By default it won’t filter by any name.


Shows everything from the thread that it was initialized in.

class eolearn.core.utilities.FeatureParser(features, new_names=False, rename_function=None, default_feature_type=None, allowed_feature_types=None)[source]

Bases: object

Takes a collection of features structured in a various ways and parses them into one way. It can parse features straight away or it can parse them only if they exist in a given EOPatch. If input format is not recognized or feature don’t exist in a given EOPatch it raises an error. The class is a generator therefore parsed features can be obtained by iterating over an instance of the class. An EOPatch is given as a parameter of the generator.

General guidelines:

  • Almost every EOTask requires an initialization parameter to define which features should be used by the task. The purpose of this class is to unite and generalize parsing of such parameters over the entire eo-learn package.

  • The idea for this class is that it should support more or less any logical way how to describe a collection of features.

  • Parameter is used as a contextual clue. In the supported formats it is used to describe the most obvious way how to specify certain parts of feature collection.

  • Supports formats defined with lists, tuples, sets and dictionaries.

Supported input formats:

  • Anything that exists in a given EOPatch is defined with

  • A feature type describing all features of that type. Example: FeatureType.DATA or FeatureType.BBOX

  • A single feature as a tuple. Example: (FeatureType.DATA, ‘BANDS’)

  • A single feature as a tuple. Example: (FeatureType.DATA, ‘BANDS’)

  • A single feature as a tuple with new name. Example (FeatureType.DATA, ‘BANDS’, ‘NEW_BANDS’)

  • A list of features (new names or not). Example:

        (FeatureType.DATA, 'BANDS'),
        (FeatureType.MASK, 'CLOUD_MASK', 'NEW_CLOUD_MASK')
  • A dictionary with feature types as keys and lists, sets, single feature or of feature names as values. Example:

        FeatureType.DATA: ['S2-BANDS', 'L8-BANDS'],
        FeatureType.MASK: {'IS_VALID', 'IS_DATA'},
        FeatureType.MASK_TIMELESS: 'LULC',
        FeatureType.TIMESTAMP: ...
  • A dictionary with feature types as keys and dictionaries, where feature names are mapped into new names, as values. Example:

        FeatureType.DATA: {
            'S2-BANDS': 'INTERPOLATED_S2_BANDS',
            'L8-BANDS': 'INTERPOLATED_L8_BANDS',
            'NDVI': ...

Note: Therese are most general input formats, but even more are supported or might be supported in the future.

Outputs of the generator:

  • tuples in form of (feature type, feature name) if parameter new_names=False

  • tuples in form of (feature type, feature name, new feature name) if parameter new_names=True

  • features (object) – A collection of features in one of the supported formats

  • new_names (bool) – If False the generator will only return tuples with in form of (feature type, feature name). If True it will return tuples (feature type, feature name, new feature name) which can be used for renaming features or creating new features out of old ones.

  • rename_function (function or None) – A function which transforms feature name into a new feature name, default is identity function. This parameter is only applied if new_names is set to True.

  • default_feature_type (FeatureType or None) –

    If feature type of any given feature is not set, this will be used. By default this is set to None. In this case if feature type of any feature is not given the following will happen:

    • if iterated over EOPatch - It will try to find a feature with matching name in EOPatch. If such features exist, it will return any of them. Otherwise it will raise an error.

    • if iterated without EOPatch - It will return instead of a feature type.

  • allowed_feature_types – Makes sure that only features of these feature types will be returned, otherwise an error is raised


set(FeatureType) or None



eolearn.core.utilities.get_common_timestamps(source, target)[source]

Return indices of timestamps from source that are also found in target.

  • source (list of datetime objects) – timestamps from source

  • target (list of datetime objects) – timestamps from target


indices of timestamps from source that are also found in target

Return type

list of ints

eolearn.core.utilities.deep_eq(fst_obj, snd_obj)[source]

Compares whether fst_obj and snd_obj are deeply equal.

In case when both fst_obj and snd_obj are of type np.ndarray or either np.memmap, they are compared using np.array_equal(fst_obj, snd_obj). Otherwise, when they are lists or tuples, they are compared for length and then deep_eq is applied component-wise. When they are dict, they are compared for key set equality, and then deep_eq is applied value-wise. For all other data types that are not list, tuple, dict, or np.ndarray, the method falls back to the __eq__ method.

Because np.ndarray is not a hashable object, it is impossible to form a set of numpy arrays, hence deep_eq works correctly.

  • fst_obj – First object compared

  • snd_obj – Second object compared


True if objects are deeply equal, False otherwise


Returns the negated mask.

If elements of input mask have 0 and non-zero values, then the returned matrix will have all elements 0 (1) where the original one has non-zero (0).


mask (np.array) – Input mask


array of same shape and dtype=int8 as input array

Return type


eolearn.core.utilities.constant_pad(X, multiple_of, up_down_rule='even', left_right_rule='even', pad_value=0)[source]

Function pads an image of shape (rows, columns, channels) with zeros.

It pads an image so that the shape becomes (rows + padded_rows, columns + padded_columns, channels), where padded_rows = (int(rows/multiple_of[0]) + 1) * multiple_of[0] - rows

Same rule is applied to columns.

  • multiple_of (tuple (rows, columns)) – make X’ rows and columns multiple of this tuple

  • up_down_rule (up_down_rule: string, (even, left, right)) – Add padded rows evenly to the top/bottom of the image, or up (top) / down (bottom) only

  • up_down_rule – Add padded columns evenly to the left/right of the image, or left / right only

  • pad_value (int) – Value to be assigned to padded rows and columns


Converts Blue, Green, Red to Red, Green, Blue.


A class decorator that signals that the class has been renamed when initialized

Example of use:

class OldNameForClass(NewNameForClass):
    ''' Deprecated version of `NewNameForClass`