ConditionalSetProperty#
- class deeptrack.features.ConditionalSetProperty(feature: Feature, condition: PropertyLike[str | bool] | None = None, **kwargs: dict[str, Any])#
Bases:
StructuralFeatureConditionally override the properties of a child feature.
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.
Note: It is advisable to use dt.Arguments instead when possible, since this feature overwrites properties, which may affect future calls to the feature.
Parameters#
- feature: Feature
The child feature whose properties will be modified conditionally.
- condition: PropertyLike[str] or PropertyLike[bool]
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: dict[str, Any]
The properties to be applied to the child feature if condition is True.
Attributes#
- __distributed__: bool
Indicates whether this feature distributes computation across inputs.
Methods#
- get(image: Any, condition: str | bool, **kwargs: dict[str, Any]) -> Any
Resolves the child feature, conditionally applying the specified properties.
Notes#
If condition is a string, the condition must be explicitly passed when resolving.
The properties applied do not persist unless explicitly stored.
Examples#
>>> import deeptrack as dt >>> import numpy as np
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 … )
Define an image: >>> image = np.ones((512, 512))
Resolve with condition met: >>> noisy_image = conditional_feature.update(image, condition=True) >>> print(noisy_image.std()) # Should be ~5 4.987707046984823
Resolve without condition: >>> clean_image = conditional_feature.update(image, condition=False) >>> print(clean_image.std()) # Should be 0 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.update(image, is_noisy=True) >>> print(noisy_image.std()) # Should be ~5 5.006310381139811
Resolve without condition: >>> clean_image = conditional_feature.update(image, is_noisy=False) >>> print(clean_image.std()) # Should be 0 0.0
Methods Summary
get(image, condition, **kwargs)Resolve the child, conditionally applying specified properties.
Methods Documentation
- get(image: Any, condition: str | bool, **kwargs: dict[str, Any]) Any#
Resolve the child, conditionally applying specified properties.
Parameters#
- image: Any
The input data or image 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:: dict of str to Any
Additional properties to apply to the child feature if the condition is True.
Returns#
- Any
The resolved child feature, with properties conditionally modified.