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]

Override to specify action performed by task.

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]

Override to specify action performed by task.

class eolearn.core.core_tasks.IOTask(path, filesystem=None, create=False, config=None)[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.

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

  • config (SHConfig or None) – A configuration object with AWS credentials. By default, is set to None and in this case the default configuration will be taken.

property filesystem

A filesystem property that unpickles an existing filesystem definition or creates a new one.

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

Implement execute function

class eolearn.core.core_tasks.SaveTask(path, filesystem=None, config=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

  • filesystem (fs.base.FS or None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path.

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

  • config (SHConfig or None) – A configuration object with AWS credentials. By default, is set to None and in this case the default configuration will be taken.

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

Saves the EOPatch to disk: folder/eopatch_folder.

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

  • eopatch_folder (str or None) – Name of EOPatch folder containing data. If None is given it won’t save anything.

Returns

The same EOPatch

Return type

EOPatch

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

Bases: eolearn.core.core_tasks.IOTask

Loads an EOPatch from a filesystem.

Parameters
  • path (str) – root directory 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.

  • 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

  • config (SHConfig or None) – A configuration object with AWS credentials. By default, is set to None and in this case the default configuration will be taken.

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

Loads the EOPatch from disk: folder/eopatch_folder.

Parameters
  • eopatch – Optional input EOPatch. If given the loaded features are merged onto it, otherwise a new EOPatch is created.

  • eopatch_folder (str or None) – Name of EOPatch folder containing data. If None is given it will return an empty or modified EOPatch (depending on the task input).

Returns

EOPatch loaded from disk

Return type

EOPatch

class eolearn.core.core_tasks.AddFeatureTask(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.RemoveFeatureTask(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.RenameFeatureTask(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.DuplicateFeatureTask(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.InitializeFeatureTask(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.MoveFeatureTask(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_method(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 = maximum(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 given EOPatch.

Example using inheritance:

class CalculateFeatures(ZipFeatureTask):
    def zip_method(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 = calc(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 = maximum(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 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.

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 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, dtype=None)[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.ExplodeBandsTask(input_feature, output_mapping)[source]

Bases: eolearn.core.eotask.EOTask

Explode a subset of bands from one feature to multiple new features.

Parameters
execute(eopatch)[source]

Override to specify action performed by task.

class eolearn.core.core_tasks.CreateEOPatchTask(*args, **kwargs)[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

class eolearn.core.core_tasks.MergeEOPatchesTask(**merge_kwargs)[source]

Bases: eolearn.core.eotask.EOTask

Merge content from multiple EOPatches into a single EOPatch.

Check EOPatch.merge for more information about the merging process.

Parameters

merge_kwargs – Keyword arguments defined for EOPatch.merge method.

execute(*eopatches)[source]
Parameters

eopatches (EOPatch) – EOPatches to be merged

Returns

A new EOPatch with merged content

Return type

EOPatch