eolearn.core.core_tasks
A collection of most basic EOTasks
- class eolearn.core.core_tasks.CopyTask(features=Ellipsis)[source]
Bases:
EOTask
Makes a shallow copy of the given EOPatch.
It copies feature type dictionaries but not the data itself.
- Parameters:
features (FeaturesSpecification) – A collection of features or feature types that will be copied into a new EOPatch.
- class eolearn.core.core_tasks.DeepCopyTask(features=Ellipsis)[source]
Bases:
CopyTask
Makes a deep copy of the given EOPatch.
- Parameters:
features – A collection of features or feature types that will be copied into a new EOPatch.
args (Any) –
kwargs (Any) –
- Return type:
Self
- class eolearn.core.core_tasks.IOTask(path, filesystem=None, create=False, config=None)[source]
Bases:
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 | 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 | 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: FS
A filesystem property that unpickles an existing filesystem definition or creates a new one.
- class eolearn.core.core_tasks.SaveTask(path, filesystem=None, config=None, **kwargs)[source]
Bases:
IOTask
Saves the given EOPatch to a filesystem.
- Parameters:
path (str) – root path where all EOPatches are saved
filesystem (FS | None) – An existing filesystem object. If not given it will be initialized according to the EOPatch path.
features – A collection of features types specifying features of which type will be saved. By default, all features will be saved.
overwrite_permission – A level of permission for overwriting an existing EOPatch
compress_level – A level of data compression and can be specified with an integer from 0 (no compression) to 9 (highest compression).
config (SHConfig | None) – A configuration object with AWS credentials. By default, is set to None and in this case the default configuration will be taken.
kwargs (Any) –
- class eolearn.core.core_tasks.LoadTask(path, filesystem=None, config=None, **kwargs)[source]
Bases:
IOTask
Loads an EOPatch from a filesystem.
- Parameters:
path (str) – root directory where all EOPatches are saved
filesystem (FS | 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 – A collection of features to be loaded. By default, all features will be loaded.
lazy_loading – If True features will be lazy loaded. Default is False
config (SHConfig | None) – A configuration object with AWS credentials. By default, is set to None and in this case the default configuration will be taken.
kwargs (Any) –
- class eolearn.core.core_tasks.AddFeatureTask(feature)[source]
Bases:
EOTask
Adds a feature to the given EOPatch.
- Parameters:
feature (FeatureSpec) – Feature to be added
- class eolearn.core.core_tasks.RemoveFeatureTask(features)[source]
Bases:
EOTask
Removes one or multiple features from the given EOPatch.
- Parameters:
features (FeaturesSpecification) – A collection of features to be removed.
- class eolearn.core.core_tasks.RenameFeatureTask(features)[source]
Bases:
EOTask
Renames one or multiple features from the given EOPatch.
- Parameters:
features (FeaturesSpecification) – A collection of features to be renamed.
- class eolearn.core.core_tasks.DuplicateFeatureTask(features, deep_copy=False)[source]
Bases:
EOTask
Duplicates one or multiple features in an EOPatch.
- Parameters:
features (FeaturesSpecification) – 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.
- Raises:
ValueError – Raises an exception when trying to duplicate a feature with an already existing feature name.
- Return type:
- class eolearn.core.core_tasks.InitializeFeatureTask(features, shape, init_value=0, dtype=<class 'numpy.uint8'>)[source]
Bases:
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 (FeaturesSpecification) – A collection of features to initialize.
shape (tuple[int, ...] | FeatureSpec) – 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 (np.dtype | type) – Type of array values.
- Raises:
ValueError – Raises an exception when passing the wrong shape argument.
- class eolearn.core.core_tasks.MoveFeatureTask(features, deep_copy=False)[source]
Bases:
EOTask
Task to copy/deepcopy fields from one EOPatch to another.
- Parameters:
features (FeaturesSpecification) – 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.
- class eolearn.core.core_tasks.MapFeatureTask(input_features, output_features, map_function=None, **kwargs)[source]
Bases:
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 (FeaturesSpecification) – A collection of the input features to be mapped.
output_features (FeaturesSpecification) – A collection of the output features to which to assign the output data.
map_function (Callable | None) – A function or lambda to be applied to the input data.
kwargs (Any) – kwargs to be passed to the map function.
- Raises:
ValueError – Raises an exception when passing feature collections with different lengths.
- class eolearn.core.core_tasks.ZipFeatureTask(input_features, output_feature, zip_function=None, **kwargs)[source]
Bases:
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 (FeaturesSpecification) – A collection of the input features to be mapped.
output_feature (SingleFeatureSpec) – An output feature object to which to assign the data.
zip_function (Callable | None) – A function or lambda to be applied to the input data.
kwargs (Any) – kwargs to be passed to the zip function.
- class eolearn.core.core_tasks.MergeFeatureTask(input_features, output_feature, zip_function=None, **kwargs)[source]
Bases:
ZipFeatureTask
Merges multiple features together by concatenating their data along the specified axis.
- Parameters:
input_features – A collection of the input features to be mapped.
output_feature – An output feature object to which to assign the data.
zip_function – A function or lambda to be applied to the input data.
kwargs (Any) – kwargs to be passed to the zip function.
args (Any) –
- Return type:
Self
- class eolearn.core.core_tasks.ExtractBandsTask(input_feature, output_feature, bands)[source]
Bases:
MapFeatureTask
Moves a subset of bands from one feature to a new one.
- Parameters:
- class eolearn.core.core_tasks.ExplodeBandsTask(input_feature, output_mapping)[source]
Bases:
EOTask
Explode a subset of bands from one feature to multiple new features.
- Parameters:
input_feature (tuple[FeatureType, str]) – A source feature from which to take the subset of bands.
output_mapping (dict[tuple[FeatureType, str], int | Iterable[int]]) – A mapping of output features into the band indices used to explode the input feature.
- class eolearn.core.core_tasks.CreateEOPatchTask(*args, **kwargs)[source]
Bases:
EOTask
Creates an EOPatch.
Stores initialization parameters and the order to the instance attribute init_args.
- Parameters:
args (Any) –
kwargs (Any) –
- Return type:
Self
- execute(**kwargs)[source]
Returns a newly created EOPatch with the given kwargs.
- Parameters:
kwargs (Any) – Any valid kwargs accepted by
EOPatch.__init__
- Returns:
A new eopatch.
- Return type: