ConditionalSetProperty#
- class deeptrack.features.ConditionalSetProperty(feature: Feature, condition: str | bool | Callable[[...], str | bool] | None = None, **kwargs: Any)#
Bases:
StructuralFeatureConditionally override the properties of a child feature.
Deprecated since version 2.0: This feature is deprecated and may be removed in a future release. It is recommended to use Arguments instead.
This feature modifies the properties of a child feature only when a specified condition is met. If the condition evaluates to True, the given properties are applied; otherwise, the child feature remains unchanged.
It is advisable to use Arguments instead when possible, since this feature overwrites properties, which may affect future calls to the feature.
If condition is a string, the condition must be explicitly passed when resolving.
The properties applied do not persist unless explicitly stored.
Parameters#
- feature: Feature
The child feature whose properties will be modified conditionally.
- condition: PropertyLike[str | bool] | None, optional
Either a boolean value (True, False) or the name of a boolean property in the feature’s property dictionary. If the condition evaluates to True, the specified properties are applied.
- **kwargs: Any
The properties to be applied to the child feature if condition is True.
Methods#
- get(inputs, condition, **kwargs) -> Any
Resolves the child feature, conditionally applying the specified properties.
Examples#
>>> import deeptrack as dt
Define an image:
>>> import numpy as np >>> >>> image = np.ones((512, 512))
Define a Gaussian noise feature:
>>> gaussian_noise = dt.Gaussian(sigma=0)
— Using a boolean condition — Apply sigma=5 only if condition=True:
>>> conditional_feature = dt.ConditionalSetProperty( ... gaussian_noise, sigma=5, ... )
Resolve with condition met:
>>> noisy_image = conditional_feature(image, condition=True) >>> round(noisy_image.std(), 1) 5.0
Resolve without condition:
>>> conditional_feature.update() # Essential to reset the property >>> clean_image = conditional_feature(image, condition=False) >>> round(clean_image.std(), 1) 0.0
— Using a string-based condition — Define condition as a string:
>>> conditional_feature = dt.ConditionalSetProperty( ... gaussian_noise, sigma=5, condition="is_noisy" ... )
Resolve with condition met:
>>> noisy_image = conditional_feature(image, is_noisy=True) >>> round(noisy_image.std(), 1) 5.0
Resolve without condition:
>>> conditional_feature.update() >>> clean_image = conditional_feature(image, is_noisy=False) >>> round(clean_image.std(), 1) 0.0
Methods Summary
get(inputs, condition, **kwargs)Resolve the child, conditionally applying specified properties.
Methods Documentation
- get(inputs: Any, condition: str | bool, **kwargs: Any) Any#
Resolve the child, conditionally applying specified properties.
Parameters#
- inputs: Any
The input data to process.
- condition: str or bool
A boolean value or the name of a boolean property in the feature’s property dictionary. If the condition evaluates to True, the specified properties are applied.
- **kwargs:: Any
Additional properties to apply to the child feature if the condition is True.
Returns#
- Any
The resolved child feature, with properties conditionally modified.