LabelSpace#
- class ansys.dpf.core.label_space.LabelSpace(label_space: dict[str, int] | LabelSpace | None = None, obj: object | None = None, server: ansys.dpf.core.server.AnyServerType | None = None)#
A class representing a label space, which allows storage and management of key-value pairs (labels).
Overview#
Fill the label space with the provided dictionary of labels. |
Return a string representation of the LabelSpace instance with keys ordered. |
|
Iterate over the labels in the label space, yielding (key, value) pairs. |
|
Return a dictionary representation of the LabelSpace instance with keys ordered. |
|
Destructor for cleaning up the label space resources. |
Import detail#
from ansys.dpf.core.label_space import LabelSpace
Method detail#
- LabelSpace.fill(label_space: dict[str, int]) None#
Fill the label space with the provided dictionary of labels.
- Parameters:
label_space (dict) – A dictionary where keys are labels (str) and values are indices (int) to be added to the label space.
Examples
>>> label_space = LabelSpace() >>> label_space.fill({"time": 1, "node": 42}) >>> print(label_space) {'node': 42, 'time': 1}
- LabelSpace.__str__() str#
Return a string representation of the LabelSpace instance with keys ordered.
- Returns:
A string representation of the label space, formatted as a dictionary with sorted keys.
- Return type:
str
Examples
>>> label_space = LabelSpace(label_space={"time": 1, "node": 42}) >>> print(label_space) {'node': 42, 'time': 1}
- LabelSpace.__iter__() collections.abc.Generator[tuple[str, int], None, None]#
Iterate over the labels in the label space, yielding (key, value) pairs.
- Yields:
tuple – A tuple of (key, value) for each label in the label space.
Examples
>>> label_space = LabelSpace(label_space={"time": 1, "node": 42}) >>> for key, value in sorted(label_space): ... print(key, value) node 42 time 1
- LabelSpace.__dict__() dict[str, int]#
Return a dictionary representation of the LabelSpace instance with keys ordered.
- Returns:
A dictionary where keys are label names (str) and values are label indices (int).
- Return type:
dict
Examples
>>> label_space = LabelSpace(label_space={"time": 1, "node": 42}) >>> d = label_space.__dict__() >>> print(d) {'node': 42, 'time': 1}
- LabelSpace.__del__() None#
Destructor for cleaning up the label space resources.
- Return type:
None