Property#
- class deeptrack.properties.Property(sampling_rule: Callable[[...], Any] | List[Any] | Dict[str, Any] | tuple | ndarray | slice | DeepTrackNode | Any, **kwargs: Property)#
Bases:
DeepTrackNode
Property of a feature in the DeepTrack2 framework.
A Property defines a rule for sampling values used to evaluate features. It supports various data types and structures, such as constants, functions, lists, iterators, dictionaries, tuples, NumPy arrays, slices, and DeepTrackNodes.
The behavior of a Property depends on the type of the sampling rule:
Constant values (including tuples and NumPy arrays): Always returns the same value.
Functions: Evaluates dynamically, potentially using other properties as arguments.
Lists or dictionaries: Evaluates and samples each member individually.
Iterators: Returns the next value in the sequence, repeating the final value indefinitely.
Slices: Samples the start, stop, and step values individually.
DeepTrackNodes (e.g., other properties or features): Uses the value computed by the node.
Dependencies between properties are tracked automatically, enabling efficient recomputation when dependencies change.
Parameters#
- sampling_ruleAny
The rule for sampling values. Can be a constant, function, list, dictionary, iterator, tuple, NumPy array, slice, or DeepTrackNode.
- **kwargsDict[‘Property’]
Additional dependencies passed as named arguments. These dependencies can be used as inputs to functions or other dynamic components of the sampling rule.
Methods#
- create_action(sampling_rule: Any, **dependencies: Dict[str, Property]) -> Callable[…, Any]
Creates an action that defines how the property is evaluated. The behavior of the action depends on the type of sampling_rule.
Examples#
Constant property:
>>> import deeptrack as dt
>>> const_prop = dt.Property(42) >>> const_prop() # Returns 42
Dynamic property using a function:
>>> const_prop = dt.Property(5) >>> dynamic_prop = dt.Property(lambda x: x * 2, x=const_prop) >>> dynamic_prop() # Returns 10
Property with a dictionary rule:
>>> dict_prop = dt.Property({"a": Property(1), "b": lambda: 2}) >>> dict_prop() # Returns {"a": 1, "b": 2}
Property with an iterable:
>>> gen = (i for i in range(3)) >>> gen_prop = dt.Property(gen) >>> gen_prop() # Returns the next value from the generator >>> gen_prop.update() >>> gen_prop() # Returns the next value
Methods Summary
create_action
(sampling_rule, **dependencies)Creates an action defining how the property is evaluated.
Methods Documentation
- create_action(sampling_rule: Callable[[...], Any] | List[Any] | Dict[str, Any] | tuple | ndarray | slice | DeepTrackNode | Any, **dependencies: Dict[str, Property]) Callable[[...], Any] #
Creates an action defining how the property is evaluated.
Parameters#
- sampling_ruleUnion[Callable[…, Any], List[Any], Dict[str, Any],
tuple, np.ndarray, slice, Generator, DeepTrackNode, Any]
The rule to sample values for the property.
- **dependenciesDict[str, Property]
Dependencies to be used in the sampling rule.
Returns#
- Callable[…, Any]
A callable that defines the evaluation behavior of the property.