eolearn.core.core_tasks

A collection of most basic EOTasks

class eolearn.core.core_tasks.CopyTask(features=Ellipsis)[source]

Bases: eolearn.core.eotask.EOTask

Makes a shallow copy of the given EOPatch.

It copies feature type dictionaries but not the data itself.

Parameters

features (an object supported by the FeatureParser) – A collection of features or feature types that will be copied into a new EOPatch.

execute(eopatch)[source]

Implement execute function

class eolearn.core.core_tasks.DeepCopyTask(features=Ellipsis)[source]

Bases: eolearn.core.core_tasks.CopyTask

Makes a deep copy of the given EOPatch.

Parameters

features (an object supported by the FeatureParser) – A collection of features or feature types that will be copied into a new EOPatch.

execute(eopatch)[source]

Implement execute function

class eolearn.core.core_tasks.IOTask(path, filesystem=None, create=False)[source]

Bases: eolearn.core.eotask.EOTask

An abstract Input/Output task that can handle a path and a filesystem object

Parameters
  • path (str) – root path where all EOPatches are saved

  • filesystem (fs.base.FS or None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path. If you intend to run this task in multiprocessing mode you shouldn’t specify this parameter.

  • create (bool) – If the filesystem path doesn’t exist this flag indicates to either create it or raise an error

property filesystem

A filesystem property that is being lazy-loaded the first time it is needed

abstract execute(*eopatches, **kwargs)[source]

Implement execute function

class eolearn.core.core_tasks.SaveTask(path, filesystem=None, **kwargs)[source]

Bases: eolearn.core.core_tasks.IOTask

Saves the given EOPatch to a filesystem

Parameters
  • path (str) – root path where all EOPatches are saved

  • features (an object supported by the FeatureParser) – A collection of features types specifying features of which type will be saved. By default all features will be saved.

  • overwrite_permission (OverwritePermission or int) – A level of permission for overwriting an existing EOPatch

  • compress_level (int) – A level of data compression and can be specified with an integer from 0 (no compression) to 9 (highest compression).

  • filesystem (fs.base.FS or None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path. If you intend to run this task in multiprocessing mode you shouldn’t specify this parameter.

execute(eopatch, *, eopatch_folder='')[source]

Saves the EOPatch to disk: folder/eopatch_folder.

Parameters
  • eopatch (EOPatch) – EOPatch which will be saved

  • eopatch_folder (str) – name of EOPatch folder containing data

Returns

The same EOPatch

Return type

EOPatch

class eolearn.core.core_tasks.SaveToDisk(folder, *args, **kwargs)[source]

Bases: eolearn.core.core_tasks.SaveTask

A deprecated version of SaveTask

Parameters
  • path (str) – root path where all EOPatches are saved

  • features (an object supported by the FeatureParser) – A collection of features types specifying features of which type will be saved. By default all features will be saved.

  • overwrite_permission (OverwritePermission or int) – A level of permission for overwriting an existing EOPatch

  • compress_level (int) – A level of data compression and can be specified with an integer from 0 (no compression) to 9 (highest compression).

  • filesystem (fs.base.FS or None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path. If you intend to run this task in multiprocessing mode you shouldn’t specify this parameter.

class eolearn.core.core_tasks.LoadTask(path, filesystem=None, **kwargs)[source]

Bases: eolearn.core.core_tasks.IOTask

Loads an EOPatch from a filesystem

Parameters
  • folder (str) – root directory where all EOPatches are saved

  • features (an object supported by the FeatureParser) – A collection of features to be loaded. By default all features will be loaded.

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

  • filesystem (fs.base.FS or None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path. If you intend to run this task in multiprocessing mode you shouldn’t specify this parameter.

execute(*, eopatch_folder='')[source]

Loads the EOPatch from disk: folder/eopatch_folder.

Parameters

eopatch_folder (str) – name of EOPatch folder containing data

Returns

EOPatch loaded from disk

Return type

EOPatch

class eolearn.core.core_tasks.LoadFromDisk(folder, *args, **kwargs)[source]

Bases: eolearn.core.core_tasks.LoadTask

A deprecated version of LoadTask

Parameters
  • folder (str) – root directory where all EOPatches are saved

  • features (an object supported by the FeatureParser) – A collection of features to be loaded. By default all features will be loaded.

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

  • filesystem (fs.base.FS or None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path. If you intend to run this task in multiprocessing mode you shouldn’t specify this parameter.

class eolearn.core.core_tasks.AddFeature(feature)[source]

Bases: eolearn.core.eotask.EOTask

Adds a feature to the given EOPatch.

Parameters

feature ((FeatureType, feature_name) or FeatureType) – Feature to be added

execute(eopatch, data)[source]

Returns the EOPatch with added features.

Parameters
  • eopatch (EOPatch) – input EOPatch

  • data (object) – data to be added to the feature

Returns

input EOPatch with the specified feature

Return type

EOPatch

class eolearn.core.core_tasks.RemoveFeature(features)[source]

Bases: eolearn.core.eotask.EOTask

Removes one or multiple features from the given EOPatch.

Parameters

features (an object supported by the FeatureParser) – A collection of features to be removed.

execute(eopatch)[source]

Returns the EOPatch with removed features.

Parameters

eopatch (EOPatch) – input EOPatch

Returns

input EOPatch without the specified feature

Return type

EOPatch

class eolearn.core.core_tasks.RenameFeature(features)[source]

Bases: eolearn.core.eotask.EOTask

Renames one or multiple features from the given EOPatch.

Parameters

features (an object supported by the FeatureParser) – A collection of features to be renamed.

execute(eopatch)[source]

Returns the EOPatch with renamed features.

Parameters

eopatch (EOPatch) – input EOPatch

Returns

input EOPatch with the renamed features

Return type

EOPatch

class eolearn.core.core_tasks.DuplicateFeature(features, deep_copy=False)[source]

Bases: eolearn.core.eotask.EOTask

Duplicates one or multiple features in an EOPatch.

Parameters
  • features (an object supported by the FeatureParser) – A collection of features to be copied.

  • deep_copy (bool) – Make a deep copy of feature’s data if set to true, else just assign it.

execute(eopatch)[source]

Returns the EOPatch with copied features.

Parameters

eopatch (EOPatch) – Input EOPatch

Returns

Input EOPatch with the duplicated features.

Return type

EOPatch

Raises

ValueError – Raises an exception when trying to duplicate a feature with an already existing feature name.

class eolearn.core.core_tasks.InitializeFeature(features, shape, init_value=0, dtype=<class 'numpy.uint8'>)[source]

Bases: eolearn.core.eotask.EOTask

Initializes the values of a feature.

Example:

InitializeFeature((FeatureType.DATA, 'data1'), shape=(5, 10, 10, 3), init_value=3)

# Initialize data of the same shape as (FeatureType.DATA, 'data1')
InitializeFeature((FeatureType.MASK, 'mask1'), shape=(FeatureType.DATA, 'data1'), init_value=1)
Parameters
  • features (an object supported by the FeatureParser) – A collection of features to initialize.

  • shape (A tuple or an object supported by the FeatureParser) – A shape object (t, n, m, d) or a feature from which to read the shape.

  • init_value (int) – A value with which to initialize the array of the new feature.

  • dtype (NumPy dtype) – Type of array values.

Raises

ValueError – Raises an exception when passing the wrong shape argument.

execute(eopatch)[source]
Parameters

eopatch (EOPatch) – Input EOPatch.

Returns

Input EOPatch with the initialized additional features.

Return type

EOPatch

class eolearn.core.core_tasks.MoveFeature(features, deep_copy=False)[source]

Bases: eolearn.core.eotask.EOTask

Task to copy/deepcopy fields from one eopatch to another.

Parameters
  • features (an object supported by the FeatureParser) – A collection of features to be moved.

  • deep_copy (bool) – Make a deep copy of feature’s data if set to true, else just assign it.

execute(src_eopatch, dst_eopatch)[source]
Parameters
  • src_eopatch (EOPatch) – Source EOPatch from which to take features.

  • dst_eopatch (EOPatch) – Destination EOPatch to which to move/copy features.

Returns

dst_eopatch with the additional features from src_eopatch.

Return type

EOPatch

class eolearn.core.core_tasks.MapFeatureTask(input_features, output_features, map_function=None, **kwargs)[source]

Bases: eolearn.core.eotask.EOTask

Applies a function to each feature in input_features of a patch and stores the results in a set of output_features.

Example using inheritance:

class MultiplyFeatures(MapFeatureTask):
    def map_function(self, f):
        return f * 2

multiply = MultiplyFeatures({FeatureType.DATA: ['f1', 'f2', 'f3']},  # input features
                            {FeatureType.MASK: ['m1', 'm2', 'm3']})  # output features

result = multiply(patch)

Example using lambda:

multiply = MapFeatureTask({FeatureType.DATA: ['f1', 'f2', 'f3']},  # input features
                          {FeatureType.MASK: ['m1', 'm2', 'm3']},  # output features
                          lambda f: f*2)                           # a function to apply to each feature

result = multiply(patch)

Example using a np.max and it’s kwargs passed as arguments to the MapFeatureTask:

maximum = MapFeatureTask((FeatureType.DATA: 'f1'),  # input features
                         (FeatureType.MASK, 'm1'),  # output feature
                         np.max,                    # a function to apply to each feature
                         axis=0)                    # function's kwargs

result = multiply(patch)
Parameters
  • input_features (an object supported by the FeatureParser) – A collection of the input features to be mapped.

  • output_features (an object supported by the FeatureParser) – A collection of the output features to which to assign the output data.

  • map_function – A function or lambda to be applied to the input data.

  • kwargs – kwargs to be passed to the map function.

Raises

ValueError – Raises an exception when passing feature collections with different lengths.

execute(eopatch)[source]
Parameters

eopatch (EOPatch) – Source EOPatch from which to read the data of input features.

Returns

An eopatch with the additional mapped features.

Return type

EOPatch

map_method(feature)[source]

A function that will be applied to the input features.

class eolearn.core.core_tasks.ZipFeatureTask(input_features, output_feature, zip_function=None, **kwargs)[source]

Bases: eolearn.core.eotask.EOTask

Passes a set of input_features to a function, which returns a single features as a result and stores it in the eopatch.

Example using inheritance:

class CalculateFeatures(ZipFeatureTask):
    def map_function(self, *f):
        return f[0] / (f[1] + f[2])

calc = CalculateFeatures({FeatureType.DATA: ['f1', 'f2', 'f3']}, # input features
                         (FeatureType.MASK, 'm1'))               # output feature

result = calc(patch)

Example using lambda:

calc = ZipFeatureTask({FeatureType.DATA: ['f1', 'f2', 'f3']},  # input features
                      (FeatureType.MASK, 'm1'),                # output feature
                      lambda f0, f1, f2: f0 / (f1 + f2))       # a function to apply to each feature

result = multiply(patch)

Example using a np.maximum and it’s kwargs passed as arguments to the ZipFeatureTask:

maximum = ZipFeatureTask({FeatureType.DATA: ['f1', 'f2']},  # input features
                         (FeatureType.MASK, 'm1'),          # output feature
                         np.maximum,                        # a function to apply to each feature
                         dtype=np.float64)                  # function's kwargs

result = multiply(patch)
Parameters
  • input_features (an object supported by the FeatureParser) – A collection of the input features to be mapped.

  • output_feature (an object supported by the FeatureParser) – An output feature object to which to assign the the data.

  • zip_function – A function or lambda to be applied to the input data.

  • kwargs – kwargs to be passed to the zip function.

execute(eopatch)[source]
Parameters

eopatch (EOPatch) – Source EOPatch from which to read the data of input features.

Returns

An eopatch with the additional zipped features.

Return type

EOPatch

zip_method(*f)[source]

A function that will be applied to the input features if overridden.

Raises

NotImplementedError – When called and was neither overridden nor function argument was provided in

__init__.

class eolearn.core.core_tasks.MergeFeatureTask(input_features, output_feature, zip_function=None, **kwargs)[source]

Bases: eolearn.core.core_tasks.ZipFeatureTask

Merges multiple features together by concatenating their data along the last axis.

Parameters
  • input_features (an object supported by the FeatureParser) – A collection of the input features to be mapped.

  • output_feature (an object supported by the FeatureParser) – An output feature object to which to assign the the data.

  • zip_function – A function or lambda to be applied to the input data.

  • kwargs – kwargs to be passed to the zip function.

zip_method(*f)[source]

Concatenates the data of features along the last axis.

class eolearn.core.core_tasks.ExtractBandsTask(input_feature, output_feature, bands)[source]

Bases: eolearn.core.core_tasks.MapFeatureTask

Moves a subset of bands from one feature to a new one.

Parameters
  • input_feature (an object supported by the FeatureParser) – A source feature from which to take the subset of bands.

  • output_feature (an object supported by the FeatureParser) – An output feature to which to write the bands.

  • bands (list) – A list of bands to be moved.

map_method(feature)[source]

A function that will be applied to the input features.

class eolearn.core.core_tasks.CreateEOPatchTask[source]

Bases: eolearn.core.eotask.EOTask

Creates an EOPatch

Stores initialization parameters and the order to the instance attribute init_args.

execute(**kwargs)[source]

Returns a newly created EOPatch with the given kwargs.

Parameters

kwargs – Any valid kwargs accepted by EOPatch.__init__

Returns

A new eopatch.

Return type

EOPatch