eolearn.core.core_tasks
A collection of most basic EOTasks
- class eolearn.core.core_tasks.CopyTask(features=Ellipsis, *, deep=False, copy_timestamps='auto')[source]
Bases:
EOTask
Makes a (shallow or deep) 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.
deep (bool) – Whether the copy should be a deep or shallow copy.
copy_timestamps (bool | Literal['auto']) –
- class eolearn.core.core_tasks.DeepCopyTask(features=Ellipsis, *, deep=False, copy_timestamps='auto')[source]
Bases:
CopyTask
[DEPRECATED] 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.
deep – Whether the copy should be a deep or shallow copy.
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, features=Ellipsis, overwrite_permission=OverwritePermission.ADD_ONLY, *, save_timestamps='auto', use_zarr=False, temporal_selection=None, compress_level=None)[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 path.
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.
features (FeaturesSpecification) – A collection of features types specifying features of which type will be saved. By default, all features will be saved.
overwrite_permission (OverwritePermission) – A level of permission for overwriting an existing EOPatch to 9 (highest compression).
use_zarr (bool) – Saves numpy-array based features into Zarr files. Requires ZARR extra dependencies.
temporal_selection (None | slice | list[int] | Literal['infer']) – Writes all of the data to the chosen temporal indices of preexisting arrays. Can be used for saving data in multiple steps for memory optimization. When set to “infer” it will match the timestamps of the EOPatch to the timestamps of the stored EOPatch to calculate indices.
save_timestamps (bool | Literal['auto']) –
compress_level (int | None) –
- Save_timestamps:
Save the timestamps of the EOPatch. With the “auto” setting timestamps are saved if features=… or if other temporal features are being saved.
- class eolearn.core.core_tasks.LoadTask(path, filesystem=None, config=None, features=Ellipsis, lazy_loading=False, *, load_timestamps='auto', temporal_selection=None)[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.
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.
features (FeaturesSpecification) – A collection of features to be loaded. By default, all features will be loaded.
lazy_loading (bool) – If True features will be lazy loaded.
temporal_selection (None | slice | list[int] | Callable[[list[dt.datetime]], list[bool]]) – Only loads data corresponding to the chosen indices. Can also be a callable that, given a list of timestamps, returns a list of booleans declaring which temporal slices to load.
load_timestamps (bool | Literal['auto']) –
- Load_timestamps:
Load the timestamps of the EOPatch. With the “auto” setting timestamps are loaded if features=… or if other temporal features are being loaded.
- execute(eopatch=None, *, eopatch_folder='', temporal_selection=Ellipsis)[source]
Loads the EOPatch from disk: folder/eopatch_folder.
- Parameters:
eopatch (EOPatch | None) – Optional input EOPatch. If given the loaded features are merged onto it, otherwise a new EOPatch is created.
eopatch_folder (str) – Name of EOPatch folder containing data.
temporal_selection (None | slice | list[int] | Callable[[list[datetime.datetime]], list[bool]] | ellipsis) – Overrides the temporal_selection parameter of task.
- Returns:
EOPatch loaded from disk
- Return type:
- class eolearn.core.core_tasks.AddFeatureTask(feature)[source]
Bases:
EOTask
Adds a feature to the given EOPatch.
- Parameters:
feature (Feature) – 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.
- 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, ...] | Feature) – 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.TemporalSubsetTask(timestamps=None)[source]
Bases:
EOTask
Extracts a temporal subset of the EOPatch.
- Parameters:
timestamps (None | list[dt.datetime] | list[int] | Callable[[list[dt.datetime]], Iterable[bool]]) – Input for the temporal_subset method of EOPatch. Can also be provided in execution arguments. Value in execution arguments takes precedence.
- 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 (Feature) – 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:
input_feature (FeaturesSpecification) – A source feature from which to take the subset of bands.
output_feature (FeaturesSpecification) – An output feature to which to write the bands.
bands (list[int]) – A list of bands to be moved.
- 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 (Feature) – A source feature from which to take the subset of bands.
output_mapping (dict[Feature, 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:
- class eolearn.core.core_tasks.MergeEOPatchesTask(**merge_kwargs)[source]
Bases:
EOTask
Merge content from multiple EOPatches into a single EOPatch.
Check
merge_eopatches
for more information.- Parameters:
merge_kwargs (Any) – Keyword arguments defined for merge_eopatches function.